Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / remoting / webapp / app_remoting / js / window_activation_menu.js
bloba279c0b876f4203262b11b56c807f578beb36960
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 /**
6 * @fileoverview
7 * Class to update the application's context menu to include host-side windows
8 * and to notify the host when one of these menu items is selected.
9 */
11 'use strict';
13 /** @suppress {duplicate} */
14 var remoting = remoting || {};
16 /**
17 * @param {remoting.ContextMenuAdapter} adapter
18 * @constructor
20 remoting.WindowActivationMenu = function(adapter) {
21 /**
22 * @type {remoting.SubmenuManager}
23 * @private
25 this.submenuManager_ = new remoting.SubmenuManager(
26 adapter,
27 chrome.i18n.getMessage(/*i18n-content*/'WINDOWS_SUBMENU_TITLE'),
28 false);
30 adapter.addListener(this.onContextMenu_.bind(this));
33 /**
34 * Add a window to the application's context menu, or update the title of an
35 * existing window.
37 * @param {number} id The window id.
38 * @param {string} title The window title.
40 remoting.WindowActivationMenu.prototype.add = function(id, title) {
41 this.submenuManager_.add(this.makeMenuId_(id), title);
42 // TODO(jamiewalch): Once crbug.com/426283 is fixed, call drawAttention()
43 // here if the window does not have focus.
46 /**
47 * Remove a window from the application's context menu.
49 * @param {number} id The window id.
51 remoting.WindowActivationMenu.prototype.remove = function(id) {
52 this.submenuManager_.remove(this.makeMenuId_(id));
55 /**
56 * Create a menu id from the given window id.
58 * @param {number} windowId
59 * @return {string}
60 * @private
62 remoting.WindowActivationMenu.prototype.makeMenuId_ = function(windowId) {
63 return 'window-' + windowId;
66 /**
67 * Handle a click on the application's context menu.
69 * @param {OnClickData=} info
70 * @private
72 remoting.WindowActivationMenu.prototype.onContextMenu_ = function(info) {
73 /** @type {Array<string>} */
74 var components = info.menuItemId.split('-');
75 if (components.length == 2 &&
76 this.makeMenuId_(parseInt(components[1], 10)) == info.menuItemId) {
77 remoting.clientSession.sendClientMessage(
78 'activateWindow',
79 JSON.stringify({ id: parseInt(components[1], 0) }));
80 if (chrome.app.window.current().isMinimized()) {
81 chrome.app.window.current().restore();