| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * @fileOverview Stores Adblock Plus data to be attached to a window. | 19 * @fileOverview Stores Adblock Plus data to be attached to a window. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 let {Utils} = require("utils"); |
| 23 |
| 22 let windowSelection = new WeakMap(); | 24 let windowSelection = new WeakMap(); |
| 23 let requestNotifierMaxId = 0; | 25 let requestNotifierMaxId = 0; |
| 24 | 26 |
| 25 /** | 27 /** |
| 26 * Active RequestNotifier instances by their ID | 28 * Active RequestNotifier instances by their ID |
| 27 * @type Map.<number,RequestNotifier> | 29 * @type Map.<number,RequestNotifier> |
| 28 */ | 30 */ |
| 29 let notifiers = new Map(); | 31 let notifiers = new Map(); |
| 30 | 32 |
| 31 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] | 33 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] |
| 32 .getService(Ci.nsIMessageListenerManager) | 34 .getService(Ci.nsIMessageListenerManager) |
| 33 .QueryInterface(Ci.nsIMessageBroadcaster); | 35 .QueryInterface(Ci.nsIMessageBroadcaster); |
| 34 messageManager.addMessageListener("AdblockPlus:FoundNodeData", onNodeData); | |
| 35 messageManager.addMessageListener("AdblockPlus:ScanComplete", onScanComplete); | |
| 36 | 36 |
| 37 onShutdown.add(() => { | 37 Utils.addChildMessageListener("AdblockPlus:FoundNodeData", onNodeData); |
| 38 messageManager.removeMessageListener("AdblockPlus:FoundNodeData", onNodeData); | 38 Utils.addChildMessageListener("AdblockPlus:ScanComplete", onScanComplete); |
| 39 messageManager.removeMessageListener("AdblockPlus:ScanComplete", onScanComplet
e); | |
| 40 }); | |
| 41 | 39 |
| 42 function onNodeData(message) | 40 function onNodeData({notifierID, data}) |
| 43 { | 41 { |
| 44 let {notifierID, data} = message.data; | |
| 45 let notifier = notifiers.get(notifierID); | 42 let notifier = notifiers.get(notifierID); |
| 46 if (notifier) | 43 if (notifier) |
| 47 notifier.notifyListener(data); | 44 notifier.notifyListener(data); |
| 48 } | 45 } |
| 49 | 46 |
| 50 function onScanComplete(message) | 47 function onScanComplete(notifierID) |
| 51 { | 48 { |
| 52 let notifier = notifiers.get(message.data); | 49 let notifier = notifiers.get(notifierID); |
| 53 if (notifier) | 50 if (notifier) |
| 54 notifier.onComplete(); | 51 notifier.onComplete(); |
| 55 } | 52 } |
| 56 | 53 |
| 57 /** | 54 /** |
| 58 * Creates a notifier object for a particular window. After creation the window | 55 * Creates a notifier object for a particular window. After creation the window |
| 59 * will first be scanned for previously saved requests. Once that scan is | 56 * will first be scanned for previously saved requests. Once that scan is |
| 60 * complete only new requests for this window will be reported. | 57 * complete only new requests for this window will be reported. |
| 61 * @param {Integer} outerWindowID ID of the window to attach the notifier to | 58 * @param {Integer} outerWindowID ID of the window to attach the notifier to |
| 62 * @param {Function} listener listener to be called whenever a new request is f
ound | 59 * @param {Function} listener listener to be called whenever a new request is f
ound |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 node = node.parentNode; | 187 node = node.parentNode; |
| 191 } | 188 } |
| 192 else | 189 else |
| 193 { | 190 { |
| 194 node = null; | 191 node = null; |
| 195 } | 192 } |
| 196 } | 193 } |
| 197 | 194 |
| 198 return null; | 195 return null; |
| 199 }; | 196 }; |
| OLD | NEW |