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-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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 /** | 30 /** |
31 * Active RequestNotifier instances by their ID | 31 * Active RequestNotifier instances by their ID |
32 * @type Map.<number,RequestNotifier> | 32 * @type Map.<number,RequestNotifier> |
33 */ | 33 */ |
34 let notifiers = new Map(); | 34 let notifiers = new Map(); |
35 | 35 |
36 addMessageListener("AdblockPlus:StartWindowScan", onStartScan); | 36 addMessageListener("AdblockPlus:StartWindowScan", onStartScan); |
37 addMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); | 37 addMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); |
38 addMessageListener("AdblockPlus:FlashNodes", onFlashNodes); | 38 addMessageListener("AdblockPlus:FlashNodes", onFlashNodes); |
| 39 addMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize); |
39 | 40 |
40 onShutdown.add(() => { | 41 onShutdown.add(() => { |
41 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan); | 42 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan); |
42 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); | 43 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); |
43 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes); | 44 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes); |
| 45 removeMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize); |
44 }); | 46 }); |
45 | 47 |
46 function onStartScan(message) | 48 function onStartScan(message) |
47 { | 49 { |
48 let {notifierID, outerWindowID} = message.data; | 50 let {notifierID, outerWindowID} = message.data; |
49 let window = Services.wm.getOuterWindowWithId(outerWindowID); | 51 let window = Services.wm.getOuterWindowWithId(outerWindowID); |
50 if (window) | 52 if (window) |
51 new RequestNotifier(window, notifierID); | 53 new RequestNotifier(window, notifierID); |
52 } | 54 } |
53 | 55 |
54 function onNotifierShutdown(message) | 56 function onNotifierShutdown(message) |
55 { | 57 { |
56 let notifier = notifiers.get(message.data); | 58 let notifier = notifiers.get(message.data); |
57 if (notifier) | 59 if (notifier) |
58 notifier.shutdown(); | 60 notifier.shutdown(); |
59 } | 61 } |
60 | 62 |
61 function onFlashNodes(message) | 63 function onFlashNodes(message) |
62 { | 64 { |
63 let {notifierID, requests, scrollToItem} = message.data; | 65 let {notifierID, requests, scrollToItem} = message.data; |
64 let notifier = notifiers.get(notifierID); | 66 let notifier = notifiers.get(notifierID); |
65 if (notifier) | 67 if (notifier) |
66 notifier.flashNodes(requests, scrollToItem); | 68 notifier.flashNodes(requests, scrollToItem); |
67 } | 69 } |
68 | 70 |
| 71 function onRetrieveNodeSize(message) |
| 72 { |
| 73 let {notifierID, responseID, requests} = message.data; |
| 74 let notifier = notifiers.get(notifierID); |
| 75 if (notifier) |
| 76 notifier.retrieveNodeSize(requests, responseID); |
| 77 } |
| 78 |
69 /** | 79 /** |
70 * Creates a notifier object for a particular window. After creation the window | 80 * Creates a notifier object for a particular window. After creation the window |
71 * will first be scanned for previously saved requests. Once that scan is | 81 * will first be scanned for previously saved requests. Once that scan is |
72 * complete only new requests for this window will be reported. | 82 * complete only new requests for this window will be reported. |
73 * @param {Window} wnd window to attach the notifier to | 83 * @param {Window} wnd window to attach the notifier to |
74 * @param {Integer} id Parent notifier ID to be messaged | 84 * @param {Integer} id Parent notifier ID to be messaged |
75 */ | 85 */ |
76 function RequestNotifier(window, notifierID) | 86 function RequestNotifier(window, notifierID) |
77 { | 87 { |
78 this.window = window; | 88 this.window = window; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 }, | 220 }, |
211 | 221 |
212 /** | 222 /** |
213 * Stops flashing nodes after a previous flashNodes() call. | 223 * Stops flashing nodes after a previous flashNodes() call. |
214 */ | 224 */ |
215 stopFlashing: function() | 225 stopFlashing: function() |
216 { | 226 { |
217 if (this.flasher) | 227 if (this.flasher) |
218 this.flasher.stop(); | 228 this.flasher.stop(); |
219 this.flasher = null; | 229 this.flasher = null; |
| 230 }, |
| 231 |
| 232 /** |
| 233 * Attempts to calculate the size of the nodes associated with the requests, |
| 234 * Sends message to parent when complete. |
| 235 * @param {number[]} requests list of request IDs that were previously |
| 236 * reported by this notifier. |
| 237 * @param {number} responseID ID to be sent with the response. |
| 238 */ |
| 239 retrieveNodeSize: function(requests, responseID) |
| 240 { |
| 241 function getNodeSize(node) |
| 242 { |
| 243 if (node instanceof Ci.nsIDOMHTMLImageElement && (node.naturalWidth || nod
e.naturalHeight)) |
| 244 return [node.naturalWidth, node.naturalHeight]; |
| 245 else if (node instanceof Ci.nsIDOMHTMLElement && (node.offsetWidth || node
.offsetHeight)) |
| 246 return [node.offsetWidth, node.offsetHeight]; |
| 247 else |
| 248 return null; |
| 249 } |
| 250 |
| 251 let size = null; |
| 252 for (let id of requests) |
| 253 { |
| 254 if (!this.nodes.has(id)) |
| 255 continue; |
| 256 |
| 257 let node = this.nodes.get(id); |
| 258 if (Cu.isDeadWrapper(node)) |
| 259 this.nodes.delete(node); |
| 260 else |
| 261 { |
| 262 size = getNodeSize(node); |
| 263 if (size) |
| 264 break; |
| 265 } |
| 266 } |
| 267 sendAsyncMessage("AdblockPlus:RetrieveNodeSizeResponse", { |
| 268 notifierID: this.id, |
| 269 responseID, |
| 270 size |
| 271 }); |
220 } | 272 } |
221 }; | 273 }; |
222 | 274 |
223 /** | 275 /** |
224 * Attaches request data to a DOM node. | 276 * Attaches request data to a DOM node. |
225 * @param {Node} node node to attach data to | 277 * @param {Node} node node to attach data to |
226 * @param {Window} topWnd top-level window the node belongs to | 278 * @param {Window} topWnd top-level window the node belongs to |
227 * @param {String} contentType request type, e.g. "IMAGE" | 279 * @param {String} contentType request type, e.g. "IMAGE" |
228 * @param {String} docDomain domain of the document that initiated the request | 280 * @param {String} docDomain domain of the document that initiated the request |
229 * @param {Boolean} thirdParty will be true if a third-party server has been re
quested | 281 * @param {Boolean} thirdParty will be true if a third-party server has been re
quested |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 stats.filters[filter.text]++; | 329 stats.filters[filter.text]++; |
278 else | 330 else |
279 stats.filters[filter.text] = 1; | 331 stats.filters[filter.text] = 1; |
280 } | 332 } |
281 | 333 |
282 // Notify listeners | 334 // Notify listeners |
283 for (let notifier of notifiers.values()) | 335 for (let notifier of notifiers.values()) |
284 if (!notifier.window || notifier.window == topWnd) | 336 if (!notifier.window || notifier.window == topWnd) |
285 notifier.notifyListener(node, entry); | 337 notifier.notifyListener(node, entry); |
286 } | 338 } |
OLD | NEW |