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.
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.
13 /** @suppress {duplicate} */
14 var remoting
= remoting
|| {};
17 * @param {remoting.ContextMenuAdapter} adapter
20 remoting
.WindowActivationMenu = function(adapter
) {
21 /** @private {remoting.SubmenuManager} */
22 this.submenuManager_
= new remoting
.SubmenuManager(
24 chrome
.i18n
.getMessage(/*i18n-content*/'WINDOWS_SUBMENU_TITLE'),
26 /** @private {function(string, string)} */
27 this.sendExtensionMessage_
= base
.doNothing
;
29 adapter
.addListener(this.onContextMenu_
.bind(this));
33 * Add a window to the application's context menu, or update the title of an
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.
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
));
55 * Create a menu id from the given window id.
57 * @param {number} windowId
61 remoting
.WindowActivationMenu
.prototype.makeMenuId_ = function(windowId
) {
62 return 'window-' + windowId
;
65 /** @param {function(string, string)} callback */
66 remoting
.WindowActivationMenu
.prototype.setExtensionMessageSender
=
68 this.sendExtensionMessage_
= callback
;
72 * Handle a click on the application's context menu.
74 * @param {OnClickData=} info
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_(
84 JSON
.stringify({ id
: parseInt(components
[1], 0) }));
85 if (chrome
.app
.window
.current().isMinimized()) {
86 chrome
.app
.window
.current().restore();