mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 1644151, convert manifest from legacy actor to JSWindowActor, r=marcosc
Differential Revision: https://phabricator.services.mozilla.com/D79573
This commit is contained in:
parent
904f6e49a7
commit
f1cd439a13
@ -15,10 +15,6 @@
|
||||
|
||||
var EXPORTED_SYMBOLS = ["ManifestMessagesChild"];
|
||||
|
||||
const { ActorChild } = ChromeUtils.import(
|
||||
"resource://gre/modules/ActorChild.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"ManifestObtainer",
|
||||
@ -35,13 +31,13 @@ ChromeUtils.defineModuleGetter(
|
||||
"resource://gre/modules/ManifestIcons.jsm"
|
||||
);
|
||||
|
||||
class ManifestMessagesChild extends ActorChild {
|
||||
class ManifestMessagesChild extends JSWindowActorChild {
|
||||
receiveMessage(message) {
|
||||
switch (message.name) {
|
||||
case "DOM:WebManifest:hasManifestLink":
|
||||
return this.hasManifestLink(message);
|
||||
return this.hasManifestLink();
|
||||
case "DOM:ManifestObtainer:Obtain":
|
||||
return this.obtainManifest(message);
|
||||
return this.obtainManifest(message.data);
|
||||
case "DOM:WebManifest:fetchIcon":
|
||||
return this.fetchIcon(message);
|
||||
}
|
||||
@ -49,49 +45,44 @@ class ManifestMessagesChild extends ActorChild {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the this.mm.content document includes a link to a web manifest.
|
||||
* @param {Object} aMsg The IPC message, which is destructured to just
|
||||
* get the id.
|
||||
* Check if the document includes a link to a web manifest.
|
||||
*/
|
||||
hasManifestLink({ data: { id } }) {
|
||||
const response = makeMsgResponse(id);
|
||||
response.result = ManifestFinder.contentHasManifestLink(this.mm.content);
|
||||
hasManifestLink() {
|
||||
const response = makeMsgResponse();
|
||||
response.result = ManifestFinder.contentHasManifestLink(this.contentWindow);
|
||||
response.success = true;
|
||||
this.mm.sendAsyncMessage("DOM:WebManifest:hasManifestLink", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously obtains a web manifest from this.mm.content by using the
|
||||
* ManifestObtainer and messages back the result.
|
||||
* @param {Object} aMsg The IPC message, which is destructured to just
|
||||
* get the id.
|
||||
* Asynchronously obtains a web manifest from this window by using the
|
||||
* ManifestObtainer and returns the result.
|
||||
* @param {Object} checkConformance True if spec conformance messages should be collected.
|
||||
*/
|
||||
async obtainManifest(message) {
|
||||
const {
|
||||
data: { id, checkConformance },
|
||||
} = message;
|
||||
const response = makeMsgResponse(id);
|
||||
async obtainManifest(options) {
|
||||
const { checkConformance } = options;
|
||||
const response = makeMsgResponse();
|
||||
try {
|
||||
response.result = await ManifestObtainer.contentObtainManifest(
|
||||
this.mm.content,
|
||||
this.contentWindow,
|
||||
{ checkConformance }
|
||||
);
|
||||
response.success = true;
|
||||
} catch (err) {
|
||||
response.result = serializeError(err);
|
||||
}
|
||||
this.mm.sendAsyncMessage("DOM:ManifestObtainer:Obtain", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a manifest and an expected icon size, ask ManifestIcons
|
||||
* to fetch the appropriate icon and send along result
|
||||
*/
|
||||
async fetchIcon({ data: { id, manifest, iconSize } }) {
|
||||
const response = makeMsgResponse(id);
|
||||
async fetchIcon({ data: { manifest, iconSize } }) {
|
||||
const response = makeMsgResponse();
|
||||
try {
|
||||
response.result = await ManifestIcons.contentFetchIcon(
|
||||
this.mm.content,
|
||||
this.contentWindow,
|
||||
manifest,
|
||||
iconSize
|
||||
);
|
||||
@ -99,7 +90,7 @@ class ManifestMessagesChild extends ActorChild {
|
||||
} catch (err) {
|
||||
response.result = serializeError(err);
|
||||
}
|
||||
this.mm.sendAsyncMessage("DOM:WebManifest:fetchIcon", response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,9 +113,8 @@ function serializeError(aError) {
|
||||
return clone;
|
||||
}
|
||||
|
||||
function makeMsgResponse(aId) {
|
||||
function makeMsgResponse() {
|
||||
return {
|
||||
id: aId,
|
||||
success: false,
|
||||
result: undefined,
|
||||
};
|
||||
|
@ -3,10 +3,6 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const { PromiseMessage } = ChromeUtils.import(
|
||||
"resource://gre/modules/PromiseMessage.jsm"
|
||||
);
|
||||
|
||||
var ManifestFinder = {
|
||||
// jshint ignore:line
|
||||
/**
|
||||
@ -32,10 +28,12 @@ var ManifestFinder = {
|
||||
if (!isXULBrowser(aBrowser)) {
|
||||
throw new TypeError("Invalid input.");
|
||||
}
|
||||
const msgKey = "DOM:WebManifest:hasManifestLink";
|
||||
const mm = aBrowser.messageManager;
|
||||
const reply = await PromiseMessage.send(mm, msgKey);
|
||||
return reply.data.result;
|
||||
|
||||
const actor = aBrowser.browsingContext.currentWindowGlobal.getActor(
|
||||
"ManifestMessages"
|
||||
);
|
||||
const reply = await actor.sendQuery("DOM:WebManifest:hasManifestLink");
|
||||
return reply.result;
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -4,21 +4,18 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const { PromiseMessage } = ChromeUtils.import(
|
||||
"resource://gre/modules/PromiseMessage.jsm"
|
||||
);
|
||||
|
||||
var ManifestIcons = {
|
||||
async browserFetchIcon(aBrowser, manifest, iconSize) {
|
||||
const msgKey = "DOM:WebManifest:fetchIcon";
|
||||
const mm = aBrowser.messageManager;
|
||||
const {
|
||||
data: { success, result },
|
||||
} = await PromiseMessage.send(mm, msgKey, { manifest, iconSize });
|
||||
if (!success) {
|
||||
throw result;
|
||||
|
||||
const actor = aBrowser.browsingContext.currentWindowGlobal.getActor(
|
||||
"ManifestMessages"
|
||||
);
|
||||
const reply = await actor.sendQuery(msgKey, { manifest, iconSize });
|
||||
if (!reply.success) {
|
||||
throw reply.result;
|
||||
}
|
||||
return result;
|
||||
return reply.result;
|
||||
},
|
||||
|
||||
async contentFetchIcon(aWindow, manifest, iconSize) {
|
||||
|
@ -27,9 +27,6 @@
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const { PromiseMessage } = ChromeUtils.import(
|
||||
"resource://gre/modules/PromiseMessage.jsm"
|
||||
);
|
||||
const { ManifestProcessor } = ChromeUtils.import(
|
||||
"resource://gre/modules/ManifestProcessor.jsm"
|
||||
);
|
||||
@ -52,15 +49,20 @@ var ManifestObtainer = {
|
||||
if (!isXULBrowser(aBrowser)) {
|
||||
throw new TypeError("Invalid input. Expected XUL browser.");
|
||||
}
|
||||
const mm = aBrowser.messageManager;
|
||||
const {
|
||||
data: { success, result },
|
||||
} = await PromiseMessage.send(mm, "DOM:ManifestObtainer:Obtain", aOptions);
|
||||
if (!success) {
|
||||
const error = toError(result);
|
||||
|
||||
const actor = aBrowser.browsingContext.currentWindowGlobal.getActor(
|
||||
"ManifestMessages"
|
||||
);
|
||||
|
||||
const reply = await actor.sendQuery(
|
||||
"DOM:ManifestObtainer:Obtain",
|
||||
aOptions
|
||||
);
|
||||
if (!reply.success) {
|
||||
const error = toError(reply.result);
|
||||
throw error;
|
||||
}
|
||||
return result;
|
||||
return reply.result;
|
||||
},
|
||||
/**
|
||||
* Public interface for obtaining a web manifest from a XUL browser.
|
||||
|
@ -295,6 +295,13 @@ let JSWINDOWACTORS = {
|
||||
allFrames: true,
|
||||
messageManagerGroups: ["browsers", ""],
|
||||
},
|
||||
|
||||
ManifestMessages: {
|
||||
child: {
|
||||
moduleURI: "resource://gre/modules/ManifestMessagesChild.jsm",
|
||||
},
|
||||
},
|
||||
|
||||
PictureInPicture: {
|
||||
parent: {
|
||||
moduleURI: "resource://gre/modules/PictureInPicture.jsm",
|
||||
@ -536,17 +543,6 @@ let JSWINDOWACTORS = {
|
||||
* sub-frames, it must use "allFrames".
|
||||
*/
|
||||
let LEGACY_ACTORS = {
|
||||
ManifestMessages: {
|
||||
child: {
|
||||
module: "resource://gre/modules/ManifestMessagesChild.jsm",
|
||||
messages: [
|
||||
"DOM:ManifestObtainer:Obtain",
|
||||
"DOM:WebManifest:fetchIcon",
|
||||
"DOM:WebManifest:hasManifestLink",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
Printing: {
|
||||
child: {
|
||||
module: "resource://gre/actors/PrintingChild.jsm",
|
||||
|
Loading…
x
Reference in New Issue
Block a user