Bug 1640135 - P1: add new attribute for dFPI; r=timhuang
authorLiang-Heng Chen <xeonchen@gmail.com>
Thu, 04 Jun 2020 10:51:04 +0000
changeset 597953 42f2bdd06a959c9d01a659be6664e4ea79939b3b
parent 597952 e9ba31526222335ae6549998b6958f33a8fdb798
child 597954 9a58e5805c830f57aa7d57ad19337803197e0c23
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 - P1: add new attribute for dFPI; r=timhuang Differential Revision: https://phabricator.services.mozilla.com/D77914
caps/OriginAttributes.cpp
caps/OriginAttributes.h
dom/chrome-webidl/ChromeUtils.webidl
--- a/caps/OriginAttributes.cpp
+++ b/caps/OriginAttributes.cpp
@@ -199,16 +199,23 @@ void OriginAttributes::CreateSuffix(nsAC
     nsAutoString sanitizedGeckoViewUserContextId(mGeckoViewSessionContextId);
     sanitizedGeckoViewUserContextId.ReplaceChar(
         dom::quota::QuotaManager::kReplaceChars, kSanitizedChar);
 
     params.Set(NS_LITERAL_STRING("geckoViewUserContextId"),
                sanitizedGeckoViewUserContextId);
   }
 
+  if (!mPartitionKey.IsEmpty()) {
+    nsAutoString sanitizedPartitionKey(mPartitionKey);
+    sanitizedPartitionKey.ReplaceChar(kSourceChar, kSanitizedChar);
+
+    params.Set(NS_LITERAL_STRING("partitionKey"), sanitizedPartitionKey);
+  }
+
   aStr.Truncate();
 
   params.Serialize(value);
   if (!value.IsEmpty()) {
     aStr.AppendLiteral("^");
     aStr.Append(NS_ConvertUTF16toUTF8(value));
   }
 
@@ -224,16 +231,20 @@ void OriginAttributes::CreateSuffix(nsAC
 
 void OriginAttributes::CreateAnonymizedSuffix(nsACString& aStr) const {
   OriginAttributes attrs = *this;
 
   if (!attrs.mFirstPartyDomain.IsEmpty()) {
     attrs.mFirstPartyDomain.AssignLiteral("_anonymizedFirstPartyDomain_");
   }
 
+  if (!attrs.mPartitionKey.IsEmpty()) {
+    attrs.mPartitionKey.AssignLiteral("_anonymizedPartitionKey_");
+  }
+
   attrs.CreateSuffix(aStr);
 }
 
 namespace {
 
 class MOZ_STACK_CLASS PopulateFromSuffixIterator final
     : public URLParams::ForEachIterator {
  public:
@@ -294,16 +305,24 @@ class MOZ_STACK_CLASS PopulateFromSuffix
 
     if (aName.EqualsLiteral("geckoViewUserContextId")) {
       MOZ_RELEASE_ASSERT(
           mOriginAttributes->mGeckoViewSessionContextId.IsEmpty());
       mOriginAttributes->mGeckoViewSessionContextId.Assign(aValue);
       return true;
     }
 
+    if (aName.EqualsLiteral("partitionKey")) {
+      MOZ_RELEASE_ASSERT(mOriginAttributes->mPartitionKey.IsEmpty());
+      nsAutoString partitionKey(aValue);
+      partitionKey.ReplaceChar(kSanitizedChar, kSourceChar);
+      mOriginAttributes->mPartitionKey.Assign(partitionKey);
+      return true;
+    }
+
     // No other attributes are supported.
     return false;
   }
 
  private:
   OriginAttributes* mOriginAttributes;
 };
 
--- a/caps/OriginAttributes.h
+++ b/caps/OriginAttributes.h
@@ -31,39 +31,45 @@ class OriginAttributes : public dom::Ori
                            const nsACString& aDomain);
   void SetFirstPartyDomain(const bool aIsTopLevelDocument,
                            const nsAString& aDomain, bool aForced = false);
 
   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) {
     if (aFlags & STRIP_FIRST_PARTY_DOMAIN) {
       mFirstPartyDomain.Truncate();
     }
 
     if (aFlags & STRIP_USER_CONTEXT_ID) {
       mUserContextId = nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID;
     }
 
     if (aFlags & STRIP_PRIVATE_BROWSING_ID) {
       mPrivateBrowsingId =
           nsIScriptSecurityManager::DEFAULT_PRIVATE_BROWSING_ID;
     }
+
+    if (aFlags & STRIP_PARITION_KEY) {
+      mPartitionKey.Truncate();
+    }
   }
 
   bool operator==(const OriginAttributes& aOther) const {
     return mInIsolatedMozBrowser == aOther.mInIsolatedMozBrowser &&
            mUserContextId == aOther.mUserContextId &&
            mPrivateBrowsingId == aOther.mPrivateBrowsingId &&
            mFirstPartyDomain == aOther.mFirstPartyDomain &&
-           mGeckoViewSessionContextId == aOther.mGeckoViewSessionContextId;
+           mGeckoViewSessionContextId == aOther.mGeckoViewSessionContextId &&
+           mPartitionKey == aOther.mPartitionKey;
   }
 
   bool operator!=(const OriginAttributes& aOther) const {
     return !(*this == aOther);
   }
 
   MOZ_MUST_USE bool EqualsIgnoringFPD(const OriginAttributes& aOther) const {
     return mInIsolatedMozBrowser == aOther.mInIsolatedMozBrowser &&
@@ -162,16 +168,21 @@ class OriginAttributesPattern : public d
     }
 
     if (mGeckoViewSessionContextId.WasPassed() &&
         mGeckoViewSessionContextId.Value() !=
             aAttrs.mGeckoViewSessionContextId) {
       return false;
     }
 
