2015-07-30 18:56:12 +03: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 https://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
2018-12-18 23:39:42 +03:00
|
|
|
|
2015-07-30 18:56:12 +03:00
|
|
|
var ManifestFinder = {
|
|
|
|
// jshint ignore:line
|
|
|
|
/**
|
|
|
|
* Check from content process if DOM Window has a conforming
|
|
|
|
* manifest link relationship.
|
|
|
|
* @param aContent DOM Window to check.
|
|
|
|
* @return {Promise<Boolean>}
|
|
|
|
*/
|
|
|
|
contentHasManifestLink(aContent) {
|
|
|
|
if (!aContent || isXULBrowser(aContent)) {
|
|
|
|
throw new TypeError("Invalid input.");
|
|
|
|
}
|
|
|
|
return checkForManifest(aContent);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check from a XUL browser (parent process) if it's content document has a
|
|
|
|
* manifest link relationship.
|
|
|
|
* @param aBrowser The XUL browser to check.
|
|
|
|
* @return {Promise}
|
|
|
|
*/
|
|
|
|
async browserHasManifestLink(aBrowser) {
|
|
|
|
if (!isXULBrowser(aBrowser)) {
|
|
|
|
throw new TypeError("Invalid input.");
|
|
|
|
}
|
2020-07-07 15:33:26 +03:00
|
|
|
|
|
|
|
const actor = aBrowser.browsingContext.currentWindowGlobal.getActor(
|
|
|
|
"ManifestMessages"
|
|
|
|
);
|
|
|
|
const reply = await actor.sendQuery("DOM:WebManifest:hasManifestLink");
|
|
|
|
return reply.result;
|
2018-12-18 23:38:43 +03:00
|
|
|
},
|
2015-07-30 18:56:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
function isXULBrowser(aBrowser) {
|
|
|
|
if (!aBrowser || !aBrowser.namespaceURI || !aBrowser.localName) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-24 12:23:52 +03:00
|
|
|
const XUL_NS =
|
|
|
|
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
return aBrowser.namespaceURI === XUL_NS && aBrowser.localName === "browser";
|
2015-07-30 18:56:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkForManifest(aWindow) {
|
|
|
|
// Only top-level browsing contexts are valid.
|
|
|
|
if (!aWindow || aWindow.top !== aWindow) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const elem = aWindow.document.querySelector("link[rel~='manifest']");
|
|
|
|
// Only if we have an element and a non-empty href attribute.
|
|
|
|
if (!elem || !elem.getAttribute("href")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = [
|
|
|
|
// jshint ignore:line
|
2018-12-18 23:38:43 +03:00
|
|
|
"ManifestFinder",
|
2015-07-30 18:56:12 +03:00
|
|
|
];
|