Bug 1640135 - P2: add new setter; r=timhuang
authorLiang-Heng Chen <xeonchen@gmail.com>
Thu, 04 Jun 2020 10:51:06 +0000
changeset 597954 9a58e5805c830f57aa7d57ad19337803197e0c23
parent 597953 42f2bdd06a959c9d01a659be6664e4ea79939b3b
child 597955 bd311336daa756c251f5b6a970ba638f7575a7b0
push id13310
push userffxbld-merge
push dateMon, 29 Jun 2020 14:50:06 +0000
treeherdermozilla-beta@15a59a0afa5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstimhuang
bugs1640135
milestone79.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 1640135 - P2: add new setter; r=timhuang Differential Revision: https://phabricator.services.mozilla.com/D77915
caps/OriginAttributes.cpp
caps/OriginAttributes.h
toolkit/components/antitracking/StoragePrincipalHelper.cpp
--- a/caps/OriginAttributes.cpp
+++ b/caps/OriginAttributes.cpp
@@ -155,16 +155,29 @@ void OriginAttributes::SetFirstPartyDoma
   // If the pref is off or this is not a top level load, bail out.
   if ((!IsFirstPartyEnabled() || !aIsTopLevelDocument) && !aForced) {
     return;
   }
 
   mFirstPartyDomain = aDomain;
 }
 
+void OriginAttributes::SetPartitionKey(nsIURI* aURI) {
+  // TODO: implement this function
+  MOZ_ASSERT(false);
+}
+
+void OriginAttributes::SetPartitionKey(const nsACString& aDomain) {
+  SetPartitionKey(NS_ConvertUTF8toUTF16(aDomain));
+}
+
+void OriginAttributes::SetPartitionKey(const nsAString& aDomain) {
+  mPartitionKey = aDomain;
+}
+
 void OriginAttributes::CreateSuffix(nsACString& aStr) const {
   URLParams params;
   nsAutoString value;
 
   //
   // Important: While serializing any string-valued attributes, perform a
   // release-mode assertion to make sure that they don't contain characters that
   // will break the quota manager when it uses the serialization for file
--- a/caps/OriginAttributes.h
+++ b/caps/OriginAttributes.h
@@ -27,16 +27,20 @@ class OriginAttributes : public dom::Ori
 
   void SetFirstPartyDomain(const bool aIsTopLevelDocument, nsIURI* aURI,
                            bool aForced = false);
   void SetFirstPartyDomain(const bool aIsTopLevelDocument,
                            const nsACString& aDomain);
   void SetFirstPartyDomain(const bool aIsTopLevelDocument,
                            const nsAString& aDomain, bool aForced = false);
 
+  void SetPartitionKey(nsIURI* aURI);
+  void SetPartitionKey(const nsACString& aDomain);
+  void SetPartitionKey(const nsAString& aDomain);
+
   enum {
     STRIP_FIRST_PARTY_DOMAIN = 0x01,
     STRIP_USER_CONTEXT_ID = 0x02,
     STRIP_PRIVATE_BROWSING_ID = 0x04,
     STRIP_PARITION_KEY = 0x08,
   };
 
   inline void StripAttributes(uint32_t aFlags) {
--- a/toolkit/components/antitracking/StoragePrincipalHelper.cpp
+++ b/toolkit/components/antitracking/StoragePrincipalHelper.cpp
@@ -42,21 +42,21 @@ bool ChooseOriginAttributes(nsIChannel* 
     // jar.  We use the lower-level ContentBlocking API here to ensure this
     // check doesn't send notifications.
     if (!ShouldPartitionStorage(rejectedReason) ||
         !StoragePartitioningEnabled(rejectedReason, cjs)) {
       return false;
     }
   }
 
-  nsAutoString domain;
-  Unused << cjs->GetFirstPartyDomain(domain);
+  nsAutoString partitionKey;
+  Unused << cjs->GetFirstPartyDomain(partitionKey);
 
-  if (!domain.IsEmpty()) {
-    aAttrs.SetFirstPartyDomain(false, domain, true /* aForced */);
+  if (!partitionKey.IsEmpty()) {
+    aAttrs.SetPartitionKey(partitionKey);
     return true;
   }
 
   // Fallback to get first-party domain from top-level principal when we can't
   // get it from CookieJarSetting. This might happen when a channel is not
   // opened via http, for example, about page.
   nsCOMPtr<nsIPrincipal> toplevelPrincipal = loadInfo->GetTopLevelPrincipal();
   if (!toplevelPrincipal) {
@@ -66,17 +66,17 @@ bool ChooseOriginAttributes(nsIChannel* 
   auto* basePrin = BasePrincipal::Cast(toplevelPrincipal);
   nsCOMPtr<nsIURI> principalURI;
 
   nsresult rv = basePrin->GetURI(getter_AddRefs(principalURI));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return false;
   }
 
-  aAttrs.SetFirstPartyDomain(false, principalURI, true /* aForced */);
+  aAttrs.SetPartitionKey(principalURI);
   return true;
 }
 
 }  // namespace
 
 // static
 nsresult StoragePrincipalHelper::Create(nsIChannel* aChannel,
                                         nsIPrincipal* aPrincipal,