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: Addressed some of Sebastian's feedback, made other improvements Created Feb. 20, 2017, 10:06 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
« no previous file with comments | « lib/utils.js ('k') | metadata.chrome » ('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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 if (header.name.toLowerCase() == "x-adblock-key" && header.value) 180 if (header.name.toLowerCase() == "x-adblock-key" && header.value)
180 { 181 {
181 let url = new URL(details.url); 182 let url = new URL(details.url);
182 let key = checkKey(header.value, url); 183 let key = checkKey(header.value, url);
183 if (key) 184 if (key)
184 { 185 {
185 // For pre-rendered tabs we don't know for sure the navigation is going 186 // For pre-rendered tabs we don't know for sure the navigation is going
186 // to happen until the onCommitted event fires. Unfortunately if we want 187 // to happen until the onCommitted event fires. Unfortunately if we want
187 // sitekey whitelisting to work for requests made before onCommitted has 188 // sitekey whitelisting to work for requests made before onCommitted has
188 // been fired we must update the page structure now anyway. 189 // been fired we must update the page structure now anyway.
189 ext._updatePageFrameStructure(details.frameId, details.tabId, details.ur l, true); 190 ext._updatePageFrameStructure(details.frameId, details.tabId,
191 details.url, true);
190 recordKey(key, page, url); 192 recordKey(key, page, url);
191 break; 193 break;
192 } 194 }
193 } 195 }
194 } 196 }
195 } 197 }
196 198
197 if (typeof chrome == "object") 199 if (typeof chrome == "object")
200 {
198 chrome.webRequest.onHeadersReceived.addListener( 201 chrome.webRequest.onHeadersReceived.addListener(
199 onHeadersReceived, 202 onHeadersReceived,
200 { 203 {
201 urls: ["http://*/*", "https://*/*"], 204 urls: ["http://*/*", "https://*/*"],
202 types: ["main_frame", "sub_frame"] 205 types: ["main_frame", "sub_frame"]
203 }, 206 },
204 ["responseHeaders"] 207 ["responseHeaders"]
205 ); 208 );
209 }
OLDNEW
« no previous file with comments | « lib/utils.js ('k') | metadata.chrome » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld