зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1561122: Cleanup SpecialPowers.loadExtension after JSWindowActor migration. r=aswan
Differential Revision: https://phabricator.services.mozilla.com/D35731 --HG-- extra : rebase_source : e35222a7dc0c2c906ac2ea35186a9dac99b5d5b9 extra : source : 43211ebfe7384909dd95cb44196eea4359156d2a
This commit is contained in:
Родитель
6eab79765c
Коммит
73f672857a
|
@ -1549,16 +1549,6 @@ class SpecialPowersAPI extends JSWindowActorChild {
|
|||
// between this content process and the chrome process.
|
||||
let id = this._nextExtensionID++;
|
||||
|
||||
let resolveStartup, resolveUnload, rejectStartup;
|
||||
let startupPromise = new Promise((resolve, reject) => {
|
||||
resolveStartup = resolve;
|
||||
rejectStartup = reject;
|
||||
});
|
||||
let unloadPromise = new Promise(resolve => { resolveUnload = resolve; });
|
||||
|
||||
startupPromise.catch(() => {
|
||||
this._extensionListeners.delete(listener);
|
||||
});
|
||||
|
||||
handler = Cu.waiveXrays(handler);
|
||||
ext = Cu.waiveXrays(ext);
|
||||
|
@ -1570,14 +1560,22 @@ class SpecialPowersAPI extends JSWindowActorChild {
|
|||
|
||||
startup() {
|
||||
state = "pending";
|
||||
sp.sendAsyncMessage("SPStartupExtension", {id});
|
||||
return startupPromise;
|
||||
return sp.sendQuery("SPStartupExtension", {id}).then(
|
||||
() => {
|
||||
state = "running";
|
||||
}, () => {
|
||||
state = "failed";
|
||||
sp._extensionListeners.delete(listener);
|
||||
return Promise.reject("startup failed");
|
||||
});
|
||||
},
|
||||
|
||||
unload() {
|
||||
state = "unloading";
|
||||
sp.sendAsyncMessage("SPUnloadExtension", {id});
|
||||
return unloadPromise;
|
||||
return sp.sendQuery("SPUnloadExtension", {id}).finally(() => {
|
||||
sp._extensionListeners.delete(listener);
|
||||
state = "unloaded";
|
||||
});
|
||||
},
|
||||
|
||||
sendMessage(...args) {
|
||||
|
@ -1589,19 +1587,9 @@ class SpecialPowersAPI extends JSWindowActorChild {
|
|||
|
||||
let listener = (msg) => {
|
||||
if (msg.data.id == id) {
|
||||
if (msg.data.type == "extensionStarted") {
|
||||
state = "running";
|
||||
resolveStartup();
|
||||
} else if (msg.data.type == "extensionSetId") {
|
||||
if (msg.data.type == "extensionSetId") {
|
||||
extension.id = msg.data.args[0];
|
||||
extension.uuid = msg.data.args[1];
|
||||
} else if (msg.data.type == "extensionFailed") {
|
||||
state = "failed";
|
||||
rejectStartup("startup failed");
|
||||
} else if (msg.data.type == "extensionUnloaded") {
|
||||
this._extensionListeners.delete(listener);
|
||||
state = "unloaded";
|
||||
resolveUnload();
|
||||
} else if (msg.data.type in handler) {
|
||||
handler[msg.data.type](...Cu.cloneInto(msg.data.args, this.contentWindow));
|
||||
} else {
|
||||
|
|
|
@ -710,7 +710,7 @@ class SpecialPowersAPIParent extends JSWindowActorParent {
|
|||
// they're run on a bare archive rather than a running instance,
|
||||
// as the add-on manager runs them.
|
||||
let extensionData = new ExtensionData(extension.rootURI);
|
||||
extensionData.loadManifest().then(
|
||||
return extensionData.loadManifest().then(
|
||||
() => {
|
||||
return extensionData.initAllLocales().then(() => {
|
||||
if (extensionData.errors.length) {
|
||||
|
@ -730,14 +730,11 @@ class SpecialPowersAPIParent extends JSWindowActorParent {
|
|||
if (extension.id) {
|
||||
await ExtensionTestCommon.setIncognitoOverride(extension);
|
||||
}
|
||||
return extension.startup();
|
||||
}).then(() => {
|
||||
this.sendAsyncMessage("SPExtensionMessage", {id, type: "extensionStarted", args: []});
|
||||
}).catch(e => {
|
||||
dump(`Extension startup failed: ${e}\n${e.stack}`);
|
||||
this.sendAsyncMessage("SPExtensionMessage", {id, type: "extensionFailed", args: []});
|
||||
return extension.startup().then(() => {}, e => {
|
||||
dump(`Extension startup failed: ${e}\n${e.stack}`);
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
case "SPExtensionMessage": {
|
||||
|
@ -751,12 +748,9 @@ class SpecialPowersAPIParent extends JSWindowActorParent {
|
|||
let id = aMessage.data.id;
|
||||
let extension = this._extensions.get(id);
|
||||
this._extensions.delete(id);
|
||||
let done = async () => {
|
||||
await extension._uninstallPromise;
|
||||
this.sendAsyncMessage("SPExtensionMessage", {id, type: "extensionUnloaded", args: []});
|
||||
};
|
||||
extension.shutdown().then(done, done);
|
||||
return undefined;
|
||||
return extension.shutdown().then(() => {
|
||||
return extension._uninstallPromise;
|
||||
});
|
||||
}
|
||||
|
||||
case "Spawn": {
|
||||
|
|
|
@ -383,7 +383,7 @@ class ResponseManager extends FilteringMessageManager {
|
|||
*/
|
||||
removeHandler(messageName, handler) {
|
||||
if (DEBUG && this.handlers.get(messageName) !== handler) {
|
||||
throw new Error(`Attempting to remove unexpected response handler for ${messageName}`);
|
||||
Cu.reportError(`Attempting to remove unexpected response handler for ${messageName}`);
|
||||
}
|
||||
this.handlers.delete(messageName);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче