| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 * @return {string} | 121 * @return {string} |
| 122 */ | 122 */ |
| 123 exports.getKey = (page, frame) => | 123 exports.getKey = (page, frame) => |
| 124 { | 124 { |
| 125 let keys = sitekeys.get(page); | 125 let keys = sitekeys.get(page); |
| 126 if (!keys) | 126 if (!keys) |
| 127 return null; | 127 return null; |
| 128 | 128 |
| 129 for (; frame != null; frame = frame.parent) | 129 for (; frame != null; frame = frame.parent) |
| 130 { | 130 { |
| 131 let key = keys[stringifyURL(frame.url)]; | 131 let key = keys.get(stringifyURL(frame.url)); |
| 132 if (key) | 132 if (key) |
| 133 return key; | 133 return key; |
| 134 } | 134 } |
| 135 | 135 |
| 136 return null; | 136 return null; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 function checkKey(token, url) | 139 function checkKey(token, url) |
| 140 { | 140 { |
| 141 let parts = token.split("_"); | 141 let parts = token.split("_"); |
| 142 if (parts.length < 2) | 142 if (parts.length < 2) |
| 143 return false; | 143 return false; |
| 144 | 144 |
| 145 let key = parts[0].replace(/=/g, ""); | 145 let key = parts[0].replace(/=/g, ""); |
| 146 let signature = parts[1]; | 146 let signature = parts[1]; |
| 147 let data = url.pathname + url.search + "\0" + | 147 let data = url.pathname + url.search + "\0" + |
| 148 url.host + "\0" + | 148 url.host + "\0" + |
| 149 window.navigator.userAgent; | 149 window.navigator.userAgent; |
| 150 if (!verifySignature(key, signature, data)) | 150 if (!verifySignature(key, signature, data)) |
| 151 return false; | 151 return false; |
| 152 | 152 |
| 153 return key; | 153 return key; |
| 154 } | 154 } |
| 155 | 155 |
| 156 function recordKey(key, page, url) | 156 function recordKey(key, page, url) |
| 157 { | 157 { |
| 158 let keys = sitekeys.get(page); | 158 let keys = sitekeys.get(page); |
| 159 if (!keys) | 159 if (!keys) |
| 160 { | 160 { |
| 161 keys = Object.create(null); | 161 keys = new Map(); |
| 162 sitekeys.set(page, keys); | 162 sitekeys.set(page, keys); |
| 163 } | 163 } |
| 164 keys[stringifyURL(url)] = key; | 164 keys.set(stringifyURL(url), key); |
| 165 } | 165 } |
| 166 | 166 |
| 167 port.on("filters.addKey", (message, sender) => | 167 port.on("filters.addKey", (message, sender) => |
| 168 { | 168 { |
| 169 let key = checkKey(message.token, sender.frame.url); | 169 let key = checkKey(message.token, sender.frame.url); |
| 170 if (key) | 170 if (key) |
| 171 recordKey(key, sender.page, sender.frame.url); | 171 recordKey(key, sender.page, sender.frame.url); |
| 172 }); | 172 }); |
| 173 | 173 |
| 174 function onHeadersReceived(details) | 174 function onHeadersReceived(details) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 194 { | 194 { |
| 195 chrome.webRequest.onHeadersReceived.addListener( | 195 chrome.webRequest.onHeadersReceived.addListener( |
| 196 onHeadersReceived, | 196 onHeadersReceived, |
| 197 { | 197 { |
| 198 urls: ["http://*/*", "https://*/*"], | 198 urls: ["http://*/*", "https://*/*"], |
| 199 types: ["main_frame", "sub_frame"] | 199 types: ["main_frame", "sub_frame"] |
| 200 }, | 200 }, |
| 201 ["responseHeaders"] | 201 ["responseHeaders"] |
| 202 ); | 202 ); |
| 203 } | 203 } |
| OLD | NEW |