зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1357486: Part 0e - Support legacy extensions in OOP mode. r=aswan
MozReview-Commit-ID: 4JHxX78HNRV --HG-- extra : rebase_source : a9cc5633536e159aa178ac8105a72cb97bbe58b7 extra : absorb_source : 68e13bd05f49581f437852dbe2d3509fc469a436 extra : histedit_source : 6c62cc352df9cfdff0b23d2392f4bcc25c5764b5
This commit is contained in:
Родитель
28759b4b6d
Коммит
7405866794
|
@ -177,7 +177,7 @@ ProxyMessenger = {
|
|||
MessageChannel.addListener(messageManagers, "Extension:Port:PostMessage", this);
|
||||
},
|
||||
|
||||
receiveMessage({target, messageName, channelId, sender, recipient, data, responseType}) {
|
||||
async receiveMessage({target, messageName, channelId, sender, recipient, data, responseType}) {
|
||||
if (recipient.toNativeApp) {
|
||||
let {childId, toNativeApp} = recipient;
|
||||
if (messageName == "Extension:Message") {
|
||||
|
@ -194,13 +194,15 @@ ProxyMessenger = {
|
|||
return;
|
||||
}
|
||||
|
||||
const noHandlerError = {
|
||||
result: MessageChannel.RESULT_NO_HANDLER,
|
||||
message: "No matching message handler for the given recipient.",
|
||||
};
|
||||
|
||||
let extension = GlobalManager.extensionMap.get(sender.extensionId);
|
||||
let receiverMM = this.getMessageManagerForRecipient(recipient);
|
||||
if (!extension || !receiverMM) {
|
||||
return Promise.reject({
|
||||
result: MessageChannel.RESULT_NO_HANDLER,
|
||||
message: "No matching message handler for the given recipient.",
|
||||
});
|
||||
return Promise.reject(noHandlerError);
|
||||
}
|
||||
|
||||
if ((messageName == "Extension:Message" ||
|
||||
|
@ -209,11 +211,48 @@ ProxyMessenger = {
|
|||
// From ext-tabs.js, undefined on Android.
|
||||
apiManager.global.tabGetSender(extension, target, sender);
|
||||
}
|
||||
return MessageChannel.sendMessage(receiverMM, messageName, data, {
|
||||
|
||||
let promise1 = MessageChannel.sendMessage(receiverMM, messageName, data, {
|
||||
sender,
|
||||
recipient,
|
||||
responseType,
|
||||
});
|
||||
|
||||
if (!extension.isEmbedded || !extension.remote) {
|
||||
return promise1;
|
||||
}
|
||||
|
||||
// If we have a remote, embedded extension, the legacy side is
|
||||
// running in a different process than the WebExtension side.
|
||||
// As a result, we need to dispatch the message to both the parent
|
||||
// and extension processes, and manually merge the results.
|
||||
let promise2 = MessageChannel.sendMessage(Services.ppmm.getChildAt(0), messageName, data, {
|
||||
sender,
|
||||
recipient,
|
||||
responseType,
|
||||
});
|
||||
|
||||
let result = undefined;
|
||||
let failures = 0;
|
||||
let tryPromise = async promise => {
|
||||
try {
|
||||
let res = await promise;
|
||||
if (result === undefined) {
|
||||
result = res;
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.result != MessageChannel.RESULT_NO_HANDLER) {
|
||||
throw e;
|
||||
}
|
||||
failures++;
|
||||
}
|
||||
};
|
||||
|
||||
await Promise.all([tryPromise(promise1), tryPromise(promise2)]);
|
||||
if (failures == 2) {
|
||||
return Promise.reject(noHandlerError);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -145,6 +145,8 @@ class EmbeddedExtension {
|
|||
version: this.version,
|
||||
});
|
||||
|
||||
this.extension.isEmbedded = true;
|
||||
|
||||
// This callback is register to the "startup" event, emitted by the Extension instance
|
||||
// after the extension manifest.json has been loaded without any errors, but before
|
||||
// starting any of the defined contexts (which give the legacy part a chance to subscribe
|
||||
|
|
|
@ -57,6 +57,7 @@ add_task(async function test_legacy_extension_context() {
|
|||
};
|
||||
|
||||
let extension = Extension.generate(extensionData);
|
||||
extension.isEmbedded = true;
|
||||
|
||||
let waitForExtensionInfo = new Promise((resolve, reject) => {
|
||||
extension.on("test-message", function testMessageListener(kind, msg, ...args) {
|
||||
|
|
|
@ -29,6 +29,8 @@ skip-if = os == "android"
|
|||
[test_ext_extensionSettingsStore.js]
|
||||
[test_ext_extension_startup_telemetry.js]
|
||||
[test_ext_idle.js]
|
||||
[test_ext_legacy_extension_context.js]
|
||||
[test_ext_legacy_extension_embedding.js]
|
||||
[test_ext_localStorage.js]
|
||||
[test_ext_management.js]
|
||||
[test_ext_management_uninstall_self.js]
|
||||
|
|
|
@ -51,8 +51,6 @@ tags = webextensions in-process-webextensions
|
|||
skip-if = os == "android" # Bug 1350559
|
||||
[test_ext_runtime_sendMessage_args.js]
|
||||
|
||||
[test_ext_legacy_extension_context.js]
|
||||
[test_ext_legacy_extension_embedding.js]
|
||||
[test_proxy_scripts.js]
|
||||
|
||||
[include:xpcshell-common.ini]
|
||||
|
|
Загрузка…
Ссылка в новой задаче