From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../mozprotocol/MozProtocolHandler.sys.mjs | 34 ++++++++++++++++++++++ toolkit/components/mozprotocol/components.conf | 20 +++++++++++++ toolkit/components/mozprotocol/moz.build | 18 ++++++++++++ toolkit/components/mozprotocol/tests/browser.ini | 5 ++++ .../mozprotocol/tests/browser_mozprotocol.js | 23 +++++++++++++++ .../components/mozprotocol/tests/mozprotocol.html | 7 +++++ 6 files changed, 107 insertions(+) create mode 100644 toolkit/components/mozprotocol/MozProtocolHandler.sys.mjs create mode 100644 toolkit/components/mozprotocol/components.conf create mode 100644 toolkit/components/mozprotocol/moz.build create mode 100644 toolkit/components/mozprotocol/tests/browser.ini create mode 100644 toolkit/components/mozprotocol/tests/browser_mozprotocol.js create mode 100644 toolkit/components/mozprotocol/tests/mozprotocol.html (limited to 'toolkit/components/mozprotocol') 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 @@ + + + + +

Test

+ + -- cgit v1.2.3