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

Side by Side Diff: lib/whitelisting.js

Issue 6393086494113792: Issue 154 - Added devtools panel showing blocked and blockable items (Closed)
Patch Set: Fixed typo in JSDoc syntax Created Feb. 2, 2016, 4:31 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/filterComposer.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";
21
20 let {defaultMatcher} = require("matcher"); 22 let {defaultMatcher} = require("matcher");
21 let {RegExpFilter} = require("filterClasses"); 23 let {RegExpFilter} = require("filterClasses");
22 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url"); 24 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url");
25 let devtools = require("devtools");
23 26
24 let pagesWithKey = new ext.PageMap(); 27 let pagesWithKey = new ext.PageMap();
25 28
26 /** 29 function match(page, url, typeMask, docDomain, sitekey)
27 * Checks whether a page is whitelisted.
28 *
29 * @param {Page} page
30 * @return {WhitelistFilter} The active filter whitelisting this page or null
31 */
32 exports.isPageWhitelisted = function(page)
33 { 30 {
34 let url = page.url; 31 let thirdParty = !!docDomain && isThirdParty(url, docDomain);
32 let urlString = stringifyURL(url);
35 33
36 return defaultMatcher.whitelist.matchesAny( 34 if (!docDomain)
37 stringifyURL(url), RegExpFilter.typeMap.DOCUMENT, 35 docDomain = getDecodedHostname(url);
38 getDecodedHostname(url), false, null 36
37 let filter = defaultMatcher.whitelist.matchesAny(
38 urlString, typeMask, docDomain, thirdParty, sitekey
39 ); 39 );
40 }; 40
41 if (filter && devtools)
42 devtools.logWhitelistedDocument(
43 page, urlString, typeMask, docDomain, filter
44 );
45
46 return filter;
47 }
41 48
42 /** 49 /**
43 * Checks whether a frame is whitelisted. 50 * Gets the active whitelisting filter for the document associated
51 * with the given page/frame, or null if it's not whitelisted.
44 * 52 *
45 * @param {Page} page 53 * @param {Page} page
46 * @param {Frame} frame 54 * @param {Frame} [frame]
47 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] Bit mask of request / content types to match 55 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT]
48 * @return {Boolean} 56 * @return {?WhitelistFilter}
49 */ 57 */
50 exports.isFrameWhitelisted = function(page, frame, typeMask) 58 exports.checkWhitelisted = function(page, frame, typeMask)
51 { 59 {
52 while (frame) 60 if (typeof typeMask == "undefined")
61 typeMask = RegExpFilter.typeMap.DOCUMENT;
62
63 if (frame)
53 { 64 {
54 let parent = frame.parent; 65 let filter = null;
55 let url = frame.url;
56 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url);
57 66
58 let filter = defaultMatcher.whitelist.matchesAny( 67 while (frame && !filter)
59 stringifyURL(url), typeMask || RegExpFilter.typeMap.DOCUMENT, 68 {
60 documentHost, isThirdParty(url, documentHost), 69 let parent = frame.parent;
61 getKey(page, frame) 70 let docDomain = extractHostFromFrame(parent);
62 ); 71 let sitekey = getKey(page, frame);
63 72
64 if (filter) 73 filter = match(page, frame.url, typeMask, docDomain, sitekey);
65 return true; 74 frame = parent;
75 }
66 76
67 frame = parent; 77 return filter;
68 } 78 }
69 79
70 return false; 80 return match(page, page.url, typeMask);
71 }; 81 };
72 82
73 let getKey = 83 let getKey =
74 /** 84 /**
75 * Gets the public key, previously recorded for the given page 85 * Gets the public key, previously recorded for the given page
76 * and frame, to be considered for the $sitekey filter option. 86 * and frame, to be considered for the $sitekey filter option.
77 * 87 *
78 * @param {Page} page 88 * @param {Page} page
79 * @param {Frame} frame 89 * @param {Frame} frame
80 * @return {string} 90 * @return {string}
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 { 144 {
135 if (token.indexOf("_") < 0) 145 if (token.indexOf("_") < 0)
136 return; 146 return;
137 147
138 let [key, signature] = token.split("_", 2); 148 let [key, signature] = token.split("_", 2);
139 key = key.replace(/=/g, ""); 149 key = key.replace(/=/g, "");
140 150
141 if (verifyKey(key, signature, frame.url)) 151 if (verifyKey(key, signature, frame.url))
142 recordKey(page, frame.url, key); 152 recordKey(page, frame.url, key);
143 }; 153 };
OLDNEW
« no previous file with comments | « lib/filterComposer.js ('k') | metadata.chrome » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld