| 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 19 matching lines...) Expand all Loading... |
| 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 addMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize); |
| 40 addMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats); |
| 40 | 41 |
| 41 onShutdown.add(() => { | 42 onShutdown.add(() => { |
| 42 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan); | 43 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan); |
| 43 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); | 44 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); |
| 44 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes); | 45 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes); |
| 45 removeMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize); | 46 removeMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize); |
| 47 removeMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats
); |
| 46 }); | 48 }); |
| 47 | 49 |
| 48 function onStartScan(message) | 50 function onStartScan(message) |
| 49 { | 51 { |
| 50 let {notifierID, outerWindowID} = message.data; | 52 let {notifierID, outerWindowID} = message.data; |
| 51 let window = Services.wm.getOuterWindowWithId(outerWindowID); | 53 let window = Services.wm.getOuterWindowWithId(outerWindowID); |
| 52 if (window) | 54 if (window) |
| 53 new RequestNotifier(window, notifierID); | 55 new RequestNotifier(window, notifierID); |
| 54 } | 56 } |
| 55 | 57 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 69 } | 71 } |
| 70 | 72 |
| 71 function onRetrieveNodeSize(message) | 73 function onRetrieveNodeSize(message) |
| 72 { | 74 { |
| 73 let {notifierID, responseID, requests} = message.data; | 75 let {notifierID, responseID, requests} = message.data; |
| 74 let notifier = notifiers.get(notifierID); | 76 let notifier = notifiers.get(notifierID); |
| 75 if (notifier) | 77 if (notifier) |
| 76 notifier.retrieveNodeSize(requests, responseID); | 78 notifier.retrieveNodeSize(requests, responseID); |
| 77 } | 79 } |
| 78 | 80 |
| 81 function onRetrieveWindowStats(message) |
| 82 { |
| 83 let {responseID, outerWindowID} = message.data; |
| 84 let window = Services.wm.getOuterWindowWithId(outerWindowID); |
| 85 if (window) |
| 86 { |
| 87 let stats = RequestNotifier.getWindowStatistics(window); |
| 88 sendAsyncMessage("AdblockPlus:RetrieveWindowStatsResponse", { |
| 89 responseID, |
| 90 stats |
| 91 }); |
| 92 } |
| 93 } |
| 94 |
| 79 /** | 95 /** |
| 80 * 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 |
| 81 * 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 |
| 82 * complete only new requests for this window will be reported. | 98 * complete only new requests for this window will be reported. |
| 83 * @param {Window} window window to attach the notifier to | 99 * @param {Window} window window to attach the notifier to |
| 84 * @param {Integer} notifierID Parent notifier ID to be messaged | 100 * @param {Integer} notifierID Parent notifier ID to be messaged |
| 85 */ | 101 */ |
| 86 function RequestNotifier(window, notifierID) | 102 function RequestNotifier(window, notifierID) |
| 87 { | 103 { |
| 88 this.window = window; | 104 this.window = window; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 stats.filters[filter]++; | 347 stats.filters[filter]++; |
| 332 else | 348 else |
| 333 stats.filters[filter] = 1; | 349 stats.filters[filter] = 1; |
| 334 } | 350 } |
| 335 | 351 |
| 336 // Notify listeners | 352 // Notify listeners |
| 337 for (let notifier of notifiers.values()) | 353 for (let notifier of notifiers.values()) |
| 338 if (!notifier.window || notifier.window == topWnd) | 354 if (!notifier.window || notifier.window == topWnd) |
| 339 notifier.notifyListener(node, entry); | 355 notifier.notifyListener(node, entry); |
| 340 } | 356 } |
| 357 |
| 358 /** |
| 359 * Retrieves the statistics for a window. |
| 360 * @return {Object} Object with the properties items, blocked, whitelisted, hidd
en, filters containing statistics for the window (might be null) |
| 361 */ |
| 362 RequestNotifier.getWindowStatistics = function(/**Window*/ wnd) |
| 363 { |
| 364 if (windowStats.has(wnd.document)) |
| 365 return windowStats.get(wnd.document); |
| 366 else |
| 367 return null; |
| 368 } |
| OLD | NEW |