diff options
author | hackademix | 2019-10-01 22:37:13 +0200 |
---|---|---|
committer | hackademix | 2019-10-01 22:37:28 +0200 |
commit | e3c09d4dc014985bd90bfe6acde1a434bf65ff9b (patch) | |
tree | 0ba7f463148afc4f5b025c07d9587489c38f59fe /src/bg | |
parent | a9a85a5c22b5ccae57498bdb649459f546c433bb (diff) | |
download | noscript-e3c09d4dc014985bd90bfe6acde1a434bf65ff9b.tar.gz noscript-e3c09d4dc014985bd90bfe6acde1a434bf65ff9b.tar.xz noscript-e3c09d4dc014985bd90bfe6acde1a434bf65ff9b.zip |
Handle edge-case policy retrieval for file:// pages loaded by session restore on startup and alike.
Diffstat (limited to 'src/bg')
-rw-r--r-- | src/bg/main.js | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/bg/main.js b/src/bg/main.js index 5e1b692..bae534f 100644 --- a/src/bg/main.js +++ b/src/bg/main.js @@ -142,9 +142,20 @@ fetchChildPolicy({url, contextUrl}, sender) { let {tab, frameId} = sender; + let policy = ns.policy; + if (!policy) { + console.log("Policy is null, initializing: %o, sending fallback.", ns.initializing); + return { + permissions: new Permissions(Permissions.DEFAULT).dry(), + unrestricted: false, + cascaded: false, + fallback: true + }; + } let topUrl = frameId === 0 ? contextUrl : tab && (tab.url || TabCache.get(tab.id)); - let policy = !Sites.isInternal(url) && ns.isEnforced(tab ? tab.id : -1) - ? ns.policy : null; + if (Sites.isInternal(url) || !ns.isEnforced(tab ? tab.id : -1)) { + policy = null; + } let permissions, unrestricted, cascaded; if (policy) { @@ -156,7 +167,7 @@ permissions = perms.dry(); } else { // otherwise either internal URL or unrestricted - permissions = new Permissions(Permissions.ALL); + permissions = new Permissions(Permissions.ALL).dry(); unrestricted = true; cascaded = false; } @@ -198,6 +209,7 @@ policy: null, local: null, sync: null, + initializing: null, unrestrictedTabs: new Set(), isEnforced(tabId = -1) { return this.policy.enforced && (tabId === -1 || !this.unrestrictedTabs.has(tabId)); @@ -210,10 +222,8 @@ start() { if (this.running) return; this.running = true; - browser.runtime.onSyncMessage.addListener(onSyncMessage); - - deferWebTraffic(init(), + deferWebTraffic(this.initalizing = init(), async () => { Commands.install(); |