Bug 945240 - Change firefox code to use uri.displaySpec when unicode URLs are wanted r=Gijs
* Make URL bar show unicode URL by making losslessDecodeURI call uri.displaySpec
* Make sure URL bar copying returns unicode variant
MozReview-Commit-ID: GTESwOSJW0P
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -407,17 +407,17 @@ var PlacesCommandHook = {
var description;
var charset;
let docInfo = await this._getPageDetails(aBrowser);
try {
title = docInfo.isErrorPage ? PlacesUtils.history.getPageTitle(uri)
: aBrowser.contentTitle;
- title = title || uri.spec;
+ title = title || uri.displaySpec;
description = docInfo.description;
charset = aBrowser.characterSet;
} catch (e) { }
if (aShowEditUI && isNewBookmark) {
// If we bookmark the page here but open right into a cancelable
// state (i.e. new bookmark in Library), start batching here so
// all of the actions can be undone in a single undo step.
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2599,17 +2599,17 @@ function URLBarSetURI(aURI) {
SetPageProxyState(valid ? "valid" : "invalid");
}
function losslessDecodeURI(aURI) {
let scheme = aURI.scheme;
if (scheme == "moz-action")
throw new Error("losslessDecodeURI should never get a moz-action URI");
- var value = aURI.spec;
+ var value = aURI.displaySpec;
let decodeASCIIOnly = !["https", "http", "file", "ftp"].includes(scheme);
// Try to decode as UTF-8 if there's no encoding sequence that we would break.
if (!/%25(?:3B|2F|3F|3A|40|26|3D|2B|24|2C|23)/i.test(value)) {
if (decodeASCIIOnly) {
// This only decodes ascii characters (hex) 20-7e, except 25 (%).
// This avoids both cases stipulated below (%-related issues, and \r, \n
// and \t, which would be %0d, %0a and %09, respectively) as well as any
@@ -6576,17 +6576,17 @@ function warnAboutClosingWindow() {
// the session alive. Hence don't prompt users to save tabs, but warn about
// closing multiple tabs.
return AppConstants.platform != "macosx"
|| (isPBWindow || gBrowser.warnAboutClosingTabs(gBrowser.closingTabsEnum.ALL));
}
var MailIntegration = {
sendLinkForBrowser(aBrowser) {
- this.sendMessage(aBrowser.currentURI.spec, aBrowser.contentTitle);
+ this.sendMessage(aBrowser.currentURI.displaySpec, aBrowser.contentTitle);
},
sendMessage(aBody, aSubject) {
// generate a mailto url based on the url and the url's title
var mailtoUrl = "mailto:";
if (aBody) {
mailtoUrl += "?body=" + encodeURIComponent(aBody);
mailtoUrl += "&subject=" + encodeURIComponent(aSubject);
@@ -7627,17 +7627,17 @@ var gIdentityHandler = {
this.refreshIdentityBlock();
}
},
onDragStart(event) {
if (gURLBar.getAttribute("pageproxystate") != "valid")
return;
- let value = gBrowser.currentURI.spec;
+ let value = gBrowser.currentURI.displaySpec;
let urlString = value + "\n" + gBrowser.contentTitle;
let htmlString = "<a href=\"" + value + "\">" + value + "</a>";
let dt = event.dataTransfer;
dt.setData("text/x-moz-url", urlString);
dt.setData("text/uri-list", value);
dt.setData("text/plain", value);
dt.setData("text/html", htmlString);
@@ -8019,23 +8019,23 @@ function switchToTabHavingURI(aURI, aOpe
}
return ret;
}
// Need to handle nsSimpleURIs here too (e.g. about:...), which don't
// work correctly with URL objects - so treat them as strings
let ignoreFragmentWhenComparing = typeof ignoreFragment == "string" &&
ignoreFragment.startsWith("whenComparing");
- let requestedCompare = cleanURL(
- aURI.spec, ignoreQueryString || replaceQueryString, ignoreFragmentWhenComparing);
+ let requestedCompare = cleanURL(
+ aURI.displaySpec, ignoreQueryString || replaceQueryString, ignoreFragmentWhenComparing);
let browsers = aWindow.gBrowser.browsers;
for (let i = 0; i < browsers.length; i++) {
let browser = browsers[i];
let browserCompare = cleanURL(
- browser.currentURI.spec, ignoreQueryString || replaceQueryString, ignoreFragmentWhenComparing);
+ browser.currentURI.displaySpec, ignoreQueryString || replaceQueryString, ignoreFragmentWhenComparing);
if (requestedCompare == browserCompare) {
aWindow.focus();
if (ignoreFragment == "whenComparingAndReplace" || replaceQueryString) {
browser.loadURI(aURI.spec);
}
aWindow.gBrowser.tabContainer.selectedIndex = i;
return true;
}
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -1433,21 +1433,21 @@
if (aTab._suppressTransientPlaceholderLabel) {
if (!title) {
return false;
}
delete aTab._suppressTransientPlaceholderLabel;
}
if (!title) {
- if (browser.currentURI.spec) {
+ if (browser.currentURI.displaySpec) {
try {
- title = this.mURIFixup.createExposableURI(browser.currentURI).spec;
+ title = this.mURIFixup.createExposableURI(browser.currentURI).displaySpec;
} catch (ex) {
- title = browser.currentURI.spec;
+ title = browser.currentURI.displaySpec;
}
}
if (title && !isBlankPageURL(title)) {
// At this point, we now have a URI.
// Let's try to unescape it using a character set
// in case the URI is not ASCII.
try {
@@ -7660,17 +7660,17 @@
tabcontainer.removeEventListener("TabAttrModified", this);
tabcontainer.removeEventListener("TabClose", this);
]]></handler>
<handler event="DOMMenuItemActive">
<![CDATA[
var tab = event.target.tab;
if (tab) {
- let overLink = tab.linkedBrowser.currentURI.spec;
+ let overLink = tab.linkedBrowser.currentURI.displaySpec;
if (overLink == "about:blank")
overLink = "";
XULBrowserWindow.setOverLink(overLink, null);
}
]]></handler>
<handler event="DOMMenuItemInactive">
<![CDATA[
--- a/browser/base/content/test/urlbar/browser_urlbarCopying.js
+++ b/browser/base/content/test/urlbar/browser_urlbarCopying.js
@@ -132,16 +132,29 @@ var tests = [
{
copyVal: "e<xample.com/\xe9>\xe9",
copyExpected: "xample.com/\xe9"
},
{
copyVal: "<example.com/\xe9>\xe9",
copyExpected: "http://example.com/\xe9"
},
+ { // Note: it seems BrowserTestUtils.loadURI fails for unicode domains
+ loadURL: "http://sub2.xn--lt-uia.mochi.test:8888/foo",
+ expectedURL: toUnicode("sub2.ält.mochi.test:8888/foo"),
+ copyExpected: toUnicode("http://sub2.ält.mochi.test:8888/foo")
+ },
+ {
+ copyVal: toUnicode("s<ub2.ält.mochi.test:8888/f>oo"),
+ copyExpected: toUnicode("ub2.ält.mochi.test:8888/f")
+ },
+ {
+ copyVal: toUnicode("<sub2.ält.mochi.test:8888/f>oo"),
+ copyExpected: toUnicode("http://sub2.ält.mochi.test:8888/f")
+ },
{
loadURL: "http://example.com/?%C3%B7%C3%B7",
expectedURL: "example.com/?\xf7\xf7",
copyExpected: "http://example.com/?%C3%B7%C3%B7"
},
{
copyVal: "e<xample.com/?\xf7>\xf7",
@@ -206,16 +219,17 @@ function runTest(testCase, cb) {
testCopy(testCase.copyVal, testCase.copyExpected, cb);
}
if (testCase.setup) {
testCase.setup();
}
if (testCase.loadURL) {
+ info(`Loading : ${testCase.loadURL}\n`);
loadURL(testCase.loadURL, doCheck);
} else {
if (testCase.setURL)
gURLBar.value = testCase.setURL;
doCheck();
}
}
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -203,17 +203,17 @@ file, You can obtain one at http://mozil
case "extension": {
returnValue = action.params.content;
break;
}
}
} else {
let originalUrl = ReaderMode.getOriginalUrlObjectForDisplay(aValue);
if (originalUrl) {
- returnValue = originalUrl.spec;
+ returnValue = originalUrl.displaySpec;
}
}
// Set the actiontype only if the user is not overriding actions.
if (action && this._pressedNoActionKeys.size == 0) {
this.setAttribute("actiontype", action.type);
} else {
this.removeAttribute("actiontype");
@@ -836,38 +836,38 @@ file, You can obtain one at http://mozil
uri = uriFixup.createFixupURI(inputVal, Ci.nsIURIFixup.FIXUP_FLAG_NONE);
} catch (e) {}
if (!uri)
return selectedVal;
}
// Avoid copying 'about:reader?url=', and always provide the original URI:
// Reader mode ensures we call createExposableURI itself.
- let readerStrippedURI = ReaderMode.getOriginalUrlObjectForDisplay(uri.spec);
+ let readerStrippedURI = ReaderMode.getOriginalUrlObjectForDisplay(uri.displaySpec);
if (readerStrippedURI) {
uri = readerStrippedURI;
} else {
// Only copy exposable URIs
try {
uri = uriFixup.createExposableURI(uri);
} catch (ex) {}
}
// If the entire URL is selected, just use the actual loaded URI,
// unless we want a decoded URI, or it's a data: or javascript: URI,
// since those are hard to read when encoded.
if (inputVal == selectedVal &&
!uri.schemeIs("javascript") && !uri.schemeIs("data") &&
!Services.prefs.getBoolPref("browser.urlbar.decodeURLsOnCopy")) {
- return uri.spec;
+ return uri.displaySpec;
}
// Just the beginning of the URL is selected, or we want a decoded
// url. First check for a trimmed value.
- let spec = uri.spec;
+ let spec = uri.displaySpec;
let trimmedSpec = this.trimValue(spec);
if (spec != trimmedSpec) {
// Prepend the portion that trimValue removed from the beginning.
// This assumes trimValue will only truncate the URL at
// the beginning or end (or both).
let trimmedSegments = spec.split(trimmedSpec);
selectedVal = trimmedSegments[0] + selectedVal;
}
@@ -1283,17 +1283,17 @@ file, You can obtain one at http://mozil
// Drag only if the entire value is selected and it's a valid URI.
var isFullSelection = this.selectionStart == 0 &&
this.selectionEnd == this.textLength;
if (!isFullSelection ||
this.getAttribute("pageproxystate") != "valid")
return;
- var urlString = gBrowser.selectedBrowser.currentURI.spec;
+ var urlString = gBrowser.selectedBrowser.currentURI.displaySpec;
var title = gBrowser.selectedBrowser.contentTitle || urlString;
var htmlString = "<a href=\"" + urlString + "\">" + urlString + "</a>";
var dt = event.dataTransfer;
dt.setData("text/x-moz-url", urlString + "\n" + title);
dt.setData("text/unicode", urlString);
dt.setData("text/html", htmlString);
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -938,17 +938,17 @@ function trimURL(aURL) {
}
let urlWithoutProtocol = url.substring(7);
let flags = Services.uriFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP |
Services.uriFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS;
let fixedUpURL, expectedURLSpec;
try {
fixedUpURL = Services.uriFixup.createFixupURI(urlWithoutProtocol, flags);
- expectedURLSpec = makeURI(aURL).spec;
+ expectedURLSpec = makeURI(aURL).displaySpec;
} catch (ex) {
return url;
}
- if (fixedUpURL.spec == expectedURLSpec) {
+ if (fixedUpURL.displaySpec == expectedURLSpec) {
return urlWithoutProtocol;
}
return url;
}