| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 73   let {notifierID, responseID, requests} = message.data; | 73   let {notifierID, responseID, requests} = message.data; | 
| 74   let notifier = notifiers.get(notifierID); | 74   let notifier = notifiers.get(notifierID); | 
| 75   if (notifier) | 75   if (notifier) | 
| 76     notifier.retrieveNodeSize(requests, responseID); | 76     notifier.retrieveNodeSize(requests, responseID); | 
| 77 } | 77 } | 
| 78 | 78 | 
| 79 /** | 79 /** | 
| 80  * 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 | 
| 81  * 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 | 
| 82  * complete only new requests for this window will be reported. | 82  * complete only new requests for this window will be reported. | 
| 83  * @param {Window} wnd  window to attach the notifier to | 83  * @param {Window} window  window to attach the notifier to | 
| 84  * @param {Integer} id  Parent notifier ID to be messaged | 84  * @param {Integer} notifierID  Parent notifier ID to be messaged | 
| 85  */ | 85  */ | 
| 86 function RequestNotifier(window, notifierID) | 86 function RequestNotifier(window, notifierID) | 
| 87 { | 87 { | 
| 88   this.window = window; | 88   this.window = window; | 
| 89   this.id = notifierID; | 89   this.id = notifierID; | 
| 90   notifiers.set(this.id, this); | 90   notifiers.set(this.id, this); | 
| 91   this.nodes = new Map(); | 91   this.nodes = new Map(); | 
| 92   this.startScan(window); | 92   this.startScan(window); | 
| 93 } | 93 } | 
| 94 exports.RequestNotifier = RequestNotifier; | 94 exports.RequestNotifier = RequestNotifier; | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 155    * Starts the initial scan of the window (will recurse into frames). | 155    * Starts the initial scan of the window (will recurse into frames). | 
| 156    * @param {Window} wnd  the window to be scanned | 156    * @param {Window} wnd  the window to be scanned | 
| 157    */ | 157    */ | 
| 158   startScan: function(wnd) | 158   startScan: function(wnd) | 
| 159   { | 159   { | 
| 160     let doc = wnd.document; | 160     let doc = wnd.document; | 
| 161     let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul
     l, false); | 161     let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul
     l, false); | 
| 162 | 162 | 
| 163     let process = function() | 163     let process = function() | 
| 164     { | 164     { | 
|  | 165       // Don't do anything if the notifier was shut down already. | 
| 165       if (!this.window) | 166       if (!this.window) | 
| 166         return; | 167         return; | 
| 167 | 168 | 
| 168       let node = walker.currentNode; | 169       let node = walker.currentNode; | 
| 169       let data = nodeData.get(node); | 170       let data = nodeData.get(node); | 
| 170       if (typeof data != "undefined") | 171       if (typeof data != "undefined") | 
| 171         for (let k in data) | 172         for (let k in data) | 
| 172           this.notifyListener(node, data[k]); | 173           this.notifyListener(node, data[k]); | 
| 173 | 174 | 
| 174       if (walker.nextNode()) | 175       if (walker.nextNode()) | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 190 | 191 | 
| 191     // Process each node in a separate event to allow other events to process | 192     // Process each node in a separate event to allow other events to process | 
| 192     this.eventsPosted++; | 193     this.eventsPosted++; | 
| 193     Utils.runAsync(process); | 194     Utils.runAsync(process); | 
| 194   }, | 195   }, | 
| 195 | 196 | 
| 196   /** | 197   /** | 
| 197    * Makes the nodes associated with the given requests blink. | 198    * Makes the nodes associated with the given requests blink. | 
| 198    * @param {number[]} requests  list of request IDs that were previously | 199    * @param {number[]} requests  list of request IDs that were previously | 
| 199    *                             reported by this notifier. | 200    *                             reported by this notifier. | 
| 200    * @param {Boolean} scrollToItem  if true, scroll to first node | 201    * @param {boolean} scrollToItem  if true, scroll to first node | 
| 201    */ | 202    */ | 
| 202   flashNodes: function(requests, scrollToItem) | 203   flashNodes: function(requests, scrollToItem) | 
| 203   { | 204   { | 
| 204     this.stopFlashing(); | 205     this.stopFlashing(); | 
| 205 | 206 | 
| 206     let nodes = []; | 207     let nodes = []; | 
| 207     for (let id of requests) | 208     for (let id of requests) | 
| 208     { | 209     { | 
| 209       if (!this.nodes.has(id)) | 210       if (!this.nodes.has(id)) | 
| 210         continue; | 211         continue; | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 269       responseID, | 270       responseID, | 
| 270       size | 271       size | 
| 271     }); | 272     }); | 
| 272   } | 273   } | 
| 273 }; | 274 }; | 
| 274 | 275 | 
| 275 /** | 276 /** | 
| 276  * Attaches request data to a DOM node. | 277  * Attaches request data to a DOM node. | 
| 277  * @param {Node} node   node to attach data to | 278  * @param {Node} node   node to attach data to | 
| 278  * @param {Window} topWnd   top-level window the node belongs to | 279  * @param {Window} topWnd   top-level window the node belongs to | 
| 279  * @param {String} contentType   request type, e.g. "IMAGE" | 280  * @param {Object} hitData | 
| 280  * @param {String} docDomain  domain of the document that initiated the request | 281  * @param {String} hitData.contentType   request type, e.g. "IMAGE" | 
| 281  * @param {Boolean} thirdParty  will be true if a third-party server has been re
     quested | 282  * @param {String} hitData.docDomain  domain of the document that initiated the 
     request | 
| 282  * @param {String} location   the address that has been requested | 283  * @param {Boolean} hitData.thirdParty  will be true if a third-party server has
      been requested | 
| 283  * @param {Filter} filter   filter applied to the request or null if none | 284  * @param {String} hitData.location   the address that has been requested | 
| 284  */ | 285  * @param {String} hitData.filter   filter applied to the request or null if non
     e | 
