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

Delta Between Two Patch Sets: lib/whitelisting.js

Issue 5644946291818496: Issue 433 - Made adjustments for $sitekey-related changes to the Matcher API (Closed)
Left Patch Set: Created Sept. 10, 2014, 3:38 p.m.
Right Patch Set: Created Sept. 15, 2014, 9:22 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « include.preload.js ('k') | webrequest.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 return false; 45 return false;
46 }; 46 };
47 47
48 let getKey = exports.getKey = function(page, frame) 48 let getKey = exports.getKey = function(page, frame)
49 { 49 {
50 let urlsWithKey = pagesWithKey.get(page); 50 let urlsWithKey = pagesWithKey.get(page);
51 if (!urlsWithKey) 51 if (!urlsWithKey)
52 return null; 52 return null;
53 53
54 while (true) 54 for (; frame != null; frame = frame.parent)
55 { 55 {
56 if (urlsWithKey[frame.url]) 56 if (urlsWithKey[frame.url])
57 return urlsWithKey[frame.url]; 57 return urlsWithKey[frame.url];
58 }
58 59
59 if (frame === frame.parent) 60 return null;
Wladimir Palant 2014/09/10 18:27:04 This isn't the DOM, it's our own structure - frame
Thomas Greiner 2014/09/15 09:24:59 Done.
60 return null;
61
62 frame = frame.parent;
63 }
64 } 61 }
65 62
66 let verifyKey = function(key, signature, url, docDomain) 63 let verifyKey = function(key, signature, url, docDomain)
67 { 64 {
68 let uri = new URI(url); 65 let uri = new URI(url);
69 let params = [ 66 let params = [
70 uri.path, // REQUEST_URI 67 uri.path, // REQUEST_URI
71 uri.asciiHost + (uri.port != -1 ? ":" + uri.port : ""), // HTTP_HOST 68 uri.asciiHost + (uri.port != -1 ? ":" + uri.port : ""), // HTTP_HOST
72 window.navigator.userAgent // HTTP_USER_AGENT 69 window.navigator.userAgent // HTTP_USER_AGENT
73 ]; 70 ];
74 71
75 return verifySignature(key, signature, params.join("\0")); 72 return verifySignature(key, signature, params.join("\0"));
76 }; 73 };
77 74
78 let recordKey = function(page, url, key) 75 let recordKey = function(page, url, key)
79 { 76 {
80 let urlsWithKey = pagesWithKey.get(page); 77 let urlsWithKey = pagesWithKey.get(page);
81 78
82 if (!urlsWithKey) 79 if (!urlsWithKey)
83 { 80 {
84 urlsWithKey = {__proto__: null}; 81 urlsWithKey = {__proto__: null};
85 pagesWithKey.set(page, urlsWithKey); 82 pagesWithKey.set(page, urlsWithKey);
86 } 83 }
87 84
88 urlsWithKey[url] = key; 85 urlsWithKey[url] = key;
89 }; 86 };
90 87
91 let processKey = exports.processKey = function(sitekey, page, frame) 88 let processKey = exports.processKey = function(token, page, frame)
92 { 89 {
93 let url = stripFragmentFromURL(frame.url); 90 let url = stripFragmentFromURL(frame.url);
94 let docDomain = extractHostFromURL((frame.parent || frame).url); 91 let docDomain = extractHostFromURL((frame.parent || frame).url);
95 92
96 let keydata = sitekey.match(/((.*?)=*)_(.*)/); 93 if (token.indexOf("_") < 0)
97 if (!keydata)
98 return; 94 return;
99 95
100 let key = keydata[1].replace(/=/g, ""); 96 let [key, signature] = token.split("_", 2);
101 let signature = keydata[3]; 97 key = key.replace(/=/g, "");
Wladimir Palant 2014/09/10 18:27:04 Why not use the same approach as in Firefox? if
Thomas Greiner 2014/09/15 09:24:59 Done.
102 if (verifyKey(key, signature, url, docDomain)) 98 if (verifyKey(key, signature, url, docDomain))
103 recordKey(page, url, key); 99 recordKey(page, url, key);
104 }; 100 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld