Bug 1510015 - Display IDN domain names properly in the storage access API doorhanger r=johannh
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 30 Nov 2018 02:17:50 +0000
changeset 505335 5d864c9b503bbed76b2a72a1b522d537c1199812
parent 505334 acd2bfce6779ada0430d1dadfc225b1f872b8db4
child 505336 219702ce053b244ef762ab0cbba07cf17cc9a940
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1510015
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1510015 - Display IDN domain names properly in the storage access API doorhanger r=johannh Differential Revision: https://phabricator.services.mozilla.com/D12984
browser/modules/PermissionUI.jsm
--- a/browser/modules/PermissionUI.jsm
+++ b/browser/modules/PermissionUI.jsm
@@ -66,16 +66,19 @@ ChromeUtils.defineModuleGetter(this, "Se
   "resource://gre/modules/Services.jsm");
 ChromeUtils.defineModuleGetter(this, "SitePermissions",
   "resource:///modules/SitePermissions.jsm");
 ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
   "resource://gre/modules/PrivateBrowsingUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "URICountListener",
   "resource:///modules/BrowserUsageTelemetry.jsm");
 
+XPCOMUtils.defineLazyServiceGetter(this, "IDNService",
+  "@mozilla.org/network/idn-service;1", "nsIIDNService");
+
 XPCOMUtils.defineLazyGetter(this, "gBrowserBundle", function() {
   return Services.strings
                  .createBundle("chrome://browser/locale/browser.properties");
 });
 
 var PermissionUI = {};
 
 /**
@@ -938,29 +941,42 @@ StorageAccessPermissionPrompt.prototype 
     return false;
   },
 
   get permissionKey() {
     // Make sure this name is unique per each third-party tracker
     return "storage-access-" + this.principal.origin;
   },
 
+  prettifyHostPort(uri) {
+    try {
+      uri = Services.uriFixup.createExposableURI(uri);
+    } catch (e) {
+      // ignore, since we can't do anything better
+    }
+    let host = IDNService.convertToDisplayIDN(uri.host, {});
+    if (uri.port != -1) {
+      host += `:${uri.port}`;
+    }
+    return host;
+  },
+
   get popupOptions() {
     return {
       displayURI: false,
-      name: this.principal.URI.hostPort,
-      secondName: this.topLevelPrincipal.URI.hostPort,
+      name: this.prettifyHostPort(this.principal.URI),
+      secondName: this.prettifyHostPort(this.topLevelPrincipal.URI),
     };
   },
 
   onShown() {
     let document = this.browser.ownerDocument;
     let label =
       gBrowserBundle.formatStringFromName("storageAccess.description.label",
-                                          [this.request.principal.URI.hostPort, "<>"], 2);
+                                          [this.prettifyHostPort(this.request.principal.URI), "<>"], 2);
     let parts = label.split("<>");
     if (parts.length == 1) {
       parts.push("");
     }
     let map = {
       "storage-access-perm-label": parts[0],
       "storage-access-perm-learnmore":
         gBrowserBundle.GetStringFromName("storageAccess.description.learnmore"),