OLD | NEW |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 /** | 18 /** |
19 * @fileOverview Code responsible for showing and hiding object tabs. | 19 * @fileOverview Code responsible for showing and hiding object tabs. |
20 */ | 20 */ |
21 | 21 |
| 22 let {port} = require("messaging"); |
| 23 |
22 /** | 24 /** |
23 * Class responsible for showing and hiding object tabs. | 25 * Class responsible for showing and hiding object tabs. |
24 * @class | 26 * @class |
25 */ | 27 */ |
26 var objTabs = | 28 var objTabs = |
27 { | 29 { |
28 /** | 30 /** |
29 * Number of milliseconds to wait until hiding tab after the mouse moves away. | 31 * Number of milliseconds to wait until hiding tab after the mouse moves away. |
30 * @type Integer | 32 * @type Integer |
31 */ | 33 */ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 */ | 69 */ |
68 hideTimer: null, | 70 hideTimer: null, |
69 | 71 |
70 /** | 72 /** |
71 * Used when hideTimer is running, time when the tab should be hidden. | 73 * Used when hideTimer is running, time when the tab should be hidden. |
72 * @type Integer | 74 * @type Integer |
73 */ | 75 */ |
74 hideTargetTime: 0, | 76 hideTargetTime: 0, |
75 | 77 |
76 /** | 78 /** |
77 * Localized texts and class names to be used for the tab. | 79 * Localized texts and class names to be used for the tab. This will be set |
| 80 * when showTabFor is called for the first time. |
78 * @type Object | 81 * @type Object |
79 */ | 82 */ |
80 texts: null, | 83 texts: null, |
81 | 84 |
82 /** | 85 /** |
83 * Called to show object tab for an element. | 86 * Called to show object tab for an element. |
84 */ | 87 */ |
85 showTabFor: function(/**Element*/ element) | 88 showTabFor: function(/**Element*/ element) |
86 { | 89 { |
87 // Object tabs aren't usable in Fennec | 90 // Object tabs aren't usable in Fennec |
88 let {application} = require("info"); | 91 let {application} = require("info"); |
89 if (application == "fennec" || application == "fennec2" || | 92 if (application == "fennec" || application == "fennec2" || |
90 application == "adblockbrowser") | 93 application == "adblockbrowser") |
91 return; | 94 return; |
92 | 95 |
93 if (!sendSyncMessage("AdblockPlus:GetObjectTabsStatus")) | 96 if (!this.texts) |
94 return; | 97 this.texts = port.emitWithResponse("getObjectTabsTexts"); |
| 98 Promise.all([port.emitWithResponse("getObjectTabsStatus"), this.texts]) |
| 99 .then(([status, texts]) => |
| 100 { |
| 101 this.texts = texts; |
| 102 if (!status) |
| 103 return; |
95 | 104 |
96 if (this.hideTimer) | 105 if (this.hideTimer) |
97 { | 106 { |
98 this.hideTimer.cancel(); | 107 this.hideTimer.cancel(); |
99 this.hideTimer = null; | 108 this.hideTimer = null; |
100 } | 109 } |
101 | 110 |
102 if (this.objtabElement) | 111 if (this.objtabElement) |
103 this.objtabElement.style.setProperty("opacity", "1", "important"); | 112 this.objtabElement.style.setProperty("opacity", "1", "important"); |
104 | 113 |
105 if (this.currentElement != element) | 114 if (this.currentElement != element) |
106 { | 115 { |
107 this._hideTab(); | 116 this._hideTab(); |
108 | 117 |
109 let {RequestNotifier} = require("child/requestNotifier"); | 118 let {RequestNotifier} = require("child/requestNotifier"); |
110 let data = RequestNotifier.getDataForNode(element, true, "OBJECT"); | 119 let data = RequestNotifier.getDataForNode(element, true, "OBJECT"); |
111 if (data) | 120 if (data) |
112 this._showTab(element, data[1]); | 121 this._showTab(element, data[1]); |
113 } | 122 } |
| 123 }); |
114 }, | 124 }, |
115 | 125 |
116 /** | 126 /** |
117 * Called to hide object tab for an element (actual hiding happens delayed). | 127 * Called to hide object tab for an element (actual hiding happens delayed). |
118 */ | 128 */ |
119 hideTabFor: function(/**Element*/ element) | 129 hideTabFor: function(/**Element*/ element) |
120 { | 130 { |
121 if (element != this.currentElement || this.hideTimer) | 131 if (element != this.currentElement || this.hideTimer) |
122 return; | 132 return; |
123 | 133 |
124 this.hideTargetTime = Date.now() + this.HIDE_DELAY; | 134 this.hideTargetTime = Date.now() + this.HIDE_DELAY; |
125 this.hideTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); | 135 this.hideTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
126 this.hideTimer.init(this, 40, Ci.nsITimer.TYPE_REPEATING_SLACK); | 136 this.hideTimer.init(this, 40, Ci.nsITimer.TYPE_REPEATING_SLACK); |
127 }, | 137 }, |
128 | 138 |
129 /** | 139 /** |
130 * Makes the tab element visible. | 140 * Makes the tab element visible. |
131 * @param {Element} element | 141 * @param {Element} element |
132 * @param {RequestEntry} data | 142 * @param {RequestEntry} data |
133 */ | 143 */ |
134 _showTab: function(element, data) | 144 _showTab: function(element, data) |
135 { | 145 { |
136 if (!this.texts) | |
137 this.texts = sendSyncMessage("AdblockPlus:GetObjectTabsTexts"); | |
138 | |
139 let doc = element.ownerDocument.defaultView.top.document; | 146 let doc = element.ownerDocument.defaultView.top.document; |
140 | 147 |
141 this.objtabElement = doc.createElementNS("http://www.w3.org/1999/xhtml", "a"
); | 148 this.objtabElement = doc.createElementNS("http://www.w3.org/1999/xhtml", "a"
); |
142 this.objtabElement.textContent = this.texts.label; | 149 this.objtabElement.textContent = this.texts.label; |
143 this.objtabElement.setAttribute("title", this.texts.tooltip); | 150 this.objtabElement.setAttribute("title", this.texts.tooltip); |
144 this.objtabElement.setAttribute("href", data.location); | 151 this.objtabElement.setAttribute("href", data.location); |
145 this.objtabElement.setAttribute("class", this.texts.classHidden); | 152 this.objtabElement.setAttribute("class", this.texts.classHidden); |
146 this.objtabElement.style.setProperty("opacity", "1", "important"); | 153 this.objtabElement.style.setProperty("opacity", "1", "important"); |
147 this.objtabElement.nodeData = data; | 154 this.objtabElement.nodeData = data; |
148 | 155 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 rect.bottom += relTop; | 315 rect.bottom += relTop; |
309 } | 316 } |
310 | 317 |
311 return rect; | 318 return rect; |
312 }, | 319 }, |
313 | 320 |
314 doBlock: function() | 321 doBlock: function() |
315 { | 322 { |
316 let {storeNodes} = require("child/contentPolicy"); | 323 let {storeNodes} = require("child/contentPolicy"); |
317 let nodesID = storeNodes([this.currentElement]); | 324 let nodesID = storeNodes([this.currentElement]); |
318 sendAsyncMessage("AdblockPlus:BlockItem", { | 325 port.emit("blockItem", { |
319 request: this.objtabElement.nodeData, | 326 request: this.objtabElement.nodeData, |
320 nodesID | 327 nodesID |
321 }); | 328 }); |
322 }, | 329 }, |
323 | 330 |
324 /** | 331 /** |
325 * Called whenever a timer fires. | 332 * Called whenever a timer fires. |
326 * @param {nsISupport} subject | 333 * @param {nsISupport} subject |
327 * @param {string} topic | 334 * @param {string} topic |
328 * @param {string} data | 335 * @param {string} data |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 event.stopPropagation(); | 396 event.stopPropagation(); |
390 | 397 |
391 objTabs.doBlock(); | 398 objTabs.doBlock(); |
392 } | 399 } |
393 else if (event.type == "mouseover") | 400 else if (event.type == "mouseover") |
394 objTabs.showTabFor(objTabs.currentElement); | 401 objTabs.showTabFor(objTabs.currentElement); |
395 else if (event.type == "mouseout") | 402 else if (event.type == "mouseout") |
396 objTabs.hideTabFor(objTabs.currentElement); | 403 objTabs.hideTabFor(objTabs.currentElement); |
397 } | 404 } |
398 exports.objectMouseEventHander = objectMouseEventHander; | 405 exports.objectMouseEventHander = objectMouseEventHander; |
OLD | NEW |