LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 20 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
21 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); | 21 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); |
22 | 22 |
23 let {Utils} = require("utils"); | 23 let {Utils} = require("utils"); |
24 let {RequestNotifier} = require("child/requestNotifier"); | 24 let {RequestNotifier} = require("child/requestNotifier"); |
25 let {storeNodes} = require("child/contentPolicy"); | 25 let {storeNodes} = require("child/contentPolicy"); |
26 | 26 |
27 let getContextInfo = | |
28 /** | 27 /** |
29 * Determines the context menu entries to be shown for a contextmenu event. | 28 * Determines the context menu entries to be shown for a contextmenu event. |
30 * @param {Event} event | 29 * @param {Event} event |
31 * @return {Array} | 30 * @return {Array} |
32 */ | 31 */ |
33 exports.getContextInfo = function(event) | 32 function getContextInfo(event) |
34 { | 33 { |
35 let items = []; | 34 let items = []; |
36 let target = event.target; | 35 let target = event.target; |
37 if (target.localName == "menupopup" && target.triggerNode) | 36 if (target.localName == "menupopup" && target.triggerNode) |
38 { | 37 { |
39 // SeaMonkey gives us the context menu's popupshowing event | 38 // SeaMonkey gives us the context menu's popupshowing event |
40 target = target.triggerNode; | 39 target = target.triggerNode; |
41 } | 40 } |
42 if (target instanceof Ci.nsIDOMHTMLMapElement || target instanceof Ci.nsIDOMHT
MLAreaElement) | 41 if (target instanceof Ci.nsIDOMHTMLMapElement || target instanceof Ci.nsIDOMHT
MLAreaElement) |
43 { | 42 { |
44 // HTML image maps will usually receive events when the mouse pointer is | 43 // HTML image maps will usually receive events when the mouse pointer is |
45 // over a different element, get the real event target. | 44 // over a different element, get the real event target. |
46 let rect = target.getClientRects()[0]; | 45 let rect = target.getClientRects()[0]; |
47 target = target.ownerDocument.elementFromPoint(Math.max(rect.left, 0), Math.
max(rect.top, 0)); | 46 target = target.ownerDocument.elementFromPoint(Math.max(rect.left, 0), Math.
max(rect.top, 0)); |
48 } | 47 } |
49 | 48 |
50 if (!target) | 49 if (!target) |
51 return items; | 50 return items; |
52 | 51 |
53 let addMenuItem = function([node, nodeData]) | 52 let addMenuItem = function([node, nodeData]) |
54 { | 53 { |
55 let nodeID = null; | 54 let nodeID = null; |
56 if (node && node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) | 55 if (node && node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) |
57 nodeID = storeNodes([node]); | 56 nodeID = storeNodes([node]); |
58 items.push([nodeID, nodeData]); | 57 items.push([nodeID, nodeData]); |
59 }.bind(this); | 58 }.bind(this); |
60 | 59 |
61 // Look up data that we have for the node | 60 // Look up data that we have for the node |
62 let data = RequestNotifier.getDataForNode(target); | 61 let data = RequestNotifier.getDataForNode(target); |
63 let hadImage = false; | 62 let hadImage = false; |
64 if (data && !data[1].filter) | 63 if (data && !data[1].filter) |
65 { | 64 { |
66 addMenuItem(data); | 65 addMenuItem(data); |
67 hadImage = (data[1].type == "IMAGE"); | 66 hadImage = (data[1].type == "IMAGE"); |
68 } | 67 } |
69 | 68 |
70 // Look for frame data | 69 // Look for frame data |
71 let wnd = Utils.getWindow(target); | 70 let wnd = Utils.getWindow(target); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 }, | 131 }, |
133 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) | 132 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) |
134 }; | 133 }; |
135 | 134 |
136 let addObserver = Utils.getPropertyWithoutCompatShims(Services.obs, "addObserver
"); | 135 let addObserver = Utils.getPropertyWithoutCompatShims(Services.obs, "addObserver
"); |
137 addObserver.call(Services.obs, ContextMenuObserver, "content-contextmenu", true)
; | 136 addObserver.call(Services.obs, ContextMenuObserver, "content-contextmenu", true)
; |
138 onShutdown.add(() => { | 137 onShutdown.add(() => { |
139 let removeObserver = Utils.getPropertyWithoutCompatShims(Services.obs, "remove
Observer"); | 138 let removeObserver = Utils.getPropertyWithoutCompatShims(Services.obs, "remove
Observer"); |
140 removeObserver.call(Services.obs, ContextMenuObserver, "content-contextmenu"); | 139 removeObserver.call(Services.obs, ContextMenuObserver, "content-contextmenu"); |
141 }); | 140 }); |
LEFT | RIGHT |