1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/modules/RemoteController.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +// -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 +// This Source Code Form is subject to the terms of the Mozilla Public 1.6 +// License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 +// file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + 1.9 +this.EXPORTED_SYMBOLS = ["RemoteController"]; 1.10 + 1.11 +const Ci = Components.interfaces; 1.12 +const Cc = Components.classes; 1.13 +const Cu = Components.utils; 1.14 + 1.15 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.16 + 1.17 +function RemoteController(browser) 1.18 +{ 1.19 + this._browser = browser; 1.20 +} 1.21 + 1.22 +RemoteController.prototype = { 1.23 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIController]), 1.24 + 1.25 + isCommandEnabled: function(aCommand) { 1.26 + // We can't synchronously ask content if a command is enabled, 1.27 + // so we always pretend is. 1.28 + // The right way forward would be to never use nsIController 1.29 + // to ask if something in content is enabled. Maybe even 1.30 + // by replacing the nsIController architecture by something else. 1.31 + // See bug 905768. 1.32 + return true; 1.33 + }, 1.34 + 1.35 + supportsCommand: function(aCommand) { 1.36 + // Optimize the lookup a bit. 1.37 + if (!aCommand.startsWith("cmd_")) 1.38 + return false; 1.39 + 1.40 + // For now only support the commands used in "browser-context.inc" 1.41 + let commands = [ 1.42 + "cmd_copyLink", 1.43 + "cmd_copyImage", 1.44 + "cmd_undo", 1.45 + "cmd_cut", 1.46 + "cmd_copy", 1.47 + "cmd_paste", 1.48 + "cmd_delete", 1.49 + "cmd_selectAll", 1.50 + "cmd_switchTextDirection" 1.51 + ]; 1.52 + 1.53 + return commands.indexOf(aCommand) >= 0; 1.54 + }, 1.55 + 1.56 + doCommand: function(aCommand) { 1.57 + this._browser.messageManager.sendAsyncMessage("ControllerCommands:Do", aCommand); 1.58 + }, 1.59 + 1.60 + onEvent: function () {} 1.61 +};