Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / remoting / webapp / crd / js / activation_handler.js
bloba483d361e967799fed5e312cf69d97d168f89d30
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
3 // found in the LICENSE file.
5 /** @suppress {duplicate} */
6 var remoting = remoting || {};
8 (function(){
10 'use strict';
12 /** @type {string} */
13 var NEW_WINDOW_MENU_ID_ = 'new-window';
15 /**
16 * A class that handles application activation.
18 * @param {base.Ipc} ipc
19 * @param {remoting.V2AppLauncher} appLauncher
20 * @constructor
22 remoting.ActivationHandler = function (ipc, appLauncher) {
23 /** @private {remoting.V2AppLauncher} */
24 this.appLauncher_ = appLauncher;
26 chrome.contextMenus.create({
27 id: NEW_WINDOW_MENU_ID_,
28 contexts: ['launcher'],
29 title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW')
30 });
32 chrome.contextMenus.onClicked.addListener(this.onContextMenu_.bind(this));
33 chrome.app.runtime.onLaunched.addListener(this.onLaunched_.bind(this));
34 ipc.register(remoting.ActivationHandler.Ipc.RELAUNCH,
35 appLauncher.restart.bind(appLauncher));
38 /** @enum {string} */
39 remoting.ActivationHandler.Ipc = {
40 RELAUNCH: 'remoting.ActivationHandler.restart'
43 /**
44 * @param {OnClickData} info
45 * @private
47 remoting.ActivationHandler.prototype.onContextMenu_ = function(info) {
48 if (info.menuItemId == NEW_WINDOW_MENU_ID_) {
49 this.appLauncher_.launch();
53 /**
54 * Called when the App is activated (e.g. from the Chrome App Launcher). It
55 * creates a new window if there are no existing ones. Otherwise, it will put
56 * focus on the last window created.
58 * @private
60 remoting.ActivationHandler.prototype.onLaunched_ = function() {
61 var windows = chrome.app.window.getAll();
62 if (windows.length >= 1) {
63 windows[windows.length - 1].focus();
64 } else {
65 this.appLauncher_.launch();
69 })();