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

Delta Between Two Patch Sets: lib/devtools.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Left Patch Set: Reduce inline eslint-disable comments Created Feb. 8, 2017, 7:27 a.m.
Right Patch Set: Use .includes again Created March 31, 2017, 8:37 a.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/csp.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-2016 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, ElemHideFilter} = require("filterClasses"); 21 WhitelistFilter,
22 ElemHideFilter,
23 ElemHideEmulationFilter} = require("filterClasses");
24
22 const {SpecialSubscription} = require("subscriptionClasses"); 25 const {SpecialSubscription} = require("subscriptionClasses");
23 const {FilterStorage} = require("filterStorage"); 26 const {FilterStorage} = require("filterStorage");
24 const {defaultMatcher} = require("matcher"); 27 const {defaultMatcher} = require("matcher");
25 const {FilterNotifier} = require("filterNotifier"); 28 const {FilterNotifier} = require("filterNotifier");
26 const {extractHostFromFrame} = require("url"); 29 const {extractHostFromFrame} = require("url");
27 const {port} = require("messaging"); 30 const {port} = require("messaging");
28 31
29 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; 32 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"];
30 33
31 // Mapping of inspected tabs to their devpanel page 34 // Mapping of inspected tabs to their devpanel page
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 77 }
75 78
76 function hasRecord(panel, request, filter) 79 function hasRecord(panel, request, filter)
77 { 80 {
78 return panel.records.some(record => 81 return panel.records.some(record =>
79 record.request.url == request.url && 82 record.request.url == request.url &&
80 record.request.docDomain == request.docDomain && 83 record.request.docDomain == request.docDomain &&
81 84
82 // Ignore partial (e.g. ELEMHIDE) whitelisting if there is already 85 // Ignore partial (e.g. ELEMHIDE) whitelisting if there is already
83 // a DOCUMENT exception which disables all means of blocking. 86 // a DOCUMENT exception which disables all means of blocking.
84 (record.request.type == "DOCUMENT" 87 (record.request.type == "DOCUMENT" ?
85 ? nonRequestTypes.indexOf(request.type) != -1 88 nonRequestTypes.includes(request.type) :
86 : record.request.type == request.type) && 89 record.request.type == request.type) &&
87 90
88 // Matched element hiding filters don't relate to a particular request, 91 // Matched element hiding filters don't relate to a particular request,
89 // so we also have to match the CSS selector in order to distinguish them. 92 // so we have to compare the selector in order to avoid duplicates.
90 (record.filter && record.filter.selector) == (filter && filter.selector) 93 (record.filter && record.filter.selector) == (filter && filter.selector)
91 ); 94 );
92 } 95 }
93 96
94 function addRecord(panel, request, filter) 97 function addRecord(panel, request, filter)
95 { 98 {
96 if (!hasRecord(panel, request, filter)) 99 if (!hasRecord(panel, request, filter))
97 { 100 {
98 panel.port.postMessage({ 101 panel.port.postMessage({
99 type: "add-record", 102 type: "add-record",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 * @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
132 * match 135 * match
133 */ 136 */
134 exports.logRequest = function(page, url, type, docDomain, 137 exports.logRequest = function(page, url, type, docDomain,
135 thirdParty, sitekey, 138 thirdParty, sitekey,
136 specificOnly, filter) 139 specificOnly, filter)
137 { 140 {
138 let panel = getActivePanel(page); 141 let panel = getActivePanel(page);
139 if (panel) 142 if (panel)
140 { 143 {
141 addRecord(panel, {url, type, docDomain, thirdParty, sitekey, specificOnly}, 144 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly};
142 filter); 145 addRecord(panel, request, filter);
143 } 146 }
144 }; 147 };
145 148
146 /** 149 /**
147 * Logs active element hiding filters to the devtools panel. 150 * Logs active element hiding filters to the devtools panel.
148 * 151 *
149 * @param {Page} page The page the elements were hidden on 152 * @param {Page} page The page the elements were hidden on
150 * @param {string[]} selectors The CSS selectors of active elemhide filters 153 * @param {string[]} selectors The CSS selectors of active elemhide filters
151 * @param {string} docDomain The IDN-decoded hostname of the document 154 * @param {string} docDomain The IDN-decoded hostname of the document
152 */ 155 */
153 function logHiddenElements(page, selectors, docDomain) 156 function logHiddenElements(page, selectors, docDomain)
154 { 157 {
155 let panel = getActivePanel(page); 158 let panel = getActivePanel(page);
156 if (panel) 159 if (panel)
157 { 160 {
158 for (let subscription of FilterStorage.subscriptions) 161 for (let subscription of FilterStorage.subscriptions)
159 { 162 {
160 if (subscription.disabled) 163 if (subscription.disabled)
161 continue; 164 continue;
162 165
163 for (let filter of subscription.filters) 166 for (let filter of subscription.filters)
164 { 167 {
165 if (!(filter instanceof ElemHideFilter)) 168 if (!(filter instanceof ElemHideFilter) &&
169 !(filter instanceof ElemHideEmulationFilter))
166 continue; 170 continue;
167 if (selectors.indexOf(filter.selector) == -1) 171 if (selectors.indexOf(filter.selector) == -1)
168 continue; 172 continue;
169 if (!filter.isActiveOnDomain(docDomain)) 173 if (!filter.isActiveOnDomain(docDomain))
170 continue; 174 continue;
171 175
172 addRecord(panel, {type: "ELEMHIDE", docDomain}, filter); 176 addRecord(panel, {type: "ELEMHIDE", docDomain}, filter);
173 } 177 }
174 } 178 }
175 } 179 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 panels[inspectedTabId] = {port: newPort, records: []}; 377 panels[inspectedTabId] = {port: newPort, records: []};
374 }); 378 });
375 379
376 port.on("devtools.traceElemHide", (message, sender) => 380 port.on("devtools.traceElemHide", (message, sender) =>
377 { 381 {
378 logHiddenElements( 382 logHiddenElements(
379 sender.page, message.selectors, 383 sender.page, message.selectors,
380 extractHostFromFrame(sender.frame) 384 extractHostFromFrame(sender.frame)
381 ); 385 );
382 }); 386 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld