Chromium Code Reviews| Index: remoting/webapp/crd/js/activation_handler.js |
| diff --git a/remoting/webapp/crd/js/activation_handler.js b/remoting/webapp/crd/js/activation_handler.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b602389f0dcf7a4e5641e049174e23794f2c9b87 |
| --- /dev/null |
| +++ b/remoting/webapp/crd/js/activation_handler.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 || {}; |
|
kelvinp
2015/01/23 22:25:07
This file is existing code pulled out from backgro
Jamie
2015/01/23 23:33:26
Was that done because background.js was getting to
kelvinp
2015/01/28 00:26:45
Ya, mainly for the IPC names, but I also think it
Jamie
2015/01/28 20:52:09
Refactoring this code is fine, but I'm a bit conce
kelvinp
2015/01/29 01:05:34
Done.
|
| + |
| +(function(){ |
| + |
| +'use strict'; |
| + |
| +/** @type {string} */ |
| +var NEW_WINDOW_MENU_ID_ = 'new-window'; |
| + |
| +/** |
| + * A class that handles application activation. |
| + * |
| + * @param {base.RemoteMethods} remoteMethods |
| + * @param {remoting.V2AppLauncher} appLauncher |
| + * @constructor |
| + */ |
| +remoting.ActivationHandler = function (remoteMethods, appLauncher) { |
| + /** |
| + * @type {remoting.V2AppLauncher} |
| + * @private |
| + */ |
| + this.appLauncher_ = appLauncher; |
| + |
| + chrome.contextMenus.create({ |
| + id: NEW_WINDOW_MENU_ID_, |
| + contexts: ['launcher'], |
| + title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW') |
| + }); |
| + |
| + chrome.contextMenus.onClicked.addListener(this.onContextMenu_.bind(this)); |
| + chrome.app.runtime.onLaunched.addListener(this.onLaunched_.bind(this)); |
| + remoteMethods.register(remoting.ActivationHandler.Request.RELAUNCH, |
| + appLauncher.restart.bind(appLauncher)); |
| +}; |
| + |
| +/** @enum {string} */ |
| +remoting.ActivationHandler.Request = { |
| + RELAUNCH: 'remoting.ActivationHandler.restart' |
| +}; |
| + |
| +/** |
| + * @param {OnClickData} info |
| + * @private |
| + */ |
| +remoting.ActivationHandler.prototype.onContextMenu_ = function(info) { |
| + if (info.menuItemId == NEW_WINDOW_MENU_ID_) { |
| + this.appLauncher_.launch(); |
| + } |
| +}; |
| + |
| +/** |
| + * Called when the App is activated (e.g. from the Chrome App Launcher). It |
| + * creates a new window if there are no existing ones. Otherwise, it will put |
| + * focus on the last window created. |
| + * |
| + * @private |
| + */ |
| +remoting.ActivationHandler.prototype.onLaunched_ = function() { |
| + var windows = chrome.app.window.getAll(); |
| + if (windows.length >= 1) { |
| + windows[windows.length - 1].focus(); |
| + } else { |
| + this.appLauncher_.launch(); |
| + } |
| +}; |
| + |
| +})(); |