Bug 1545807 - Fall back to the principal-based slow code path inside ThirdPartyUtil::IsThirdPartyWindow() when we face a document without a cached base domain; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 25 Apr 2019 07:47:58 +0000
changeset 471318 b9f3ca50c00e6226e0c4877ef9199c714f8a5a5b
parent 471317 d4f22be5eb413a9d2cb5eb610d6f9c0cee6039cf
child 471319 904076df6327430699a83cfc75c2caca72dfa872
push id112913
push useropoprus@mozilla.com
push dateThu, 25 Apr 2019 22:21:16 +0000
treeherdermozilla-inbound@5279ac14ae48 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1545807
milestone68.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 1545807 - Fall back to the principal-based slow code path inside ThirdPartyUtil::IsThirdPartyWindow() when we face a document without a cached base domain; r=baku Differential Revision: https://phabricator.services.mozilla.com/D28524
dom/base/ThirdPartyUtil.cpp
--- a/dom/base/ThirdPartyUtil.cpp
+++ b/dom/base/ThirdPartyUtil.cpp
@@ -151,17 +151,28 @@ ThirdPartyUtil::IsThirdPartyWindow(mozID
   NS_ENSURE_ARG(aWindow);
   NS_ASSERTION(aResult, "null outparam pointer");
 
   bool result;
 
   nsCString bottomDomain =
       GetBaseDomainFromWindow(nsPIDOMWindowOuter::From(aWindow));
   if (bottomDomain.IsEmpty()) {
-    return NS_ERROR_FAILURE;
+    // We may have an about:blank window here.  Fall back to the slower code
+    // path which is principal aware.
+    nsCOMPtr<nsIURI> currentURI;
+    nsresult rv = GetURIFromWindow(aWindow, getter_AddRefs(currentURI));
+    if (NS_FAILED(rv)) {
+      return rv;
+    }
+
+    rv = GetBaseDomain(currentURI, bottomDomain);
+    if (NS_FAILED(rv)) {
+      return rv;
+    }
   }
 
   if (aURI) {
     // Determine whether aURI is foreign with respect to currentURI.
     nsresult rv = IsThirdPartyInternal(bottomDomain, aURI, &result);
     if (NS_FAILED(rv)) return rv;
 
     if (result) {
@@ -183,21 +194,30 @@ ThirdPartyUtil::IsThirdPartyWindow(mozID
     if (parent == current) {
       // We're at the topmost content window. We already know the answer.
       *aResult = false;
       return NS_OK;
     }
 
     nsCString parentDomain = GetBaseDomainFromWindow(parent);
     if (parentDomain.IsEmpty()) {
-      return NS_ERROR_FAILURE;
+      // We may have an about:blank window here.  Fall back to the slower code
+      // path which is principal aware.
+      nsCOMPtr<nsIURI> parentURI;
+      nsresult rv = GetURIFromWindow(parent, getter_AddRefs(parentURI));
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = IsThirdPartyInternal(bottomDomain, parentURI, &result);
+      if (NS_FAILED(rv)) {
+        return rv;
+      }
+    } else {
+      result = IsThirdPartyInternal(bottomDomain, parentDomain);
     }
 
-    result = IsThirdPartyInternal(bottomDomain, parentDomain);
-
     if (result) {
       *aResult = true;
       return NS_OK;
     }
 
     current = parent;
   } while (1);