Bug 1067293 - Omit "https://".r=dao

Differential Revision: https://phabricator.services.mozilla.com/D184933
This commit is contained in:
Marc Seibert 2023-08-09 22:27:21 +00:00
parent 955295d44b
commit 229719aff7
7 changed files with 113 additions and 61 deletions

View File

@ -516,6 +516,8 @@ pref("browser.urlbar.maxCharsForSearchSuggestions", 100);
pref("browser.urlbar.trimURLs", true);
pref("browser.urlbar.trimHttps", false);
// If changed to true, copying the entire URL from the location bar will put the
// human readable (percent-decoded) URL on the clipboard.
pref("browser.urlbar.decodeURLsOnCopy", false);

View File

@ -3350,7 +3350,16 @@ export class UrlbarInput {
if (fixedURI) {
try {
let expectedURI = Services.io.newURI(this._untrimmedValue);
untrim = fixedURI.displaySpec != expectedURI.displaySpec;
if (
lazy.UrlbarPrefs.get("trimHttps") &&
this._untrimmedValue.startsWith("https://")
) {
untrim =
fixedURI.displaySpec.replace("http://", "https://") !=
expectedURI.displaySpec; // FIXME bug 1847723: Figure out a way to do this without manually messing with the fixed up URI.
} else {
untrim = fixedURI.displaySpec != expectedURI.displaySpec;
}
} catch (ex) {
untrim = true;
}

View File

@ -405,6 +405,9 @@ const PREF_URLBAR_DEFAULTS = new Map([
// Remove redundant portions from URLs.
["trimURLs", true],
// Remove 'https://' from url when urlbar is focused.
["trimHttps", true],
// If true, top sites may include sponsored ones.
["sponsoredTopSites", false],

View File

@ -269,8 +269,12 @@ export class UrlbarValueFormatter {
let { domain, origin, preDomain, schemeWSlashes, trimmedLength, url } =
urlMetaData;
// We strip http, so we should not show the scheme box for it.
if (!lazy.UrlbarPrefs.get("trimURLs") || schemeWSlashes != "http://") {
// When the scheme has been stripped, don't show the box for it.
if (
!lazy.UrlbarPrefs.get("trimURLs") ||
schemeWSlashes != lazy.BrowserUIUtils.trimURLProtocol
) {
this.scheme.value = schemeWSlashes;
this.inputField.style.setProperty(
"--urlbar-scheme-size",

View File

@ -40,13 +40,17 @@ async function testVal(urlFormatString, clobberedURLString = null) {
}
add_task(async function () {
const prefname = "browser.urlbar.formatting.enabled";
const PREF_FORMATTING = "browser.urlbar.formatting.enabled";
const PREF_TRIM_HTTPS = "browser.urlbar.trimHttps";
registerCleanupFunction(function () {
Services.prefs.clearUserPref(prefname);
Services.prefs.clearUserPref(PREF_FORMATTING);
Services.prefs.clearUserPref(PREF_TRIM_HTTPS);
gURLBar.setURI();
});
Services.prefs.setBoolPref(PREF_TRIM_HTTPS, false);
gBrowser.selectedBrowser.focus();
await testVal("<https://>mozilla.org");
@ -152,7 +156,7 @@ add_task(async function () {
await testVal("foo-://mozilla.org/");
// Disable formatting.
Services.prefs.setBoolPref(prefname, false);
Services.prefs.setBoolPref(PREF_FORMATTING, false);
await testVal("https://mozilla.org");
});

View File

@ -1,53 +1,38 @@
add_task(async function () {
const PREF_TRIMURLS = "browser.urlbar.trimURLs";
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
registerCleanupFunction(async function () {
BrowserTestUtils.removeTab(tab);
Services.prefs.clearUserPref(PREF_TRIMURLS);
gURLBar.setURI();
});
// Avoid search service sync init warnings due to URIFixup, when running the
// test alone.
await Services.search.init();
Services.prefs.setBoolPref(PREF_TRIMURLS, true);
testVal("http://mozilla.org/", "mozilla.org");
testVal("https://mozilla.org/", "https://mozilla.org");
testVal("http://mözilla.org/", "mözilla.org");
function testValues(trimmedProtocol, notTrimmedProtocol) {
testVal(trimmedProtocol + "mozilla.org/", "mozilla.org");
testVal(
notTrimmedProtocol + "mozilla.org/",
notTrimmedProtocol + "mozilla.org"
);
testVal(trimmedProtocol + "mözilla.org/", "mözilla.org");
// This isn't a valid public suffix, thus we should untrim it or it would
// end up doing a search.
testVal("http://mozilla.imaginatory/");
testVal("http://www.mozilla.org/", "www.mozilla.org");
testVal("http://sub.mozilla.org/", "sub.mozilla.org");
testVal("http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org");
testVal("http://mozilla.org/file.ext", "mozilla.org/file.ext");
testVal("http://mozilla.org/sub/", "mozilla.org/sub/");
testVal(trimmedProtocol + "mozilla.imaginatory/");
testVal(trimmedProtocol + "www.mozilla.org/", "www.mozilla.org");
testVal(trimmedProtocol + "sub.mozilla.org/", "sub.mozilla.org");
testVal(
trimmedProtocol + "sub1.sub2.sub3.mozilla.org/",
"sub1.sub2.sub3.mozilla.org"
);
testVal(trimmedProtocol + "mozilla.org/file.ext", "mozilla.org/file.ext");
testVal(trimmedProtocol + "mozilla.org/sub/", "mozilla.org/sub/");
testVal("http://ftp.mozilla.org/", "ftp.mozilla.org");
testVal("http://ftp1.mozilla.org/", "ftp1.mozilla.org");
testVal("http://ftp42.mozilla.org/", "ftp42.mozilla.org");
testVal("http://ftpx.mozilla.org/", "ftpx.mozilla.org");
testVal(trimmedProtocol + "ftp.mozilla.org/", "ftp.mozilla.org");
testVal(trimmedProtocol + "ftp1.mozilla.org/", "ftp1.mozilla.org");
testVal(trimmedProtocol + "ftp42.mozilla.org/", "ftp42.mozilla.org");
testVal(trimmedProtocol + "ftpx.mozilla.org/", "ftpx.mozilla.org");
testVal("ftp://ftp.mozilla.org/", "ftp://ftp.mozilla.org");
testVal("ftp://ftp1.mozilla.org/", "ftp://ftp1.mozilla.org");
testVal("ftp://ftp42.mozilla.org/", "ftp://ftp42.mozilla.org");
testVal("ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org");
testVal("https://user:pass@mozilla.org/", "https://user:pass@mozilla.org");
testVal("https://user@mozilla.org/", "https://user@mozilla.org");
testVal("http://user:pass@mozilla.org/", "user:pass@mozilla.org");
testVal("http://user@mozilla.org/", "user@mozilla.org");
testVal("http://sub.mozilla.org:666/", "sub.mozilla.org:666");
testVal("https://[fe80::222:19ff:fe11:8c76]/file.ext");
testVal("http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]");
testVal("https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext");
testVal(
"http://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext",
"user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"
notTrimmedProtocol + "user:pass@mozilla.org/",
notTrimmedProtocol + "user:pass@mozilla.org"
);
testVal(
notTrimmedProtocol + "user@mozilla.org/",
notTrimmedProtocol + "user@mozilla.org"
);
testVal("mailto:admin@mozilla.org");
@ -55,6 +40,33 @@ add_task(async function () {
testVal("about:config");
testVal("jar:http://mozilla.org/example.jar!/");
testVal("view-source:http://mozilla.org/");
}
add_task(async function () {
const PREF_TRIM_URLS = "browser.urlbar.trimURLs";
const PREF_TRIM_HTTPS = "browser.urlbar.trimHttps";
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
registerCleanupFunction(async function () {
BrowserTestUtils.removeTab(tab);
Services.prefs.clearUserPref(PREF_TRIM_URLS);
Services.prefs.clearUserPref(PREF_TRIM_HTTPS);
gURLBar.setURI();
});
Services.prefs.setBoolPref(PREF_TRIM_HTTPS, false);
// Avoid search service sync init warnings due to URIFixup, when running the
// test alone.
await Services.search.init();
Services.prefs.setBoolPref(PREF_TRIM_URLS, true);
testValues("http://", "https://");
Services.prefs.setBoolPref(PREF_TRIM_HTTPS, true);
testValues("https://", "http://");
Services.prefs.setBoolPref(PREF_TRIM_HTTPS, false);
// Behaviour for hosts with no dots depends on the whitelist:
let fixupWhitelistPref = "browser.fixup.domainwhitelist.localhost";
@ -71,17 +83,28 @@ add_task(async function () {
// This host is whitelisted, it can be trimmed.
testVal("http://localhost/ foo bar baz", "localhost/ foo bar baz");
testVal("http://user:pass@mozilla.org/", "user:pass@mozilla.org");
testVal("http://user@mozilla.org/", "user@mozilla.org");
testVal("http://sub.mozilla.org:666/", "sub.mozilla.org:666");
testVal("https://[fe80::222:19ff:fe11:8c76]/file.ext");
testVal("http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]");
testVal("https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext");
testVal(
"http://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext",
"user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"
);
// This is not trimmed because it's not in the domain whitelist.
testVal(
"http://localhost.localdomain/ foo bar baz",
"http://localhost.localdomain/ foo bar baz"
);
Services.prefs.setBoolPref(PREF_TRIMURLS, false);
Services.prefs.setBoolPref(PREF_TRIM_URLS, false);
testVal("http://mozilla.org/");
Services.prefs.setBoolPref(PREF_TRIMURLS, true);
Services.prefs.setBoolPref(PREF_TRIM_URLS, true);
let promiseLoaded = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,

View File

@ -5,6 +5,13 @@
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
XPCOMUtils.defineLazyPreferenceGetter(
lazy,
"trimHttps",
"browser.urlbar.trimHttps"
);
export var BrowserUIUtils = {
/**
* Check whether a page can be considered as 'empty', that its URI
@ -141,24 +148,24 @@ export var BrowserUIUtils = {
return aURL.replace(/^((?:http|https|ftp):\/\/[^/]+)\/$/, "$1");
},
get trimURLProtocol() {
return lazy.trimHttps ? "https://" : "http://";
},
/**
* Returns a URL which has been trimmed by removing 'http://' and any
* trailing slash (in http/https/ftp urls).
* Note that a trimmed url may not load the same page as the original url, so
* before loading it, it must be passed through URIFixup, to check trimming
* doesn't change its destination. We don't run the URIFixup check here,
* because trimURL is in the page load path (see onLocationChange), so it
* must be fast and simple.
* Returns a URL which has been trimmed by removing 'http://' or 'https://',
* when the pref 'trimHttps' is set to true, and any trailing slash
* (in http/https/ftp urls). Note that a trimmed url may not load the same
* page as the original url, so before loading it, it must be passed through
* URIFixup, to check trimming doesn't change its destination. We don't run
* the URIFixup check here, because trimURL is in the page load path
* (see onLocationChange), so it must be fast and simple.
*
* @param {string} aURL The URL to trim.
* @returns {string} The trimmed string.
*/
get trimURLProtocol() {
return "http://";
},
trimURL(aURL) {
let url = this.removeSingleTrailingSlashFromURL(aURL);
// Remove "http://" prefix.
return url.startsWith(this.trimURLProtocol)
? url.substring(this.trimURLProtocol.length)
: url;