Index: lib/whitelisting.js |
diff --git a/lib/whitelisting.js b/lib/whitelisting.js |
index dca8adc4278bf9de368f42e70eb997b750613088..3283952bf860f7db1d853941ef76643db4a8862c 100644 |
--- a/lib/whitelisting.js |
+++ b/lib/whitelisting.js |
@@ -134,11 +134,11 @@ exports.getKey = function(page, frame) |
return null; |
}; |
-function recordKey(token, page, url) |
+function checkKey(token, url) |
{ |
let parts = token.split("_"); |
if (parts.length < 2) |
- return; |
+ return false; |
let key = parts[0].replace(/=/g, ""); |
let signature = parts[1]; |
@@ -146,8 +146,13 @@ function recordKey(token, page, url) |
url.host + "\0" + |
window.navigator.userAgent; |
if (!verifySignature(key, signature, data)) |
- return; |
+ return false; |
+ return key; |
+} |
+ |
+function recordKey(key, page, url) |
+{ |
let keys = sitekeys.get(page); |
if (!keys) |
{ |
@@ -159,7 +164,9 @@ function recordKey(token, page, url) |
port.on("filters.addKey", (message, sender) => |
{ |
- recordKey(message.token, sender.page, sender.frame.url); |
+ let key = checkKey(message.token, sender.frame.url); |
+ if (key) |
+ recordKey(key, sender.page, sender.frame.url); |
}); |
function onHeadersReceived(details) |
@@ -167,8 +174,23 @@ function onHeadersReceived(details) |
let page = new ext.Page({id: details.tabId}); |
for (let header of details.responseHeaders) |
+ { |
if (header.name.toLowerCase() == "x-adblock-key" && header.value) |
- recordKey(header.value, page, new URL(details.url)); |
+ { |
+ let url = new URL(details.url); |
+ let key = checkKey(header.value, url); |
+ if (key) |
+ { |
+ // For pre-rendered tabs we don't know for sure the navigation is going |
+ // to happen until the onCommitted event fires. Unfortunately if we want |
+ // sitekey whitelisting to work for requests made before onCommitted has |
+ // been fired we must update the page structure now anyway. |
+ ext._updatePageFrameStructure(details.frameId, details.tabId, details.url, true); |
+ recordKey(key, page, url); |
+ break; |
+ } |
+ } |
+ } |
} |
if (typeof chrome == "object") |