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 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 let {notifierID, requests, scrollToItem} = message.data; | 63 let {notifierID, requests, scrollToItem} = message.data; |
64 let notifier = notifiers.get(notifierID); | 64 let notifier = notifiers.get(notifierID); |
65 if (notifier) | 65 if (notifier) |
66 notifier.flashNodes(requests, scrollToItem); | 66 notifier.flashNodes(requests, scrollToItem); |
67 } | 67 } |
68 | 68 |
69 /** | 69 /** |
70 * Creates a notifier object for a particular window. After creation the window | 70 * 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 | 71 * will first be scanned for previously saved requests. Once that scan is |
72 * complete only new requests for this window will be reported. | 72 * complete only new requests for this window will be reported. |
73 * @param {Window} wnd window to attach the notifier to | 73 * @param {Window} window window to attach the notifier to |
74 * @param {Integer} id Parent notifier ID to be messaged | 74 * @param {Integer} notifierID Parent notifier ID to be messaged |
75 */ | 75 */ |
76 function RequestNotifier(window, notifierID) | 76 function RequestNotifier(window, notifierID) |
77 { | 77 { |
78 this.window = window; | 78 this.window = window; |
79 this.id = notifierID; | 79 this.id = notifierID; |
80 notifiers.set(this.id, this); | 80 notifiers.set(this.id, this); |
81 this.nodes = new Map(); | 81 this.nodes = new Map(); |
82 this.startScan(window); | 82 this.startScan(window); |
83 } | 83 } |
84 exports.RequestNotifier = RequestNotifier; | 84 exports.RequestNotifier = RequestNotifier; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 * Starts the initial scan of the window (will recurse into frames). | 145 * Starts the initial scan of the window (will recurse into frames). |
146 * @param {Window} wnd the window to be scanned | 146 * @param {Window} wnd the window to be scanned |
147 */ | 147 */ |
148 startScan: function(wnd) | 148 startScan: function(wnd) |
149 { | 149 { |
150 let doc = wnd.document; | 150 let doc = wnd.document; |
151 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul
l, false); | 151 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul
l, false); |
152 | 152 |
153 let process = function() | 153 let process = function() |
154 { | 154 { |
| 155 // Don't do anything if the notifier was shut down already. |
155 if (!this.window) | 156 if (!this.window) |
156 return; | 157 return; |
157 | 158 |
158 let node = walker.currentNode; | 159 let node = walker.currentNode; |
159 let data = nodeData.get(node); | 160 let data = nodeData.get(node); |
160 if (typeof data != "undefined") | 161 if (typeof data != "undefined") |
161 for (let k in data) | 162 for (let k in data) |
162 this.notifyListener(node, data[k]); | 163 this.notifyListener(node, data[k]); |
163 | 164 |
164 if (walker.nextNode()) | 165 if (walker.nextNode()) |
(...skipping 15 matching lines...) Expand all Loading... |
180 | 181 |
181 // Process each node in a separate event to allow other events to process | 182 // Process each node in a separate event to allow other events to process |
182 this.eventsPosted++; | 183 this.eventsPosted++; |
183 Utils.runAsync(process); | 184 Utils.runAsync(process); |
184 }, | 185 }, |
185 | 186 |
186 /** | 187 /** |
187 * Makes the nodes associated with the given requests blink. | 188 * Makes the nodes associated with the given requests blink. |
188 * @param {number[]} requests list of request IDs that were previously | 189 * @param {number[]} requests list of request IDs that were previously |
189 * reported by this notifier. | 190 * reported by this notifier. |
190 * @param {Boolean} scrollToItem if true, scroll to first node | 191 * @param {boolean} scrollToItem if true, scroll to first node |
191 */ | 192 */ |
192 flashNodes: function(requests, scrollToItem) | 193 flashNodes: function(requests, scrollToItem) |
193 { | 194 { |
194 this.stopFlashing(); | 195 this.stopFlashing(); |
195 | 196 |
196 let nodes = []; | 197 let nodes = []; |
197 for (let id of requests) | 198 for (let id of requests) |
198 { | 199 { |
199 if (!this.nodes.has(id)) | 200 if (!this.nodes.has(id)) |
200 continue; | 201 continue; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 stats.filters[filter.text]++; | 278 stats.filters[filter.text]++; |
278 else | 279 else |
279 stats.filters[filter.text] = 1; | 280 stats.filters[filter.text] = 1; |
280 } | 281 } |
281 | 282 |
282 // Notify listeners | 283 // Notify listeners |
283 for (let notifier of notifiers.values()) | 284 for (let notifier of notifiers.values()) |
284 if (!notifier.window || notifier.window == topWnd) | 285 if (!notifier.window || notifier.window == topWnd) |
285 notifier.notifyListener(node, entry); | 286 notifier.notifyListener(node, entry); |
286 } | 287 } |
LEFT | RIGHT |