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

Side by Side Diff: lib/whitelisting.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Patch Set: Rebased Created March 17, 2017, 12:41 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 | « lib/utils.js ('k') | notification.js » ('j') | 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 /** @module whitelisting */ 18 /** @module whitelisting */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {defaultMatcher} = require("matcher"); 22 const {defaultMatcher} = require("matcher");
23 const {RegExpFilter} = require("filterClasses"); 23 const {RegExpFilter} = require("filterClasses");
24 const {DownloadableSubscription} = require("subscriptionClasses");
25 const {FilterNotifier} = require("filterNotifier"); 24 const {FilterNotifier} = require("filterNotifier");
26 const {stringifyURL, getDecodedHostname, 25 const {stringifyURL, getDecodedHostname,
27 extractHostFromFrame, isThirdParty} = require("url"); 26 extractHostFromFrame, isThirdParty} = require("url");
28 const {port} = require("messaging"); 27 const {port} = require("messaging");
29 const devtools = require("devtools"); 28 const devtools = require("devtools");
30 const {verifySignature} = require("rsa"); 29 const {verifySignature} = require("rsa");
31 30
32 let sitekeys = new ext.PageMap(); 31 let sitekeys = new ext.PageMap();
33 32
34 function match(page, url, typeMask, docDomain, sitekey) 33 function match(page, url, typeMask, docDomain, sitekey)
35 { 34 {
36 let thirdParty = !!docDomain && isThirdParty(url, docDomain); 35 let thirdParty = !!docDomain && isThirdParty(url, docDomain);
37 let urlString = stringifyURL(url); 36 let urlString = stringifyURL(url);
38 37
39 if (!docDomain) 38 if (!docDomain)
40 docDomain = getDecodedHostname(url); 39 docDomain = getDecodedHostname(url);
41 40
42 let filter = defaultMatcher.whitelist.matchesAny( 41 let filter = defaultMatcher.whitelist.matchesAny(
43 urlString, typeMask, docDomain, thirdParty, sitekey 42 urlString, typeMask, docDomain, thirdParty, sitekey
44 ); 43 );
45 44
46 if (filter && devtools) 45 if (filter && devtools)
46 {
47 devtools.logWhitelistedDocument( 47 devtools.logWhitelistedDocument(
48 page, urlString, typeMask, docDomain, filter 48 page, urlString, typeMask, docDomain, filter
49 ); 49 );
50 }
50 51
51 return filter; 52 return filter;
52 } 53 }
53 54
54 let checkWhitelisted = 55 let checkWhitelisted =
55 /** 56 /**
56 * Gets the active whitelisting filter for the document associated 57 * Gets the active whitelisting filter for the document associated
57 * with the given page/frame, or null if it's not whitelisted. 58 * with the given page/frame, or null if it's not whitelisted.
58 * 59 *
59 * @param {Page} page 60 * @param {Page} page
60 * @param {Frame} [frame] 61 * @param {Frame} [frame]
61 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] 62 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT]
62 * @return {?WhitelistFilter} 63 * @return {?WhitelistFilter}
63 */ 64 */
64 exports.checkWhitelisted = (page, frame, typeMask) => 65 exports.checkWhitelisted = (page, frame, typeMask) =>
65 { 66 {
66 if (typeof typeMask == "undefined") 67 if (typeof typeMask == "undefined")
67 typeMask = RegExpFilter.typeMap.DOCUMENT; 68 typeMask = RegExpFilter.typeMap.DOCUMENT;
68 69
69 if (frame) 70 if (frame)
70 { 71 {
71 let filter = null; 72 let filter = null;
72 73
73 while (frame && !filter) 74 while (frame && !filter)
74 { 75 {
75 let parent = frame.parent; 76 let {parent} = frame;
76 let docDomain = extractHostFromFrame(parent); 77 let docDomain = extractHostFromFrame(parent);
77 let sitekey = getKey(page, frame); 78 let sitekey = getKey(page, frame);
78 79
79 filter = match(page, frame.url, typeMask, docDomain, sitekey); 80 filter = match(page, frame.url, typeMask, docDomain, sitekey);
80 frame = parent; 81 frame = parent;
81 } 82 }
82 83
83 return filter; 84 return filter;
84 } 85 }
85 86
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 if (key) 184 if (key)
184 { 185 {
185 recordKey(key, page, url); 186 recordKey(key, page, url);
186 break; 187 break;
187 } 188 }
188 } 189 }
189 } 190 }
190 } 191 }
191 192
192 if (typeof chrome == "object") 193 if (typeof chrome == "object")
194 {
193 chrome.webRequest.onHeadersReceived.addListener( 195 chrome.webRequest.onHeadersReceived.addListener(
194 onHeadersReceived, 196 onHeadersReceived,
195 { 197 {
196 urls: ["http://*/*", "https://*/*"], 198 urls: ["http://*/*", "https://*/*"],
197 types: ["main_frame", "sub_frame"] 199 types: ["main_frame", "sub_frame"]
198 }, 200 },
199 ["responseHeaders"] 201 ["responseHeaders"]
200 ); 202 );
203 }
OLDNEW
« no previous file with comments | « lib/utils.js ('k') | notification.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld