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

Side by Side Diff: lib/whitelisting.js

Issue 6292212006518784: Noissue - Added documentation for exported functions to the "whitelisting" module (Closed)
Patch Set: Created Feb. 28, 2015, 5:25 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 | « no previous file | no next file » | 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 let {defaultMatcher} = require("matcher"); 18 let {defaultMatcher} = require("matcher");
19 let {WhitelistFilter} = require("filterClasses"); 19 let {WhitelistFilter} = require("filterClasses");
20 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url"); 20 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url");
21 21
22 let pagesWithKey = new ext.PageMap(); 22 let pagesWithKey = new ext.PageMap();
23 23
24 /**
25 * Checks whether a page is whitelisted.
26 *
27 * @param {Page} page
28 * @return {WhitelistFilter} The active filter whitelisting this page or null
29 */
24 function isPageWhitelisted(page) 30 function isPageWhitelisted(page)
25 { 31 {
26 let url = page.url; 32 let url = page.url;
27 let filter = defaultMatcher.matchesAny( 33 let filter = defaultMatcher.matchesAny(
28 stringifyURL(url), "DOCUMENT", 34 stringifyURL(url), "DOCUMENT",
29 getDecodedHostname(url), false, null 35 getDecodedHostname(url), false, null
30 ); 36 );
31 37
32 return (filter instanceof WhitelistFilter ? filter : null); 38 return (filter instanceof WhitelistFilter ? filter : null);
33 } 39 }
34 exports.isPageWhitelisted = isPageWhitelisted; 40 exports.isPageWhitelisted = isPageWhitelisted;
35 41
42 /**
43 * Checks whether a frame is whitelisted.
44 *
45 * @param {Page} page
46 * @param {Frame} frame
47 * @param {string} [type=DOCUMENT] The request type to check whether
48 * the frame is whitelisted for.
49 * @return {Boolean}
50 */
36 function isFrameWhitelisted(page, frame, type) 51 function isFrameWhitelisted(page, frame, type)
37 { 52 {
38 while (frame) 53 while (frame)
39 { 54 {
40 let parent = frame.parent; 55 let parent = frame.parent;
41 let url = frame.url; 56 let url = frame.url;
42 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url); 57 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url);
43 58
44 let filter = defaultMatcher.matchesAny( 59 let filter = defaultMatcher.matchesAny(
45 stringifyURL(url), type || "DOCUMENT", 60 stringifyURL(url), type || "DOCUMENT",
46 documentHost, isThirdParty(url, documentHost), 61 documentHost, isThirdParty(url, documentHost),
47 getKey(page, frame) 62 getKey(page, frame)
48 ); 63 );
49 64
50 if (filter instanceof WhitelistFilter) 65 if (filter instanceof WhitelistFilter)
51 return true; 66 return true;
52 67
53 frame = parent; 68 frame = parent;
54 } 69 }
55 70
56 return false; 71 return false;
57 } 72 }
58 exports.isFrameWhitelisted = isFrameWhitelisted; 73 exports.isFrameWhitelisted = isFrameWhitelisted;
59 74
75 /**
76 * Gets the public key, previously recorded for the given page
77 * and frame, to be considered for the $sitekey filter option.
78 *
79 * @param {Page} page
80 * @param {Frame} frame
81 * @return {string}
82 */
60 function getKey(page, frame) 83 function getKey(page, frame)
61 { 84 {
62 let urlsWithKey = pagesWithKey.get(page); 85 let urlsWithKey = pagesWithKey.get(page);
63 if (!urlsWithKey) 86 if (!urlsWithKey)
64 return null; 87 return null;
65 88
66 for (; frame != null; frame = frame.parent) 89 for (; frame != null; frame = frame.parent)
67 { 90 {
68 let key = urlsWithKey[stringifyURL(frame.url)]; 91 let key = urlsWithKey[stringifyURL(frame.url)];
69 if (key) 92 if (key)
(...skipping 21 matching lines...) Expand all
91 114
92 if (!urlsWithKey) 115 if (!urlsWithKey)
93 { 116 {
94 urlsWithKey = Object.create(null); 117 urlsWithKey = Object.create(null);
95 pagesWithKey.set(page, urlsWithKey); 118 pagesWithKey.set(page, urlsWithKey);
96 } 119 }
97 120
98 urlsWithKey[stringifyURL(url)] = key; 121 urlsWithKey[stringifyURL(url)] = key;
99 } 122 }
100 123
124 /**
125 * Validates signatures given by the "X-Adblock-Key" request
126 * header or the "data-adblockkey" attribute of the document
127 * element. If the signature is valid, the public key will be
128 * recorded and considered for the $sitekey filter option.
129 *
130 * @param {string} token The base64-encoded public key and
131 * signature separated by an underscrore.
132 * @param {Page} page
133 * @param {Frame} frame
134 */
101 function processKey(token, page, frame) 135 function processKey(token, page, frame)
102 { 136 {
103 if (token.indexOf("_") < 0) 137 if (token.indexOf("_") < 0)
104 return; 138 return;
105 139
106 let [key, signature] = token.split("_", 2); 140 let [key, signature] = token.split("_", 2);
107 key = key.replace(/=/g, ""); 141 key = key.replace(/=/g, "");
108 142
109 if (verifyKey(key, signature, frame.url)) 143 if (verifyKey(key, signature, frame.url))
110 recordKey(page, frame.url, key); 144 recordKey(page, frame.url, key);
111 } 145 }
112 exports.processKey = processKey; 146 exports.processKey = processKey;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld