Bug 1507991 - Part 2: Serialize domain in ContentPrincipalInfo, r=baku
☠☠ backed out by 177cf2f812d5 ☠ ☠
authorNika Layzell <nika@thelayzells.com>
Tue, 26 Feb 2019 15:48:00 +0000
changeset 519101 15116b423375866d2aa2456f9137281cf19fa5a7
parent 519100 a483c170d712dd84d11151ec8610fd871dd4f10d
child 519102 71c093a6dace9b1b4f376ae623b38f6e7f2fcbbe
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)
reviewersbaku
bugs1507991
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 1507991 - Part 2: Serialize domain in ContentPrincipalInfo, r=baku This is needed to maintain full feature parity with the existing nsIPrincipal serializer while switching to using the PrincipalInfo-based one. Depends on D20853 Differential Revision: https://phabricator.services.mozilla.com/D20854
caps/nsJSPrincipals.cpp
dom/serviceworkers/ServiceWorkerRegistrar.cpp
dom/serviceworkers/test/gtest/TestReadWrite.cpp
ipc/glue/BackgroundUtils.cpp
ipc/glue/PBackgroundSharedTypes.ipdlh
--- a/caps/nsJSPrincipals.cpp
+++ b/caps/nsJSPrincipals.cpp
@@ -240,18 +240,19 @@ static bool ReadPrincipalInfo(JSStructur
 #ifdef FUZZING
     if (originNoSuffix.IsEmpty()) {
       return false;
     }
 #endif
 
     MOZ_DIAGNOSTIC_ASSERT(!originNoSuffix.IsEmpty());
 
-    aInfo =
-        ContentPrincipalInfo(attrs, originNoSuffix, spec, std::move(policies));
+    // XXX: Do we care about mDomain for structured clone?
+    aInfo = ContentPrincipalInfo(attrs, originNoSuffix, spec, Nothing(),
+                                 std::move(policies));
   } else {
 #ifdef FUZZING
     return false;
 #else
     MOZ_CRASH("unexpected principal structured clone tag");
 #endif
   }
 
--- a/dom/serviceworkers/ServiceWorkerRegistrar.cpp
+++ b/dom/serviceworkers/ServiceWorkerRegistrar.cpp
@@ -109,17 +109,17 @@ nsresult CreatePrincipalInfo(nsILineInpu
   rv = GetOrigin(aEntry->scope(), origin);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // CSP will be applied during the script load.
   nsTArray<mozilla::ipc::ContentSecurityPolicy> policies;
   aEntry->principal() = mozilla::ipc::ContentPrincipalInfo(
-      attrs, origin, aEntry->scope(), std::move(policies));
+      attrs, origin, aEntry->scope(), Nothing(), std::move(policies));
 
   return NS_OK;
 }
 
 }  // namespace
 
 NS_IMPL_ISUPPORTS(ServiceWorkerRegistrar, nsIObserver, nsIAsyncShutdownBlocker)
 
--- a/dom/serviceworkers/test/gtest/TestReadWrite.cpp
+++ b/dom/serviceworkers/test/gtest/TestReadWrite.cpp
@@ -269,17 +269,18 @@ TEST(ServiceWorkerRegistrar, TestWriteDa
       reg.currentWorkerActivatedTime() = PR_Now();
       reg.lastUpdateTime() = PR_Now();
 
       nsAutoCString spec;
       spec.AppendPrintf("spec write %d", i);
 
       nsTArray<mozilla::ipc::ContentSecurityPolicy> policies;
       reg.principal() = mozilla::ipc::ContentPrincipalInfo(
-          mozilla::OriginAttributes(i, i % 2), spec, spec, std::move(policies));
+          mozilla::OriginAttributes(i, i % 2), spec, spec, Nothing(),
+          std::move(policies));
 
       swr->TestRegisterServiceWorker(reg);
     }
 
     nsresult rv = swr->TestWriteData();
     ASSERT_EQ(NS_OK, rv) << "WriteData() should not fail";
   }
 