| 285 RequestNotifier.addNodeData = function(node, topWnd, contentType, docDomain, thi
     rdParty, location, filter) | 286  * @param {String} hitData.filterType  type of filter applied to the request | 
|  | 287  */ | 
|  | 288 RequestNotifier.addNodeData = function(node, topWnd, {contentType, docDomain, th
     irdParty, location, filter, filterType}) | 
| 286 { | 289 { | 
| 287   let entry = { | 290   let entry = { | 
| 288     id: ++requestEntryMaxId, | 291     id: ++requestEntryMaxId, | 
| 289     type: contentType, | 292     type: contentType, | 
| 290     docDomain, thirdParty, location, filter | 293     docDomain, thirdParty, location, filter | 
| 291   }; | 294   }; | 
| 292 | 295 | 
| 293   let existingData = nodeData.get(node); | 296   let existingData = nodeData.get(node); | 
| 294   if (typeof existingData == "undefined") | 297   if (typeof existingData == "undefined") | 
| 295   { | 298   { | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 306     windowStats.set(topWnd.document, { | 309     windowStats.set(topWnd.document, { | 
| 307       items: 0, | 310       items: 0, | 
| 308       hidden: 0, | 311       hidden: 0, | 
| 309       blocked: 0, | 312       blocked: 0, | 
| 310       whitelisted: 0, | 313       whitelisted: 0, | 
| 311       filters: {} | 314       filters: {} | 
| 312     }); | 315     }); | 
| 313   } | 316   } | 
| 314 | 317 | 
| 315   let stats = windowStats.get(topWnd.document); | 318   let stats = windowStats.get(topWnd.document); | 
| 316   let filterType = (filter ? filter.type : null); |  | 
| 317   if (filterType != "elemhide" && filterType != "elemhideexception" && filterTyp
     e != "cssproperty") | 319   if (filterType != "elemhide" && filterType != "elemhideexception" && filterTyp
     e != "cssproperty") | 
| 318     stats.items++; | 320     stats.items++; | 
| 319   if (filter) | 321   if (filter) | 
| 320   { | 322   { | 
| 321     if (filterType == "blocking") | 323     if (filterType == "blocking") | 
| 322       stats.blocked++; | 324       stats.blocked++; | 
| 323     else if (filterType == "whitelist" || filterType == "elemhideexception") | 325     else if (filterType == "whitelist" || filterType == "elemhideexception") | 
| 324       stats.whitelisted++; | 326       stats.whitelisted++; | 
| 325     else if (filterType == "elemhide" || filterType == "cssproperty") | 327     else if (filterType == "elemhide" || filterType == "cssproperty") | 
| 326       stats.hidden++; | 328       stats.hidden++; | 
| 327 | 329 | 
| 328     if (filter.text in stats.filters) | 330     if (filter in stats.filters) | 
| 329       stats.filters[filter.text]++; | 331       stats.filters[filter]++; | 
| 330     else | 332     else | 
| 331       stats.filters[filter.text] = 1; | 333       stats.filters[filter] = 1; | 
| 332   } | 334   } | 
| 333 | 335 | 
| 334   // Notify listeners | 336   // Notify listeners | 
| 335   for (let notifier of notifiers.values()) | 337   for (let notifier of notifiers.values()) | 
| 336     if (!notifier.window || notifier.window == topWnd) | 338     if (!notifier.window || notifier.window == topWnd) | 
| 337       notifier.notifyListener(node, entry); | 339       notifier.notifyListener(node, entry); | 
| 338 } | 340 } | 
| LEFT | RIGHT | 
|---|