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 * remoting.ContextMenuAdapter implementation backed by chrome.contextMenus.
12 /** @suppress {duplicate} */
13 var remoting
= remoting
|| {};
17 * @implements {remoting.ContextMenuAdapter}
19 remoting
.ContextMenuChrome = function() {
23 * @param {string} id An identifier for the menu entry.
24 * @param {string} title The text to display in the menu.
25 * @param {boolean} isCheckable True if the state of this menu entry should
26 * have a check-box and manage its toggle state automatically.
27 * @param {string=} opt_parentId The id of the parent menu item for submenus.
29 remoting
.ContextMenuChrome
.prototype.create = function(
30 id
, title
, isCheckable
, opt_parentId
) {
33 method
: 'addContextMenuId',
36 chrome
.runtime
.getBackgroundPage(this.postMessage_
.bind(this, message
));
40 contexts
: ['launcher'],
42 parentId
: opt_parentId
45 params
.type
= 'checkbox';
47 chrome
.contextMenus
.create(params
);
52 * @param {string} title
54 remoting
.ContextMenuChrome
.prototype.updateTitle = function(id
, title
) {
55 chrome
.contextMenus
.update(id
, {title
: title
});
60 * @param {boolean} checked
62 remoting
.ContextMenuChrome
.prototype.updateCheckState = function(id
, checked
) {
63 chrome
.contextMenus
.update(id
, {checked
: checked
});
69 remoting
.ContextMenuChrome
.prototype.remove = function(id
) {
70 chrome
.contextMenus
.remove(id
);
72 method
: 'removeContextMenuId',
75 chrome
.runtime
.getBackgroundPage(this.postMessage_
.bind(this, message
));
79 * @param {function(OnClickData):void} listener
81 remoting
.ContextMenuChrome
.prototype.addListener = function(listener
) {
82 chrome
.contextMenus
.onClicked
.addListener(listener
);
87 * @param {Window} backgroundPage
89 remoting
.ContextMenuChrome
.prototype.postMessage_ = function(
90 message
, backgroundPage
) {
91 backgroundPage
.postMessage(message
, '*');