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

Delta Between Two Patch Sets: lib/child/requestNotifier.js

Issue 29329810: Issue 3274 - Unbreak collecting window stats (Closed)
Left Patch Set: Created Nov. 6, 2015, 12:35 p.m.
Right Patch Set: Rebased and improved JSDoc comments Created Nov. 12, 2015, 3:08 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/child/contentPolicy.js ('k') | lib/contentPolicy.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 let {notifierID, responseID, requests} = message.data; 73 let {notifierID, responseID, requests} = message.data;
74 let notifier = notifiers.get(notifierID); 74 let notifier = notifiers.get(notifierID);
75 if (notifier) 75 if (notifier)
76 notifier.retrieveNodeSize(requests, responseID); 76 notifier.retrieveNodeSize(requests, responseID);
77 } 77 }
78 78
79 /** 79 /**
80 * 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
81 * 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
82 * complete only new requests for this window will be reported. 82 * complete only new requests for this window will be reported.
83 * @param {Window} wnd window to attach the notifier to 83 * @param {Window} window window to attach the notifier to
84 * @param {Integer} id Parent notifier ID to be messaged 84 * @param {Integer} notifierID Parent notifier ID to be messaged
85 */ 85 */
86 function RequestNotifier(window, notifierID) 86 function RequestNotifier(window, notifierID)
87 { 87 {
88 this.window = window; 88 this.window = window;
89 this.id = notifierID; 89 this.id = notifierID;
90 notifiers.set(this.id, this); 90 notifiers.set(this.id, this);
91 this.nodes = new Map(); 91 this.nodes = new Map();
92 this.startScan(window); 92 this.startScan(window);
93 } 93 }
94 exports.RequestNotifier = RequestNotifier; 94 exports.RequestNotifier = RequestNotifier;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 * Starts the initial scan of the window (will recurse into frames). 155 * Starts the initial scan of the window (will recurse into frames).
156 * @param {Window} wnd the window to be scanned 156 * @param {Window} wnd the window to be scanned
157 */ 157 */
158 startScan: function(wnd) 158 startScan: function(wnd)
159 { 159 {
160 let doc = wnd.document; 160 let doc = wnd.document;
161 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul l, false); 161 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul l, false);
162 162
163 let process = function() 163 let process = function()
164 { 164 {
165 // Don't do anything if the notifier was shut down already.
165 if (!this.window) 166 if (!this.window)
166 return; 167 return;
167 168
168 let node = walker.currentNode; 169 let node = walker.currentNode;
169 let data = nodeData.get(node); 170 let data = nodeData.get(node);
170 if (typeof data != "undefined") 171 if (typeof data != "undefined")
171 for (let k in data) 172 for (let k in data)
172 this.notifyListener(node, data[k]); 173 this.notifyListener(node, data[k]);
173 174
174 if (walker.nextNode()) 175 if (walker.nextNode())
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 responseID, 270 responseID,
270 size 271 size
271 }); 272 });
272 } 273 }
273 }; 274 };
274 275
275 /** 276 /**
276 * Attaches request data to a DOM node. 277 * Attaches request data to a DOM node.
277 * @param {Node} node node to attach data to 278 * @param {Node} node node to attach data to
278 * @param {Window} topWnd top-level window the node belongs to 279 * @param {Window} topWnd top-level window the node belongs to
279 * @param {String} contentType request type, e.g. "IMAGE" 280 * @param {Object} hitData
280 * @param {String} docDomain domain of the document that initiated the request 281 * @param {String} hitData.contentType request type, e.g. "IMAGE"
281 * @param {Boolean} thirdParty will be true if a third-party server has been re quested 282 * @param {String} hitData.docDomain domain of the document that initiated the request
282 * @param {String} location the address that has been requested 283 * @param {Boolean} hitData.thirdParty will be true if a third-party server has been requested
283 * @param {String} filter filter applied to the request or null if none 284 * @param {String} hitData.location the address that has been requested
284 * @param {String} filterType type of filter applied to the request 285 * @param {String} hitData.filter filter applied to the request or null if non e
286 * @param {String} hitData.filterType type of filter applied to the request
285 */ 287 */
286 RequestNotifier.addNodeData = function(node, topWnd, {contentType, docDomain, th irdParty, location, filter, filterType}) 288 RequestNotifier.addNodeData = function(node, topWnd, {contentType, docDomain, th irdParty, location, filter, filterType})
287 { 289 {
288 let entry = { 290 let entry = {
289 id: ++requestEntryMaxId, 291 id: ++requestEntryMaxId,
290 type: contentType, 292 type: contentType,
291 docDomain, thirdParty, location, filter 293 docDomain, thirdParty, location, filter
292 }; 294 };
293 295
294 let existingData = nodeData.get(node); 296 let existingData = nodeData.get(node);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 stats.filters[filter]++; 331 stats.filters[filter]++;
330 else 332 else
331 stats.filters[filter] = 1; 333 stats.filters[filter] = 1;
332 } 334 }
333 335
334 // Notify listeners 336 // Notify listeners
335 for (let notifier of notifiers.values()) 337 for (let notifier of notifiers.values())
336 if (!notifier.window || notifier.window == topWnd) 338 if (!notifier.window || notifier.window == topWnd)
337 notifier.notifyListener(node, entry); 339 notifier.notifyListener(node, entry);
338 } 340 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld