Index: remoting/webapp/background/background.js |
diff --git a/remoting/webapp/background/background.js b/remoting/webapp/background/background.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..db2b5e209bef7adf9ec30ce6a23902e3feffd3fa |
--- /dev/null |
+++ b/remoting/webapp/background/background.js |
@@ -0,0 +1,72 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** @suppress {duplicate} */ |
+var remoting = remoting || {}; |
+ |
+(function(){ |
Jamie
2014/08/12 02:24:57
We don't use this construct elsewhere, and IIRC, i
kelvinp
2014/08/12 18:22:44
Before this CL, JSCompile is not run on background
Jamie
2014/08/12 20:42:53
Acknowledged.
|
+ |
+/** @return {boolean} */ |
+function isAppsV2() { |
+ var manifest = chrome.runtime.getManifest(); |
+ if (manifest && manifest.app && manifest.app.background) { |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+/** @param {remoting.AppLauncher} appLauncher */ |
+function initializeAppV2(appLauncher) { |
+ /** @type {string} */ |
+ var kNewWindowId = 'new-window'; |
+ |
+ /** @param {OnClickData} info */ |
+ function onContextMenu(info) { |
+ if (info.menuItemId == kNewWindowId) { |
+ appLauncher.launch(); |
+ } |
+ } |
+ |
+ function initializeContextMenu() { |
+ chrome.contextMenus.create({ |
+ id: kNewWindowId, |
+ contexts: ['launcher'], |
+ title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW') |
Jamie
2014/08/12 02:24:57
Please verify that moving this string to a new fil
kelvinp
2014/08/12 18:22:44
Hence the renaming of the file in remoting.gyp.
|
+ }); |
+ chrome.contextMenus.onClicked.addListener(onContextMenu); |
+ } |
+ |
+ initializeContextMenu(); |
+ chrome.app.runtime.onLaunched.addListener(appLauncher.launch); |
Jamie
2014/08/12 02:24:57
Does appLauncher.launch need a bind()?
kelvinp
2014/08/12 18:22:44
No, AppLauncher.launch does not refer to any local
Jamie
2014/08/12 20:42:52
The question is whether it's a static function or
|
+} |
+ |
+/** |
+ * The background service is responsible for listening to incoming connection |
+ * requests from the hangout page and the webapp. |
Jamie
2014/08/12 02:24:57
s/hangout/Hangouts/ (branding)
kelvinp
2014/08/12 18:22:44
Done.
|
+ * @param {remoting.AppLauncher} appLauncher |
+ */ |
+function initializeBackgroundService(appLauncher) { |
+ /** @type {remoting.It2MeService} */ |
+ var it2meService = new remoting.It2MeService(appLauncher); |
+ it2meService.init(); |
+ remoting.it2meService = it2meService; |
+ |
+ chrome.runtime.onSuspend.addListener(function() { |
+ it2meService.dispose(); |
+ }); |
+} |
+ |
+function main() { |
+ /** @type {remoting.AppLauncher} */ |
+ var appLauncher = new remoting.V1AppLauncher(); |
+ if (isAppsV2()) { |
+ appLauncher = new remoting.V2AppLauncher(); |
+ initializeAppV2(appLauncher); |
+ } |
+ initializeBackgroundService(appLauncher); |
+} |
+ |
+main(); |
+ |
+}()); |