summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhackademix2019-04-08 13:08:17 +0200
committerhackademix2019-04-08 13:08:17 +0200
commita489c192d6ab3bc70cf6af90f4a60c04a2a76a9d (patch)
tree5dff76fa5c306296688b0fd694e8a3a60bd10564
parent5ffd53ee89767e1ca08d41516e968aab06cf42d3 (diff)
downloadnoscript-a489c192d6ab3bc70cf6af90f4a60c04a2a76a9d.tar.gz
noscript-a489c192d6ab3bc70cf6af90f4a60c04a2a76a9d.tar.xz
noscript-a489c192d6ab3bc70cf6af90f4a60c04a2a76a9d.zip
Make RequestGuard's header processing synchronous on non-supporting browsers.
-rw-r--r--src/bg/ChildPolicies.js9
-rw-r--r--src/bg/RequestGuard.js14
2 files changed, 15 insertions, 8 deletions
diff --git a/src/bg/ChildPolicies.js b/src/bg/ChildPolicies.js
index e5024e7..58b18ca 100644
--- a/src/bg/ChildPolicies.js
+++ b/src/bg/ChildPolicies.js
@@ -51,10 +51,6 @@
}
};
- if (!browser.contentScripts) { // #chromium fallback
- Scripts.register = () => {};
- }
-
let flatten = arr => arr.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []);
let protocolRx = /^(\w+):/i;
@@ -196,4 +192,9 @@
},
};
+
+ if (!browser.contentScripts) { // #chromium fallback
+ Scripts.register = ChildPolicies.update = () => {};
+ }
+
}
diff --git a/src/bg/RequestGuard.js b/src/bg/RequestGuard.js
index c1771aa..bdf2ea2 100644
--- a/src/bg/RequestGuard.js
+++ b/src/bg/RequestGuard.js
@@ -296,7 +296,9 @@ var RequestGuard = (() => {
}
return ALLOW;
},
- async onHeadersReceived(request) {
+ onHeadersReceived(request) {
+ let result = ALLOW;
+ let promises = [];
// called for main_frame, sub_frame and object
// check for duplicate calls
let headersModified = false;
@@ -324,7 +326,7 @@ var RequestGuard = (() => {
if (isMainFrame) {
if (policy.autoAllowTop && perms === policy.DEFAULT) {
policy.set(Sites.optimalKey(url), perms = policy.TRUSTED.tempTwin);
- await ChildPolicies.update(policy);
+ promises.push(ChildPolicies.update(policy));
}
capabilities = perms.capabilities;
} else {
@@ -360,12 +362,16 @@ var RequestGuard = (() => {
headersModified = true;
}
if (headersModified) {
- return {responseHeaders};
+ result = {responseHeaders};
}
} catch (e) {
error(e, "Error in onHeadersReceived", request);
}
- return ALLOW;
+ promises = promises.filter(p => p instanceof Promise);
+ if (promises.length > 0) {
+ return Promise.all(promises).then(() => result);
+ }
+ return result;
},
onResponseStarted(request) {
debug("onResponseStarted", request);