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

Side by Side Diff: lib/whitelisting.js

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

Powered by Google App Engine
This is Rietveld