Bug 1708422: part 16) Rename `mozInlineSpellChecker::SpellCheckerTimeSlice` to `mozIn...
[gecko.git] / dom / manifest / ManifestFinder.jsm
blob675bf0fdf62ef36629830b059274fd81536d9862
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/. */
4 "use strict";
6 var ManifestFinder = {
7   /**
8    * Check from content process if DOM Window has a conforming
9    * manifest link relationship.
10    * @param aContent DOM Window to check.
11    * @return {Promise<Boolean>}
12    */
13   contentHasManifestLink(aContent) {
14     if (!aContent || isXULBrowser(aContent)) {
15       throw new TypeError("Invalid input.");
16     }
17     return checkForManifest(aContent);
18   },
20   /**
21    * Check from a XUL browser (parent process) if it's content document has a
22    * manifest link relationship.
23    * @param aBrowser The XUL browser to check.
24    * @return {Promise}
25    */
26   async browserHasManifestLink(aBrowser) {
27     if (!isXULBrowser(aBrowser)) {
28       throw new TypeError("Invalid input.");
29     }
31     const actor = aBrowser.browsingContext.currentWindowGlobal.getActor(
32       "ManifestMessages"
33     );
34     const reply = await actor.sendQuery("DOM:WebManifest:hasManifestLink");
35     return reply.result;
36   },
39 function isXULBrowser(aBrowser) {
40   if (!aBrowser || !aBrowser.namespaceURI || !aBrowser.localName) {
41     return false;
42   }
43   const XUL_NS =
44     "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
45   return aBrowser.namespaceURI === XUL_NS && aBrowser.localName === "browser";
48 function checkForManifest(aWindow) {
49   // Only top-level browsing contexts are valid.
50   if (!aWindow || aWindow.top !== aWindow) {
51     return false;
52   }
53   const elem = aWindow.document.querySelector("link[rel~='manifest']");
54   // Only if we have an element and a non-empty href attribute.
55   if (!elem || !elem.getAttribute("href")) {
56     return false;
57   }
58   return true;
61 var EXPORTED_SYMBOLS = ["ManifestFinder"];