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

Side by Side Diff: lib/whitelisting.js

Issue 29357576: Issue 4483 - Update page structure when sitekey is received (Closed)
Patch Set: Avoid updating the page structure twice Created Oct. 17, 2016, 11:03 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« chrome/ext/background.js ('K') | « chrome/ext/background.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-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
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 for (; frame != null; frame = frame.parent) 127 for (; frame != null; frame = frame.parent)
128 { 128 {
129 let key = keys[stringifyURL(frame.url)]; 129 let key = keys[stringifyURL(frame.url)];
130 if (key) 130 if (key)
131 return key; 131 return key;
132 } 132 }
133 133
134 return null; 134 return null;
135 }; 135 };
136 136
137 function recordKey(token, page, url) 137 function checkKey(token, url)
138 { 138 {
139 let parts = token.split("_"); 139 let parts = token.split("_");
140 if (parts.length < 2) 140 if (parts.length < 2)
141 return; 141 return false;
142 142
143 let key = parts[0].replace(/=/g, ""); 143 let key = parts[0].replace(/=/g, "");
144 let signature = parts[1]; 144 let signature = parts[1];
145 let data = url.pathname + url.search + "\0" + 145 let data = url.pathname + url.search + "\0" +
146 url.host + "\0" + 146 url.host + "\0" +
147 window.navigator.userAgent; 147 window.navigator.userAgent;
148 if (!verifySignature(key, signature, data)) 148 if (!verifySignature(key, signature, data))
149 return; 149 return false;
150 150
151 return key;
152 }
153
154 function recordKey(key, page, url)
155 {
151 let keys = sitekeys.get(page); 156 let keys = sitekeys.get(page);
152 if (!keys) 157 if (!keys)
153 { 158 {
154 keys = Object.create(null); 159 keys = Object.create(null);
155 sitekeys.set(page, keys); 160 sitekeys.set(page, keys);
156 } 161 }
157 keys[stringifyURL(url)] = key; 162 keys[stringifyURL(url)] = key;
158 } 163 }
159 164
160 port.on("filters.addKey", (message, sender) => 165 port.on("filters.addKey", (message, sender) =>
161 { 166 {
162 recordKey(message.token, sender.page, sender.frame.url); 167 let key = checkKey(message.token, sender.frame.url);
168 if (key)
169 recordKey(key, sender.page, sender.frame.url);
163 }); 170 });
164 171
165 function onHeadersReceived(details) 172 function onHeadersReceived(details)
166 { 173 {
167 let page = new ext.Page({id: details.tabId}); 174 let page = new ext.Page({id: details.tabId});
168 175
169 for (let header of details.responseHeaders) 176 for (let header of details.responseHeaders)
177 {
170 if (header.name.toLowerCase() == "x-adblock-key" && header.value) 178 if (header.name.toLowerCase() == "x-adblock-key" && header.value)
171 recordKey(header.value, page, new URL(details.url)); 179 {
180 let url = new URL(details.url);
181 let key = checkKey(header.value, url);
182 if (key)
183 {
184 // For pre-rendered tabs we don't know for sure the navigation is going
185 // to happen until the onCommitted event fires. Unfortunately if we want
186 // sitekey whitelisting to work for requests made before onCommitted has
187 // been fired we must update the page structure now anyway.
188 ext._updatePageFrameStructure(details.frameId, details.tabId, details.ur l, true);
189 recordKey(key, page, url);
190 break;
191 }
192 }
193 }
172 } 194 }
173 195
174 if (typeof chrome == "object") 196 if (typeof chrome == "object")
175 chrome.webRequest.onHeadersReceived.addListener( 197 chrome.webRequest.onHeadersReceived.addListener(
176 onHeadersReceived, 198 onHeadersReceived,
177 { 199 {
178 urls: ["http://*/*", "https://*/*"], 200 urls: ["http://*/*", "https://*/*"],
179 types: ["main_frame", "sub_frame"] 201 types: ["main_frame", "sub_frame"]
180 }, 202 },
181 ["responseHeaders"] 203 ["responseHeaders"]
182 ); 204 );
OLDNEW
« chrome/ext/background.js ('K') | « chrome/ext/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld