Lily Chen | ab36a11 | 2019-09-19 20:17:28 | [diff] [blame] | 1 | // 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 Varga | ec19305 | 2021-12-01 10:25:05 | [diff] [blame] | 8 | #include <set> |
| 9 | |
cfredric | 326a0bc | 2022-01-12 18:51:30 | [diff] [blame] | 10 | #include "base/callback_forward.h" |
cfredric | cee9749 | 2021-01-29 18:48:45 | [diff] [blame] | 11 | #include "base/containers/flat_map.h" |
cfredric | 53da1f39 | 2022-01-24 18:50:02 | [diff] [blame] | 12 | #include "base/containers/flat_set.h" |
Lily Chen | ab36a11 | 2019-09-19 20:17:28 | [diff] [blame] | 13 | #include "net/base/net_export.h" |
cfredric | 326a0bc | 2022-01-12 18:51:30 | [diff] [blame] | 14 | #include "net/base/schemeful_site.h" |
Lily Chen | ab36a11 | 2019-09-19 20:17:28 | [diff] [blame] | 15 | #include "net/cookies/canonical_cookie.h" |
| 16 | #include "net/cookies/cookie_constants.h" |
Dylan Cutler | 69a51c9 | 2021-12-08 16:32:01 | [diff] [blame] | 17 | #include "net/cookies/cookie_partition_key.h" |
Chris Fredrickson | c2efa96f | 2022-08-04 20:40:44 | [diff] [blame^] | 18 | #include "net/cookies/first_party_set_entry.h" |
cfredric | b7ae6d3 | 2022-01-05 22:08:31 | [diff] [blame] | 19 | #include "net/cookies/first_party_set_metadata.h" |
cfredric | 362c4a0 | 2021-07-09 22:40:40 | [diff] [blame] | 20 | #include "net/cookies/same_party_context.h" |
Lei Zhang | 698df03c | 2021-05-21 04:23:34 | [diff] [blame] | 21 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 22 | #include "url/gurl.h" |
Lily Chen | ab36a11 | 2019-09-19 20:17:28 | [diff] [blame] | 23 | |
| 24 | namespace net { |
| 25 | |
cfredric | 716f3f80 | 2020-12-14 22:19:50 | [diff] [blame] | 26 | class SchemefulSite; |
Maks Orlovich | 8be0e25 | 2019-12-09 18:35:49 | [diff] [blame] | 27 | class SiteForCookies; |
| 28 | |
Lily Chen | ab36a11 | 2019-09-19 20:17:28 | [diff] [blame] | 29 | class NET_EXPORT CookieAccessDelegate { |
| 30 | public: |
| 31 | CookieAccessDelegate(); |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 32 | |
| 33 | CookieAccessDelegate(const CookieAccessDelegate&) = delete; |
| 34 | CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete; |
| 35 | |
Lily Chen | ab36a11 | 2019-09-19 20:17:28 | [diff] [blame] | 36 | virtual ~CookieAccessDelegate(); |
| 37 | |
Maks Orlovich | bd04d78 | 2020-11-17 21:23:34 | [diff] [blame] | 38 | // Returns true if the passed in |url| should be permitted to access secure |
| 39 | // cookies in addition to URLs that normally do so. Returning false from this |
| 40 | // method on a URL that would already be treated as secure by default, e.g. an |
| 41 | // https:// one has no effect. |
| 42 | virtual bool ShouldTreatUrlAsTrustworthy(const GURL& url) const; |
| 43 | |
Lily Chen | ab36a11 | 2019-09-19 20:17:28 | [diff] [blame] | 44 | // Gets the access semantics to apply to |cookie|, based on its domain (i.e., |
| 45 | // whether a policy specifies that legacy access semantics should apply). |
| 46 | virtual CookieAccessSemantics GetAccessSemantics( |
| 47 | const CanonicalCookie& cookie) const = 0; |
| 48 | |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 49 | // Returns whether a cookie should be attached regardless of its SameSite |
| 50 | // value vs the request context. |
| 51 | virtual bool ShouldIgnoreSameSiteRestrictions( |
| 52 | const GURL& url, |
Maks Orlovich | 8be0e25 | 2019-12-09 18:35:49 | [diff] [blame] | 53 | const SiteForCookies& site_for_cookies) const = 0; |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 54 | |
cfredric | 0b52285 | 2022-01-19 18:44:53 | [diff] [blame] | 55 | // Calls `callback` with metadata indicating whether `site` is same-party with |
cfredric | b7ae6d3 | 2022-01-05 22:08:31 | [diff] [blame] | 56 | // `party_context` and `top_frame_site`; and `site`'s owner, if applicable.. |
| 57 | // If `top_frame_site` is nullptr, then `site` will be checked only against |
| 58 | // `party_context`. |
cfredric | 0b52285 | 2022-01-19 18:44:53 | [diff] [blame] | 59 | // |
cfredric | c24b2e1 | 2022-02-08 15:24:25 | [diff] [blame] | 60 | // This may return a result synchronously, or asynchronously invoke `callback` |
| 61 | // with the result. The callback will be invoked iff the return value is |
| 62 | // nullopt; i.e. a result will be provided via return value or callback, but |
| 63 | // not both, and not neither. |
| 64 | [[nodiscard]] virtual absl::optional<FirstPartySetMetadata> |
| 65 | ComputeFirstPartySetMetadataMaybeAsync( |
cfredric | 716f3f80 | 2020-12-14 22:19:50 | [diff] [blame] | 66 | const net::SchemefulSite& site, |
cfredric | 362c4a0 | 2021-07-09 22:40:40 | [diff] [blame] | 67 | const net::SchemefulSite* top_frame_site, |
cfredric | 0b52285 | 2022-01-19 18:44:53 | [diff] [blame] | 68 | const std::set<net::SchemefulSite>& party_context, |
| 69 | base::OnceCallback<void(FirstPartySetMetadata)> callback) const = 0; |
cfredric | 716f3f80 | 2020-12-14 22:19:50 | [diff] [blame] | 70 | |
cfredric | 3a374b6b | 2022-01-22 00:41:49 | [diff] [blame] | 71 | // Computes the owner of a `site`'s First-Party Set if `site` is in a |
| 72 | // non-trivial set; `nullopt` otherwise. |
| 73 | // |
cfredric | c24b2e1 | 2022-02-08 15:24:25 | [diff] [blame] | 74 | // This may return a result synchronously, or asynchronously invoke `callback` |
| 75 | // with the result. The callback will be invoked iff the return value is |
| 76 | // nullopt; i.e. a result will be provided via return value or callback, but |
| 77 | // not both, and not neither. |
Chris Fredrickson | c2efa96f | 2022-08-04 20:40:44 | [diff] [blame^] | 78 | [[nodiscard]] virtual absl::optional<absl::optional<net::FirstPartySetEntry>> |
cfredric | c24b2e1 | 2022-02-08 15:24:25 | [diff] [blame] | 79 | FindFirstPartySetOwner( |
cfredric | 3a374b6b | 2022-01-22 00:41:49 | [diff] [blame] | 80 | const net::SchemefulSite& site, |
Chris Fredrickson | c2efa96f | 2022-08-04 20:40:44 | [diff] [blame^] | 81 | base::OnceCallback<void(absl::optional<net::FirstPartySetEntry>)> |
| 82 | callback) const = 0; |
Dylan Cutler | 69a51c9 | 2021-12-08 16:32:01 | [diff] [blame] | 83 | |
cfredric | 53da1f39 | 2022-01-24 18:50:02 | [diff] [blame] | 84 | // Computes the owners of a set of sites' First-Party Sets if the site are in |
| 85 | // non-trivial sets. If a given site is not in a non-trivial set, the output |
| 86 | // does not contain a corresponding owner. |
| 87 | // |
cfredric | c24b2e1 | 2022-02-08 15:24:25 | [diff] [blame] | 88 | // This may return a result synchronously, or asynchronously invoke `callback` |
| 89 | // with the result. The callback will be invoked iff the return value is |
| 90 | // nullopt; i.e. a result will be provided via return value or callback, but |
| 91 | // not both, and not neither. |
| 92 | [[nodiscard]] virtual absl::optional< |
Chris Fredrickson | c2efa96f | 2022-08-04 20:40:44 | [diff] [blame^] | 93 | base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>> |
cfredric | c24b2e1 | 2022-02-08 15:24:25 | [diff] [blame] | 94 | FindFirstPartySetOwners( |
cfredric | 53da1f39 | 2022-01-24 18:50:02 | [diff] [blame] | 95 | const base::flat_set<net::SchemefulSite>& sites, |
Chris Fredrickson | c2efa96f | 2022-08-04 20:40:44 | [diff] [blame^] | 96 | base::OnceCallback< |
| 97 | void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)> |
| 98 | callback) const = 0; |
cfredric | 53da1f39 | 2022-01-24 18:50:02 | [diff] [blame] | 99 | |
Dylan Cutler | 69a51c9 | 2021-12-08 16:32:01 | [diff] [blame] | 100 | // Converts the CookiePartitionKey's site to its First-Party Set owner if |
| 101 | // the site is in a nontrivial set. |
cfredric | 1580f61 | 2022-01-13 19:53:30 | [diff] [blame] | 102 | // |
cfredric | c24b2e1 | 2022-02-08 15:24:25 | [diff] [blame] | 103 | // This may return a result synchronously, or asynchronously invoke `callback` |
| 104 | // with the result. The callback will be invoked iff the return value is |
| 105 | // nullopt; i.e. a result will be provided via return value or callback, but |
| 106 | // not both, and not neither. |
| 107 | [[nodiscard]] static absl::optional<CookiePartitionKey> |
| 108 | FirstPartySetifyPartitionKey( |
Dylan Cutler | 69a51c9 | 2021-12-08 16:32:01 | [diff] [blame] | 109 | const CookieAccessDelegate* delegate, |
cfredric | 1580f61 | 2022-01-13 19:53:30 | [diff] [blame] | 110 | const CookiePartitionKey& cookie_partition_key, |
cfredric | c24b2e1 | 2022-02-08 15:24:25 | [diff] [blame] | 111 | base::OnceCallback<void(CookiePartitionKey)> callback); |
Lily Chen | ab36a11 | 2019-09-19 20:17:28 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace net |
| 115 | |
| 116 | #endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_ |