summaryrefslogtreecommitdiffstats
path: root/dom/manifest/ManifestFinder.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/manifest/ManifestFinder.sys.mjs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/manifest/ManifestFinder.sys.mjs')
-rw-r--r--dom/manifest/ManifestFinder.sys.mjs57
1 files changed, 57 insertions, 0 deletions
diff --git a/dom/manifest/ManifestFinder.sys.mjs b/dom/manifest/ManifestFinder.sys.mjs
new file mode 100644
index 0000000000..1f8a23462b
--- /dev/null
+++ b/dom/manifest/ManifestFinder.sys.mjs
@@ -0,0 +1,57 @@
+/* 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/. */
+
+export var ManifestFinder = {
+ /**
+ * 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.");
+ }
+
+ const actor =
+ aBrowser.browsingContext.currentWindowGlobal.getActor("ManifestMessages");
+ const reply = await actor.sendQuery("DOM:WebManifest:hasManifestLink");
+ return reply.result;
+ },
+};
+
+function isXULBrowser(aBrowser) {
+ if (!aBrowser || !aBrowser.namespaceURI || !aBrowser.localName) {
+ return false;
+ }
+ const XUL_NS =
+ "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+ return aBrowser.namespaceURI === XUL_NS && aBrowser.localName === "browser";
+}
+
+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;
+}