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

Side by Side Diff: lib/devtools.js

Issue 29404613: Issue 5117 - Identify ElemHideEmulationFilters based on the filter text in the devtools panel (Closed)
Patch Set: Created April 6, 2017, 2:53 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
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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, 22 ElemHideFilter} = require("filterClasses");
23 ElemHideEmulationFilter} = require("filterClasses");
24
25 const {SpecialSubscription} = require("subscriptionClasses"); 23 const {SpecialSubscription} = require("subscriptionClasses");
26 const {FilterStorage} = require("filterStorage"); 24 const {FilterStorage} = require("filterStorage");
27 const {defaultMatcher} = require("matcher"); 25 const {defaultMatcher} = require("matcher");
28 const {FilterNotifier} = require("filterNotifier"); 26 const {FilterNotifier} = require("filterNotifier");
29 const {extractHostFromFrame} = require("url"); 27 const {extractHostFromFrame} = require("url");
30 const {port} = require("messaging"); 28 const {port} = require("messaging");
31 29
32 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; 30 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"];
33 31
34 // Mapping of inspected tabs to their devpanel page 32 // Mapping of inspected tabs to their devpanel page
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 { 141 {
144 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; 142 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly};
145 addRecord(panel, request, filter); 143 addRecord(panel, request, filter);
146 } 144 }
147 }; 145 };
148 146
149 /** 147 /**
150 * Logs active element hiding filters to the devtools panel. 148 * Logs active element hiding filters to the devtools panel.
151 * 149 *
152 * @param {Page} page The page the elements were hidden on 150 * @param {Page} page The page the elements were hidden on
153 * @param {string[]} selectors The CSS selectors of active elemhide filters 151 * @param {string[]} selectors The selectors of applied ElemHideFilters
152 * @param {string[]} filters The text of applied ElemHideEmulationFilters
154 * @param {string} docDomain The IDN-decoded hostname of the document 153 * @param {string} docDomain The IDN-decoded hostname of the document
155 */ 154 */
156 function logHiddenElements(page, selectors, docDomain) 155 function logHiddenElements(page, selectors, filters, docDomain)
157 { 156 {
158 let panel = getActivePanel(page); 157 let panel = getActivePanel(page);
159 if (panel) 158 if (panel)
160 { 159 {
161 for (let subscription of FilterStorage.subscriptions) 160 for (let subscription of FilterStorage.subscriptions)
162 { 161 {
163 if (subscription.disabled) 162 if (subscription.disabled)
164 continue; 163 continue;
165 164
166 for (let filter of subscription.filters) 165 for (let filter of subscription.filters)
167 { 166 {
168 if (!(filter instanceof ElemHideFilter) && 167 // We only know the exact filter in case of element hiding emulation.
169 !(filter instanceof ElemHideEmulationFilter)) 168 // For regular element hiding filters, the content script only knows
170 continue; 169 // the selector, so we have to find a filter that has an identical
171 if (selectors.indexOf(filter.selector) == -1) 170 // selector and is active on the domain the match was reported from.
172 continue; 171 let isActiveElemHideFilter = filter instanceof ElemHideFilter &&
173 if (!filter.isActiveOnDomain(docDomain)) 172 selectors.includes(filter.selector) &&
174 continue; 173 filter.isActiveOnDomain(docDomain);
175 174
176 addRecord(panel, {type: "ELEMHIDE", docDomain}, filter); 175 if (isActiveElemHideFilter || filters.includes(filter.text))
176 addRecord(panel, {type: "ELEMHIDE", docDomain}, filter);
177 } 177 }
178 } 178 }
179 } 179 }
180 } 180 }
181 181
182 /** 182 /**
183 * Logs a whitelisting filter, that disables (some kind of) 183 * Logs a whitelisting filter, that disables (some kind of)
184 * blocking for a particular document, to the devtools panel. 184 * blocking for a particular document, to the devtools panel.
185 * 185 *
186 * @param {Page} page The page the whitelisting is active on 186 * @param {Page} page The page the whitelisting is active on
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 FilterNotifier.off("subscription.added", onSubscriptionAdded); 373 FilterNotifier.off("subscription.added", onSubscriptionAdded);
374 } 374 }
375 }); 375 });
376 376
377 panels[inspectedTabId] = {port: newPort, records: []}; 377 panels[inspectedTabId] = {port: newPort, records: []};
378 }); 378 });
379 379
380 port.on("devtools.traceElemHide", (message, sender) => 380 port.on("devtools.traceElemHide", (message, sender) =>
381 { 381 {
382 logHiddenElements( 382 logHiddenElements(
383 sender.page, message.selectors, 383 sender.page, message.selectors, message.filters,
384 extractHostFromFrame(sender.frame) 384 extractHostFromFrame(sender.frame)
385 ); 385 );
386 }); 386 });
OLDNEW
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld