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

Side by Side Diff: lib/whitelisting.js

Issue 29338491: Issue 3823 - Split up message responder code (Closed)
Patch Set: Use require() inline Created March 21, 2016, 7:53 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/messaging.js ('k') | metadata.common » ('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 let {defaultMatcher} = require("matcher"); 22 let {defaultMatcher} = require("matcher");
23 let {RegExpFilter} = require("filterClasses"); 23 let {RegExpFilter} = require("filterClasses");
24 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url"); 24 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url");
25 let {port} = require("messaging");
25 let devtools = require("devtools"); 26 let devtools = require("devtools");
26 27
27 let pagesWithKey = new ext.PageMap(); 28 let pagesWithKey = new ext.PageMap();
28 29
29 function match(page, url, typeMask, docDomain, sitekey) 30 function match(page, url, typeMask, docDomain, sitekey)
30 { 31 {
31 let thirdParty = !!docDomain && isThirdParty(url, docDomain); 32 let thirdParty = !!docDomain && isThirdParty(url, docDomain);
32 let urlString = stringifyURL(url); 33 let urlString = stringifyURL(url);
33 34
34 if (!docDomain) 35 if (!docDomain)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 123
123 if (!urlsWithKey) 124 if (!urlsWithKey)
124 { 125 {
125 urlsWithKey = Object.create(null); 126 urlsWithKey = Object.create(null);
126 pagesWithKey.set(page, urlsWithKey); 127 pagesWithKey.set(page, urlsWithKey);
127 } 128 }
128 129
129 urlsWithKey[stringifyURL(url)] = key; 130 urlsWithKey[stringifyURL(url)] = key;
130 } 131 }
131 132
133 let processKey =
132 /** 134 /**
133 * Validates signatures given by the "X-Adblock-Key" response 135 * Validates signatures given by the "X-Adblock-Key" response
134 * header or the "data-adblockkey" attribute of the document 136 * header or the "data-adblockkey" attribute of the document
135 * element. If the signature is valid, the public key will be 137 * element. If the signature is valid, the public key will be
136 * recorded and considered for the $sitekey filter option. 138 * recorded and considered for the $sitekey filter option.
137 * 139 *
138 * @param {string} token The base64-encoded public key and 140 * @param {string} token The base64-encoded public key and
139 * signature separated by an underscrore. 141 * signature separated by an underscrore.
140 * @param {Page} page 142 * @param {Page} page
141 * @param {Frame} frame 143 * @param {Frame} frame
142 */ 144 */
143 exports.processKey = function(token, page, frame) 145 exports.processKey = function(token, page, frame)
144 { 146 {
145 if (token.indexOf("_") < 0) 147 if (token.indexOf("_") < 0)
146 return; 148 return;
147 149
148 let [key, signature] = token.split("_", 2); 150 let [key, signature] = token.split("_", 2);
149 key = key.replace(/=/g, ""); 151 key = key.replace(/=/g, "");
150 152
151 if (verifyKey(key, signature, frame.url)) 153 if (verifyKey(key, signature, frame.url))
152 recordKey(page, frame.url, key); 154 recordKey(page, frame.url, key);
153 }; 155 };
156
157 port.on("filters.addKey", (message, sender) =>
158 {
159 processKey(message.token, sender.page, sender.frame);
160 });
OLDNEW
« no previous file with comments | « lib/messaging.js ('k') | metadata.common » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld