• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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_COOKIES_COOKIE_ACCESS_DELEGATE_H_
6 #define NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_
7 
8 #include <optional>
9 
10 #include "base/containers/flat_map.h"
11 #include "base/containers/flat_set.h"
12 #include "base/functional/callback_forward.h"
13 #include "net/base/net_export.h"
14 #include "net/base/schemeful_site.h"
15 #include "net/cookies/canonical_cookie.h"
16 #include "net/cookies/cookie_constants.h"
17 #include "net/cookies/cookie_partition_key.h"
18 #include "net/first_party_sets/first_party_set_entry.h"
19 #include "net/first_party_sets/first_party_set_metadata.h"
20 #include "net/first_party_sets/first_party_sets_cache_filter.h"
21 #include "url/gurl.h"
22 
23 namespace net {
24 
25 class SchemefulSite;
26 class SiteForCookies;
27 
28 class NET_EXPORT CookieAccessDelegate {
29  public:
30   CookieAccessDelegate();
31 
32   CookieAccessDelegate(const CookieAccessDelegate&) = delete;
33   CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete;
34 
35   virtual ~CookieAccessDelegate();
36 
37   // Returns true if the passed in |url| should be permitted to access secure
38   // cookies in addition to URLs that normally do so. Returning false from this
39   // method on a URL that would already be treated as secure by default, e.g. an
40   // https:// one has no effect.
41   virtual bool ShouldTreatUrlAsTrustworthy(const GURL& url) const;
42 
43   // Gets the access semantics to apply to |cookie|, based on its domain (i.e.,
44   // whether a policy specifies that legacy access semantics should apply).
45   virtual CookieAccessSemantics GetAccessSemantics(
46       const CanonicalCookie& cookie) const = 0;
47 
48   // Gets the access to legacy cookie scope `cookie`, based on its domain (i.e.,
49   // whether a policy specifies this legacy cookie scope should apply).
50   virtual CookieLegacyScope GetAccessForLegacyCookieScope(
51       const CanonicalCookie& cookie) const = 0;
52 
53   // Returns whether a cookie should be attached regardless of its SameSite
54   // value vs the request context.
55   virtual bool ShouldIgnoreSameSiteRestrictions(
56       const GURL& url,
57       const SiteForCookies& site_for_cookies) const = 0;
58 
59   // Calls `callback` with First-Party Sets metadata about `site` and
60   // `top_frame_site`, and cache filter info for `site`. Cache filter info is
61   // used to determine if the existing HTTP cache entries for `site` are allowed
62   // to be accessed.
63   //
64   // This may return a result synchronously, or asynchronously invoke `callback`
65   // with the result. The callback will be invoked iff the return value is
66   // nullopt; i.e. a result will be provided via return value or callback, but
67   // not both, and not neither.
68   [[nodiscard]] virtual std::optional<
69       std::pair<FirstPartySetMetadata, FirstPartySetsCacheFilter::MatchInfo>>
70   ComputeFirstPartySetMetadataMaybeAsync(
71       const net::SchemefulSite& site,
72       const net::SchemefulSite* top_frame_site,
73       base::OnceCallback<void(FirstPartySetMetadata,
74                               FirstPartySetsCacheFilter::MatchInfo)> callback)
75       const = 0;
76 
77   // Returns the entries of a set of sites if the sites are in non-trivial sets.
78   // If a given site is not in a non-trivial set, the output does not contain a
79   // corresponding entry.
80   //
81   // This may return a result synchronously, or asynchronously invoke `callback`
82   // with the result. The callback will be invoked iff the return value is
83   // nullopt; i.e. a result will be provided via return value or callback, but
84   // not both, and not neither.
85   [[nodiscard]] virtual std::optional<
86       base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>>
87   FindFirstPartySetEntries(
88       const base::flat_set<net::SchemefulSite>& sites,
89       base::OnceCallback<
90           void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)>
91           callback) const = 0;
92 };
93 
94 }  // namespace net
95 
96 #endif  // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_
97