Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / remoting / webapp / app_remoting / js / context_menu_chrome.js
blobc46838678eb03e52242e6a64a22fb766c1cf8d82
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() {
22 /**
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) {
31 if (!opt_parentId) {
32 var message = {
33 method: 'addContextMenuId',
34 id: id
36 chrome.runtime.getBackgroundPage(this.postMessage_.bind(this, message));
38 var params = {
39 id: id,
40 contexts: ['launcher'],
41 title: title,
42 parentId: opt_parentId
44 if (isCheckable) {
45 params.type = 'checkbox';
47 chrome.contextMenus.create(params);
50 /**
51 * @param {string} id
52 * @param {string} title
54 remoting.ContextMenuChrome.prototype.updateTitle = function(id, title) {
55 chrome.contextMenus.update(id, {title: title});
58 /**
59 * @param {string} id
60 * @param {boolean} checked
62 remoting.ContextMenuChrome.prototype.updateCheckState = function(id, checked) {
63 chrome.contextMenus.update(id, {checked: checked});
66 /**
67 * @param {string} id
69 remoting.ContextMenuChrome.prototype.remove = function(id) {
70 chrome.contextMenus.remove(id);
71 var message = {
72 method: 'removeContextMenuId',
73 id: id
75 chrome.runtime.getBackgroundPage(this.postMessage_.bind(this, message));
78 /**
79 * @param {function(OnClickData):void} listener
81 remoting.ContextMenuChrome.prototype.addListener = function(listener) {
82 chrome.contextMenus.onClicked.addListener(listener);
85 /**
86 * @param {*} message
87 * @param {Window} backgroundPage
89 remoting.ContextMenuChrome.prototype.postMessage_ = function(
90 message, backgroundPage) {
91 backgroundPage.postMessage(message, '*');