Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / webapp / app_remoting / js / context_menu_chrome.js
blob285eb0cff000f54ac81d7fa2a4844a3e2afec8a5
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 * remoting.ContextMenuAdapter implementation backed by chrome.contextMenus.
8 */
10 'use strict';
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
15 /**
16 * @constructor
17 * @implements {remoting.ContextMenuAdapter}
19 remoting.ContextMenuChrome = function() {};
21 remoting.ContextMenuChrome.prototype.dispose = function() {
22 chrome.contextMenus.removeAll();
25 /**
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) {
34 if (!opt_parentId) {
35 var message = {
36 method: 'addContextMenuId',
37 id: id
39 chrome.runtime.getBackgroundPage(this.postMessage_.bind(this, message));
41 var params = {
42 id: id,
43 contexts: ['launcher'],
44 title: title,
45 parentId: opt_parentId
47 if (isCheckable) {
48 params.type = 'checkbox';
50 chrome.contextMenus.create(params);
53 /**
54 * @param {string} id
55 * @param {string} title
57 remoting.ContextMenuChrome.prototype.updateTitle = function(id, title) {
58 chrome.contextMenus.update(id, {title: title});
61 /**
62 * @param {string} id
63 * @param {boolean} checked
65 remoting.ContextMenuChrome.prototype.updateCheckState = function(id, checked) {
66 chrome.contextMenus.update(id, {checked: checked});
69 /**
70 * @param {string} id
72 remoting.ContextMenuChrome.prototype.remove = function(id) {
73 chrome.contextMenus.remove(id);
74 var message = {
75 method: 'removeContextMenuId',
76 id: id
78 chrome.runtime.getBackgroundPage(this.postMessage_.bind(this, message));
81 /**
82 * @param {function(OnClickData):void} listener
84 remoting.ContextMenuChrome.prototype.addListener = function(listener) {
85 chrome.contextMenus.onClicked.addListener(
86 /** @type {function(Object, Tab=)} */ (listener));
89 /**
90 * @param {*} message
91 * @param {Window=} backgroundPage
93 remoting.ContextMenuChrome.prototype.postMessage_ = function(
94 message, backgroundPage) {
95 backgroundPage.postMessage(message, '*');