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

Side by Side Diff: lib/requestNotifier.js

Issue 29329502: Issue 3222 - Add unique request notifier ID (Closed)
Patch Set: Created Oct. 29, 2015, 6:45 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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 Cu.import("resource://gre/modules/Services.jsm"); 22 Cu.import("resource://gre/modules/Services.jsm");
23 23
24 let {Utils} = require("utils"); 24 let {Utils} = require("utils");
25 let {BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, ElemHideExce ption} = require("filterClasses"); 25 let {BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, ElemHideExce ption} = require("filterClasses");
26 26
27 let nodeData = new WeakMap(); 27 let nodeData = new WeakMap();
28 let windowStats = new WeakMap(); 28 let windowStats = new WeakMap();
29 let windowSelection = new WeakMap(); 29 let windowSelection = new WeakMap();
30 let requestNotifierMaxId = 0;
30 let requestEntryMaxId = 0; 31 let requestEntryMaxId = 0;
31 32
32 /** 33 /**
33 * List of notifiers in use - these notifiers need to receive notifications on 34 * Active RequestNotifier instances by their ID
34 * new requests. 35 * @type Map
35 * @type RequestNotifier[]
36 */ 36 */
37 let activeNotifiers = []; 37 let notifiers = new Map();
38 38
39 /** 39 /**
40 * Creates a notifier object for a particular window. After creation the window 40 * Creates a notifier object for a particular window. After creation the window
41 * will first be scanned for previously saved requests. Once that scan is 41 * will first be scanned for previously saved requests. Once that scan is
42 * complete only new requests for this window will be reported. 42 * complete only new requests for this window will be reported.
43 * @param {Window} wnd window to attach the notifier to 43 * @param {Window} wnd window to attach the notifier to
44 * @param {Function} listener listener to be called whenever a new request is f ound 44 * @param {Function} listener listener to be called whenever a new request is f ound
45 * @param {Object} [listenerObj] "this" pointer to be used when calling the lis tener 45 * @param {Object} [listenerObj] "this" pointer to be used when calling the lis tener
46 */ 46 */
47 function RequestNotifier(wnd, listener, listenerObj) 47 function RequestNotifier(wnd, listener, listenerObj)
48 { 48 {
49 this.window = wnd; 49 this.window = wnd;
50 this.listener = listener; 50 this.listener = listener;
51 this.listenerObj = listenerObj || null; 51 this.listenerObj = listenerObj || null;
52 activeNotifiers.push(this); 52 this.id = ++requestNotifierMaxId;
53 notifiers.set(this.id, this);
53 if (wnd) 54 if (wnd)
54 this.startScan(wnd); 55 this.startScan(wnd);
55 else 56 else
56 this.scanComplete = true; 57 this.scanComplete = true;
57 } 58 }
58 exports.RequestNotifier = RequestNotifier; 59 exports.RequestNotifier = RequestNotifier;
59 60
60 RequestNotifier.prototype = 61 RequestNotifier.prototype =
61 { 62 {
62 /** 63 /**
64 * The unique ID of this notifier.
65 * @type Integer
66 */
67 id: null,
68
69 /**
63 * The window this notifier is associated with. 70 * The window this notifier is associated with.
64 * @type Window 71 * @type Window
65 */ 72 */
66 window: null, 73 window: null,
67 74
68 /** 75 /**
69 * The listener to be called when a new request is found. 76 * The listener to be called when a new request is found.
70 * @type Function 77 * @type Function
71 */ 78 */
72 listener: null, 79 listener: null,
(...skipping 13 matching lines...) Expand all
86 /** 93 /**
87 * Shuts down the notifier once it is no longer used. The listener 94 * Shuts down the notifier once it is no longer used. The listener
88 * will no longer be called after that. 95 * will no longer be called after that.
89 */ 96 */
90 shutdown: function() 97 shutdown: function()
91 { 98 {
92 delete this.window; 99 delete this.window;
93 delete this.listener; 100 delete this.listener;
94 delete this.listenerObj; 101 delete this.listenerObj;
95 102
96 for (let i = activeNotifiers.length - 1; i >= 0; i--) 103 notifiers.delete(this.id);
97 if (activeNotifiers[i] == this)
98 activeNotifiers.splice(i, 1);
99 }, 104 },
100 105
101 /** 106 /**
102 * Notifies listener about a new request. 107 * Notifies listener about a new request.
103 * @param {Window} wnd 108 * @param {Window} wnd
104 * @param {Node} node 109 * @param {Node} node
105 * @param {RequestEntry} entry 110 * @param {RequestEntry} entry
106 */ 111 */
107 notifyListener: function(wnd, node, entry) 112 notifyListener: function(wnd, node, entry)
108 { 113 {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 else if (filter instanceof ElemHideFilter) 283 else if (filter instanceof ElemHideFilter)
279 stats.hidden++; 284 stats.hidden++;
280 285
281 if (filter.text in stats.filters) 286 if (filter.text in stats.filters)
282 stats.filters[filter.text]++; 287 stats.filters[filter.text]++;
283 else 288 else
284 stats.filters[filter.text] = 1; 289 stats.filters[filter.text] = 1;
285 } 290 }
286 291
287 // Notify listeners 292 // Notify listeners
288 for (let notifier of activeNotifiers) 293 for (let notifier of notifiers.values())
289 if (!notifier.window || notifier.window == topWnd) 294 if (!notifier.window || notifier.window == topWnd)
290 notifier.notifyListener(topWnd, node, this); 295 notifier.notifyListener(topWnd, node, this);
291 } 296 }
292 RequestEntry.prototype = 297 RequestEntry.prototype =
293 { 298 {
294 /** 299 /**
295 * id of request (used to determine last entry attached to a node) 300 * id of request (used to determine last entry attached to a node)
296 * @type integer 301 * @type integer
297 */ 302 */
298 id: 0, 303 id: 0,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 if (typeof existingData == "undefined") 336 if (typeof existingData == "undefined")
332 { 337 {
333 existingData = {}; 338 existingData = {};
334 nodeData.set(node, existingData); 339 nodeData.set(node, existingData);
335 } 340 }
336 341
337 // Add this request to the node data 342 // Add this request to the node data
338 existingData[this.type + " " + this.location] = this; 343 existingData[this.type + " " + this.location] = this;
339 } 344 }
340 }; 345 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld