From fcd7c4aef0c4b81dafd90ce38f41918ac58da139 Mon Sep 17 00:00:00 2001 From: hackademix Date: Sun, 29 Sep 2019 00:50:43 +0200 Subject: Replace cookie-based hacks with synchronous messaging (currently shimmed) to retrieve fallback and per-tab restriction policies. --- src/bg/RequestGuard.js | 6 +++++- src/bg/main.js | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src/bg') diff --git a/src/bg/RequestGuard.js b/src/bg/RequestGuard.js index 8d30fe7..3936df9 100644 --- a/src/bg/RequestGuard.js +++ b/src/bg/RequestGuard.js @@ -287,8 +287,12 @@ var RequestGuard = (() => { if (policyType) { let {url, originUrl, documentUrl} = request; let isFetch = "fetch" === policyType; + if ((isFetch || "frame" === policyType) && - (((isFetch && !originUrl || url === originUrl) && originUrl === documentUrl + (((isFetch && (!originUrl || + browser.runtime.onSyncMessage && + url.includes(browser.runtime.onSyncMessage.ENDPOINT_PREFIX) + ) || url === originUrl) && originUrl === documentUrl // some extensions make them both undefined, // see https://github.com/eight04/image-picka/issues/150 ) || diff --git a/src/bg/main.js b/src/bg/main.js index ed53603..9c30d4f 100644 --- a/src/bg/main.js +++ b/src/bg/main.js @@ -141,24 +141,26 @@ }, fetchChildPolicy({url, contextUrl}, sender) { - if (!url) url = sender.url; let {tab} = sender; - let tabUrl = tab.url; - if (!contextUrl) contextUrl = tabUrl; - + let topUrl = tab.url || TabCache.get(tab.id); let policy = !Sites.isInternal(url) && ns.isEnforced(tab.id) ? ns.policy : null; - let permissions = Permissions.ALL; + let permissions, unrestricted, cascaded; if (policy) { let perms = policy.get(url, contextUrl).perms; - if (tabUrl && ns.sync.cascadeRestrictions) { - perms = policy.cascadeRestrictions(perms, tabUrl); + cascaded = ns.sync.cascadeRestrictions; + if (topUrl && cascaded) { + perms = policy.cascadeRestrictions(perms, topUrl); } permissions = perms.dry(); - } // otherwise either internal URL or unrestricted - - return {permissions}; + } else { + // otherwise either internal URL or unrestricted + permissions = new Permissions(Permissions.ALL); + unrestricted = true; + cascaded = false; + } + return {permissions, unrestricted, cascaded}; }, async openStandalonePopup() { -- cgit v1.2.3