|
1 // -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 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/. |
|
5 |
|
6 this.EXPORTED_SYMBOLS = ["RemoteController"]; |
|
7 |
|
8 const Ci = Components.interfaces; |
|
9 const Cc = Components.classes; |
|
10 const Cu = Components.utils; |
|
11 |
|
12 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
13 |
|
14 function RemoteController(browser) |
|
15 { |
|
16 this._browser = browser; |
|
17 } |
|
18 |
|
19 RemoteController.prototype = { |
|
20 QueryInterface: XPCOMUtils.generateQI([Ci.nsIController]), |
|
21 |
|
22 isCommandEnabled: function(aCommand) { |
|
23 // We can't synchronously ask content if a command is enabled, |
|
24 // so we always pretend is. |
|
25 // The right way forward would be to never use nsIController |
|
26 // to ask if something in content is enabled. Maybe even |
|
27 // by replacing the nsIController architecture by something else. |
|
28 // See bug 905768. |
|
29 return true; |
|
30 }, |
|
31 |
|
32 supportsCommand: function(aCommand) { |
|
33 // Optimize the lookup a bit. |
|
34 if (!aCommand.startsWith("cmd_")) |
|
35 return false; |
|
36 |
|
37 // For now only support the commands used in "browser-context.inc" |
|
38 let commands = [ |
|
39 "cmd_copyLink", |
|
40 "cmd_copyImage", |
|
41 "cmd_undo", |
|
42 "cmd_cut", |
|
43 "cmd_copy", |
|
44 "cmd_paste", |
|
45 "cmd_delete", |
|
46 "cmd_selectAll", |
|
47 "cmd_switchTextDirection" |
|
48 ]; |
|
49 |
|
50 return commands.indexOf(aCommand) >= 0; |
|
51 }, |
|
52 |
|
53 doCommand: function(aCommand) { |
|
54 this._browser.messageManager.sendAsyncMessage("ControllerCommands:Do", aCommand); |
|
55 }, |
|
56 |
|
57 onEvent: function () {} |
|
58 }; |