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

Delta Between Two Patch Sets: lib/devtools.js

Issue 29713631: Issue 5760 - Use relative require paths (Closed)
Left Patch Set: Created March 3, 2018, 4:09 a.m.
Right Patch Set: Address PS4 comments, rebase Created April 5, 2018, 11:09 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/filterComposer.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, 21 WhitelistFilter,
22 ElemHideFilter} = require("../adblockpluscore/lib/filterClasses"); 22 ElemHideFilter} = require("../adblockpluscore/lib/filterClasses");
23 const {SpecialSubscription} = require( 23 const {SpecialSubscription} =
24 "../adblockpluscore/lib/subscriptionClasses"); 24 require("../adblockpluscore/lib/subscriptionClasses");
25 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage"); 25 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage");
26 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); 26 const {defaultMatcher} = require("../adblockpluscore/lib/matcher");
27 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 27 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier");
28 const {extractHostFromFrame} = require("./url"); 28 const {extractHostFromFrame} = require("./url");
29 const {port} = require("./messaging"); 29 const {port} = require("./messaging");
30 30
31 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; 31 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE",
32 32 "GENERICBLOCK", "GENERICHIDE", "CSP"];
33 // Mapping of inspected tabs to their devpanel page 33
34 // and recorded items. We can't use a PageMap here,
35 // because data must persist after navigation/reload.
36 let panels = new Map(); 34 let panels = new Map();
37 35
38 function isActivePanel(panel) 36 function isActivePanel(panel)
39 { 37 {
40 return panel && !panel.reload && !panel.reloading; 38 return panel && !panel.reload && !panel.reloading;
41 } 39 }
42 40
43 function getActivePanel(page) 41 function getActivePanel(tabId)
44 { 42 {
45 let panel = panels.get(page.id); 43 let panel = panels.get(tabId);
46 if (isActivePanel(panel)) 44 if (isActivePanel(panel))
47 return panel; 45 return panel;
48 return null; 46 return null;
49 } 47 }
50 48
51 function getFilterInfo(filter) 49 function getFilterInfo(filter)
52 { 50 {
53 if (!filter) 51 if (!filter)
54 return null; 52 return null;
55 53
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 request.docDomain, 113 request.docDomain,
116 request.thirdParty, 114 request.thirdParty,
117 request.sitekey, 115 request.sitekey,
118 request.specificOnly 116 request.specificOnly
119 ); 117 );
120 } 118 }
121 119
122 /** 120 /**
123 * Logs a request to the devtools panel. 121 * Logs a request to the devtools panel.
124 * 122 *
125 * @param {?Page} page The page the request occured on or null if 123 * @param {number[]} tabIds The tabIds associated with the request
126 * the request isn't associated with a page
127 * @param {string} url The URL of the request 124 * @param {string} url The URL of the request
128 * @param {string} type The request type 125 * @param {string} type The request type
129 * @param {string} docDomain The IDN-decoded hostname of the document 126 * @param {string} docDomain The IDN-decoded hostname of the document
130 * @param {boolean} thirdParty Whether the origin of the request and 127 * @param {boolean} thirdParty Whether the origin of the request and
131 * document differs 128 * document differs
132 * @param {?string} sitekey The active sitekey if there is any 129 * @param {?string} sitekey The active sitekey if there is any
133 * @param {?boolean} specificOnly Whether generic filters should be ignored 130 * @param {?boolean} specificOnly Whether generic filters should be ignored
134 * @param {?BlockingFilter} filter The matched filter or null if there is no 131 * @param {?BlockingFilter} filter The matched filter or null if there is no
135 * match 132 * match
136 */ 133 */
137 exports.logRequest = function(page, url, type, docDomain, 134 exports.logRequest = function(tabIds, url, type, docDomain,
138 thirdParty, sitekey, 135 thirdParty, sitekey,
139 specificOnly, filter) 136 specificOnly, filter)
140 { 137 {
141 if (panels.size == 0) 138 if (panels.size == 0)
142 return; 139 return;
143 140
144 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; 141 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly};
145 for (let [tabId, panel] of panels) 142 for (let [tabId, panel] of panels)
146 if ((!page || page.id == tabId) && isActivePanel(panel)) 143 if ((tabIds.length == 0 || tabIds.includes(tabId)) && isActivePanel(panel))
147 addRecord(panel, request, filter); 144 addRecord(panel, request, filter);
148 }; 145 };
149 146
150 /** 147 /**
151 * Logs active element hiding filters to the devtools panel. 148 * Logs active element hiding filters to the devtools panel.
152 * 149 *
153 * @param {Page} page The page the elements were hidden on 150 * @param {number} tabId The ID of the tab, the elements were hidden in
154 * @param {string[]} selectors The selectors of applied ElemHideFilters 151 * @param {string[]} selectors The selectors of applied ElemHideFilters
155 * @param {string[]} filters The text of applied ElemHideEmulationFilters 152 * @param {string[]} filters The text of applied ElemHideEmulationFilters
156 * @param {string} docDomain The IDN-decoded hostname of the document 153 * @param {string} docDomain The IDN-decoded hostname of the document
157 */ 154 */
158 function logHiddenElements(page, selectors, filters, docDomain) 155 function logHiddenElements(tabId, selectors, filters, docDomain)
159 { 156 {
160 let panel = getActivePanel(page); 157 let panel = getActivePanel(tabId);
161 if (panel) 158 if (panel)
162 { 159 {
163 for (let subscription of FilterStorage.subscriptions) 160 for (let subscription of FilterStorage.subscriptions)
164 { 161 {
165 if (subscription.disabled) 162 if (subscription.disabled)
166 continue; 163 continue;
167 164
168 for (let filter of subscription.filters) 165 for (let filter of subscription.filters)
169 { 166 {
170 // We only know the exact filter in case of element hiding emulation. 167 // We only know the exact filter in case of element hiding emulation.
171 // For regular element hiding filters, the content script only knows 168 // For regular element hiding filters, the content script only knows
172 // the selector, so we have to find a filter that has an identical 169 // the selector, so we have to find a filter that has an identical
173 // selector and is active on the domain the match was reported from. 170 // selector and is active on the domain the match was reported from.
174 let isActiveElemHideFilter = filter instanceof ElemHideFilter && 171 let isActiveElemHideFilter = filter instanceof ElemHideFilter &&
175 selectors.includes(filter.selector) && 172 selectors.includes(filter.selector) &&
176 filter.isActiveOnDomain(docDomain); 173 filter.isActiveOnDomain(docDomain);
177 174
178 if (isActiveElemHideFilter || filters.includes(filter.text)) 175 if (isActiveElemHideFilter || filters.includes(filter.text))
179 addRecord(panel, {type: "ELEMHIDE", docDomain}, filter); 176 addRecord(panel, {type: "ELEMHIDE", docDomain}, filter);
180 } 177 }
181 } 178 }
182 } 179 }
183 } 180 }
184 181
185 /** 182 /**
186 * Logs a whitelisting filter, that disables (some kind of) 183 * Logs a whitelisting filter, that disables (some kind of)
187 * blocking for a particular document, to the devtools panel. 184 * blocking for a particular document, to the devtools panel.
188 * 185 *
189 * @param {Page} page The page the whitelisting is active on 186 * @param {number} tabId The tabId the whitelisting is active for
190 * @param {string} url The url of the whitelisted document 187 * @param {string} url The url of the whitelisted document
191 * @param {number} typeMask The bit mask of whitelisting types checked 188 * @param {number} typeMask The bit mask of whitelisting types checked
192 * for 189 * for
193 * @param {string} docDomain The IDN-decoded hostname of the parent 190 * @param {string} docDomain The IDN-decoded hostname of the parent
194 * document 191 * document
195 * @param {WhitelistFilter} filter The matched whitelisting filter 192 * @param {WhitelistFilter} filter The matched whitelisting filter
196 */ 193 */
197 exports.logWhitelistedDocument = function(page, url, typeMask, docDomain, 194 exports.logWhitelistedDocument = function(tabId, url, typeMask, docDomain,
198 filter) 195 filter)
199 { 196 {
200 let panel = getActivePanel(page); 197 let panel = getActivePanel(tabId);
201 if (panel) 198 if (panel)
202 { 199 {
203 for (let type of nonRequestTypes) 200 for (let type of nonRequestTypes)
204 { 201 {
205 if (typeMask & filter.contentType & RegExpFilter.typeMap[type]) 202 if (typeMask & filter.contentType & RegExpFilter.typeMap[type])
206 addRecord(panel, {url, type, docDomain}, filter); 203 addRecord(panel, {url, type, docDomain}, filter);
207 } 204 }
208 } 205 }
209 }; 206 };
210 207
211 /** 208 /**
212 * Checks whether a page is inspected by the devtools panel. 209 * Checks whether a tab is inspected by the devtools panel.
213 * 210 *
214 * @param {Page} page 211 * @param {number} tabId
215 * @return {boolean} 212 * @return {boolean}
216 */ 213 */
217 exports.hasPanel = function(page) 214 exports.hasPanel = function(tabId)
218 { 215 {
219 return panels.has(page.id); 216 return panels.has(tabId);
220 }; 217 };
221 218
222 function onBeforeRequest(details) 219 function onBeforeRequest(details)
223 { 220 {
224 let panel = panels.get(details.tabId); 221 let panel = panels.get(details.tabId);
225 222
226 // Clear the devtools panel and reload the inspected tab without caching 223 // Clear the devtools panel and reload the inspected tab without caching
227 // when a new request is issued. However, make sure that we don't end up 224 // when a new request is issued. However, make sure that we don't end up
228 // in an infinite recursion if we already triggered a reload. 225 // in an infinite recursion if we already triggered a reload.
229 if (panel.reloading) 226 if (panel.reloading)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 FilterNotifier.off("subscription.added", onSubscriptionAdded); 371 FilterNotifier.off("subscription.added", onSubscriptionAdded);
375 } 372 }
376 }); 373 });
377 374
378 panels.set(inspectedTabId, {port: newPort, records: []}); 375 panels.set(inspectedTabId, {port: newPort, records: []});
379 }); 376 });
380 377
381 port.on("devtools.traceElemHide", (message, sender) => 378 port.on("devtools.traceElemHide", (message, sender) =>
382 { 379 {
383 logHiddenElements( 380 logHiddenElements(
384 sender.page, message.selectors, message.filters, 381 sender.page.id, message.selectors, message.filters,
385 extractHostFromFrame(sender.frame) 382 extractHostFromFrame(sender.frame)
386 ); 383 );
387 }); 384 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld