diff options
author | hackademix | 2019-02-01 00:28:33 +0100 |
---|---|---|
committer | hackademix | 2019-02-01 00:28:33 +0100 |
commit | 781514cfb946fb49bc1e2c52f16f808f26856f41 (patch) | |
tree | fb1e23838f73b6330d769d2f7417a7cfc78981c1 /src | |
parent | d076a517ba97da60791ded641a7952a784203d59 (diff) | |
download | noscript-781514cfb946fb49bc1e2c52f16f808f26856f41.tar.gz noscript-781514cfb946fb49bc1e2c52f16f808f26856f41.tar.xz noscript-781514cfb946fb49bc1e2c52f16f808f26856f41.zip |
Graceful degradation for missing WebExtensions APIs on Chromium.
Diffstat (limited to 'src')
-rw-r--r-- | src/bg/ChildPolicies.js | 4 | ||||
-rw-r--r-- | src/bg/RequestGuard.js | 9 | ||||
-rw-r--r-- | src/bg/deferWebTraffic.js | 2 | ||||
-rw-r--r-- | src/ui/Prompts.js | 10 |
4 files changed, 17 insertions, 8 deletions
diff --git a/src/bg/ChildPolicies.js b/src/bg/ChildPolicies.js index 74aeccb..5727762 100644 --- a/src/bg/ChildPolicies.js +++ b/src/bg/ChildPolicies.js @@ -51,6 +51,10 @@ } }; + 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; diff --git a/src/bg/RequestGuard.js b/src/bg/RequestGuard.js index a174eba..d27bacb 100644 --- a/src/bg/RequestGuard.js +++ b/src/bg/RequestGuard.js @@ -20,7 +20,10 @@ var RequestGuard = (() => { media: "media", other: "", }; - const allTypes = Object.keys(policyTypesMap); + const allTypes = UA.isMozilla ? Object.keys(policyTypesMap) + : ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", + "object", "xmlhttprequest", "ping", "csp_report", "media", "websocket", "other"]; + Object.assign(policyTypesMap, {"webgl": "webgl"}); // fake types const TabStatus = { map: new Map(), @@ -254,7 +257,7 @@ var RequestGuard = (() => { return redirected; } const ABORT = {cancel: true}, ALLOW = {}; - const INTERNAL_SCHEME = /^(?:chrome|resource|moz-extension|about):/; + const INTERNAL_SCHEME = /^(?:chrome|resource|(?:moz|chrome)-extension|about):/; const listeners = { onBeforeRequest(request) { try { @@ -326,7 +329,7 @@ var RequestGuard = (() => { capabilities = perms.capabilities; } else { capabilities = perms.capabilities; - if (frameAncestors.length > 0) { + if (frameAncestors && frameAncestors.length > 0) { // cascade top document's restrictions to subframes let topUrl = frameAncestors.pop().url; let topPerms = policy.get(topUrl, topUrl).perms; diff --git a/src/bg/deferWebTraffic.js b/src/bg/deferWebTraffic.js index a384e29..571073a 100644 --- a/src/bg/deferWebTraffic.js +++ b/src/bg/deferWebTraffic.js @@ -31,7 +31,7 @@ function deferWebTraffic(promiseToWaitFor, next) { if (type === "main_frame") { seenTabs.add(tabId); } else if (documentUrl) { - if (frameId !== 0) { + if (frameId !== 0 && request.frameAncestors) { documentUrl = request.frameAncestors.pop().url; } reloadTab(tabId); diff --git a/src/ui/Prompts.js b/src/ui/Prompts.js index 03ea9ee..ed83ac2 100644 --- a/src/ui/Prompts.js +++ b/src/ui/Prompts.js @@ -7,14 +7,16 @@ var Prompts = (() => { async open(data) { promptData = data; this.close(); - this.currentWindow = await browser.windows.create({ + let options = { url: browser.extension.getURL("ui/prompt.html"), type: "panel", - allowScriptsToClose: true, - // titlePreface: "NoScript ", width: data.features.width, height: data.features.height, - }); + }; + if (UA.isMozilla) { + options.allowScriptsToClose = true; + } + this.currentWindow = await browser.windows.create(options); } async close() { if (this.currentWindow) { |