2015-04-22 17:46:00 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.*/
|
|
|
|
/*
|
|
|
|
* Manifest obtainer frame script implementation of:
|
2015-05-26 21:04:59 +00:00
|
|
|
* http://www.w3.org/TR/appmanifest/#obtaining
|
2015-04-22 17:46:00 +00:00
|
|
|
*
|
|
|
|
* It searches a top-level browsing context for
|
|
|
|
* a <link rel=manifest> element. Then fetches
|
|
|
|
* and processes the linked manifest.
|
|
|
|
*
|
|
|
|
* BUG: https://bugzilla.mozilla.org/show_bug.cgi?id=1083410
|
|
|
|
*/
|
2015-07-30 15:56:12 +00:00
|
|
|
/*globals Task, ManifestObtainer, ManifestFinder, content, sendAsyncMessage, addMessageListener, Components*/
|
|
|
|
"use strict";
|
2015-04-22 17:46:00 +00:00
|
|
|
const {
|
2015-06-02 19:42:19 +00:00
|
|
|
utils: Cu,
|
2015-04-22 17:46:00 +00:00
|
|
|
} = Components;
|
2015-07-30 15:56:12 +00:00
|
|
|
Cu.import("resource://gre/modules/ManifestObtainer.jsm");
|
|
|
|
Cu.import("resource://gre/modules/ManifestFinder.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2015-04-22 17:46:00 +00:00
|
|
|
|
2015-07-30 15:56:12 +00:00
|
|
|
const MessageHandler = {
|
|
|
|
registerListeners() {
|
|
|
|
addMessageListener(
|
|
|
|
"DOM:WebManifest:hasManifestLink",
|
|
|
|
this.hasManifestLink.bind(this)
|
|
|
|
);
|
|
|
|
addMessageListener(
|
|
|
|
"DOM:ManifestObtainer:Obtain",
|
|
|
|
this.obtainManifest.bind(this)
|
|
|
|
);
|
|
|
|
},
|
2015-07-29 14:58:00 +00:00
|
|
|
|
2015-07-30 15:56:12 +00:00
|
|
|
/**
|
|
|
|
* Check if the content document includes a link to a web manifest.
|
|
|
|
* @param {Object} aMsg The IPC message, which is destructured to just
|
|
|
|
* get the id.
|
|
|
|
*/
|
|
|
|
hasManifestLink({data: {id}}) {
|
|
|
|
const response = makeMsgResponse(id);
|
|
|
|
response.result = ManifestFinder.contentHasManifestLink(content);
|
|
|
|
response.success = true;
|
|
|
|
sendAsyncMessage("DOM:WebManifest:hasManifestLink", response);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously obtains a web manifest from content by using the
|
|
|
|
* ManifestObtainer and messages back the result.
|
|
|
|
* @param {Object} aMsg The IPC message, which is destructured to just
|
|
|
|
* get the id.
|
|
|
|
*/
|
|
|
|
obtainManifest: Task.async(function* ({data: {id}}) {
|
|
|
|
const response = makeMsgResponse(id);
|
|
|
|
try {
|
|
|
|
response.result = yield ManifestObtainer.contentObtainManifest(content);
|
|
|
|
response.success = true;
|
|
|
|
} catch (err) {
|
|
|
|
response.result = serializeError(err);
|
|
|
|
}
|
|
|
|
sendAsyncMessage("DOM:ManifestObtainer:Obtain", response);
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Utility function to Serializes an JS Error, so it can be transferred over
|
|
|
|
* the message channel.
|
|
|
|
* FIX ME: https://bugzilla.mozilla.org/show_bug.cgi?id=1172586
|
|
|
|
* @param {Error} aError The error to serialize.
|
|
|
|
* @return {Object} The serialized object.
|
|
|
|
*/
|
|
|
|
function serializeError(aError) {
|
2015-07-17 01:45:59 +00:00
|
|
|
const clone = {
|
2015-07-30 15:56:12 +00:00
|
|
|
"fileName": aError.fileName,
|
|
|
|
"lineNumber": aError.lineNumber,
|
|
|
|
"columnNumber": aError.columnNumber,
|
|
|
|
"stack": aError.stack,
|
|
|
|
"message": aError.message,
|
|
|
|
"name": aError.name
|
2015-07-17 01:45:59 +00:00
|
|
|
};
|
|
|
|
return clone;
|
|
|
|
}
|
2015-07-08 03:26:32 +00:00
|
|
|
|
2015-07-30 15:56:12 +00:00
|
|
|
function makeMsgResponse(aId) {
|
|
|
|
return {
|
|
|
|
id: aId,
|
|
|
|
success: false,
|
|
|
|
result: undefined
|
2015-07-08 03:26:32 +00:00
|
|
|
};
|
2015-07-30 15:56:12 +00:00
|
|
|
}
|
2015-07-30 13:11:48 +00:00
|
|
|
|
2015-07-30 15:56:12 +00:00
|
|
|
MessageHandler.registerListeners();
|