• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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_SAME_PARTY_CONTEXT_H_
6 #define NET_FIRST_PARTY_SETS_SAME_PARTY_CONTEXT_H_
7 
8 #include <ostream>
9 
10 #include "net/base/net_export.h"
11 
12 namespace net {
13 
14 // This struct bundles together a few different notions of same-party-ness.
15 // `context_type()` gives the notion of same-party-ness that Chromium should use
16 // in all cases except metrics; other accessors are just for metrics purposes,
17 // to explore the impact of different definitions of "same-party".
18 class NET_EXPORT SamePartyContext {
19  public:
20   // Computed for every cookie access attempt but is only relevant for SameParty
21   // cookies.
22   enum class Type {
23     // The opposite to kSameParty. Should be the default value.
24     kCrossParty = 0,
25     // If the request URL is in the same First-Party Sets as the top-frame site
26     // and each member of the isolation_info.party_context.
27     kSameParty = 1,
28   };
29 
30   SamePartyContext() = default;
31   explicit SamePartyContext(Type context_type);
32 
33   bool operator==(const SamePartyContext& other) const;
34 
35   // How trusted is the current browser environment when it comes to accessing
36   // SameParty cookies. Default is not trusted, e.g. kCrossParty.
context_type()37   Type context_type() const { return context_type_; }
38 
39   // Creates a SamePartyContext that is as permissive as possible.
40   static SamePartyContext MakeInclusive();
41 
42  private:
43   Type context_type_ = Type::kCrossParty;
44 };
45 
46 NET_EXPORT std::ostream& operator<<(std::ostream& os,
47                                     const SamePartyContext& spc);
48 
49 }  // namespace net
50 
51 #endif  // NET_FIRST_PARTY_SETS_SAME_PARTY_CONTEXT_H_
52