mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-22 16:37:31 +09:00
Add WebExtension clone and image bitmap compatibility fallbacks
This commit is contained in:
parent
990887b8af
commit
a16ea2362b
2 changed files with 74 additions and 5 deletions
|
|
@ -773,6 +773,21 @@ class ExtensionPageContextChild extends BaseContext {
|
||||||
}
|
}
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
|
|
||||||
|
// Older UXP WebIDL bindings throw synchronously when extensions use
|
||||||
|
// createImageBitmap() as a zero-argument feature probe. Keep valid calls
|
||||||
|
// native, but make the probe harmless in extension pages.
|
||||||
|
if (typeof contentWindow.createImageBitmap == "function") {
|
||||||
|
let nativeCreateImageBitmap = contentWindow.createImageBitmap;
|
||||||
|
try {
|
||||||
|
contentWindow.createImageBitmap = function(...args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
return contentWindow.Promise.resolve(null);
|
||||||
|
}
|
||||||
|
return nativeCreateImageBitmap.apply(this, args);
|
||||||
|
};
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
Schemas.exportLazyGetter(contentWindow, "browser", () => {
|
Schemas.exportLazyGetter(contentWindow, "browser", () => {
|
||||||
let browserObj = Cu.createObjectIn(contentWindow);
|
let browserObj = Cu.createObjectIn(contentWindow);
|
||||||
Schemas.inject(browserObj, this.childManager);
|
Schemas.inject(browserObj, this.childManager);
|
||||||
|
|
@ -1055,4 +1070,3 @@ Object.assign(ExtensionChild, {
|
||||||
Messenger,
|
Messenger,
|
||||||
Port,
|
Port,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,61 @@ class FilteringMessageManagerMap extends Map {
|
||||||
const MESSAGE_MESSAGE = "MessageChannel:Message";
|
const MESSAGE_MESSAGE = "MessageChannel:Message";
|
||||||
const MESSAGE_RESPONSE = "MessageChannel:Response";
|
const MESSAGE_RESPONSE = "MessageChannel:Response";
|
||||||
|
|
||||||
|
function makeMessageCloneable(value, seen = new Set()) {
|
||||||
|
if (value === null || value === undefined ||
|
||||||
|
typeof value == "string" || typeof value == "number" ||
|
||||||
|
typeof value == "boolean") {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
if (typeof value != "object") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (value instanceof Ci.nsIURI) {
|
||||||
|
return value.spec;
|
||||||
|
}
|
||||||
|
if (value instanceof Ci.nsIFile) {
|
||||||
|
return value.path;
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
if (seen.has(value)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
seen.add(value);
|
||||||
|
|
||||||
|
let className = Cu.getClassName(value, true);
|
||||||
|
if (className == "Array") {
|
||||||
|
return value.map(item => makeMessageCloneable(item, seen));
|
||||||
|
}
|
||||||
|
if (className != "Object") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = {};
|
||||||
|
for (let key of Object.keys(value)) {
|
||||||
|
let item = makeMessageCloneable(value[key], seen);
|
||||||
|
if (item !== undefined) {
|
||||||
|
result[key] = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendMessageWithCloneFallback(target, name, data) {
|
||||||
|
try {
|
||||||
|
target.sendAsyncMessage(name, data);
|
||||||
|
} catch (e) {
|
||||||
|
let message = String(e && e.message || e);
|
||||||
|
if (!e || (e.result != Cr.NS_ERROR_DOM_DATA_CLONE_ERR &&
|
||||||
|
message.indexOf("clone") == -1)) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
target.sendAsyncMessage(name, makeMessageCloneable(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.MessageChannel = {
|
this.MessageChannel = {
|
||||||
init() {
|
init() {
|
||||||
Services.obs.addObserver(this, "message-manager-close", false);
|
Services.obs.addObserver(this, "message-manager-close", false);
|
||||||
|
|
@ -517,7 +572,7 @@ this.MessageChannel = {
|
||||||
|
|
||||||
if (responseType == this.RESPONSE_NONE) {
|
if (responseType == this.RESPONSE_NONE) {
|
||||||
try {
|
try {
|
||||||
target.sendAsyncMessage(MESSAGE_MESSAGE, message);
|
sendMessageWithCloneFallback(target, MESSAGE_MESSAGE, message);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Caller is not expecting a reply, so dump the error to the console.
|
// Caller is not expecting a reply, so dump the error to the console.
|
||||||
Cu.reportError(e);
|
Cu.reportError(e);
|
||||||
|
|
@ -544,7 +599,7 @@ this.MessageChannel = {
|
||||||
deferred.promise.then(cleanup, cleanup);
|
deferred.promise.then(cleanup, cleanup);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
target.sendAsyncMessage(MESSAGE_MESSAGE, message);
|
sendMessageWithCloneFallback(target, MESSAGE_MESSAGE, message);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
deferred.reject(e);
|
deferred.reject(e);
|
||||||
}
|
}
|
||||||
|
|
@ -644,7 +699,7 @@ this.MessageChannel = {
|
||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
|
|
||||||
target.sendAsyncMessage(MESSAGE_RESPONSE, response);
|
sendMessageWithCloneFallback(target, MESSAGE_RESPONSE, response);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
let response = {
|
let response = {
|
||||||
|
|
@ -668,7 +723,7 @@ this.MessageChannel = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
target.sendAsyncMessage(MESSAGE_RESPONSE, response);
|
sendMessageWithCloneFallback(target, MESSAGE_RESPONSE, response);
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
Cu.reportError(e);
|
Cu.reportError(e);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue