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

Unified Diff: lib/whitelisting.js

Issue 29357576: Issue 4483 - Update page structure when sitekey is received (Closed)
Patch Set: Created Oct. 17, 2016, 10:16 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/ext/background.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/whitelisting.js
diff --git a/lib/whitelisting.js b/lib/whitelisting.js
index dca8adc4278bf9de368f42e70eb997b750613088..02f5adb310b971c6c8bd7206566860d4a60c6f8a 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);
+ recordKey(key, page, url);
+ break;
+ }
+ }
+ }
}
if (typeof chrome == "object")
« no previous file with comments | « chrome/ext/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld