Graceful degradation for missing WebExtensions APIs on Chromium.

This commit is contained in:
hackademix 2019-02-01 00:28:33 +01:00
parent d076a517ba
commit 781514cfb9
4 changed files with 17 additions and 8 deletions

View File

@ -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 flatten = arr => arr.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []);
let protocolRx = /^(\w+):/i; let protocolRx = /^(\w+):/i;

View File

@ -20,7 +20,10 @@ var RequestGuard = (() => {
media: "media", media: "media",
other: "", 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 Object.assign(policyTypesMap, {"webgl": "webgl"}); // fake types
const TabStatus = { const TabStatus = {
map: new Map(), map: new Map(),
@ -254,7 +257,7 @@ var RequestGuard = (() => {
return redirected; return redirected;
} }
const ABORT = {cancel: true}, ALLOW = {}; const ABORT = {cancel: true}, ALLOW = {};
const INTERNAL_SCHEME = /^(?:chrome|resource|moz-extension|about):/; const INTERNAL_SCHEME = /^(?:chrome|resource|(?:moz|chrome)-extension|about):/;
const listeners = { const listeners = {
onBeforeRequest(request) { onBeforeRequest(request) {
try { try {
@ -326,7 +329,7 @@ var RequestGuard = (() => {
capabilities = perms.capabilities; capabilities = perms.capabilities;
} else { } else {
capabilities = perms.capabilities; capabilities = perms.capabilities;
if (frameAncestors.length > 0) { if (frameAncestors && frameAncestors.length > 0) {
// cascade top document's restrictions to subframes // cascade top document's restrictions to subframes
let topUrl = frameAncestors.pop().url; let topUrl = frameAncestors.pop().url;
let topPerms = policy.get(topUrl, topUrl).perms; let topPerms = policy.get(topUrl, topUrl).perms;

View File

@ -31,7 +31,7 @@ function deferWebTraffic(promiseToWaitFor, next) {
if (type === "main_frame") { if (type === "main_frame") {
seenTabs.add(tabId); seenTabs.add(tabId);
} else if (documentUrl) { } else if (documentUrl) {
if (frameId !== 0) { if (frameId !== 0 && request.frameAncestors) {
documentUrl = request.frameAncestors.pop().url; documentUrl = request.frameAncestors.pop().url;
} }
reloadTab(tabId); reloadTab(tabId);

View File

@ -7,14 +7,16 @@ var Prompts = (() => {
async open(data) { async open(data) {
promptData = data; promptData = data;
this.close(); this.close();
this.currentWindow = await browser.windows.create({ let options = {
url: browser.extension.getURL("ui/prompt.html"), url: browser.extension.getURL("ui/prompt.html"),
type: "panel", type: "panel",
allowScriptsToClose: true,
// titlePreface: "NoScript ",
width: data.features.width, width: data.features.width,
height: data.features.height, height: data.features.height,
}); };
if (UA.isMozilla) {
options.allowScriptsToClose = true;
}
this.currentWindow = await browser.windows.create(options);
} }
async close() { async close() {
if (this.currentWindow) { if (this.currentWindow) {