Bug 1366327 - deal with about:reader, IDNA and non-exposable URIs better for copy/email link, r?adw
MozReview-Commit-ID: AnZa3mq2zMY
--- a/browser/base/content/browser-pageActions.js
+++ b/browser/base/content/browser-pageActions.js
@@ -676,17 +676,17 @@ BrowserPageActions.copyURL = {
onPlacedInPanel(buttonNode) {
BrowserPageActions.takeNodeAttributeFromPanel(buttonNode, "title");
},
onCommand(event, buttonNode) {
BrowserPageActions.panelNode.hidePopup();
Cc["@mozilla.org/widget/clipboardhelper;1"]
.getService(Ci.nsIClipboardHelper)
- .copyString(gBrowser.selectedBrowser.currentURI.spec);
+ .copyString(gURLBar.makeURIReadable(gBrowser.selectedBrowser.currentURI).displaySpec);
},
};
// email link
BrowserPageActions.emailLink = {
onPlacedInPanel(buttonNode) {
BrowserPageActions.takeNodeAttributeFromPanel(buttonNode, "title");
},
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -6721,17 +6721,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.displaySpec, aBrowser.contentTitle);
+ this.sendMessage(gURLBar.makeURIReadable(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);
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -936,16 +936,36 @@ file, You can obtain one at http://mozil
// Force not showing the dropped URI immediately.
gBrowser.userTypedValue = null;
URLBarSetURI();
}
}
]]></body>
</method>
+ <method name="makeURIReadable">
+ <parameter name="aURI"/>
+ <body>
+ <![CDATA[
+ // Avoid copying 'about:reader?url=', and always provide the original URI:
+ // Reader mode ensures we call createExposableURI itself.
+ let readerStrippedURI = ReaderMode.getOriginalUrlObjectForDisplay(aURI.displaySpec);
+ if (readerStrippedURI) {
+ aURI = readerStrippedURI;
+ } else {
+ // Only copy exposable URIs
+ try {
+ aURI = Services.uriFixup.createExposableURI(aURI);
+ } catch (ex) {}
+ }
+ return aURI;
+ ]]>
+ </body>
+ </method>
+
<method name="_getSelectedValueForClipboard">
<body><![CDATA[
// Grab the actual input field's value, not our value, which could include moz-action:
var inputVal = this.inputField.value;
let selection = this.editor.selection;
var selectedVal = selection.toString();
// Handle multiple-range selection as a string for simplicity.
@@ -974,27 +994,17 @@ file, You can obtain one at http://mozil
// We're dealing with an autocompleted value, create a new URI from that.
try {
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.displaySpec);
- if (readerStrippedURI) {
- uri = readerStrippedURI;
- } else {
- // Only copy exposable URIs
- try {
- uri = uriFixup.createExposableURI(uri);
- } catch (ex) {}
- }
+ uri = this.makeURIReadable(uri);
// 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.displaySpec;