| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
| 6 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
| 7 | 7 |
| 8 (function(){ | 8 (function(){ |
| 9 | 9 |
| 10 /** | 10 'use strict'; |
| 11 * A class that handles application activation. | |
| 12 * | |
| 13 * @param {remoting.AppLauncher} appLauncher | |
| 14 * @constructor | |
| 15 */ | |
| 16 function ActivationHandler(appLauncher) { | |
| 17 /** | |
| 18 * @type {remoting.AppLauncher} | |
| 19 * @private | |
| 20 */ | |
| 21 this.appLauncher_ = appLauncher; | |
| 22 | |
| 23 chrome.contextMenus.create({ | |
| 24 id: ActivationHandler.NEW_WINDOW_MENU_ID_, | |
| 25 contexts: ['launcher'], | |
| 26 title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW') | |
| 27 }); | |
| 28 | |
| 29 chrome.contextMenus.onClicked.addListener(this.onContextMenu_.bind(this)); | |
| 30 chrome.app.runtime.onLaunched.addListener(this.onLaunched_.bind(this)); | |
| 31 } | |
| 32 | |
| 33 /** @type {string} */ | |
| 34 ActivationHandler.NEW_WINDOW_MENU_ID_ = 'new-window'; | |
| 35 | |
| 36 /** | |
| 37 * @param {OnClickData} info | |
| 38 * @private | |
| 39 */ | |
| 40 ActivationHandler.prototype.onContextMenu_ = function(info) { | |
| 41 if (info.menuItemId == ActivationHandler.NEW_WINDOW_MENU_ID_) { | |
| 42 this.appLauncher_.launch(); | |
| 43 } | |
| 44 }; | |
| 45 | |
| 46 /** | |
| 47 * Called when the App is activated (e.g. from the Chrome App Launcher). It | |
| 48 * creates a new window if there are no existing ones. Otherwise, it will put | |
| 49 * focus on the last window created. | |
| 50 * | |
| 51 * @private | |
| 52 */ | |
| 53 ActivationHandler.prototype.onLaunched_ = function() { | |
| 54 var windows = chrome.app.window.getAll(); | |
| 55 if (windows.length >= 1) { | |
| 56 windows[windows.length - 1].focus(); | |
| 57 } else { | |
| 58 this.appLauncher_.launch(); | |
| 59 } | |
| 60 }; | |
| 61 | 11 |
| 62 /** | 12 /** |
| 63 * The background service is responsible for listening to incoming connection | 13 * The background service is responsible for listening to incoming connection |
| 64 * requests from Hangouts and the webapp. | 14 * requests from Hangouts and the webapp. |
| 65 * | 15 * |
| 66 * @param {remoting.AppLauncher} appLauncher | 16 * @param {remoting.AppLauncher} appLauncher |
| 67 */ | 17 */ |
| 68 function initializeBackgroundService(appLauncher) { | 18 function initializeBackgroundService(appLauncher) { |
| 69 function initializeIt2MeService() { | 19 function initializeIt2MeService() { |
| 70 /** @type {remoting.It2MeService} */ | 20 /** @type {remoting.It2MeService} */ |
| 71 remoting.it2meService = new remoting.It2MeService(appLauncher); | 21 remoting.it2meService = new remoting.It2MeService(appLauncher); |
| 72 remoting.it2meService.init(); | 22 remoting.it2meService.init(); |
| 73 } | 23 } |
| 74 | 24 |
| 75 chrome.runtime.onSuspend.addListener(function() { | 25 chrome.runtime.onSuspend.addListener(function() { |
| 76 base.debug.assert(remoting.it2meService != null); | 26 base.debug.assert(remoting.it2meService != null); |
| 77 remoting.it2meService.dispose(); | 27 remoting.it2meService.dispose(); |
| 78 remoting.it2meService = null; | 28 remoting.it2meService = null; |
| 79 }); | 29 }); |
| 80 | 30 |
| 81 remoting.settings = new remoting.Settings(); | 31 remoting.settings = new remoting.Settings(); |
| 82 | 32 |
| 83 chrome.runtime.onSuspendCanceled.addListener(initializeIt2MeService); | 33 chrome.runtime.onSuspendCanceled.addListener(initializeIt2MeService); |
| 84 initializeIt2MeService(); | 34 initializeIt2MeService(); |
| 85 } | 35 } |
| 86 | 36 |
| 87 function main() { | 37 function main() { |
| 88 if (base.isAppsV2()) { | 38 if (base.isAppsV2()) { |
| 89 new ActivationHandler(new remoting.V2AppLauncher()); | 39 new remoting.ActivationHandler(new base.RemoteMethods(), |
| 40 new remoting.V2AppLauncher()); |
| 90 } | 41 } |
| 91 } | 42 } |
| 92 | 43 |
| 93 remoting.enableHangoutsRemoteAssistance = function() { | 44 remoting.enableHangoutsRemoteAssistance = function() { |
| 94 /** @type {remoting.AppLauncher} */ | 45 /** @type {remoting.AppLauncher} */ |
| 95 var appLauncher = base.isAppsV2() ? new remoting.V1AppLauncher(): | 46 var appLauncher = base.isAppsV2() ? new remoting.V1AppLauncher(): |
| 96 new remoting.V2AppLauncher(); | 47 new remoting.V2AppLauncher(); |
| 97 initializeBackgroundService(appLauncher); | 48 initializeBackgroundService(appLauncher); |
| 98 }; | 49 }; |
| 99 | 50 |
| 100 window.addEventListener('load', main, false); | 51 window.addEventListener('load', main, false); |
| 101 | 52 |
| 102 }()); | 53 }()); |
| OLD | NEW |