From a489c192d6ab3bc70cf6af90f4a60c04a2a76a9d Mon Sep 17 00:00:00 2001 From: hackademix Date: Mon, 8 Apr 2019 13:08:17 +0200 Subject: Make RequestGuard's header processing synchronous on non-supporting browsers. --- src/bg/ChildPolicies.js | 9 +++++---- src/bg/RequestGuard.js | 14 ++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'src/bg') 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); -- cgit v1.2.3