| 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} window  window to attach the notifier to | 83  * @param {Window} window  window to attach the notifier to | 
| 74  * @param {Integer} notifierID  Parent notifier ID to be messaged | 84  * @param {Integer} notifierID  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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 211   }, | 221   }, | 
| 212 | 222 | 
| 213   /** | 223   /** | 
| 214    * Stops flashing nodes after a previous flashNodes() call. | 224    * Stops flashing nodes after a previous flashNodes() call. | 
| 215    */ | 225    */ | 
| 216   stopFlashing: function() | 226   stopFlashing: function() | 
| 217   { | 227   { | 
| 218     if (this.flasher) | 228     if (this.flasher) | 
| 219       this.flasher.stop(); | 229       this.flasher.stop(); | 
| 220     this.flasher = null; | 230     this.flasher = null; | 
|  | 231   }, | 
|  | 232 | 
|  | 233   /** | 
|  | 234    * Attempts to calculate the size of the nodes associated with the requests, | 
|  | 235    * Sends message to parent when complete. | 
|  | 236    * @param {number[]} requests  list of request IDs that were previously | 
|  | 237    *                             reported by this notifier. | 
|  | 238    * @param {number} responseID  ID to be sent with the response. | 
|  | 239    */ | 
|  | 240   retrieveNodeSize: function(requests, responseID) | 
|  | 241   { | 
|  | 242     function getNodeSize(node) | 
|  | 243     { | 
|  | 244       if (node instanceof Ci.nsIDOMHTMLImageElement && (node.naturalWidth || nod
     e.naturalHeight)) | 
|  | 245         return [node.naturalWidth, node.naturalHeight]; | 
|  | 246       else if (node instanceof Ci.nsIDOMHTMLElement && (node.offsetWidth || node
     .offsetHeight)) | 
|  | 247         return [node.offsetWidth, node.offsetHeight]; | 
|  | 248       else | 
|  | 249         return null; | 
|  | 250     } | 
|  | 251 | 
|  | 252     let size = null; | 
|  | 253     for (let id of requests) | 
|  | 254     { | 
|  | 255       if (!this.nodes.has(id)) | 
|  | 256         continue; | 
|  | 257 | 
|  | 258       let node = this.nodes.get(id); | 
|  | 259       if (Cu.isDeadWrapper(node)) | 
|  | 260         this.nodes.delete(node); | 
|  | 261       else | 
|  | 262       { | 
|  | 263         size = getNodeSize(node); | 
|  | 264         if (size) | 
|  | 265           break; | 
|  | 266       } | 
|  | 267     } | 
|  | 268     sendAsyncMessage("AdblockPlus:RetrieveNodeSizeResponse", { | 
|  | 269       notifierID: this.id, | 
|  | 270       responseID, | 
|  | 271       size | 
|  | 272     }); | 
| 221   } | 273   } | 
| 222 }; | 274 }; | 
| 223 | 275 | 
| 224 /** | 276 /** | 
| 225  * Attaches request data to a DOM node. | 277  * Attaches request data to a DOM node. | 
| 226  * @param {Node} node   node to attach data to | 278  * @param {Node} node   node to attach data to | 
| 227  * @param {Window} topWnd   top-level window the node belongs to | 279  * @param {Window} topWnd   top-level window the node belongs to | 
| 228  * @param {String} contentType   request type, e.g. "IMAGE" | 280  * @param {String} contentType   request type, e.g. "IMAGE" | 
| 229  * @param {String} docDomain  domain of the document that initiated the request | 281  * @param {String} docDomain  domain of the document that initiated the request | 
| 230  * @param {Boolean} thirdParty  will be true if a third-party server has been re
     quested | 282  * @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... | 
| 278       stats.filters[filter.text]++; | 330       stats.filters[filter.text]++; | 
| 279     else | 331     else | 
| 280       stats.filters[filter.text] = 1; | 332       stats.filters[filter.text] = 1; | 
| 281   } | 333   } | 
| 282 | 334 | 
| 283   // Notify listeners | 335   // Notify listeners | 
| 284   for (let notifier of notifiers.values()) | 336   for (let notifier of notifiers.values()) | 
| 285     if (!notifier.window || notifier.window == topWnd) | 337     if (!notifier.window || notifier.window == topWnd) | 
| 286       notifier.notifyListener(node, entry); | 338       notifier.notifyListener(node, entry); | 
| 287 } | 339 } | 
| OLD | NEW | 
|---|