blob: 6f01f056522cccdf841104118629c0223f01e909 [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"
Lily Chenab36a112019-09-19 20:17:2812#include "net/base/net_export.h"
cfredric326a0bc2022-01-12 18:51:3013#include "net/base/schemeful_site.h"
Lily Chenab36a112019-09-19 20:17:2814#include "net/cookies/canonical_cookie.h"
15#include "net/cookies/cookie_constants.h"
Dylan Cutler69a51c92021-12-08 16:32:0116#include "net/cookies/cookie_partition_key.h"
cfredricb7ae6d32022-01-05 22:08:3117#include "net/cookies/first_party_set_metadata.h"
cfredric362c4a02021-07-09 22:40:4018#include "net/cookies/same_party_context.h"
Lei Zhang698df03c2021-05-21 04:23:3419#include "third_party/abseil-cpp/absl/types/optional.h"
Lily Chen0db055b2019-11-15 20:29:0220#include "url/gurl.h"
Lily Chenab36a112019-09-19 20:17:2821
22namespace net {
23
cfredric716f3f802020-12-14 22:19:5024class SchemefulSite;
Maks Orlovich8be0e252019-12-09 18:35:4925class SiteForCookies;
26
Lily Chenab36a112019-09-19 20:17:2827class NET_EXPORT CookieAccessDelegate {
28 public:
29 CookieAccessDelegate();
Peter Boström293b1342021-09-22 17:31:4330
31 CookieAccessDelegate(const CookieAccessDelegate&) = delete;
32 CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete;
33
Lily Chenab36a112019-09-19 20:17:2834 virtual ~CookieAccessDelegate();
35
Maks Orlovichbd04d782020-11-17 21:23:3436 // Returns true if the passed in |url| should be permitted to access secure
37 // cookies in addition to URLs that normally do so. Returning false from this
38 // method on a URL that would already be treated as secure by default, e.g. an
39 // https:// one has no effect.
40 virtual bool ShouldTreatUrlAsTrustworthy(const GURL& url) const;
41
Lily Chenab36a112019-09-19 20:17:2842 // Gets the access semantics to apply to |cookie|, based on its domain (i.e.,
43 // whether a policy specifies that legacy access semantics should apply).
44 virtual CookieAccessSemantics GetAccessSemantics(
45 const CanonicalCookie& cookie) const = 0;
46
Lily Chen0db055b2019-11-15 20:29:0247 // Returns whether a cookie should be attached regardless of its SameSite
48 // value vs the request context.
49 virtual bool ShouldIgnoreSameSiteRestrictions(
50 const GURL& url,
Maks Orlovich8be0e252019-12-09 18:35:4951 const SiteForCookies& site_for_cookies) const = 0;
Lily Chen0db055b2019-11-15 20:29:0252
cfredric0b522852022-01-19 18:44:5353 // Calls `callback` with metadata indicating whether `site` is same-party with
cfredricb7ae6d32022-01-05 22:08:3154 // `party_context` and `top_frame_site`; and `site`'s owner, if applicable..
55 // If `top_frame_site` is nullptr, then `site` will be checked only against
56 // `party_context`.
cfredric0b522852022-01-19 18:44:5357 //
58 // `callback` may be invoked synchronously or asynchronously.
59 virtual void ComputeFirstPartySetMetadataMaybeAsync(
cfredric716f3f802020-12-14 22:19:5060 const net::SchemefulSite& site,
cfredric362c4a02021-07-09 22:40:4061 const net::SchemefulSite* top_frame_site,
cfredric0b522852022-01-19 18:44:5362 const std::set<net::SchemefulSite>& party_context,
63 base::OnceCallback<void(FirstPartySetMetadata)> callback) const = 0;
cfredric716f3f802020-12-14 22:19:5064
Dylan Cutler69a51c92021-12-08 16:32:0165 // Returns the owner of a `site`'s First-Party Set if `site` is in a
66 // non-trivial set. Returns nullopt otherwise.
67 virtual absl::optional<net::SchemefulSite> FindFirstPartySetOwner(
68 const net::SchemefulSite& site) const = 0;
69
70 // Creates a CookiePartitionKey that takes whether the top-frame site is in a
71 // First-Party Set into account. If FPS are not enabled, it returns a cookie
72 // partition key that does not take FPS into account.
73 //
74 // Should always return nullopt if partitioned cookies are disabled or if
75 // the NIK has no top-frame site.
76 static absl::optional<CookiePartitionKey> CreateCookiePartitionKey(
77 const CookieAccessDelegate* delegate,
78 const NetworkIsolationKey& network_isolation_key);
79
80 // Converts the CookiePartitionKey's site to its First-Party Set owner if
81 // the site is in a nontrivial set.
cfredric1580f612022-01-13 19:53:3082 //
83 // May invoke `callback` either synchronously or asynchronously.
84 static void FirstPartySetifyPartitionKey(
Dylan Cutler69a51c92021-12-08 16:32:0185 const CookieAccessDelegate* delegate,
cfredric1580f612022-01-13 19:53:3086 const CookiePartitionKey& cookie_partition_key,
87 base::OnceCallback<void(absl::optional<CookiePartitionKey>)> callback);
Dylan Cutler69a51c92021-12-08 16:32:0188
cfredric326a0bc2022-01-12 18:51:3089 // Computes the First-Party Sets.
90 //
91 // May invoke `callback` either synchronously or asynchronously.
92 virtual void RetrieveFirstPartySets(
93 base::OnceCallback<void(
94 base::flat_map<net::SchemefulSite, std::set<net::SchemefulSite>>)>
95 callback) const = 0;
Lily Chenab36a112019-09-19 20:17:2896};
97
98} // namespace net
99
100#endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_