summaryrefslogtreecommitdiffstats
path: root/toolkit/components/mozprotocol
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/mozprotocol')
-rw-r--r--toolkit/components/mozprotocol/MozProtocolHandler.sys.mjs34
-rw-r--r--toolkit/components/mozprotocol/components.conf20
-rw-r--r--toolkit/components/mozprotocol/moz.build18
-rw-r--r--toolkit/components/mozprotocol/tests/browser.ini5
-rw-r--r--toolkit/components/mozprotocol/tests/browser_mozprotocol.js23
-rw-r--r--toolkit/components/mozprotocol/tests/mozprotocol.html7
6 files changed, 107 insertions, 0 deletions
diff --git a/toolkit/components/mozprotocol/MozProtocolHandler.sys.mjs b/toolkit/components/mozprotocol/MozProtocolHandler.sys.mjs
new file mode 100644
index 0000000000..6629f274d8
--- /dev/null
+++ b/toolkit/components/mozprotocol/MozProtocolHandler.sys.mjs
@@ -0,0 +1,34 @@
+/* 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/. */
+
+import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+export function MozProtocolHandler() {
+ XPCOMUtils.defineLazyPreferenceGetter(
+ this,
+ "urlToLoad",
+ "toolkit.mozprotocol.url",
+ "https://www.mozilla.org/about/manifesto/"
+ );
+}
+
+MozProtocolHandler.prototype = {
+ scheme: "moz",
+ defaultPort: -1,
+ protocolFlags: Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD,
+
+ newChannel(uri, loadInfo) {
+ const kCanada = "https://www.mozilla.org/contact/communities/canada/";
+ let realURL = NetUtil.newURI(
+ uri && uri.spec == "moz://eh" ? kCanada : this.urlToLoad
+ );
+ let channel = Services.io.newChannelFromURIWithLoadInfo(realURL, loadInfo);
+ loadInfo.resultPrincipalURI = realURL;
+ return channel;
+ },
+
+ QueryInterface: ChromeUtils.generateQI(["nsIProtocolHandler"]),
+};
diff --git a/toolkit/components/mozprotocol/components.conf b/toolkit/components/mozprotocol/components.conf
new file mode 100644
index 0000000000..c3918a5416
--- /dev/null
+++ b/toolkit/components/mozprotocol/components.conf
@@ -0,0 +1,20 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+Classes = [
+ {
+ 'cid': '{47a45e5f-691e-4799-8686-14f8d3fc0f8c}',
+ 'contract_ids': ['@mozilla.org/network/protocol;1?name=moz'],
+ 'esModule': 'resource://gre/modules/MozProtocolHandler.sys.mjs',
+ 'constructor': 'MozProtocolHandler',
+ 'protocol_config': {
+ 'scheme': 'moz',
+ 'flags': [
+ 'URI_DANGEROUS_TO_LOAD',
+ ],
+ },
+ },
+]
diff --git a/toolkit/components/mozprotocol/moz.build b/toolkit/components/mozprotocol/moz.build
new file mode 100644
index 0000000000..976c6435b2
--- /dev/null
+++ b/toolkit/components/mozprotocol/moz.build
@@ -0,0 +1,18 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+with Files("**"):
+ BUG_COMPONENT = ("Toolkit", "General")
+
+EXTRA_JS_MODULES += [
+ "MozProtocolHandler.sys.mjs",
+]
+
+XPCOM_MANIFESTS += [
+ "components.conf",
+]
+
+BROWSER_CHROME_MANIFESTS += ["tests/browser.ini"]
diff --git a/toolkit/components/mozprotocol/tests/browser.ini b/toolkit/components/mozprotocol/tests/browser.ini
new file mode 100644
index 0000000000..168882a671
--- /dev/null
+++ b/toolkit/components/mozprotocol/tests/browser.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+
+[browser_mozprotocol.js]
+support-files =
+ mozprotocol.html
diff --git a/toolkit/components/mozprotocol/tests/browser_mozprotocol.js b/toolkit/components/mozprotocol/tests/browser_mozprotocol.js
new file mode 100644
index 0000000000..7301d22a88
--- /dev/null
+++ b/toolkit/components/mozprotocol/tests/browser_mozprotocol.js
@@ -0,0 +1,23 @@
+// Check that entering moz://a into the address bar directs us to a new url
+add_task(async function () {
+ let path = getRootDirectory(gTestPath).substring(
+ "chrome://mochitests/content/".length
+ );
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ [
+ "toolkit.mozprotocol.url",
+ `https://example.com/${path}mozprotocol.html`,
+ ],
+ ],
+ });
+
+ await BrowserTestUtils.withNewTab("about:blank", async function () {
+ BrowserTestUtils.loadURIString(gBrowser, "moz://a");
+ await BrowserTestUtils.waitForLocationChange(
+ gBrowser,
+ `https://example.com/${path}mozprotocol.html`
+ );
+ ok(true, "Made it to the expected page");
+ });
+});
diff --git a/toolkit/components/mozprotocol/tests/mozprotocol.html b/toolkit/components/mozprotocol/tests/mozprotocol.html
new file mode 100644
index 0000000000..3d6549e00f
--- /dev/null
+++ b/toolkit/components/mozprotocol/tests/mozprotocol.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+<p><a id="link" href="moz://a">Test</a></p>
+</body>
+</html>