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

Side by Side Diff: lib/devtools.js

Issue 29715577: Issue 6449 - Switch to Harmony modules (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Add lib/.eslintrc.json Created March 6, 2018, 10:30 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-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 import {RegExpFilter, WhitelistFilter, ElemHideFilter} from "filterClasses";
19 19 import {SpecialSubscription} from "subscriptionClasses";
20 const {RegExpFilter, 20 import {FilterStorage} from "filterStorage";
21 WhitelistFilter, 21 import {defaultMatcher} from "matcher";
22 ElemHideFilter} = require("filterClasses"); 22 import {FilterNotifier} from "filterNotifier";
23 const {SpecialSubscription} = require("subscriptionClasses"); 23 import {extractHostFromFrame} from "url";
24 const {FilterStorage} = require("filterStorage"); 24 import {port} from "messaging";
25 const {defaultMatcher} = require("matcher");
26 const {FilterNotifier} = require("filterNotifier");
27 const {extractHostFromFrame} = require("url");
28 const {port} = require("messaging");
29 25
30 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; 26 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"];
31 27
32 // Mapping of inspected tabs to their devpanel page 28 // Mapping of inspected tabs to their devpanel page
33 // and recorded items. We can't use a PageMap here, 29 // and recorded items. We can't use a PageMap here,
34 // because data must persist after navigation/reload. 30 // because data must persist after navigation/reload.
35 let panels = new Map(); 31 let panels = new Map();
36 32
37 function isActivePanel(panel) 33 function isActivePanel(panel)
38 { 34 {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 * @param {string} url The URL of the request 122 * @param {string} url The URL of the request
127 * @param {string} type The request type 123 * @param {string} type The request type
128 * @param {string} docDomain The IDN-decoded hostname of the document 124 * @param {string} docDomain The IDN-decoded hostname of the document
129 * @param {boolean} thirdParty Whether the origin of the request and 125 * @param {boolean} thirdParty Whether the origin of the request and
130 * document differs 126 * document differs
131 * @param {?string} sitekey The active sitekey if there is any 127 * @param {?string} sitekey The active sitekey if there is any
132 * @param {?boolean} specificOnly Whether generic filters should be ignored 128 * @param {?boolean} specificOnly Whether generic filters should be ignored
133 * @param {?BlockingFilter} filter The matched filter or null if there is no 129 * @param {?BlockingFilter} filter The matched filter or null if there is no
134 * match 130 * match
135 */ 131 */
136 exports.logRequest = function(page, url, type, docDomain, 132 export function logRequest(page, url, type, docDomain, thirdParty, sitekey,
137 thirdParty, sitekey, 133 specificOnly, filter)
138 specificOnly, filter)
139 { 134 {
140 if (panels.size == 0) 135 if (panels.size == 0)
141 return; 136 return;
142 137
143 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; 138 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly};
144 for (let [tabId, panel] of panels) 139 for (let [tabId, panel] of panels)
145 if ((!page || page.id == tabId) && isActivePanel(panel)) 140 if ((!page || page.id == tabId) && isActivePanel(panel))
146 addRecord(panel, request, filter); 141 addRecord(panel, request, filter);
147 }; 142 }
148 143
149 /** 144 /**
150 * Logs active element hiding filters to the devtools panel. 145 * Logs active element hiding filters to the devtools panel.
151 * 146 *
152 * @param {Page} page The page the elements were hidden on 147 * @param {Page} page The page the elements were hidden on
153 * @param {string[]} selectors The selectors of applied ElemHideFilters 148 * @param {string[]} selectors The selectors of applied ElemHideFilters
154 * @param {string[]} filters The text of applied ElemHideEmulationFilters 149 * @param {string[]} filters The text of applied ElemHideEmulationFilters
155 * @param {string} docDomain The IDN-decoded hostname of the document 150 * @param {string} docDomain The IDN-decoded hostname of the document
156 */ 151 */
157 function logHiddenElements(page, selectors, filters, docDomain) 152 function logHiddenElements(page, selectors, filters, docDomain)
(...skipping 28 matching lines...) Expand all
186 * blocking for a particular document, to the devtools panel. 181 * blocking for a particular document, to the devtools panel.
187 * 182 *
188 * @param {Page} page The page the whitelisting is active on 183 * @param {Page} page The page the whitelisting is active on
189 * @param {string} url The url of the whitelisted document 184 * @param {string} url The url of the whitelisted document
190 * @param {number} typeMask The bit mask of whitelisting types checked 185 * @param {number} typeMask The bit mask of whitelisting types checked
191 * for 186 * for
192 * @param {string} docDomain The IDN-decoded hostname of the parent 187 * @param {string} docDomain The IDN-decoded hostname of the parent
193 * document 188 * document
194 * @param {WhitelistFilter} filter The matched whitelisting filter 189 * @param {WhitelistFilter} filter The matched whitelisting filter
195 */ 190 */
196 exports.logWhitelistedDocument = function(page, url, typeMask, docDomain, 191 export function logWhitelistedDocument(page, url, typeMask, docDomain, filter)
197 filter)
198 { 192 {
199 let panel = getActivePanel(page); 193 let panel = getActivePanel(page);
200 if (panel) 194 if (panel)
201 { 195 {
202 for (let type of nonRequestTypes) 196 for (let type of nonRequestTypes)
203 { 197 {
204 if (typeMask & filter.contentType & RegExpFilter.typeMap[type]) 198 if (typeMask & filter.contentType & RegExpFilter.typeMap[type])
205 addRecord(panel, {url, type, docDomain}, filter); 199 addRecord(panel, {url, type, docDomain}, filter);
206 } 200 }
207 } 201 }
208 }; 202 }
209 203
210 /** 204 /**
211 * Checks whether a page is inspected by the devtools panel. 205 * Checks whether a page is inspected by the devtools panel.
212 * 206 *
213 * @param {Page} page 207 * @param {Page} page
214 * @return {boolean} 208 * @return {boolean}
215 */ 209 */
216 exports.hasPanel = function(page) 210 export function hasPanel(page)
217 { 211 {
218 return panels.has(page.id); 212 return panels.has(page.id);
219 }; 213 }
220 214
221 function onBeforeRequest(details) 215 function onBeforeRequest(details)
222 { 216 {
223 let panel = panels.get(details.tabId); 217 let panel = panels.get(details.tabId);
224 218
225 // Clear the devtools panel and reload the inspected tab without caching 219 // Clear the devtools panel and reload the inspected tab without caching
226 // when a new request is issued. However, make sure that we don't end up 220 // when a new request is issued. However, make sure that we don't end up
227 // in an infinite recursion if we already triggered a reload. 221 // in an infinite recursion if we already triggered a reload.
228 if (panel.reloading) 222 if (panel.reloading)
229 { 223 {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 panels.set(inspectedTabId, {port: newPort, records: []}); 371 panels.set(inspectedTabId, {port: newPort, records: []});
378 }); 372 });
379 373
380 port.on("devtools.traceElemHide", (message, sender) => 374 port.on("devtools.traceElemHide", (message, sender) =>
381 { 375 {
382 logHiddenElements( 376 logHiddenElements(
383 sender.page, message.selectors, message.filters, 377 sender.page, message.selectors, message.filters,
384 extractHostFromFrame(sender.frame) 378 extractHostFromFrame(sender.frame)
385 ); 379 );
386 }); 380 });
OLDNEW
« lib/.eslintrc.json ('K') | « lib/cssInjection.js ('k') | lib/filterComposer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld