| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 responseID, | 89 responseID, |
| 90 stats | 90 stats |
| 91 }); | 91 }); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * Creates a notifier object for a particular window. After creation the window | 96 * Creates a notifier object for a particular window. After creation the window |
| 97 * will first be scanned for previously saved requests. Once that scan is | 97 * will first be scanned for previously saved requests. Once that scan is |
| 98 * complete only new requests for this window will be reported. | 98 * complete only new requests for this window will be reported. |
| 99 * @param {Window} wnd window to attach the notifier to | 99 * @param {Window} window window to attach the notifier to |
| 100 * @param {Integer} id Parent notifier ID to be messaged | 100 * @param {Integer} notifierID Parent notifier ID to be messaged |
| 101 */ | 101 */ |
| 102 function RequestNotifier(window, notifierID) | 102 function RequestNotifier(window, notifierID) |
| 103 { | 103 { |
| 104 this.window = window; | 104 this.window = window; |
| 105 this.id = notifierID; | 105 this.id = notifierID; |
| 106 notifiers.set(this.id, this); | 106 notifiers.set(this.id, this); |
| 107 this.nodes = new Map(); | 107 this.nodes = new Map(); |
| 108 this.startScan(window); | 108 this.startScan(window); |
| 109 } | 109 } |
| 110 exports.RequestNotifier = RequestNotifier; | 110 exports.RequestNotifier = RequestNotifier; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 * Starts the initial scan of the window (will recurse into frames). | 171 * Starts the initial scan of the window (will recurse into frames). |
| 172 * @param {Window} wnd the window to be scanned | 172 * @param {Window} wnd the window to be scanned |
| 173 */ | 173 */ |
| 174 startScan: function(wnd) | 174 startScan: function(wnd) |
| 175 { | 175 { |
| 176 let doc = wnd.document; | 176 let doc = wnd.document; |
| 177 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul
l, false); | 177 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul
l, false); |
| 178 | 178 |
| 179 let process = function() | 179 let process = function() |
| 180 { | 180 { |
| 181 // Don't do anything if the notifier was shut down already. |
| 181 if (!this.window) | 182 if (!this.window) |
| 182 return; | 183 return; |
| 183 | 184 |
| 184 let node = walker.currentNode; | 185 let node = walker.currentNode; |
| 185 let data = nodeData.get(node); | 186 let data = nodeData.get(node); |
| 186 if (typeof data != "undefined") | 187 if (typeof data != "undefined") |
| 187 for (let k in data) | 188 for (let k in data) |
| 188 this.notifyListener(node, data[k]); | 189 this.notifyListener(node, data[k]); |
| 189 | 190 |
| 190 if (walker.nextNode()) | 191 if (walker.nextNode()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 206 | 207 |
| 207 // Process each node in a separate event to allow other events to process | 208 // Process each node in a separate event to allow other events to process |
| 208 this.eventsPosted++; | 209 this.eventsPosted++; |
| 209 Utils.runAsync(process); | 210 Utils.runAsync(process); |
| 210 }, | 211 }, |
| 211 | 212 |
| 212 /** | 213 /** |
| 213 * Makes the nodes associated with the given requests blink. | 214 * Makes the nodes associated with the given requests blink. |
| 214 * @param {number[]} requests list of request IDs that were previously | 215 * @param {number[]} requests list of request IDs that were previously |
| 215 * reported by this notifier. | 216 * reported by this notifier. |
| 216 * @param {Boolean} scrollToItem if true, scroll to first node | 217 * @param {boolean} scrollToItem if true, scroll to first node |
| 217 */ | 218 */ |
| 218 flashNodes: function(requests, scrollToItem) | 219 flashNodes: function(requests, scrollToItem) |
| 219 { | 220 { |
| 220 this.stopFlashing(); | 221 this.stopFlashing(); |
| 221 | 222 |
| 222 let nodes = []; | 223 let nodes = []; |
| 223 for (let id of requests) | 224 for (let id of requests) |
| 224 { | 225 { |
| 225 if (!this.nodes.has(id)) | 226 if (!this.nodes.has(id)) |
| 226 continue; | 227 continue; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 responseID, | 286 responseID, |
| 286 size | 287 size |
| 287 }); | 288 }); |
| 288 } | 289 } |
| 289 }; | 290 }; |
| 290 | 291 |
| 291 /** | 292 /** |
| 292 * Attaches request data to a DOM node. | 293 * Attaches request data to a DOM node. |
| 293 * @param {Node} node node to attach data to | 294 * @param {Node} node node to attach data to |
| 294 * @param {Window} topWnd top-level window the node belongs to | 295 * @param {Window} topWnd top-level window the node belongs to |
| 295 * @param {String} contentType request type, e.g. "IMAGE" | 296 * @param {Object} hitData |
| 296 * @param {String} docDomain domain of the document that initiated the request | 297 * @param {String} hitData.contentType request type, e.g. "IMAGE" |
| 297 * @param {Boolean} thirdParty will be true if a third-party server has been re
quested | 298 * @param {String} hitData.docDomain domain of the document that initiated the
request |
| 298 * @param {String} location the address that has been requested | 299 * @param {Boolean} hitData.thirdParty will be true if a third-party server has
been requested |
| 299 * @param {String} filter filter applied to the request or null if none | 300 * @param {String} hitData.location the address that has been requested |
| 300 * @param {String} filterType type of filter applied to the request | 301 * @param {String} hitData.filter filter applied to the request or null if non
e |
| 302 * @param {String} hitData.filterType type of filter applied to the request |
| 301 */ | 303 */ |
| 302 RequestNotifier.addNodeData = function(node, topWnd, {contentType, docDomain, th
irdParty, location, filter, filterType}) | 304 RequestNotifier.addNodeData = function(node, topWnd, {contentType, docDomain, th
irdParty, location, filter, filterType}) |
| 303 { | 305 { |
| 304 let entry = { | 306 let entry = { |
| 305 id: ++requestEntryMaxId, | 307 id: ++requestEntryMaxId, |
| 306 type: contentType, | 308 type: contentType, |
| 307 docDomain, thirdParty, location, filter | 309 docDomain, thirdParty, location, filter |
| 308 }; | 310 }; |
| 309 | 311 |
| 310 let existingData = nodeData.get(node); | 312 let existingData = nodeData.get(node); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 350 } |
| 349 | 351 |
| 350 // Notify listeners | 352 // Notify listeners |
| 351 for (let notifier of notifiers.values()) | 353 for (let notifier of notifiers.values()) |
| 352 if (!notifier.window || notifier.window == topWnd) | 354 if (!notifier.window || notifier.window == topWnd) |
| 353 notifier.notifyListener(node, entry); | 355 notifier.notifyListener(node, entry); |
| 354 } | 356 } |
| 355 | 357 |
| 356 /** | 358 /** |
| 357 * Retrieves the statistics for a window. | 359 * Retrieves the statistics for a window. |
| 358 * @result {Object} Object with the properties items, blocked, whitelisted, hidd
en, filters containing statistics for the window (might be null) | 360 * @return {Object} Object with the properties items, blocked, whitelisted, hidd
en, filters containing statistics for the window (might be null) |
| 359 */ | 361 */ |
| 360 RequestNotifier.getWindowStatistics = function(/**Window*/ wnd) | 362 RequestNotifier.getWindowStatistics = function(/**Window*/ wnd) |
| 361 { | 363 { |
| 362 if (windowStats.has(wnd.document)) | 364 if (windowStats.has(wnd.document)) |
| 363 return windowStats.get(wnd.document); | 365 return windowStats.get(wnd.document); |
| 364 else | 366 else |
| 365 return null; | 367 return null; |
| 366 } | 368 } |
| LEFT | RIGHT |