Bug 1325955 - Prevent providing wrong baseDomain if scheme is not recognized r=sebastian a=gchang
authorJulian_Chu <walkingice0204@gmail.com>
Thu, 16 Mar 2017 18:12:04 +0800
changeset 395413 578e94e40a70a5ba175857ada48c7a15cbd00473
parent 395412 7d216471a7c2c4c25c0d6b15ce8ae61486ab8f57
child 395414 3394e3fa0f1e9d6b5b1d032a29e59d2db0230ecd
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, gchang
bugs1325955
milestone54.0a2
Bug 1325955 - Prevent providing wrong baseDomain if scheme is not recognized r=sebastian a=gchang If location change to some special scheme, we might misuse the location to parse domain. Now only get base domain from host if the scheme is recognized.(http/https/ftp) MozReview-Commit-ID: 4MkrNfsUJqQ --- mobile/android/chrome/content/browser.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -4399,31 +4399,23 @@ Tab.prototype = {
     }
 
     // Reset state of click-to-play plugin notifications.
     clearTimeout(this.pluginDoorhangerTimeout);
     this.pluginDoorhangerTimeout = null;
     this.shouldShowPluginDoorhanger = true;
     this.clickToPlayPluginsActivated = false;
 
-    let documentURI = contentWin.document.documentURIObject.spec;
-
-    // If reader mode, get the base domain for the original url.
-    let strippedURI = this._stripAboutReaderURL(documentURI);
-
-    // Borrowed from desktop Firefox: https://hg.mozilla.org/mozilla-central/annotate/72835344333f/browser/base/content/urlbarBindings.xml#l236
-    let matchedURL = strippedURI.match(/^((?:[a-z]+:\/\/)?(?:[^\/]+@)?)(.+?)(?::\d+)?(?:\/|$)/);
     let baseDomain = "";
-    if (matchedURL) {
-      var domain = "";
-      [, , domain] = matchedURL;
-
+    // For recognized scheme, get base domain from host.
+    let principalURI = contentWin.document.nodePrincipal.URI;
+    if (principalURI && ["http", "https", "ftp"].includes(principalURI.scheme) && principalURI.host) {
       try {
-        baseDomain = Services.eTLD.getBaseDomainFromHost(domain);
-        if (!domain.endsWith(baseDomain)) {
+        baseDomain = Services.eTLD.getBaseDomainFromHost(principalURI.host);
+        if (!principalURI.host.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) {}
     }
 
     // If we are navigating to a new location with a different host,