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 https://mozilla.org/MPL/2.0/. */
5 export var ManifestFinder = {
7 * Check from content process if DOM Window has a conforming
8 * manifest link relationship.
9 * @param aContent DOM Window to check.
10 * @return {Promise<Boolean>}
12 contentHasManifestLink(aContent) {
13 if (!aContent || isXULBrowser(aContent)) {
14 throw new TypeError("Invalid input.");
16 return checkForManifest(aContent);
20 * Check from a XUL browser (parent process) if it's content document has a
21 * manifest link relationship.
22 * @param aBrowser The XUL browser to check.
25 async browserHasManifestLink(aBrowser) {
26 if (!isXULBrowser(aBrowser)) {
27 throw new TypeError("Invalid input.");
31 aBrowser.browsingContext.currentWindowGlobal.getActor("ManifestMessages");
32 const reply = await actor.sendQuery("DOM:WebManifest:hasManifestLink");
37 function isXULBrowser(aBrowser) {
38 if (!aBrowser || !aBrowser.namespaceURI || !aBrowser.localName) {
42 "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
43 return aBrowser.namespaceURI === XUL_NS && aBrowser.localName === "browser";
46 function checkForManifest(aWindow) {
47 // Only top-level browsing contexts are valid.
48 if (!aWindow || aWindow.top !== aWindow) {
51 const elem = aWindow.document.querySelector("link[rel~='manifest']");
52 // Only if we have an element and a non-empty href attribute.
53 if (!elem || !elem.getAttribute("href")) {