blob: ee8e3d0fab27ef7f087194ad8fcfb6f17b042592 [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2019 The Chromium Authors
Lily Chenab36a112019-09-19 20:17:282// 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
cfredriccee97492021-01-29 18:48:4510#include "base/containers/flat_map.h"
cfredric53da1f392022-01-24 18:50:0211#include "base/containers/flat_set.h"
Avi Drissman41c4a412023-01-11 22:45:3712#include "base/functional/callback_forward.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 Fredrickson33273122022-08-31 22:41:0018#include "net/first_party_sets/first_party_set_entry.h"
Chris Fredrickson7f518812022-09-01 18:36:4819#include "net/first_party_sets/first_party_set_metadata.h"
Chris Fredricksone6f22812022-09-06 19:37:3920#include "net/first_party_sets/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
Chris Fredrickson3d8dbd382022-08-12 18:46:2171 // Returns the entries of a set of sites if the sites are in non-trivial sets.
72 // If a given site is not in a non-trivial set, the output does not contain a
73 // corresponding entry.
cfredric53da1f392022-01-24 18:50:0274 //
cfredricc24b2e12022-02-08 15:24:2575 // This may return a result synchronously, or asynchronously invoke `callback`
76 // with the result. The callback will be invoked iff the return value is
77 // nullopt; i.e. a result will be provided via return value or callback, but
78 // not both, and not neither.
79 [[nodiscard]] virtual absl::optional<
Chris Fredricksonc2efa96f2022-08-04 20:40:4480 base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>>
Sam LeDouxdde1ba292022-09-14 15:18:4881 FindFirstPartySetEntries(
cfredric53da1f392022-01-24 18:50:0282 const base::flat_set<net::SchemefulSite>& sites,
Chris Fredricksonc2efa96f2022-08-04 20:40:4483 base::OnceCallback<
84 void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)>
85 callback) const = 0;
Lily Chenab36a112019-09-19 20:17:2886};
87
88} // namespace net
89
90#endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_