+    if (mPartitionKey.WasPassed() &&
+        mPartitionKey.Value() != aAttrs.mPartitionKey) {
+      return false;
+    }
+
     return true;
   }
 
   bool Overlaps(const OriginAttributesPattern& aOther) const {
     if (mInIsolatedMozBrowser.WasPassed() &&
         aOther.mInIsolatedMozBrowser.WasPassed() &&
         mInIsolatedMozBrowser.Value() != aOther.mInIsolatedMozBrowser.Value()) {
       return false;
@@ -195,15 +206,20 @@ class OriginAttributesPattern : public d
 
     if (mGeckoViewSessionContextId.WasPassed() &&
         aOther.mGeckoViewSessionContextId.WasPassed() &&
         mGeckoViewSessionContextId.Value() !=
             aOther.mGeckoViewSessionContextId.Value()) {
       return false;
     }
 
+    if (mPartitionKey.WasPassed() && aOther.mPartitionKey.WasPassed() &&
+        mPartitionKey.Value() != aOther.mPartitionKey.Value()) {
+      return false;
+    }
+
     return true;
   }
 };
 
 }  // namespace mozilla
 
 #endif /* mozilla_OriginAttributes_h */
--- a/dom/chrome-webidl/ChromeUtils.webidl
+++ b/dom/chrome-webidl/ChromeUtils.webidl
@@ -625,25 +625,27 @@ dictionary IOActivityDataDictionary {
  */
 [GenerateInitFromJSON]
 dictionary OriginAttributesDictionary {
   unsigned long userContextId = 0;
   boolean inIsolatedMozBrowser = false;
   unsigned long privateBrowsingId = 0;
   DOMString firstPartyDomain = "";
   DOMString geckoViewSessionContextId = "";
+  DOMString partitionKey = "";
 };
 
 [GenerateInitFromJSON, GenerateToJSON]
 dictionary OriginAttributesPatternDictionary {
   unsigned long userContextId;
   boolean inIsolatedMozBrowser;
   unsigned long privateBrowsingId;
   DOMString firstPartyDomain;
   DOMString geckoViewSessionContextId;
+  DOMString partitionKey;
 };
 
 dictionary CompileScriptOptionsDictionary {
   /**
    * The character set from which to decode the script.
    */
   DOMString charset = "utf-8";