same_party_context.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_COOKIES_SAME_PARTY_CONTEXT_H_
  5. #define NET_COOKIES_SAME_PARTY_CONTEXT_H_
  6. #include <ostream>
  7. #include "net/base/net_export.h"
  8. namespace net {
  9. // This struct bundles together a few different notions of same-party-ness.
  10. // `context_type()` gives the notion of same-party-ness that Chromium should use
  11. // in all cases except metrics; other accessors are just for metrics purposes,
  12. // to explore the impact of different definitions of "same-party".
  13. class NET_EXPORT SamePartyContext {
  14. public:
  15. // Computed for every cookie access attempt but is only relevant for SameParty
  16. // cookies.
  17. enum class Type {
  18. // The opposite to kSameParty. Should be the default value.
  19. kCrossParty = 0,
  20. // If the request URL is in the same First-Party Sets as the top-frame site
  21. // and each member of the isolation_info.party_context.
  22. kSameParty = 1,
  23. };
  24. SamePartyContext() = default;
  25. explicit SamePartyContext(Type context_type);
  26. bool operator==(const SamePartyContext& other) const;
  27. // How trusted is the current browser environment when it comes to accessing
  28. // SameParty cookies. Default is not trusted, e.g. kCrossParty.
  29. Type context_type() const { return context_type_; }
  30. // Creates a SamePartyContext that is as permissive as possible.
  31. static SamePartyContext MakeInclusive();
  32. private:
  33. Type context_type_ = Type::kCrossParty;
  34. };
  35. NET_EXPORT std::ostream& operator<<(std::ostream& os,
  36. const SamePartyContext& spc);
  37. } // namespace net
  38. #endif // NET_COOKIES_SAME_PARTY_CONTEXT_H_