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

Delta Between Two Patch Sets: lib/devtools.js

Issue 29417597: Issue 5161 - Use maps and sets where appropriate (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Created April 19, 2017, 4:33 p.m.
Right Patch Set: Minor unrelated changes Created May 21, 2017, 10:15 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 | « ext/background.js ('k') | lib/popupBlocker.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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 15 matching lines...) Expand all
26 const {FilterNotifier} = require("filterNotifier"); 26 const {FilterNotifier} = require("filterNotifier");
27 const {extractHostFromFrame} = require("url"); 27 const {extractHostFromFrame} = require("url");
28 const {port} = require("messaging"); 28 const {port} = require("messaging");
29 29
30 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; 30 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"];
31 31
32 // Mapping of inspected tabs to their devpanel page 32 // Mapping of inspected tabs to their devpanel page
33 // and recorded items. We can't use a PageMap here, 33 // and recorded items. We can't use a PageMap here,
34 // because data must persist after navigation/reload. 34 // because data must persist after navigation/reload.
35 let panels = new Map(); 35 let panels = new Map();
36
37 function hasPanels()
38 {
39 return panels.size > 0;
Sebastian Noack 2017/04/29 22:46:32 Now where this check is less obscure, there isn't
Manish Jethani 2017/05/04 14:47:34 Changed here and in popupBlocker.
40 }
41 36
42 function getActivePanel(page) 37 function getActivePanel(page)
43 { 38 {
44 let panel = panels.get(page.id); 39 let panel = panels.get(page.id);
45 if (panel && !panel.reload && !panel.reloading) 40 if (panel && !panel.reload && !panel.reloading)
46 return panel; 41 return panel;
47 return null; 42 return null;
48 } 43 }
49 44
50 function getFilterInfo(filter) 45 function getFilterInfo(filter)
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 let match = newPort.name.match(/^devtools-(\d+)$/); 332 let match = newPort.name.match(/^devtools-(\d+)$/);
338 if (!match) 333 if (!match)
339 return; 334 return;
340 335
341 let inspectedTabId = parseInt(match[1], 10); 336 let inspectedTabId = parseInt(match[1], 10);
342 let localOnBeforeRequest = onBeforeRequest.bind(); 337 let localOnBeforeRequest = onBeforeRequest.bind();
343 338
344 chrome.webRequest.onBeforeRequest.addListener( 339 chrome.webRequest.onBeforeRequest.addListener(
345 localOnBeforeRequest, 340 localOnBeforeRequest,
346 { 341 {
347 urls: ["<all_urls>"], 342 urls: ["http://*/*", "https://*/*"],
348 types: ["main_frame"], 343 types: ["main_frame"],
349 tabId: inspectedTabId 344 tabId: inspectedTabId
350 } 345 }
351 ); 346 );
352 347
353 if (!hasPanels()) 348 if (panels.size == 0)
354 { 349 {
355 ext.pages.onLoading.addListener(onLoading); 350 ext.pages.onLoading.addListener(onLoading);
356 FilterNotifier.on("filter.added", onFilterAdded); 351 FilterNotifier.on("filter.added", onFilterAdded);
357 FilterNotifier.on("filter.removed", onFilterRemoved); 352 FilterNotifier.on("filter.removed", onFilterRemoved);
358 FilterNotifier.on("subscription.added", onSubscriptionAdded); 353 FilterNotifier.on("subscription.added", onSubscriptionAdded);
359 } 354 }
360 355
361 newPort.onDisconnect.addListener(() => 356 newPort.onDisconnect.addListener(() =>
362 { 357 {
363 panels.delete(inspectedTabId); 358 panels.delete(inspectedTabId);
364 chrome.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest); 359 chrome.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest);
365 360
366 if (!hasPanels()) 361 if (panels.size == 0)
367 { 362 {
368 ext.pages.onLoading.removeListener(onLoading); 363 ext.pages.onLoading.removeListener(onLoading);
369 FilterNotifier.off("filter.added", onFilterAdded); 364 FilterNotifier.off("filter.added", onFilterAdded);
370 FilterNotifier.off("filter.removed", onFilterRemoved); 365 FilterNotifier.off("filter.removed", onFilterRemoved);
371 FilterNotifier.off("subscription.added", onSubscriptionAdded); 366 FilterNotifier.off("subscription.added", onSubscriptionAdded);
372 } 367 }
373 }); 368 });
374 369
375 panels.set(inspectedTabId, {port: newPort, records: []}); 370 panels.set(inspectedTabId, {port: newPort, records: []});
376 }); 371 });
377 372
378 port.on("devtools.traceElemHide", (message, sender) => 373 port.on("devtools.traceElemHide", (message, sender) =>
379 { 374 {
380 logHiddenElements( 375 logHiddenElements(
381 sender.page, message.selectors, message.filters, 376 sender.page, message.selectors, message.filters,
382 extractHostFromFrame(sender.frame) 377 extractHostFromFrame(sender.frame)
383 ); 378 );
384 }); 379 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld