Bug 1526891 - Part 3: Get origin and base domain strings using MozURL for all URIs; r=asuth
authorJan Varga <jan.varga@gmail.com>
Sat, 23 Feb 2019 17:01:22 +0100
changeset 520816 cd67c16e6554d4e8d67388961ba403746efa221d
parent 520815 875bba6627b329803cb02bf0c40d028d0520121b
child 520817 d6d4cb60bb71b533714f0269dc4af54cd9506ee3
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1526891
milestone67.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 1526891 - Part 3: Get origin and base domain strings using MozURL for all URIs; r=asuth Differential Revision: https://phabricator.services.mozilla.com/D20912
dom/cache/DBSchema.cpp
dom/quota/ActorsParent.cpp
dom/serviceworkers/ServiceWorkerRegistrar.cpp
--- a/dom/cache/DBSchema.cpp
+++ b/dom/cache/DBSchema.cpp
@@ -2491,32 +2491,19 @@ nsresult ReadResponse(mozIStorageConnect
 
     nsCString origin;
     url->Origin(origin);
 
     // CSP is recovered from the headers, no need to initialise it here.
     nsTArray<mozilla::ipc::ContentSecurityPolicy> policies;
 
     nsCString baseDomain;
-    if (url->Scheme() == "file") {
-      // The file scheme is not handled by third party utils properly, use the
-      // origin string for now.
-      baseDomain = origin;
-    } else {
-      nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
-          do_GetService(THIRDPARTYUTIL_CONTRACTID);
-      if (!thirdPartyUtil) {
-        return NS_ERROR_FAILURE;
-      }
-
-      rv = thirdPartyUtil->GetBaseDomainFromSchemeHost(url->Scheme(),
-                                                       url->Host(), baseDomain);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
+    rv = url->BaseDomain(baseDomain);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
     }
 
     aSavedResponseOut->mValue.principalInfo() =
         Some(mozilla::ipc::ContentPrincipalInfo(
             attrs, origin, specNoSuffix, Nothing(), std::move(policies),
             baseDomain));
   }
 
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -5372,84 +5372,46 @@ bool QuotaManager::IsPrincipalInfoValid(
 
       // Verify the principal spec parses.
       RefPtr<MozURL> specURL;
       nsresult rv = MozURL::Init(getter_AddRefs(specURL), info.spec());
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return false;
       }
 
-      nsDependentCSubstring scheme = specURL->Scheme();
-
-      // Verify the principal originNoSuffix parses.
-      RefPtr<MozURL> originNoSuffixURL;
-      rv = MozURL::Init(getter_AddRefs(originNoSuffixURL),
-                        info.originNoSuffix());
-      if (NS_WARN_IF(NS_FAILED(rv))) {
+      // Verify the principal originNoSuffix matches spec.
+      nsCString originNoSuffix;
+      specURL->Origin(originNoSuffix);
+
+      if (NS_WARN_IF(originNoSuffix != info.originNoSuffix())) {
+        QM_WARNING("originNoSuffix (%s) doesn't match passed one (%s)!",
+                   originNoSuffix.get(), info.originNoSuffix().get());
         return false;
       }
 
-      // Verify the principal originNoSuffix matches spec. Skip the check for
-      // some special schemes which are not supported by MozURL::Origin yet.
-      if (!scheme.EqualsLiteral("file") &&
-          !scheme.EqualsLiteral("indexeddb") &&
-          !scheme.EqualsLiteral("moz-extension") &&
-          !scheme.EqualsLiteral("moz-safe-about") &&
-          !scheme.EqualsLiteral("resource")) {
-        nsCString originNoSuffix;
-        specURL->Origin(originNoSuffix);
-
-        if (NS_WARN_IF(info.originNoSuffix() != originNoSuffix)) {
-          return false;
-        }
-      }
-
       if (NS_WARN_IF(info.originNoSuffix().EqualsLiteral(kChromeOrigin))) {
         return false;
       }
 
       // Verify the principal baseDomain exists.
       if (NS_WARN_IF(info.baseDomain().IsVoid())) {
         return false;
       }
 
-      // Verify the principal baseDomain parses.
-      nsCString baseDomainForParsing;
-      if (!scheme.EqualsLiteral("indexeddb") &&
-          !scheme.EqualsLiteral("moz-safe-about")) {
-        baseDomainForParsing = scheme + NS_LITERAL_CSTRING("://");
-      }
-      baseDomainForParsing.Append(info.baseDomain());
-
-      RefPtr<MozURL> baseDomainURL;
-      rv = MozURL::Init(getter_AddRefs(baseDomainURL), baseDomainForParsing);
+      // Verify the principal baseDomain matches spec.
+      nsCString baseDomain;
+      rv = specURL->BaseDomain(baseDomain);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return false;
       }
 
-      // Verify the principal baseDomain matches spec. Skip the check for
-      // some special schemes which are not handled by
-      // mozIThirdPartyUtil::GetBaseDomainFromSchemeHost.
-      if (!scheme.EqualsLiteral("file") &&
-          !scheme.EqualsLiteral("indexeddb") &&
-          !scheme.EqualsLiteral("moz-safe-about")) {
-        nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
-            do_GetService(THIRDPARTYUTIL_CONTRACTID);
-
-        nsCString baseDomain;
-        rv = thirdPartyUtil->GetBaseDomainFromSchemeHost(specURL->Scheme(),
-                                                         specURL->Host(),
-                                                         baseDomain);
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          return false;
-        }
-
-        if (NS_WARN_IF(info.baseDomain() != baseDomain)) {
-          return false;
-        }
+      if (NS_WARN_IF(baseDomain != info.baseDomain())) {
+        QM_WARNING("baseDomain (%s) doesn't match passed one (%s)!",
+                   baseDomain.get(), info.baseDomain().get());
+        return false;
       }
 
       return true;
     }
 
     default: { break; }
   }
 
--- a/dom/serviceworkers/ServiceWorkerRegistrar.cpp
+++ b/dom/serviceworkers/ServiceWorkerRegistrar.cpp
@@ -59,32 +59,19 @@ nsresult GetOriginAndBaseDomain(const ns
   RefPtr<net::MozURL> url;
   nsresult rv = net::MozURL::Init(getter_AddRefs(url), aURL);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   url->Origin(aOrigin);
 
-  if (url->Scheme() == "file") {
-    // The file scheme is not handled by third party utils properly, use the
-    // origin string for now.
-    aBaseDomain = aOrigin;
-  } else {
-    nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
-        do_GetService(THIRDPARTYUTIL_CONTRACTID);
-    if (!thirdPartyUtil) {
-      return NS_ERROR_FAILURE;
-    }
-
-    rv = thirdPartyUtil->GetBaseDomainFromSchemeHost(url->Scheme(), url->Host(),
-                                                     aBaseDomain);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
+  rv = url->BaseDomain(aBaseDomain);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
   }
 
   return NS_OK;
 }
 
 nsresult ReadLine(nsILineInputStream* aStream, nsACString& aValue) {
   bool hasMoreLines;
   nsresult rv = aStream->ReadLine(aValue, &hasMoreLines);