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: Created Nov. 9, 2015, 1: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 | « lib/child/objectTabs.js ('k') | lib/contentPolicy.js » ('j') | 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
(...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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 let node = this.nodes.get(id); 283 let node = this.nodes.get(id);
274 if (Cu.isDeadWrapper(node)) 284 if (Cu.isDeadWrapper(node))
275 this.nodes.delete(node); 285 this.nodes.delete(node);
276 else 286 else
277 { 287 {
278 size = getNodeSize(node); 288 size = getNodeSize(node);
279 if (size) 289 if (size)
280 break; 290 break;
281 } 291 }
282 } 292 }
283 sendAsyncMessage("AdblockPlus:RetrieveNodeSizeResponse", { 293 sendAsyncMessage("AdblockPlus:NotifierResponse", {
284 notifierID: this.id, 294 notifierID: this.id,
285 responseID, 295 responseID,
286 size 296 response: size
297 });
298 },
299
300 /**
301 * Stores the nodes associated with the requests and generates a unique ID
302 * for them that can be used with Policy.refilterNodes(). Sends message to
303 * parent when complete.
304 * @param {number[]} requests list of request IDs that were previously
305 * reported by this notifier.
306 * @param {number} responseID ID to be sent with the response.
307 */
308 storeNodesForEntries: function(requests, responseID)
309 {
310 let nodes = [];
311 for (let id of requests)
312 {
313 if (!this.nodes.has(id))
314 continue;
315
316 let node = this.nodes.get(id);
317 if (Cu.isDeadWrapper(node))
318 this.nodes.delete(node);
319 else
320 nodes.push(node);
321 }
322
323 let {storeNodes} = require("child/contentPolicy");
324 let id = storeNodes(nodes);
325 sendAsyncMessage("AdblockPlus:NotifierResponse", {
326 notifierID: this.id,
327 responseID,
328 response: id
287 }); 329 });
288 } 330 }
289 }; 331 };
290 332
291 /** 333 /**
292 * Attaches request data to a DOM node. 334 * Attaches request data to a DOM node.
293 * @param {Node} node node to attach data to 335 * @param {Node} node node to attach data to
294 * @param {Window} topWnd top-level window the node belongs to 336 * @param {Window} topWnd top-level window the node belongs to
295 * @param {String} contentType request type, e.g. "IMAGE" 337 * @param {String} contentType request type, e.g. "IMAGE"
296 * @param {String} docDomain domain of the document that initiated the request 338 * @param {String} docDomain domain of the document that initiated the request
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 node = node.parentNode; 445 node = node.parentNode;
404 } 446 }
405 else 447 else
406 { 448 {
407 node = null; 449 node = null;
408 } 450 }
409 } 451 }
410 452
411 return null; 453 return null;
412 }; 454 };
OLDNEW
« no previous file with comments | « lib/child/objectTabs.js ('k') | lib/contentPolicy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld