commit 0dcb946b8e1ac82a696182e068d3e08c81d325d0
parent 54e123f5c44b09bef25ed6379d07e2228f9e9038
Author: Gijs Kruitbosch <gijskruitbosch@gmail.com>
Date: Thu, 4 Dec 2025 13:44:56 +0000
Bug 1941148 - improve URI handling in aboutNetErrorHelpers.mjs and NetErrorChild, r=emz,frontend-codestyle-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D274293
Diffstat:
4 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/toolkit/actors/NetErrorChild.sys.mjs b/toolkit/actors/NetErrorChild.sys.mjs
@@ -7,6 +7,7 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AppInfo: "chrome://remote/content/shared/AppInfo.sys.mjs",
+ BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
});
import { RemotePageChild } from "resource://gre/actors/RemotePageChild.sys.mjs";
@@ -19,7 +20,7 @@ export class NetErrorChild extends RemotePageChild {
// to allow content-privileged about:neterror or about:certerror to use it.
const exportableFunctions = [
"RPMGetAppBuildID",
- "RPMGetInnerMostURI",
+ "RPMGetHostForDisplay",
"RPMRecordGleanEvent",
"RPMCheckAlternateHostAvailable",
"RPMGetHttpResponseHeader",
@@ -70,13 +71,11 @@ export class NetErrorChild extends RemotePageChild {
}
}
- RPMGetInnerMostURI(uriString) {
- let uri = Services.io.newURI(uriString);
- if (uri instanceof Ci.nsINestedURI) {
- uri = uri.QueryInterface(Ci.nsINestedURI).innermostURI;
- }
-
- return uri.spec;
+ RPMGetHostForDisplay(document) {
+ // Note: not document.documentURIObject, which will be the network error
+ // page's URI - we want the URI of the page that failed to load.
+ let uri = document.mozDocumentURIIfNotForErrorPages;
+ return lazy.BrowserUtils.formatURIForDisplay(uri);
}
RPMGetAppBuildID() {
diff --git a/toolkit/content/aboutNetErrorHelpers.mjs b/toolkit/content/aboutNetErrorHelpers.mjs
@@ -41,12 +41,7 @@ export function getCSSClass() {
}
export function getHostName() {
- try {
- return new URL(RPMGetInnerMostURI(document.location.href)).hostname;
- } catch (error) {
- console.error("Could not parse URL", error);
- }
- return "";
+ return RPMGetHostForDisplay(document);
}
export function retryThis(buttonEl) {
diff --git a/toolkit/modules/RemotePageAccessManager.sys.mjs b/toolkit/modules/RemotePageAccessManager.sys.mjs
@@ -56,7 +56,7 @@ export let RemotePageAccessManager = {
"services.settings.last_update_seconds",
],
RPMGetAppBuildID: ["*"],
- RPMGetInnerMostURI: ["*"],
+ RPMGetHostForDisplay: ["*"],
RPMIsWindowPrivate: ["*"],
},
"about:home": {
@@ -110,7 +110,7 @@ export let RemotePageAccessManager = {
"security.certerror.hideAddException",
"security.certerrors.felt-privacy-v1",
],
- RPMGetInnerMostURI: ["*"],
+ RPMGetHostForDisplay: ["*"],
RPMGetHttpResponseHeader: ["*"],
RPMIsTRROnlyFailure: ["*"],
RPMIsFirefox: ["*"],
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/remote-page.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/remote-page.mjs
@@ -12,7 +12,7 @@ export default {
btoa: "readonly",
RPMAddTRRExcludedDomain: "readonly",
RPMGetAppBuildID: "readonly",
- RPMGetInnerMostURI: "readonly",
+ RPMGetHostForDisplay: "readonly",
RPMGetIntPref: "readonly",
RPMGetStringPref: "readonly",
RPMGetBoolPref: "readonly",