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: Rebased. Created March 7, 2017, 10:44 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 *
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 function hasRecord(panel, request, filter) 79 function hasRecord(panel, request, filter)
80 { 80 {
81 return panel.records.some(record => 81 return panel.records.some(record =>
82 record.request.url == request.url && 82 record.request.url == request.url &&
83 record.request.docDomain == request.docDomain && 83 record.request.docDomain == request.docDomain &&
84 84
85 // Ignore partial (e.g. ELEMHIDE) whitelisting if there is already 85 // Ignore partial (e.g. ELEMHIDE) whitelisting if there is already
86 // a DOCUMENT exception which disables all means of blocking. 86 // a DOCUMENT exception which disables all means of blocking.
87 (record.request.type == "DOCUMENT" 87 (record.request.type == "DOCUMENT" ?
88 ? nonRequestTypes.indexOf(request.type) != -1 88 nonRequestTypes.includes(request.type) :
89 : record.request.type == request.type) && 89 record.request.type == request.type) &&
90 90
91 // Matched element hiding filters don't relate to a particular request, 91 // Matched element hiding filters don't relate to a particular request,
92 // 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.
93 (record.filter && record.filter.selector) == (filter && filter.selector) 93 (record.filter && record.filter.selector) == (filter && filter.selector)
94 ); 94 );
95 } 95 }
96 96
97 function addRecord(panel, request, filter) 97 function addRecord(panel, request, filter)
98 { 98 {
99 if (!hasRecord(panel, request, filter)) 99 if (!hasRecord(panel, request, filter))
100 { 100 {
101 panel.port.postMessage({ 101 panel.port.postMessage({
102 type: "add-record", 102 type: "add-record",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 * @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
135 * match 135 * match
136 */ 136 */
137 exports.logRequest = function(page, url, type, docDomain, 137 exports.logRequest = function(page, url, type, docDomain,
138 thirdParty, sitekey, 138 thirdParty, sitekey,
139 specificOnly, filter) 139 specificOnly, filter)
140 { 140 {
141 let panel = getActivePanel(page); 141 let panel = getActivePanel(page);
142 if (panel) 142 if (panel)
143 { 143 {
144 addRecord(panel, {url, type, docDomain, thirdParty, sitekey, specificOnly}, 144 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly};
145 filter); 145 addRecord(panel, request, filter);
146 } 146 }
147 }; 147 };
148 148
149 /** 149 /**
150 * Logs active element hiding filters to the devtools panel. 150 * Logs active element hiding filters to the devtools panel.
151 * 151 *
152 * @param {Page} page The page the elements were hidden on 152 * @param {Page} page The page the elements were hidden on
153 * @param {string[]} selectors The CSS selectors of active elemhide filters 153 * @param {string[]} selectors The CSS selectors of active elemhide filters
154 * @param {string} docDomain The IDN-decoded hostname of the document 154 * @param {string} docDomain The IDN-decoded hostname of the document
155 */ 155 */
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 }; 217 };
218 218
219 function onBeforeRequest(details) 219 function onBeforeRequest(details)
220 { 220 {
221 let panel = panels[details.tabId]; 221 let panel = panels[details.tabId];
222 222
223 // Clear the devtools panel and reload the inspected tab without caching 223 // Clear the devtools panel and reload the inspected tab without caching
224 // 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
225 // in an infinite recursion if we already triggered a reload. 225 // in an infinite recursion if we already triggered a reload.
226 if (panel.reloading) 226 if (panel.reloading)
227 {
227 panel.reloading = false; 228 panel.reloading = false;
229 }
228 else 230 else
229 { 231 {
230 panel.records = []; 232 panel.records = [];
231 panel.port.postMessage({type: "reset"}); 233 panel.port.postMessage({type: "reset"});
232 234
233 // We can't repeat the request if it isn't a GET request. Chrome would 235 // We can't repeat the request if it isn't a GET request. Chrome would
234 // prompt the user to confirm reloading the page, and POST requests are 236 // prompt the user to confirm reloading the page, and POST requests are
235 // known to cause issues on many websites if repeated. 237 // known to cause issues on many websites if repeated.
236 if (details.method == "GET") 238 if (details.method == "GET")
237 panel.reload = true; 239 panel.reload = true;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 panels[inspectedTabId] = {port: newPort, records: []}; 377 panels[inspectedTabId] = {port: newPort, records: []};
376 }); 378 });
377 379
378 port.on("devtools.traceElemHide", (message, sender) => 380 port.on("devtools.traceElemHide", (message, sender) =>
379 { 381 {
380 logHiddenElements( 382 logHiddenElements(
381 sender.page, message.selectors, 383 sender.page, message.selectors,
382 extractHostFromFrame(sender.frame) 384 extractHostFromFrame(sender.frame)
383 ); 385 );
384 }); 386 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld