Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/requestNotifier.js

Issue 29329884: Issue 3224 - Unbreak filter assistant (Closed)
Patch Set: Rebased Created Nov. 12, 2015, 3:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 21 matching lines...) Expand all
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 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] 36 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
37 .getService(Ci.nsIMessageListenerManager) 37 .getService(Ci.nsIMessageListenerManager)
38 .QueryInterface(Ci.nsIMessageBroadcaster); 38 .QueryInterface(Ci.nsIMessageBroadcaster);
39 39
40 Utils.addChildMessageListener("AdblockPlus:FoundNodeData", onNodeData); 40 Utils.addChildMessageListener("AdblockPlus:FoundNodeData", onNodeData);
41 Utils.addChildMessageListener("AdblockPlus:ScanComplete", onScanComplete); 41 Utils.addChildMessageListener("AdblockPlus:ScanComplete", onScanComplete);
42 Utils.addChildMessageListener("AdblockPlus:RetrieveNodeSizeResponse", onNodeSize Received); 42 Utils.addChildMessageListener("AdblockPlus:NotifierResponse", onNotifierResponse );
43 Utils.addChildMessageListener("AdblockPlus:RetrieveWindowStatsResponse", onWindo wStatsReceived); 43 Utils.addChildMessageListener("AdblockPlus:RetrieveWindowStatsResponse", onWindo wStatsReceived);
44 44
45 function onNodeData({notifierID, data}) 45 function onNodeData({notifierID, data})
46 { 46 {
47 let notifier = notifiers.get(notifierID); 47 let notifier = notifiers.get(notifierID);
48 if (notifier) 48 if (notifier)
49 notifier.notifyListener(data); 49 notifier.notifyListener(data);
50 } 50 }
51 51
52 function onScanComplete(notifierID) 52 function onScanComplete(notifierID)
53 { 53 {
54 let notifier = notifiers.get(notifierID); 54 let notifier = notifiers.get(notifierID);
55 if (notifier) 55 if (notifier)
56 notifier.onComplete(); 56 notifier.onComplete();
57 } 57 }
58 58
59 function onNodeSizeReceived({notifierID, responseID, size}) 59 function onNotifierResponse({notifierID, responseID, response})
60 { 60 {
61 let notifier = notifiers.get(notifierID); 61 let notifier = notifiers.get(notifierID);
62 if (notifier) 62 if (notifier)
63 notifier.onNodeSizeReceived(responseID, size); 63 notifier.onResponse(responseID, response);
64 } 64 }
65 65
66 function onWindowStatsReceived({responseID, stats}) 66 function onWindowStatsReceived({responseID, stats})
67 { 67 {
68 let callback = windowStatsCallbacks.get(responseID); 68 let callback = windowStatsCallbacks.get(responseID);
69 windowStatsCallbacks.delete(responseID); 69 windowStatsCallbacks.delete(responseID);
70 if (typeof callback == "function") 70 if (typeof callback == "function")
71 callback(stats); 71 callback(stats);
72 } 72 }
73 73
74 /** 74 /**
75 * Creates a notifier object for a particular window. After creation the window 75 * Creates a notifier object for a particular window. After creation the window
76 * will first be scanned for previously saved requests. Once that scan is 76 * will first be scanned for previously saved requests. Once that scan is
77 * complete only new requests for this window will be reported. 77 * complete only new requests for this window will be reported.
78 * @param {Integer} outerWindowID ID of the window to attach the notifier to 78 * @param {Integer} outerWindowID ID of the window to attach the notifier to
79 * @param {Function} listener listener to be called whenever a new request is f ound 79 * @param {Function} listener listener to be called whenever a new request is f ound
80 * @param {Object} [listenerObj] "this" pointer to be used when calling the lis tener 80 * @param {Object} [listenerObj] "this" pointer to be used when calling the lis tener
81 */ 81 */
82 function RequestNotifier(outerWindowID, listener, listenerObj) 82 function RequestNotifier(outerWindowID, listener, listenerObj)
83 { 83 {
84 this.listener = listener; 84 this.listener = listener;
85 this.listenerObj = listenerObj || null; 85 this.listenerObj = listenerObj || null;
86 this.id = ++requestNotifierMaxId; 86 this.id = ++requestNotifierMaxId;
87 notifiers.set(this.id, this); 87 notifiers.set(this.id, this);
88 this._nodeSizeCallbacks = new Map(); 88 this._callbacks = new Map();
89 89
90 messageManager.broadcastAsyncMessage("AdblockPlus:StartWindowScan", { 90 messageManager.broadcastAsyncMessage("AdblockPlus:StartWindowScan", {
91 notifierID: this.id, 91 notifierID: this.id,
92 outerWindowID: outerWindowID 92 outerWindowID: outerWindowID
93 }); 93 });
94 } 94 }
95 exports.RequestNotifier = RequestNotifier; 95 exports.RequestNotifier = RequestNotifier;
96 96
97 RequestNotifier.prototype = 97 RequestNotifier.prototype =
98 { 98 {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (!requests) 156 if (!requests)
157 requests = []; 157 requests = [];
158 158
159 messageManager.broadcastAsyncMessage("AdblockPlus:FlashNodes", { 159 messageManager.broadcastAsyncMessage("AdblockPlus:FlashNodes", {
160 notifierID: this.id, 160 notifierID: this.id,
161 requests, 161 requests,
162 scrollToItem 162 scrollToItem
163 }); 163 });
164 }, 164 },
165 165
166 _nodeSizeMaxResponseID: 0, 166 _maxResponseID: 0,
167 _nodeSizeCallbacks: null, 167 _callbacks: null,
168 168
169 /** 169 /**
170 * Attempts to calculate the size of the nodes associated with the requests. 170 * Attempts to calculate the size of the nodes associated with the requests.
171 * Callback will only be called on success.
172 * @param {number[]} requests list of request IDs that were previously 171 * @param {number[]} requests list of request IDs that were previously
173 * reported by this notifier. 172 * reported by this notifier.
174 * @param {Function} callback function to be called with two parameters (x,y) 173 * @param {Function} callback function to be called with two parameters (x,y)
175 */ 174 */
176 retrieveNodeSize: function(requests, callback) 175 retrieveNodeSize: function(requests, callback)
177 { 176 {
178 if (!requests) 177 if (!requests)
179 requests = []; 178 requests = [];
180 179
181 let id = ++this._nodeSizeMaxResponseID; 180 let id = ++this._maxResponseID;
182 this._nodeSizeCallbacks.set(id, callback); 181 this._callbacks.set(id, callback);
183 182
184 messageManager.broadcastAsyncMessage("AdblockPlus:RetrieveNodeSize", { 183 messageManager.broadcastAsyncMessage("AdblockPlus:RetrieveNodeSize", {
185 notifierID: this.id, 184 notifierID: this.id,
186 responseID: id, 185 responseID: id,
187 requests, 186 requests,
188 }); 187 });
189 }, 188 },
190 189
191 onNodeSizeReceived: function(responseID, size) 190 onResponse: function(responseID, response)
192 { 191 {
193 let callback = this._nodeSizeCallbacks.get(responseID); 192 let callback = this._callbacks.get(responseID);
194 this._nodeSizeCallbacks.delete(responseID); 193 this._callbacks.delete(responseID);
195 if (size && typeof callback == "function") 194 if (typeof callback == "function")
196 callback(size); 195 callback(response);
196 },
197
198 /**
199 * Stores the nodes associated with the requests and generates a unique ID
200 * for them that can be used with Policy.refilterNodes(). Note that
201 * Policy.deleteNodes() always has to be called to release the memory.
202 * @param {number[]} requests list of request IDs that were previously
203 * reported by this notifier.
204 * @param {Function} callback function to be called with the nodes ID.
205 */
206 storeNodesForEntries: function(requests, callback)
207 {
208 if (!requests)
209 requests = [];
210
211 let id = ++this._maxResponseID;
212 this._callbacks.set(id, callback);
213
214 messageManager.broadcastAsyncMessage("AdblockPlus:StoreNodesForEntries", {
215 notifierID: this.id,
216 responseID: id,
217 requests,
218 });
197 } 219 }
198 }; 220 };
199 221
200 RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection ) 222 RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection )
201 { 223 {
202 windowSelection.set(wnd.document, selection); 224 windowSelection.set(wnd.document, selection);
203 }; 225 };
204 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/ 226 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/
205 { 227 {
206 if (windowSelection.has(wnd.document)) 228 if (windowSelection.has(wnd.document))
(...skipping 12 matching lines...) Expand all
219 RequestNotifier.getWindowStatistics = function(outerWindowID, callback) 241 RequestNotifier.getWindowStatistics = function(outerWindowID, callback)
220 { 242 {
221 let id = ++windowStatsMaxResponseID; 243 let id = ++windowStatsMaxResponseID;
222 windowStatsCallbacks.set(id, callback); 244 windowStatsCallbacks.set(id, callback);
223 245
224 messageManager.broadcastAsyncMessage("AdblockPlus:RetrieveWindowStats", { 246 messageManager.broadcastAsyncMessage("AdblockPlus:RetrieveWindowStats", {
225 responseID: id, 247 responseID: id,
226 outerWindowID 248 outerWindowID
227 }); 249 });
228 } 250 }
OLDNEW
« lib/child/contentPolicy.js ('K') | « lib/objectTabs.js ('k') | lib/ui.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld