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() {};
21 remoting.ContextMenuChrome.prototype.dispose = function() {
22 chrome.contextMenus.removeAll();
26 * @param {string} id An identifier for the menu entry.
27 * @param {string} title The text to display in the menu.
28 * @param {boolean} isCheckable True if the state of this menu entry should
29 * have a check-box and manage its toggle state automatically.
30 * @param {string=} opt_parentId The id of the parent menu item for submenus.
32 remoting.ContextMenuChrome.prototype.create = function(
33 id, title, isCheckable, opt_parentId) {
36 method: 'addContextMenuId',
39 chrome.runtime.getBackgroundPage(this.postMessage_.bind(this, message));
43 contexts: ['launcher'],
45 parentId: opt_parentId
48 params.type = 'checkbox';
50 chrome.contextMenus.create(params);
55 * @param {string} title
57 remoting.ContextMenuChrome.prototype.updateTitle = function(id, title) {
58 chrome.contextMenus.update(id, {title: title});
63 * @param {boolean} checked
65 remoting.ContextMenuChrome.prototype.updateCheckState = function(id, checked) {
66 chrome.contextMenus.update(id, {checked: checked});
72 remoting.ContextMenuChrome.prototype.remove = function(id) {
73 chrome.contextMenus.remove(id);
75 method: 'removeContextMenuId',
78 chrome.runtime.getBackgroundPage(this.postMessage_.bind(this, message));
82 * @param {function(OnClickData):void} listener
84 remoting.ContextMenuChrome.prototype.addListener = function(listener) {
85 chrome.contextMenus.onClicked.addListener(
86 /** @type {function(Object, Tab=)} */ (listener));
91 * @param {Window=} backgroundPage
93 remoting.ContextMenuChrome.prototype.postMessage_ = function(
94 message, backgroundPage) {
95 backgroundPage.postMessage(message, '*');