Bug 1366327 - deal with about:reader, IDNA and non-exposable URIs better for copy/email link, r?adw draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 17 Aug 2017 13:11:06 +0100
changeset 648265 8b0c5ee780ca22bed7cffc53d2d6aa7212dd7fb6
parent 648046 932388b8c22c9775264e543697ce918415db9e23
child 726753 5f2c937eee5ba388a91bc2dfce43d9d3577f773b
push id74676
push usergijskruitbosch@gmail.com
push dateThu, 17 Aug 2017 13:20:06 +0000
reviewersadw
bugs1366327
milestone57.0a1
Bug 1366327 - deal with about:reader, IDNA and non-exposable URIs better for copy/email link, r?adw MozReview-Commit-ID: AnZa3mq2zMY
browser/base/content/browser-pageActions.js
browser/base/content/browser.js
browser/base/content/urlbarBindings.xml
--- 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;