mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1202478 - [webext] Run WebExtension callbacks asynchronously (r=gabor)
This commit is contained in:
parent
da4cdc43c0
commit
0c1c783bf4
@ -30,7 +30,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
||||
|
||||
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
|
||||
var {
|
||||
runSafeWithoutClone,
|
||||
runSafeSyncWithoutClone,
|
||||
MessageBroker,
|
||||
Messenger,
|
||||
ignoreEvent,
|
||||
@ -137,12 +137,12 @@ Script.prototype = {
|
||||
|
||||
for (let url of this.css) {
|
||||
url = extension.baseURI.resolve(url);
|
||||
runSafeWithoutClone(winUtils.loadSheetUsingURIString, url, winUtils.AUTHOR_SHEET);
|
||||
runSafeSyncWithoutClone(winUtils.loadSheetUsingURIString, url, winUtils.AUTHOR_SHEET);
|
||||
}
|
||||
|
||||
if (this.options.cssCode) {
|
||||
let url = "data:text/css;charset=utf-8," + encodeURIComponent(this.options.cssCode);
|
||||
runSafeWithoutClone(winUtils.loadSheetUsingURIString, url, winUtils.AUTHOR_SHEET);
|
||||
runSafeSyncWithoutClone(winUtils.loadSheetUsingURIString, url, winUtils.AUTHOR_SHEET);
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ Script.prototype = {
|
||||
charset: "UTF-8",
|
||||
async: AppConstants.platform == "gonk"
|
||||
}
|
||||
Services.scriptloader.loadSubScriptWithOptions(url, options);
|
||||
runSafeSyncWithoutClone(Services.scriptloader.loadSubScriptWithOptions, url, options);
|
||||
}
|
||||
|
||||
if (this.options.jsCode) {
|
||||
|
@ -15,16 +15,41 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Run a function and report exceptions.
|
||||
function runSafeWithoutClone(f, ...args)
|
||||
function runSafeSyncWithoutClone(f, ...args)
|
||||
{
|
||||
try {
|
||||
return f(...args);
|
||||
} catch (e) {
|
||||
dump(`Extension error: ${e} ${e.fileName} ${e.lineNumber}\n${e.stack}\n${Error().stack}`);
|
||||
dump(`Extension error: ${e} ${e.fileName} ${e.lineNumber}\n[[Exception stack\n${e.stack}Current stack\n${Error().stack}]]\n`);
|
||||
Cu.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Run a function and report exceptions.
|
||||
function runSafeWithoutClone(f, ...args)
|
||||
{
|
||||
if (typeof(f) != "function") {
|
||||
dump(`Extension error: expected function\n${Error().stack}`);
|
||||
return;
|
||||
}
|
||||
|
||||
Services.tm.currentThread.dispatch(function() {
|
||||
runSafeSyncWithoutClone(f, ...args);
|
||||
}, Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
// Run a function, cloning arguments into context.cloneScope, and
|
||||
// report exceptions. |f| is expected to be in context.cloneScope.
|
||||
function runSafeSync(context, f, ...args)
|
||||
{
|
||||
try {
|
||||
args = Cu.cloneInto(args, context.cloneScope);
|
||||
} catch (e) {
|
||||
dump(`runSafe failure\n${context.cloneScope}\n${Error().stack}`);
|
||||
}
|
||||
return runSafeSyncWithoutClone(f, ...args);
|
||||
}
|
||||
|
||||
// Run a function, cloning arguments into context.cloneScope, and
|
||||
// report exceptions. |f| is expected to be in context.cloneScope.
|
||||
function runSafe(context, f, ...args)
|
||||
@ -96,6 +121,11 @@ function EventManager(context, name, register)
|
||||
|
||||
EventManager.prototype = {
|
||||
addListener(callback) {
|
||||
if (typeof(callback) != "function") {
|
||||
dump(`Expected function\n${Error().stack}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.registered) {
|
||||
this.context.callOnClose(this);
|
||||
|
||||
@ -132,7 +162,7 @@ EventManager.prototype = {
|
||||
|
||||
fireWithoutClone(...args) {
|
||||
for (let callback of this.callbacks) {
|
||||
runSafeWithoutClone(callback, ...args);
|
||||
runSafeSyncWithoutClone(callback, ...args);
|
||||
}
|
||||
},
|
||||
|
||||
@ -534,7 +564,9 @@ function flushJarCache(jarFile)
|
||||
|
||||
this.ExtensionUtils = {
|
||||
runSafeWithoutClone,
|
||||
runSafeSyncWithoutClone,
|
||||
runSafe,
|
||||
runSafeSync,
|
||||
DefaultWeakMap,
|
||||
EventManager,
|
||||
SingletonEventManager,
|
||||
|
@ -45,7 +45,7 @@ function WebNavigationEventManager(context, eventName)
|
||||
return;
|
||||
}
|
||||
|
||||
return runSafe(context, callback, data2);
|
||||
runSafe(context, callback, data2);
|
||||
};
|
||||
|
||||
WebNavigation[eventName].addListener(listener);
|
||||
|
@ -10,7 +10,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "WebRequest",
|
||||
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
|
||||
var {
|
||||
SingletonEventManager,
|
||||
runSafe,
|
||||
runSafeSync,
|
||||
} = ExtensionUtils;
|
||||
|
||||
// EventManager-like class specifically for WebRequest. Inherits from
|
||||
@ -53,7 +53,7 @@ function WebRequestEventManager(context, eventName)
|
||||
}
|
||||
}
|
||||
|
||||
return runSafe(context, callback, data2);
|
||||
return runSafeSync(context, callback, data2);
|
||||
};
|
||||
|
||||
let filter2 = {};
|
||||
|
Loading…
Reference in New Issue
Block a user