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

Side by Side Diff: lib/devtools.js

Issue 29418679: Issue 5042 - Adds handling for requests which are not associated with browser tab (Closed)
Patch Set: rebase Created May 30, 2017, 9:04 a.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-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 16 matching lines...) Expand all
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 36
37 function isActivePanel(panel)
38 {
39 if (panel && !panel.reload && !panel.reloading)
Sebastian Noack 2017/05/30 11:10:49 The if/else is redundant, You can just return the
Jon Sonesen 2017/05/31 08:28:17 Acknowledged.
40 return true;
41 return false;
42 }
43
37 function getActivePanel(page) 44 function getActivePanel(page)
38 { 45 {
39 let panel = panels.get(page.id); 46 let panel = panels.get(page.id);
40 if (panel && !panel.reload && !panel.reloading) 47 if (isActivePanel(panel))
41 return panel; 48 return panel;
42 return null; 49 return null;
43 } 50 }
44 51
45 function getFilterInfo(filter) 52 function getFilterInfo(filter)
46 { 53 {
47 if (!filter) 54 if (!filter)
48 return null; 55 return null;
49 56
50 let userDefined = false; 57 let userDefined = false;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 /** 123 /**
117 * Logs a request to the devtools panel. 124 * Logs a request to the devtools panel.
118 * 125 *
119 * @param {Page} page The page the request occured on 126 * @param {Page} page The page the request occured on
120 * @param {string} url The URL of the request 127 * @param {string} url The URL of the request
121 * @param {string} type The request type 128 * @param {string} type The request type
122 * @param {string} docDomain The IDN-decoded hostname of the document 129 * @param {string} docDomain The IDN-decoded hostname of the document
123 * @param {boolean} thirdParty Whether the origin of the request and 130 * @param {boolean} thirdParty Whether the origin of the request and
124 * document differs 131 * document differs
125 * @param {?string} sitekey The active sitekey if there is any 132 * @param {?string} sitekey The active sitekey if there is any
126 * @param {?boolean} specificOnly Whether generic filters should be ignored 133 * @param {?boolean} specificOnly Whether generic filters should be ignored
Sebastian Noack 2017/05/30 11:10:48 Please replace {Page} with {?Page} above, in order
Jon Sonesen 2017/05/31 08:28:17 Sure, does this mean it should be moved down to wh
Sebastian Noack 2017/05/31 08:35:01 No. The arguments should be listed in the order th
127 * @param {?BlockingFilter} filter The matched filter or null if there is no 134 * @param {?BlockingFilter} filter The matched filter or null if there is no
128 * match 135 * match
129 */ 136 */
130 exports.logRequest = function(page, url, type, docDomain, 137 exports.logRequest = function(page, url, type, docDomain,
131 thirdParty, sitekey, 138 thirdParty, sitekey,
132 specificOnly, filter) 139 specificOnly, filter)
133 { 140 {
134 let panel = getActivePanel(page); 141 if (panels.size == 0)
135 if (panel) 142 return;
143 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly};
144 if (page)
136 { 145 {
137 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; 146 let panel = getActivePanel(page);
138 addRecord(panel, request, filter); 147 if (panel)
148 addRecord(panel, request, filter);
149 return;
139 } 150 }
151 for (let panel of panels.values())
152 if (isActivePanel(panel))
153 addRecord(panel, request, filter);
Sebastian Noack 2017/05/30 11:10:49 This would be somewhat less efficient, in case you
Jon Sonesen 2017/05/31 08:28:18 Yeah I like this, will do. Thanks.
140 }; 154 };
141 155
142 /** 156 /**
143 * Logs active element hiding filters to the devtools panel. 157 * Logs active element hiding filters to the devtools panel.
144 * 158 *
145 * @param {Page} page The page the elements were hidden on 159 * @param {Page} page The page the elements were hidden on
146 * @param {string[]} selectors The selectors of applied ElemHideFilters 160 * @param {string[]} selectors The selectors of applied ElemHideFilters
147 * @param {string[]} filters The text of applied ElemHideEmulationFilters 161 * @param {string[]} filters The text of applied ElemHideEmulationFilters
148 * @param {string} docDomain The IDN-decoded hostname of the document 162 * @param {string} docDomain The IDN-decoded hostname of the document
149 */ 163 */
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 panels.set(inspectedTabId, {port: newPort, records: []}); 384 panels.set(inspectedTabId, {port: newPort, records: []});
371 }); 385 });
372 386
373 port.on("devtools.traceElemHide", (message, sender) => 387 port.on("devtools.traceElemHide", (message, sender) =>
374 { 388 {
375 logHiddenElements( 389 logHiddenElements(
376 sender.page, message.selectors, message.filters, 390 sender.page, message.selectors, message.filters,
377 extractHostFromFrame(sender.frame) 391 extractHostFromFrame(sender.frame)
378 ); 392 );
379 }); 393 });
OLDNEW

Powered by Google App Engine
This is Rietveld