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

Side by Side Diff: lib/child/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 19 matching lines...) Expand all
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:StoreNodesForEntries", onStoreNodes);
40 addMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats); 41 addMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats);
41 42
42 onShutdown.add(() => { 43 onShutdown.add(() => {
43 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan); 44 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan);
44 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); 45 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown);
45 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes); 46 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes);
46 removeMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize); 47 removeMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize);
48 removeMessageListener("AdblockPlus:StoreNodesForEntries", onStoreNodes);
47 removeMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats ); 49 removeMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats );
48 }); 50 });
49 51
50 function onStartScan(message) 52 function onStartScan(message)
51 { 53 {
52 let {notifierID, outerWindowID} = message.data; 54 let {notifierID, outerWindowID} = message.data;
53 let window = Services.wm.getOuterWindowWithId(outerWindowID); 55 let window = Services.wm.getOuterWindowWithId(outerWindowID);
54 if (window) 56 if (window)
55 new RequestNotifier(window, notifierID); 57 new RequestNotifier(window, notifierID);
56 } 58 }
(...skipping 14 matching lines...) Expand all
71 } 73 }
72 74
73 function onRetrieveNodeSize(message) 75 function onRetrieveNodeSize(message)
74 { 76 {
75 let {notifierID, responseID, requests} = message.data; 77 let {notifierID, responseID, requests} = message.data;
76 let notifier = notifiers.get(notifierID); 78 let notifier = notifiers.get(notifierID);
77 if (notifier) 79 if (notifier)
78 notifier.retrieveNodeSize(requests, responseID); 80 notifier.retrieveNodeSize(requests, responseID);
79 } 81 }
80 82
83 function onStoreNodes(message)
84 {
85 let {notifierID, responseID, requests} = message.data;
86 let notifier = notifiers.get(notifierID);
87 if (notifier)
88 notifier.storeNodesForEntries(requests, responseID);
89 }
90
81 function onRetrieveWindowStats(message) 91 function onRetrieveWindowStats(message)
82 { 92 {
83 let {responseID, outerWindowID} = message.data; 93 let {responseID, outerWindowID} = message.data;
84 let window = Services.wm.getOuterWindowWithId(outerWindowID); 94 let window = Services.wm.getOuterWindowWithId(outerWindowID);
85 if (window) 95 if (window)
86 { 96 {
87 let stats = RequestNotifier.getWindowStatistics(window); 97 let stats = RequestNotifier.getWindowStatistics(window);
88 sendAsyncMessage("AdblockPlus:RetrieveWindowStatsResponse", { 98 sendAsyncMessage("AdblockPlus:RetrieveWindowStatsResponse", {
89 responseID, 99 responseID,
90 stats 100 stats
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 let node = this.nodes.get(id); 284 let node = this.nodes.get(id);
275 if (Cu.isDeadWrapper(node)) 285 if (Cu.isDeadWrapper(node))
276 this.nodes.delete(node); 286 this.nodes.delete(node);
277 else 287 else
278 { 288 {
279 size = getNodeSize(node); 289 size = getNodeSize(node);
280 if (size) 290 if (size)
281 break; 291 break;
282 } 292 }
283 } 293 }
284 sendAsyncMessage("AdblockPlus:RetrieveNodeSizeResponse", { 294 sendAsyncMessage("AdblockPlus:NotifierResponse", {
285 notifierID: this.id, 295 notifierID: this.id,
286 responseID, 296 responseID,
287 size 297 response: size
298 });
299 },
300
301 /**
302 * Stores the nodes associated with the requests and generates a unique ID
303 * for them that can be used with Policy.refilterNodes(). Sends message to
304 * parent when complete.
305 * @param {number[]} requests list of request IDs that were previously
306 * reported by this notifier.
307 * @param {number} responseID ID to be sent with the response.
308 */
309 storeNodesForEntries: function(requests, responseID)
310 {
311 let nodes = [];
312 for (let id of requests)
313 {
314 if (!this.nodes.has(id))
315 continue;
316
317 let node = this.nodes.get(id);
318 if (Cu.isDeadWrapper(node))
319 this.nodes.delete(node);
320 else
321 nodes.push(node);
322 }
323
324 let {storeNodes} = require("child/contentPolicy");
325 let id = storeNodes(nodes);
326 sendAsyncMessage("AdblockPlus:NotifierResponse", {
327 notifierID: this.id,
328 responseID,
329 response: id
288 }); 330 });
289 } 331 }
290 }; 332 };
291 333
292 /** 334 /**
293 * Attaches request data to a DOM node. 335 * Attaches request data to a DOM node.
294 * @param {Node} node node to attach data to 336 * @param {Node} node node to attach data to
295 * @param {Window} topWnd top-level window the node belongs to 337 * @param {Window} topWnd top-level window the node belongs to
296 * @param {Object} hitData 338 * @param {Object} hitData
297 * @param {String} hitData.contentType request type, e.g. "IMAGE" 339 * @param {String} hitData.contentType request type, e.g. "IMAGE"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 node = node.parentNode; 447 node = node.parentNode;
406 } 448 }
407 else 449 else
408 { 450 {
409 node = null; 451 node = null;
410 } 452 }
411 } 453 }
412 454
413 return null; 455 return null;
414 }; 456 };
OLDNEW
« lib/child/contentPolicy.js ('K') | « lib/child/objectTabs.js ('k') | lib/contentPolicy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld