1 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 function RemoteController(browser) {
7 this._browser = browser;
9 // A map of commands that have had their enabled/disabled state assigned. The
10 // value of each key will be true if enabled, and false if disabled.
11 this._supportedCommands = {};
14 RemoteController.prototype = {
15 QueryInterface: ChromeUtils.generateQI([
17 Ci.nsICommandController,
20 isCommandEnabled(aCommand) {
21 return this._supportedCommands[aCommand] || false;
24 supportsCommand(aCommand) {
25 return aCommand in this._supportedCommands;
29 this._browser.messageManager.sendAsyncMessage(
30 "ControllerCommands:Do",
35 getCommandStateWithParams(aCommand, aCommandParams) {
36 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
39 doCommandWithParams(aCommand, aCommandParams) {
44 if (aCommand == "cmd_lookUpDictionary") {
45 // Although getBoundingClientRect of the element is logical pixel, but
46 // x and y parameter of cmd_lookUpDictionary are device pixel.
47 // So we need calculate child process's coordinate using correct unit.
48 let rect = this._browser.getBoundingClientRect();
49 let scale = this._browser.ownerGlobal.devicePixelRatio;
53 value: aCommandParams.getLongValue("x") - rect.left * scale,
57 value: aCommandParams.getLongValue("y") - rect.top * scale,
61 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
63 this._browser.messageManager.sendAsyncMessage(
64 "ControllerCommands:DoWithParams",
69 getSupportedCommands() {
70 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
75 // This is intended to be called from the browser binding to update
76 // the enabled and disabled commands.
77 enableDisableCommands(aAction, aEnabledCommands, aDisabledCommands) {
78 // Clear the list first
79 this._supportedCommands = {};
81 for (let command of aEnabledCommands) {
82 this._supportedCommands[command] = true;
85 for (let command of aDisabledCommands) {
86 this._supportedCommands[command] = false;
89 // Don't update anything if we're not the active element
90 if (this._browser != this._browser.ownerDocument.activeElement) {
93 this._browser.ownerGlobal.updateCommands(aAction);