Bug 1325955 - Prevent providing wrong baseDomain if scheme is not recognized r=sebastian

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(-)

--HG--
extra : rebase_source : d7acb12c3e7498a8bc8a03e40727fbe050616df2
This commit is contained in:
Julian_Chu 2017-03-16 18:12:04 +08:00
parent 13bb4e5210
commit 14a267bf2b

View file

@ -4437,21 +4437,13 @@ Tab.prototype = {
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);