blob: 71878fad70be656805537d7e57225f32a2696e58 [file] [log] [blame]
Lily Chenab36a112019-09-19 20:17:281// Copyright 2019 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
5#ifndef NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_
6#define NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_
7
Peter Vargaec193052021-12-01 10:25:058#include <set>
9
cfredric326a0bc2022-01-12 18:51:3010#include "base/callback_forward.h"
cfredriccee97492021-01-29 18:48:4511#include "base/containers/flat_map.h"
cfredric53da1f392022-01-24 18:50:0212#include "base/containers/flat_set.h"
Lily Chenab36a112019-09-19 20:17:2813#include "net/base/net_export.h"
cfredric326a0bc2022-01-12 18:51:3014#include "net/base/schemeful_site.h"
Lily Chenab36a112019-09-19 20:17:2815#include "net/cookies/canonical_cookie.h"
16#include "net/cookies/cookie_constants.h"
Dylan Cutler69a51c92021-12-08 16:32:0117#include "net/cookies/cookie_partition_key.h"
cfredricb7ae6d32022-01-05 22:08:3118#include "net/cookies/first_party_set_metadata.h"
cfredric362c4a02021-07-09 22:40:4019#include "net/cookies/same_party_context.h"
Lei Zhang698df03c2021-05-21 04:23:3420#include "third_party/abseil-cpp/absl/types/optional.h"
Lily Chen0db055b2019-11-15 20:29:0221#include "url/gurl.h"
Lily Chenab36a112019-09-19 20:17:2822
23namespace net {
24
cfredric716f3f802020-12-14 22:19:5025class SchemefulSite;
Maks Orlovich8be0e252019-12-09 18:35:4926class SiteForCookies;
27
Lily Chenab36a112019-09-19 20:17:2828class NET_EXPORT CookieAccessDelegate {
29 public:
30 CookieAccessDelegate();
Peter Boström293b1342021-09-22 17:31:4331
32 CookieAccessDelegate(const CookieAccessDelegate&) = delete;
33 CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete;
34
Lily Chenab36a112019-09-19 20:17:2835 virtual ~CookieAccessDelegate();
36
Maks Orlovichbd04d782020-11-17 21:23:3437 // 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
Lily Chenab36a112019-09-19 20:17:2843 // 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
Lily Chen0db055b2019-11-15 20:29:0248 // Returns whether a cookie should be attached regardless of its SameSite
49 // value vs the request context.
50 virtual bool ShouldIgnoreSameSiteRestrictions(
51 const GURL& url,
Maks Orlovich8be0e252019-12-09 18:35:4952 const SiteForCookies& site_for_cookies) const = 0;
Lily Chen0db055b2019-11-15 20:29:0253
cfredric0b522852022-01-19 18:44:5354 // Calls `callback` with metadata indicating whether `site` is same-party with
cfredricb7ae6d32022-01-05 22:08:3155 // `party_context` and `top_frame_site`; and `site`'s owner, if applicable..
56 // If `top_frame_site` is nullptr, then `site` will be checked only against
57 // `party_context`.
cfredric0b522852022-01-19 18:44:5358 //
cfredricc24b2e12022-02-08 15:24:2559 // This may return a result synchronously, or asynchronously invoke `callback`
60 // with the result. The callback will be invoked iff the return value is
61 // nullopt; i.e. a result will be provided via return value or callback, but
62 // not both, and not neither.
63 [[nodiscard]] virtual absl::optional<FirstPartySetMetadata>
64 ComputeFirstPartySetMetadataMaybeAsync(
cfredric716f3f802020-12-14 22:19:5065 const net::SchemefulSite& site,
cfredric362c4a02021-07-09 22:40:4066 const net::SchemefulSite* top_frame_site,
cfredric0b522852022-01-19 18:44:5367 const std::set<net::SchemefulSite>& party_context,
68 base::OnceCallback<void(FirstPartySetMetadata)> callback) const = 0;
cfredric716f3f802020-12-14 22:19:5069
cfredric3a374b6b2022-01-22 00:41:4970 // Computes the owner of a `site`'s First-Party Set if `site` is in a
71 // non-trivial set; `nullopt` otherwise.
72 //
cfredricc24b2e12022-02-08 15:24:2573 // This may return a result synchronously, or asynchronously invoke `callback`
74 // with the result. The callback will be invoked iff the return value is
75 // nullopt; i.e. a result will be provided via return value or callback, but
76 // not both, and not neither.
77 [[nodiscard]] virtual absl::optional<absl::optional<net::SchemefulSite>>
78 FindFirstPartySetOwner(
cfredric3a374b6b2022-01-22 00:41:4979 const net::SchemefulSite& site,
80 base::OnceCallback<void(absl::optional<net::SchemefulSite>)> callback)
81 const = 0;
Dylan Cutler69a51c92021-12-08 16:32:0182
cfredric53da1f392022-01-24 18:50:0283 // Computes the owners of a set of sites' First-Party Sets if the site are in
84 // non-trivial sets. If a given site is not in a non-trivial set, the output
85 // does not contain a corresponding owner.
86 //
cfredricc24b2e12022-02-08 15:24:2587 // This may return a result synchronously, or asynchronously invoke `callback`
88 // with the result. The callback will be invoked iff the return value is
89 // nullopt; i.e. a result will be provided via return value or callback, but
90 // not both, and not neither.
91 [[nodiscard]] virtual absl::optional<
92 base::flat_map<net::SchemefulSite, net::SchemefulSite>>
93 FindFirstPartySetOwners(
cfredric53da1f392022-01-24 18:50:0294 const base::flat_set<net::SchemefulSite>& sites,
95 base::OnceCallback<void(
96 base::flat_map<net::SchemefulSite, net::SchemefulSite>)> callback)
97 const = 0;
98
Dylan Cutler69a51c92021-12-08 16:32:0199 // Converts the CookiePartitionKey's site to its First-Party Set owner if
100 // the site is in a nontrivial set.
cfredric1580f612022-01-13 19:53:30101 //
cfredricc24b2e12022-02-08 15:24:25102 // This may return a result synchronously, or asynchronously invoke `callback`
103 // with the result. The callback will be invoked iff the return value is
104 // nullopt; i.e. a result will be provided via return value or callback, but
105 // not both, and not neither.
106 [[nodiscard]] static absl::optional<CookiePartitionKey>
107 FirstPartySetifyPartitionKey(
Dylan Cutler69a51c92021-12-08 16:32:01108 const CookieAccessDelegate* delegate,
cfredric1580f612022-01-13 19:53:30109 const CookiePartitionKey& cookie_partition_key,
cfredricc24b2e12022-02-08 15:24:25110 base::OnceCallback<void(CookiePartitionKey)> callback);
Dylan Cutler69a51c92021-12-08 16:32:01111
cfredric326a0bc2022-01-12 18:51:30112 // Computes the First-Party Sets.
113 //
cfredricc24b2e12022-02-08 15:24:25114 // This may return a result synchronously, or asynchronously invoke `callback`
115 // with the result. The callback will be invoked iff the return value is
116 // nullopt; i.e. a result will be provided via return value or callback, but
117 // not both, and not neither.
118 [[nodiscard]] virtual absl::optional<
119 base::flat_map<net::SchemefulSite, std::set<net::SchemefulSite>>>
120 RetrieveFirstPartySets(
cfredric326a0bc2022-01-12 18:51:30121 base::OnceCallback<void(
122 base::flat_map<net::SchemefulSite, std::set<net::SchemefulSite>>)>
123 callback) const = 0;
Lily Chenab36a112019-09-19 20:17:28124};
125
126} // namespace net
127
128#endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_