@@ -858,17 +859,18 @@ TEST(ServiceWorkerRegistrar, TestDedupeW
       reg.updateViaCache() =
           nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_IMPORTS;
 
       nsAutoCString spec;
       spec.AppendPrintf("spec write dedupe/%d", i);
 
       nsTArray<mozilla::ipc::ContentSecurityPolicy> policies;
       reg.principal() = mozilla::ipc::ContentPrincipalInfo(
-          mozilla::OriginAttributes(0, false), spec, spec, std::move(policies));
+          mozilla::OriginAttributes(0, false), spec, spec, Nothing(),
+          std::move(policies));
 
       swr->TestRegisterServiceWorker(reg);
     }
 
     nsresult rv = swr->TestWriteData();
     ASSERT_EQ(NS_OK, rv) << "WriteData() should not fail";
   }
 
--- a/ipc/glue/BackgroundUtils.cpp
+++ b/ipc/glue/BackgroundUtils.cpp
@@ -99,16 +99,29 @@ already_AddRefed<nsIPrincipal> Principal
       // Origin must match what the_new_principal.getOrigin returns.
       nsAutoCString originNoSuffix;
       rv = principal->GetOriginNoSuffix(originNoSuffix);
       if (NS_WARN_IF(NS_FAILED(rv)) ||
           !info.originNoSuffix().Equals(originNoSuffix)) {
         MOZ_CRASH("Origin must be available when deserialized");
       }
 
+      if (info.domain()) {
+        nsCOMPtr<nsIURI> domain;
+        rv = NS_NewURI(getter_AddRefs(domain), *info.domain());
+        if (NS_WARN_IF(NS_FAILED(rv))) {
+          return nullptr;
+        }
+
+        rv = principal->SetDomain(domain);
+        if (NS_WARN_IF(NS_FAILED(rv))) {
+          return nullptr;
+        }
+      }
+
       if (info.securityPolicies().Length() > 0) {
         nsCOMPtr<nsIContentSecurityPolicy> csp =
             do_CreateInstance(NS_CSPCONTEXT_CONTRACTID, &rv);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return nullptr;
         }
 
         rv = csp->SetRequestContext(nullptr, principal);
@@ -271,30 +284,45 @@ nsresult PrincipalToPrincipalInfo(nsIPri
   }
 
   nsCString originNoSuffix;
   rv = aPrincipal->GetOriginNoSuffix(originNoSuffix);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
+  nsCOMPtr<nsIURI> domainUri;
+  rv = aPrincipal->GetDomain(getter_AddRefs(domainUri));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  Maybe<nsCString> domain;
+  if (domainUri) {
+    domain.emplace();
+    rv = domainUri->GetSpec(domain.ref());
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+  }
+
   nsCOMPtr<nsIContentSecurityPolicy> csp;
   rv = aPrincipal->GetCsp(getter_AddRefs(csp));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsTArray<ContentSecurityPolicy> policies;
   if (csp) {
     PopulateContentSecurityPolicies(csp, policies);
   }
 
   *aPrincipalInfo =
       ContentPrincipalInfo(aPrincipal->OriginAttributesRef(), originNoSuffix,
-                           spec, std::move(policies));
+                           spec, domain, std::move(policies));
   return NS_OK;
 }
 
 bool IsPincipalInfoPrivate(const PrincipalInfo& aPrincipalInfo) {
   if (aPrincipalInfo.type() != ipc::PrincipalInfo::TContentPrincipalInfo) {
     return false;
   }
 
--- a/ipc/glue/PBackgroundSharedTypes.ipdlh
+++ b/ipc/glue/PBackgroundSharedTypes.ipdlh
@@ -25,16 +25,18 @@ struct ContentPrincipalInfo
   // on.
   // Another important reason why we have this attribute is that
   // ContentPrincipalInfo is used out of the main-thread. Having this value
   // here allows us to retrive the origin without creating a full nsIPrincipal.
   nsCString originNoSuffix;
 
   nsCString spec;
 
+  nsCString? domain;
+
   ContentSecurityPolicy[] securityPolicies;
 };
 
 struct SystemPrincipalInfo
 { };
 
 struct NullPrincipalInfo
 {