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

Side by Side Diff: lib/child/requestNotifier.js

Issue 29333172: Issue 3259 - Store blockable items selection in the content process (Closed)
Patch Set: Created Jan. 4, 2016, 8:08 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
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 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); 21 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
22 22
23 let {Utils} = require("utils"); 23 let {Utils} = require("utils");
24 let {Flasher} = require("child/flasher"); 24 let {Flasher} = require("child/flasher");
25 25
26 let nodeData = new WeakMap(); 26 let nodeData = new WeakMap();
27 let windowStats = new WeakMap(); 27 let windowStats = new WeakMap();
28 let windowData = new WeakMap();
28 let requestEntryMaxId = 0; 29 let requestEntryMaxId = 0;
29 30
30 /** 31 /**
31 * Active RequestNotifier instances by their ID 32 * Active RequestNotifier instances by their ID
32 * @type Map.<number,RequestNotifier> 33 * @type Map.<number,RequestNotifier>
33 */ 34 */
34 let notifiers = new Map(); 35 let notifiers = new Map();
35 36
36 addMessageListener("AdblockPlus:StartWindowScan", onStartScan); 37 addMessageListener("AdblockPlus:StartWindowScan", onStartScan);
37 addMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); 38 addMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown);
38 addMessageListener("AdblockPlus:FlashNodes", onFlashNodes); 39 addMessageListener("AdblockPlus:FlashNodes", onFlashNodes);
39 addMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize); 40 addMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize);
40 addMessageListener("AdblockPlus:StoreNodesForEntries", onStoreNodes); 41 addMessageListener("AdblockPlus:StoreNodesForEntries", onStoreNodes);
41 addMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats); 42 addMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats);
43 addMessageListener("AdblockPlus:StoreWindowData", onStoreWindowData);
44 addMessageListener("AdblockPlus:RetrieveWindowData", onRetrieveWindowData);
42 45
43 onShutdown.add(() => { 46 onShutdown.add(() => {
44 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan); 47 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan);
45 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); 48 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown);
46 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes); 49 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes);
47 removeMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize); 50 removeMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize);
48 removeMessageListener("AdblockPlus:StoreNodesForEntries", onStoreNodes); 51 removeMessageListener("AdblockPlus:StoreNodesForEntries", onStoreNodes);
49 removeMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats ); 52 removeMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats );
53 removeMessageListener("AdblockPlus:StoreWindowData", onStoreWindowData);
54 removeMessageListener("AdblockPlus:RetrieveWindowData", onRetrieveWindowData);
50 }); 55 });
51 56
52 function onStartScan(message) 57 function onStartScan(message)
53 { 58 {
54 let {notifierID, outerWindowID} = message.data; 59 let {notifierID, outerWindowID} = message.data;
55 let window = Services.wm.getOuterWindowWithId(outerWindowID); 60 let window = Services.wm.getOuterWindowWithId(outerWindowID);
56 if (window) 61 if (window)
57 new RequestNotifier(window, notifierID); 62 new RequestNotifier(window, notifierID);
58 } 63 }
59 64
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if (window) 100 if (window)
96 { 101 {
97 let stats = RequestNotifier.getWindowStatistics(window); 102 let stats = RequestNotifier.getWindowStatistics(window);
98 sendAsyncMessage("AdblockPlus:RetrieveWindowStatsResponse", { 103 sendAsyncMessage("AdblockPlus:RetrieveWindowStatsResponse", {
99 responseID, 104 responseID,
100 stats 105 stats
101 }); 106 });
102 } 107 }
103 } 108 }
104 109
110 function onStoreWindowData(message)
111 {
112 let {outerWindowID, data} = message.data;
113 let window = Services.wm.getOuterWindowWithId(outerWindowID);
114 if (window)
115 windowData.set(window.document, data);
116 };
117
118 function onRetrieveWindowData(message)
119 {
120 let {responseID, outerWindowID} = message.data;
121 let window = Services.wm.getOuterWindowWithId(outerWindowID);
122 if (window)
123 {
124 let data = windowData.get(window.document) || null;
125 sendAsyncMessage("AdblockPlus:RetrieveWindowDataResponse", {
126 responseID,
127 data
128 });
129 }
130 };
131
105 /** 132 /**
106 * Creates a notifier object for a particular window. After creation the window 133 * Creates a notifier object for a particular window. After creation the window
107 * will first be scanned for previously saved requests. Once that scan is 134 * will first be scanned for previously saved requests. Once that scan is
108 * complete only new requests for this window will be reported. 135 * complete only new requests for this window will be reported.
109 * @param {Window} window window to attach the notifier to 136 * @param {Window} window window to attach the notifier to
110 * @param {Integer} notifierID Parent notifier ID to be messaged 137 * @param {Integer} notifierID Parent notifier ID to be messaged
111 */ 138 */
112 function RequestNotifier(window, notifierID) 139 function RequestNotifier(window, notifierID)
113 { 140 {
114 this.window = window; 141 this.window = window;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 node = node.parentNode; 474 node = node.parentNode;
448 } 475 }
449 else 476 else
450 { 477 {
451 node = null; 478 node = null;
452 } 479 }
453 } 480 }
454 481
455 return null; 482 return null;
456 }; 483 };
OLDNEW
« no previous file with comments | « chrome/content/ui/sidebar.js ('k') | lib/requestNotifier.js » ('j') | lib/requestNotifier.js » ('J')

Powered by Google App Engine
This is Rietveld