Bug 1524857 - Part 1: Separate base domain for doorhangers from base domain used for domain highlighting. r=Gijs a=lizzard
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 07 Feb 2019 19:23:47 +0000
changeset 515873 7c5414a3d4b04aa772211fb9aca5b2f7f038992d
parent 515872 0cfbcd1d35c4868ba6698971ef5efb2ebf5085e6
child 515874 8b10cbe1b8877f492a4d54bb7c6f5fe03b4016b2
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, lizzard
bugs1524857, 1325955
milestone66.0
Bug 1524857 - Part 1: Separate base domain for doorhangers from base domain used for domain highlighting. r=Gijs a=lizzard Currently, the Android front-end uses a tab's base domain both for permission prompt doorhangers, as well as for doing domain highlighting in the URL bar. The base domain in turn is based on the document's nodePrincipal's URI. As per bug 1325955, the nodePrincipal is the right choice for permission prompts, but it causes some problems for domain highlighting instead: For error pages for example, the nodePrincipal's URI will be some variety of about:neterror, which means that the front-end won't be able to do any domain highlighting based on that, since a) we don't generate any baseDomain anyway because the URI's scheme isn't HTTP(S)/FTP, and b) even if we did, the nodePrincipal's baseDomain won't match the contents of the URI displayed in the URL bar. Therefore, we want to separate these two concerns, and generate two baseDomains: One based on the nodePrincipal for use in permission prompts, and one based on the display URI, which going forward will power our domain highlighting. Differential Revision: https://phabricator.services.mozilla.com/D18586
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3670,16 +3670,37 @@ function truncate(text, max) {
 
   if (text.length <= max) {
     return text;
   }
 
   return text.slice(0, max) + "…";
 }
 
+/**
+ * We want to extract base domains only from URIs using one of the following
+ * schemes.
+ */
+const PERMITTED_BASE_DOMAIN_SCHEMES = new Set(["http", "https", "ftp"]);
+
+function getBaseDomain(aURI) {
+  let baseDomain = "";
+  if (aURI && PERMITTED_BASE_DOMAIN_SCHEMES.has(aURI.scheme)) {
+    try {
+      baseDomain = Services.eTLD.getBaseDomainFromHost(aURI.displayHost);
+      if (!aURI.displayHost.endsWith(baseDomain)) {
+        // getBaseDomainFromHost converts its resultant to ACE.
+        let IDNService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
+        baseDomain = IDNService.convertACEtoUTF8(baseDomain);
+      }
+    } catch (e) {}
+  }
+  return baseDomain;
+}
+
 Tab.prototype = {
   create: function(aURL, aParams) {
     if (this.browser)
       return;
 
     aParams = aParams || {};
 
     this.browser = document.createElement("browser");
@@ -4643,29 +4664,18 @@ Tab.prototype = {
 
     // Let the reader logic know about same document changes because we won't get a DOMContentLoaded
     // or pageshow event, but we'll still want to update the reader view button to account for this change.
     // This mirrors the desktop logic in TabsProgressListener.
     if (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT) {
       this.browser.messageManager.sendAsyncMessage("Reader:PushState", {isArticle: this.browser.isArticle});
     }
 
-    let baseDomain = "";
-    // For recognized scheme, get base domain from host.
-    let principalURI = contentWin.document.nodePrincipal.URI;
-    if (principalURI && ["http", "https", "ftp"].includes(principalURI.scheme) && principalURI.displayHost) {
-      try {
-        baseDomain = Services.eTLD.getBaseDomainFromHost(principalURI.displayHost);
-        if (!principalURI.displayHost.endsWith(baseDomain)) {
-          // getBaseDomainFromHost converts its resultant to ACE.
-          let IDNService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
-          baseDomain = IDNService.convertACEtoUTF8(baseDomain);
-        }
-      } catch (e) {}
-    }
+    let baseDomain = getBaseDomain(contentWin.document.nodePrincipal.URI);
+    let highlightDomain = getBaseDomain(fixedURI);
 
     // If we are navigating to a new location with a different host,
     // clear any URL origin that might have been pinned to this tab.
     let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
     let appOrigin = ss.getTabValue(this, "appOrigin");
     if (appOrigin) {
       let originHost = "";
       try {
@@ -4706,16 +4716,17 @@ Tab.prototype = {
     }
 
     let message = {
       type: "Content:LocationChange",
       tabID: this.id,
       uri: truncate(fixedURI.displaySpec, MAX_URI_LENGTH),
       userRequested: this.userRequested || "",
       baseDomain,
+      highlightDomain,
       contentType: (contentType ? contentType : ""),
       sameDocument,
 
       canGoBack: webNav.canGoBack,
       canGoForward: webNav.canGoForward,
     };
 
     GlobalEventDispatcher.sendRequest(message);