1 // Copyright 2022 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_FIRST_PARTY_SETS_FIRST_PARTY_SET_METADATA_H_ 6 #define NET_FIRST_PARTY_SETS_FIRST_PARTY_SET_METADATA_H_ 7 8 #include "net/base/net_export.h" 9 #include "net/first_party_sets/first_party_set_entry.h" 10 #include "net/first_party_sets/same_party_context.h" 11 #include "third_party/abseil-cpp/absl/types/optional.h" 12 13 namespace net { 14 15 // This class bundles together metadata about the First-Party Set associated 16 // with a given context. 17 class NET_EXPORT FirstPartySetMetadata { 18 public: 19 FirstPartySetMetadata(); 20 21 // `frame_entry` and `top_frame_entry` must live for the duration of the ctor; 22 // nullptr indicates that there's no First-Party Set that's associated with 23 // the current frame or the top frame, respectively, in the given context. 24 FirstPartySetMetadata(const SamePartyContext& context, 25 const FirstPartySetEntry* frame_entry, 26 const FirstPartySetEntry* top_frame_entry); 27 28 FirstPartySetMetadata(FirstPartySetMetadata&&); 29 FirstPartySetMetadata& operator=(FirstPartySetMetadata&&); 30 31 ~FirstPartySetMetadata(); 32 33 bool operator==(const FirstPartySetMetadata& other) const; 34 bool operator!=(const FirstPartySetMetadata& other) const; 35 context()36 const SamePartyContext& context() const { return context_; } 37 38 // Returns a optional<T>& instead of a T* so that operator== can be defined 39 // more easily. frame_entry()40 const absl::optional<FirstPartySetEntry>& frame_entry() const { 41 return frame_entry_; 42 } top_frame_entry()43 const absl::optional<FirstPartySetEntry>& top_frame_entry() const { 44 return top_frame_entry_; 45 } 46 47 // Returns true if `frame_entry` and `top_frame_entry` are both non-null and 48 // have the same primary. This is different from `context_.context_type()` 49 // because it only checks if the the frames' sites are in the same set 50 // regardless of their ancestor chain. 51 bool AreSitesInSameFirstPartySet() const; 52 53 private: 54 SamePartyContext context_ = SamePartyContext(); 55 absl::optional<FirstPartySetEntry> frame_entry_ = absl::nullopt; 56 absl::optional<FirstPartySetEntry> top_frame_entry_ = absl::nullopt; 57 }; 58 59 NET_EXPORT std::ostream& operator<<(std::ostream& os, 60 const FirstPartySetMetadata& fpsm); 61 62 } // namespace net 63 64 #endif // NET_FIRST_PARTY_SETS_FIRST_PARTY_SET_METADATA_H_ 65