Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / remoting / webapp / app_remoting / js / window_activation_menu.js
blob72039b7fdf578c4911b6f981e75e14b8fa59ddcc
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 /** @private {remoting.SubmenuManager} */
22 this.submenuManager_ = new remoting.SubmenuManager(
23 adapter,
24 chrome.i18n.getMessage(/*i18n-content*/'WINDOWS_SUBMENU_TITLE'),
25 false);
26 /** @private {function(string, string)} */
27 this.sendExtensionMessage_ = base.doNothing;
29 adapter.addListener(this.onContextMenu_.bind(this));
32 /**
33 * Add a window to the application's context menu, or update the title of an
34 * existing window.
36 * @param {number} id The window id.
37 * @param {string} title The window title.
39 remoting.WindowActivationMenu.prototype.add = function(id, title) {
40 this.submenuManager_.add(this.makeMenuId_(id), title);
41 // TODO(jamiewalch): Once crbug.com/426283 is fixed, call drawAttention()
42 // here if the window does not have focus.
45 /**
46 * Remove a window from the application's context menu.
48 * @param {number} id The window id.
50 remoting.WindowActivationMenu.prototype.remove = function(id) {
51 this.submenuManager_.remove(this.makeMenuId_(id));
54 /**
55 * Create a menu id from the given window id.
57 * @param {number} windowId
58 * @return {string}
59 * @private
61 remoting.WindowActivationMenu.prototype.makeMenuId_ = function(windowId) {
62 return 'window-' + windowId;
65 /** @param {function(string, string)} callback */
66 remoting.WindowActivationMenu.prototype.setExtensionMessageSender =
67 function(callback) {
68 this.sendExtensionMessage_ = callback;
71 /**
72 * Handle a click on the application's context menu.
74 * @param {OnClickData=} info
75 * @private
77 remoting.WindowActivationMenu.prototype.onContextMenu_ = function(info) {
78 var menuId = info.menuItemId.toString();
79 var components = menuId.split('-');
80 if (components.length == 2 &&
81 this.makeMenuId_(parseInt(components[1], 10)) == menuId) {
82 this.sendExtensionMessage_(
83 'activateWindow',
84 JSON.stringify({ id: parseInt(components[1], 0) }));
85 if (chrome.app.window.current().isMinimized()) {
86 chrome.app.window.current().restore();