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

Delta Between Two Patch Sets: lib/devtools.js

Issue 29705719: Issue 6402 - Split filter hit / request logging out into own API (Closed)
Left Patch Set: Addressed Sebastian's feedback Created March 21, 2018, 3:14 p.m.
Right Patch Set: Addressed Manish's feedback Created May 9, 2018, 5:53 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/cssInjection.js ('k') | lib/hitLogger.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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 "use strict"; 18 "use strict";
19 19
20 const {RegExpFilter, 20 const {RegExpFilter,
21 WhitelistFilter} = require("filterClasses"); 21 WhitelistFilter,
22 const {SpecialSubscription} = require("subscriptionClasses"); 22 ElemHideFilter} = require("../adblockpluscore/lib/filterClasses");
23 const {defaultMatcher} = require("matcher"); 23 const {SpecialSubscription} =
24 const {FilterNotifier} = require("filterNotifier"); 24 require("../adblockpluscore/lib/subscriptionClasses");
25 const {extractHostFromFrame} = require("url"); 25 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage");
26 const {port} = require("messaging"); 26 const {defaultMatcher} = require("../adblockpluscore/lib/matcher");
27 const {HitLogger} = require("hitLogger"); 27 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier");
28 28 const {extractHostFromFrame} = require("./url");
29 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; 29 const {port} = require("./messaging");
30 30 const {HitLogger, nonRequestTypes} = require("./hitLogger");
31 // Mapping of inspected tabs to their devpanel page 31
32 // and recorded items. We can't use a PageMap here,
33 // because data must persist after navigation/reload.
34 let panels = new Map(); 32 let panels = new Map();
35 33
36 function isActivePanel(panel) 34 function isActivePanel(panel)
37 { 35 {
38 return panel && !panel.reload && !panel.reloading; 36 return panel && !panel.reload && !panel.reloading;
39 } 37 }
40 38
41 function getActivePanel(page) 39 function getActivePanel(tabId)
42 { 40 {
43 let panel = panels.get(page.id); 41 let panel = panels.get(tabId);
44 if (isActivePanel(panel)) 42 if (isActivePanel(panel))
45 return panel; 43 return panel;
46 return null; 44 return null;
47 } 45 }
48 46
49 function getFilterInfo(filter) 47 function getFilterInfo(filter)
50 { 48 {
51 if (!filter) 49 if (!filter)
52 return null; 50 return null;
53 51
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 record.request.type == request.type) && 84 record.request.type == request.type) &&
87 85
88 // Matched element hiding filters don't relate to a particular request, 86 // Matched element hiding filters don't relate to a particular request,
89 // so we have to compare the selector in order to avoid duplicates. 87 // so we have to compare the selector in order to avoid duplicates.
90 (record.filter && record.filter.selector) == (filter && filter.selector) 88 (record.filter && record.filter.selector) == (filter && filter.selector)
91 ); 89 );
92 } 90 }
93 91
94 function addRecord(panel, request, filter) 92 function addRecord(panel, request, filter)
95 { 93 {
96 if (isActivePanel(panel) && !hasRecord(panel, request, filter)) 94 if (!hasRecord(panel, request, filter))
kzar 2018/03/21 15:18:45 Since we can no longer do the `isActivePanel` che
97 { 95 {
98 panel.port.postMessage({ 96 panel.port.postMessage({
99 type: "add-record", 97 type: "add-record",
100 request, 98 request,
101 filter: getFilterInfo(filter) 99 filter: getFilterInfo(filter)
102 }); 100 });
103 101
104 panel.records.push({request, filter}); 102 panel.records.push({request, filter});
105 } 103 }
106 } 104 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 233
236 browser.runtime.onConnect.addListener(newPort => 234 browser.runtime.onConnect.addListener(newPort =>
237 { 235 {
238 let match = newPort.name.match(/^devtools-(\d+)$/); 236 let match = newPort.name.match(/^devtools-(\d+)$/);
239 if (!match) 237 if (!match)
240 return; 238 return;
241 239
242 let inspectedTabId = parseInt(match[1], 10); 240 let inspectedTabId = parseInt(match[1], 10);
243 let localOnBeforeRequest = onBeforeRequest.bind(); 241 let localOnBeforeRequest = onBeforeRequest.bind();
244 let panel = {port: newPort, records: []}; 242 let panel = {port: newPort, records: []};
243 let hitListener = addRecord.bind(null, panel);
245 244
246 browser.webRequest.onBeforeRequest.addListener( 245 browser.webRequest.onBeforeRequest.addListener(
247 localOnBeforeRequest, 246 localOnBeforeRequest,
248 { 247 {
249 urls: ["http://*/*", "https://*/*"], 248 urls: ["http://*/*", "https://*/*"],
250 types: ["main_frame"], 249 types: ["main_frame"],
251 tabId: inspectedTabId 250 tabId: inspectedTabId
252 } 251 }
253 ); 252 );
254 253
255 if (panels.size == 0) 254 if (panels.size == 0)
256 { 255 {
257 ext.pages.onLoading.addListener(onLoading); 256 ext.pages.onLoading.addListener(onLoading);
258 FilterNotifier.on("filter.added", onFilterAdded); 257 FilterNotifier.on("filter.added", onFilterAdded);
259 FilterNotifier.on("filter.removed", onFilterRemoved); 258 FilterNotifier.on("filter.removed", onFilterRemoved);
260 FilterNotifier.on("subscription.added", onSubscriptionAdded); 259 FilterNotifier.on("subscription.added", onSubscriptionAdded);
261 } 260 }
262 261
263 let hitListener = addRecord.bind(null, panel);
264
265 newPort.onDisconnect.addListener(() => 262 newPort.onDisconnect.addListener(() =>
266 { 263 {
267 HitLogger.off(inspectedTabId, hitListener); 264 HitLogger.removeListener(inspectedTabId, hitListener);
268 panels.delete(inspectedTabId); 265 panels.delete(inspectedTabId);
269 browser.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest); 266 browser.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest);
270 267
271 if (panels.size == 0) 268 if (panels.size == 0)
272 { 269 {
273 ext.pages.onLoading.removeListener(onLoading); 270 ext.pages.onLoading.removeListener(onLoading);
274 FilterNotifier.off("filter.added", onFilterAdded); 271 FilterNotifier.off("filter.added", onFilterAdded);
275 FilterNotifier.off("filter.removed", onFilterRemoved); 272 FilterNotifier.off("filter.removed", onFilterRemoved);
276 FilterNotifier.off("subscription.added", onSubscriptionAdded); 273 FilterNotifier.off("subscription.added", onSubscriptionAdded);
277 } 274 }
278 }); 275 });
279 276
280 HitLogger.on(inspectedTabId, hitListener); 277 HitLogger.addListener(inspectedTabId, hitListener);
281 panels.set(inspectedTabId, panel); 278 panels.set(inspectedTabId, panel);
282 }); 279 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld