1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.*/
5 * Manifest obtainer frame script implementation of:
6 * http://www.w3.org/TR/appmanifest/#obtaining
8 * It searches a top-level browsing context for
9 * a <link rel=manifest> element. Then fetches
10 * and processes the linked manifest.
12 * BUG: https://bugzilla.mozilla.org/show_bug.cgi?id=1083410
17 ChromeUtils.defineESModuleGetters(lazy, {
18 ManifestFinder: "resource://gre/modules/ManifestFinder.sys.mjs",
19 ManifestIcons: "resource://gre/modules/ManifestIcons.sys.mjs",
20 ManifestObtainer: "resource://gre/modules/ManifestObtainer.sys.mjs",
23 export class ManifestMessagesChild extends JSWindowActorChild {
24 receiveMessage(message) {
25 switch (message.name) {
26 case "DOM:WebManifest:hasManifestLink":
27 return this.hasManifestLink();
28 case "DOM:ManifestObtainer:Obtain":
29 return this.obtainManifest(message.data);
30 case "DOM:WebManifest:fetchIcon":
31 return this.fetchIcon(message);
37 * Check if the document includes a link to a web manifest.
40 const response = makeMsgResponse();
41 response.result = lazy.ManifestFinder.contentHasManifestLink(
44 response.success = true;
49 * Asynchronously obtains a web manifest from this window by using the
50 * ManifestObtainer and returns the result.
51 * @param {Object} checkConformance True if spec conformance messages should be collected.
53 async obtainManifest(options) {
54 const { checkConformance } = options;
55 const response = makeMsgResponse();
57 response.result = await lazy.ManifestObtainer.contentObtainManifest(
61 response.success = true;
63 response.result = serializeError(err);
69 * Given a manifest and an expected icon size, ask ManifestIcons
70 * to fetch the appropriate icon and send along result
72 async fetchIcon({ data: { manifest, iconSize } }) {
73 const response = makeMsgResponse();
75 response.result = await lazy.ManifestIcons.contentFetchIcon(
80 response.success = true;
82 response.result = serializeError(err);
89 * Utility function to Serializes an JS Error, so it can be transferred over
90 * the message channel.
91 * FIX ME: https://bugzilla.mozilla.org/show_bug.cgi?id=1172586
92 * @param {Error} aError The error to serialize.
93 * @return {Object} The serialized object.
95 function serializeError(aError) {
97 fileName: aError.fileName,
98 lineNumber: aError.lineNumber,
99 columnNumber: aError.columnNumber,
101 message: aError.message,
107 function makeMsgResponse() {