Left: | ||
Right: |
OLD | NEW |
---|---|
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 | 20 |
21 let pagesWithKey = new ext.PageMap(); | 21 let pagesWithKey = new ext.PageMap(); |
22 | 22 |
23 let isWhitelisted = exports.isWhitelisted = function(url, parentUrl, type, key) | 23 function isWhitelisted(url, parentUrl, type, key) |
24 { | 24 { |
25 let filter = defaultMatcher.matchesAny( | 25 let filter = defaultMatcher.matchesAny( |
26 stripFragmentFromURL(url), | 26 stripFragmentFromURL(url), |
27 type || "DOCUMENT", | 27 type || "DOCUMENT", |
28 extractHostFromURL(parentUrl || url), | 28 extractHostFromURL(parentUrl || url), |
29 false, | 29 false, |
30 key | 30 key |
31 ); | 31 ); |
32 | 32 |
33 return (filter instanceof WhitelistFilter ? filter : null); | 33 return (filter instanceof WhitelistFilter ? filter : null); |
34 }; | 34 } |
35 exports.isWhitelisted = isWhitelisted; | |
35 | 36 |
36 let isFrameWhitelisted = exports.isFrameWhitelisted = function(page, frame, type ) | 37 function isFrameWhitelisted(page, frame, type) |
37 { | 38 { |
38 for (; frame != null; frame = frame.parent) | 39 for (; frame != null; frame = frame.parent) |
39 { | 40 { |
40 let key = getKey(page, frame); | 41 let key = getKey(page, frame); |
41 if (isWhitelisted(frame.url, (frame.parent || {}).url, type, key)) | 42 if (isWhitelisted(frame.url, (frame.parent || {}).url, type, key)) |
42 return true; | 43 return true; |
43 } | 44 } |
44 | 45 |
45 return false; | 46 return false; |
46 }; | 47 } |
48 exports.isFrameWhitelisted = isFrameWhitelisted; | |
47 | 49 |
48 let getKey = exports.getKey = function(page, frame) | 50 function getKey(page, frame) |
kzar
2015/01/21 14:12:55
Shouldn't getKey be declared before isFrameWhiteli
Sebastian Noack
2015/01/21 14:24:49
Yes, we usually declare functions before they are
| |
49 { | 51 { |
50 let urlsWithKey = pagesWithKey.get(page); | 52 let urlsWithKey = pagesWithKey.get(page); |
51 if (!urlsWithKey) | 53 if (!urlsWithKey) |
52 return null; | 54 return null; |
53 | 55 |
54 for (; frame != null; frame = frame.parent) | 56 for (; frame != null; frame = frame.parent) |
55 { | 57 { |
56 if (urlsWithKey[frame.url]) | 58 if (urlsWithKey[frame.url]) |
57 return urlsWithKey[frame.url]; | 59 return urlsWithKey[frame.url]; |
58 } | 60 } |
59 | 61 |
60 return null; | 62 return null; |
61 } | 63 } |
64 exports.getKey = getKey; | |
62 | 65 |
63 let verifyKey = function(key, signature, url) | 66 function verifyKey(key, signature, url) |
64 { | 67 { |
65 url = new URL(url); | 68 url = new URL(url); |
66 let params = [ | 69 let params = [ |
67 url.pathname + url.search, // REQUEST_URI | 70 url.pathname + url.search, // REQUEST_URI |
68 url.host, // HTTP_HOST | 71 url.host, // HTTP_HOST |
69 window.navigator.userAgent // HTTP_USER_AGENT | 72 window.navigator.userAgent // HTTP_USER_AGENT |
70 ]; | 73 ]; |
71 | 74 |
72 return verifySignature(key, signature, params.join("\0")); | 75 return verifySignature(key, signature, params.join("\0")); |
73 }; | 76 } |
74 | 77 |
75 let recordKey = function(page, url, key) | 78 function recordKey(page, url, key) |
76 { | 79 { |
77 let urlsWithKey = pagesWithKey.get(page); | 80 let urlsWithKey = pagesWithKey.get(page); |
78 | 81 |
79 if (!urlsWithKey) | 82 if (!urlsWithKey) |
80 { | 83 { |
81 urlsWithKey = {__proto__: null}; | 84 urlsWithKey = {__proto__: null}; |
82 pagesWithKey.set(page, urlsWithKey); | 85 pagesWithKey.set(page, urlsWithKey); |
83 } | 86 } |
84 | 87 |
85 urlsWithKey[url] = key; | 88 urlsWithKey[url] = key; |
86 }; | 89 } |
87 | 90 |
88 let processKey = exports.processKey = function(token, page, frame) | 91 function processKey(token, page, frame) |
89 { | 92 { |
90 let url = stripFragmentFromURL(frame.url); | 93 let url = stripFragmentFromURL(frame.url); |
91 | 94 |
92 if (token.indexOf("_") < 0) | 95 if (token.indexOf("_") < 0) |
93 return; | 96 return; |
94 | 97 |
95 let [key, signature] = token.split("_", 2); | 98 let [key, signature] = token.split("_", 2); |
96 key = key.replace(/=/g, ""); | 99 key = key.replace(/=/g, ""); |
97 | 100 |
98 if (verifyKey(key, signature, url)) | 101 if (verifyKey(key, signature, url)) |
99 recordKey(page, url, key); | 102 recordKey(page, url, key); |
100 }; | 103 } |
104 exports.processKey = processKey; | |
OLD | NEW |