Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: remoting/webapp/crd/js/background.js

Issue 844503007: Fix CRD opens a window every time it's clicked in the launcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/webapp/js_proto/chrome_proto.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** @param {remoting.AppLauncher} appLauncher */ 10 /**
11 function initializeAppV2(appLauncher) { 11 * A class that handles application activation.
12 /** @type {string} */ 12 *
13 var kNewWindowId = 'new-window'; 13 * @param {remoting.AppLauncher} appLauncher
14 * @constructor
15 */
16 function ActivationHandler(appLauncher) {
17 /**
18 * @type {remoting.AppLauncher}
19 * @private
20 */
21 this.appLauncher_ = appLauncher;
14 22
15 /** @param {OnClickData} info */ 23 chrome.contextMenus.create({
16 function onContextMenu(info) { 24 id: ActivationHandler.NEW_WINDOW_MENU_ID_,
17 if (info.menuItemId == kNewWindowId) { 25 contexts: ['launcher'],
18 appLauncher.launch(); 26 title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW')
19 } 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();
20 } 43 }
44 };
21 45
22 function initializeContextMenu() { 46 /**
23 chrome.contextMenus.create({ 47 * Called when the App is activated (e.g. from the Chrome App Launcher). It
24 id: kNewWindowId, 48 * creates a new window if there are no existing ones. Otherwise, it will put
25 contexts: ['launcher'], 49 * focus on the last window created.
26 title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW') 50 *
27 }); 51 * @private
28 chrome.contextMenus.onClicked.addListener(onContextMenu); 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 return;
Jamie 2015/01/14 03:07:23 I think an else would be more readable than an ear
29 } 58 }
30 59 this.appLauncher_.launch();
31 initializeContextMenu(); 60 };
32 chrome.app.runtime.onLaunched.addListener(
33 appLauncher.launch.bind(appLauncher)
34 );
35 }
36 61
37 /** 62 /**
38 * The background service is responsible for listening to incoming connection 63 * The background service is responsible for listening to incoming connection
39 * requests from Hangouts and the webapp. 64 * requests from Hangouts and the webapp.
40 * 65 *
41 * @param {remoting.AppLauncher} appLauncher 66 * @param {remoting.AppLauncher} appLauncher
42 */ 67 */
43 function initializeBackgroundService(appLauncher) { 68 function initializeBackgroundService(appLauncher) {
44 function initializeIt2MeService() { 69 function initializeIt2MeService() {
45 /** @type {remoting.It2MeService} */ 70 /** @type {remoting.It2MeService} */
46 remoting.it2meService = new remoting.It2MeService(appLauncher); 71 remoting.it2meService = new remoting.It2MeService(appLauncher);
47 remoting.it2meService.init(); 72 remoting.it2meService.init();
48 } 73 }
49 74
50 chrome.runtime.onSuspend.addListener(function() { 75 chrome.runtime.onSuspend.addListener(function() {
51 base.debug.assert(remoting.it2meService != null); 76 base.debug.assert(remoting.it2meService != null);
52 remoting.it2meService.dispose(); 77 remoting.it2meService.dispose();
53 remoting.it2meService = null; 78 remoting.it2meService = null;
54 }); 79 });
55 80
56 remoting.settings = new remoting.Settings(); 81 remoting.settings = new remoting.Settings();
57 82
58 chrome.runtime.onSuspendCanceled.addListener(initializeIt2MeService); 83 chrome.runtime.onSuspendCanceled.addListener(initializeIt2MeService);
59 initializeIt2MeService(); 84 initializeIt2MeService();
60 } 85 }
61 86
62 function main() { 87 function main() {
63 if (base.isAppsV2()) { 88 if (base.isAppsV2()) {
64 var appLauncher = new remoting.V2AppLauncher(); 89 new ActivationHandler(new remoting.V2AppLauncher());
65 initializeAppV2(appLauncher);
66 } 90 }
67 } 91 }
68 92
69 remoting.enableHangoutsRemoteAssistance = function() { 93 remoting.enableHangoutsRemoteAssistance = function() {
70 /** @type {remoting.AppLauncher} */ 94 /** @type {remoting.AppLauncher} */
71 var appLauncher = base.isAppsV2() ? new remoting.V1AppLauncher(): 95 var appLauncher = base.isAppsV2() ? new remoting.V1AppLauncher():
72 new remoting.V2AppLauncher(); 96 new remoting.V2AppLauncher();
73 initializeBackgroundService(appLauncher); 97 initializeBackgroundService(appLauncher);
74 }; 98 };
75 99
76 window.addEventListener('load', main, false); 100 window.addEventListener('load', main, false);
77 101
78 }()); 102 }());
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/js_proto/chrome_proto.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698