blob: 1de6b038ab2a407d030cb8c2f927f94ef7616a3d [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"
Chris Fredricksonc2efa96f2022-08-04 20:40:4418#include "net/cookies/first_party_set_entry.h"
cfredricb7ae6d32022-01-05 22:08:3119#include "net/cookies/first_party_set_metadata.h"
cfredric362c4a02021-07-09 22:40:4020#include "net/cookies/same_party_context.h"
Lei Zhang698df03c2021-05-21 04:23:3421#include "third_party/abseil-cpp/absl/types/optional.h"
Lily Chen0db055b2019-11-15 20:29:0222#include "url/gurl.h"
Lily Chenab36a112019-09-19 20:17:2823
24namespace net {
25
cfredric716f3f802020-12-14 22:19:5026class SchemefulSite;
Maks Orlovich8be0e252019-12-09 18:35:4927class SiteForCookies;
28
Lily Chenab36a112019-09-19 20:17:2829class NET_EXPORT CookieAccessDelegate {
30 public:
31 CookieAccessDelegate();
Peter Boström293b1342021-09-22 17:31:4332
33 CookieAccessDelegate(const CookieAccessDelegate&) = delete;
34 CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete;
35
Lily Chenab36a112019-09-19 20:17:2836 virtual ~CookieAccessDelegate();
37
Maks Orlovichbd04d782020-11-17 21:23:3438 // 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 Chenab36a112019-09-19 20:17:2844 // 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 Chen0db055b2019-11-15 20:29:0249 // 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 Orlovich8be0e252019-12-09 18:35:4953 const SiteForCookies& site_for_cookies) const = 0;
Lily Chen0db055b2019-11-15 20:29:0254
cfredric0b522852022-01-19 18:44:5355 // Calls `callback` with metadata indicating whether `site` is same-party with
cfredricb7ae6d32022-01-05 22:08:3156 // `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`.
cfredric0b522852022-01-19 18:44:5359 //
cfredricc24b2e12022-02-08 15:24:2560 // 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(
cfredric716f3f802020-12-14 22:19:5066 const net::SchemefulSite& site,
cfredric362c4a02021-07-09 22:40:4067 const net::SchemefulSite* top_frame_site,
cfredric0b522852022-01-19 18:44:5368 const std::set<net::SchemefulSite>& party_context,
69 base::OnceCallback<void(FirstPartySetMetadata)> callback) const = 0;
cfredric716f3f802020-12-14 22:19:5070
cfredric3a374b6b2022-01-22 00:41:4971 // Computes the owner of a `site`'s First-Party Set if `site` is in a
72 // non-trivial set; `nullopt` otherwise.
73 //
cfredricc24b2e12022-02-08 15:24:2574 // 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 Fredricksonc2efa96f2022-08-04 20:40:4478 [[nodiscard]] virtual absl::optional<absl::optional<net::FirstPartySetEntry>>
cfredricc24b2e12022-02-08 15:24:2579 FindFirstPartySetOwner(
cfredric3a374b6b2022-01-22 00:41:4980 const net::SchemefulSite& site,
Chris Fredricksonc2efa96f2022-08-04 20:40:4481 base::OnceCallback<void(absl::optional<net::FirstPartySetEntry>)>
82 callback) const = 0;
Dylan Cutler69a51c92021-12-08 16:32:0183
cfredric53da1f392022-01-24 18:50:0284 // 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 //
cfredricc24b2e12022-02-08 15:24:2588 // 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 Fredricksonc2efa96f2022-08-04 20:40:4493 base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>>
cfredricc24b2e12022-02-08 15:24:2594 FindFirstPartySetOwners(
cfredric53da1f392022-01-24 18:50:0295 const base::flat_set<net::SchemefulSite>& sites,
Chris Fredricksonc2efa96f2022-08-04 20:40:4496 base::OnceCallback<
97 void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)>
98 callback) const = 0;
cfredric53da1f392022-01-24 18:50:0299
Dylan Cutler69a51c92021-12-08 16:32:01100 // Converts the CookiePartitionKey's site to its First-Party Set owner if
101 // the site is in a nontrivial set.
cfredric1580f612022-01-13 19:53:30102 //
cfredricc24b2e12022-02-08 15:24:25103 // 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 Cutler69a51c92021-12-08 16:32:01109 const CookieAccessDelegate* delegate,
cfredric1580f612022-01-13 19:53:30110 const CookiePartitionKey& cookie_partition_key,
cfredricc24b2e12022-02-08 15:24:25111 base::OnceCallback<void(CookiePartitionKey)> callback);
Lily Chenab36a112019-09-19 20:17:28112};
113
114} // namespace net
115
116#endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_