blob: 5136c46992ee73352f24e6566a668ff1054ff141 [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
cfredriccee97492021-01-29 18:48:4510#include "base/containers/flat_map.h"
Lily Chenab36a112019-09-19 20:17:2811#include "net/base/net_export.h"
12#include "net/cookies/canonical_cookie.h"
13#include "net/cookies/cookie_constants.h"
Dylan Cutler69a51c92021-12-08 16:32:0114#include "net/cookies/cookie_partition_key.h"
cfredricb7ae6d32022-01-05 22:08:3115#include "net/cookies/first_party_set_metadata.h"
cfredric362c4a02021-07-09 22:40:4016#include "net/cookies/same_party_context.h"
Lei Zhang698df03c2021-05-21 04:23:3417#include "third_party/abseil-cpp/absl/types/optional.h"
Lily Chen0db055b2019-11-15 20:29:0218#include "url/gurl.h"
Lily Chenab36a112019-09-19 20:17:2819
20namespace net {
21
cfredric716f3f802020-12-14 22:19:5022class SchemefulSite;
Maks Orlovich8be0e252019-12-09 18:35:4923class SiteForCookies;
24
Lily Chenab36a112019-09-19 20:17:2825class NET_EXPORT CookieAccessDelegate {
26 public:
27 CookieAccessDelegate();
Peter Boström293b1342021-09-22 17:31:4328
29 CookieAccessDelegate(const CookieAccessDelegate&) = delete;
30 CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete;
31
Lily Chenab36a112019-09-19 20:17:2832 virtual ~CookieAccessDelegate();
33
Maks Orlovichbd04d782020-11-17 21:23:3434 // Returns true if the passed in |url| should be permitted to access secure
35 // cookies in addition to URLs that normally do so. Returning false from this
36 // method on a URL that would already be treated as secure by default, e.g. an
37 // https:// one has no effect.
38 virtual bool ShouldTreatUrlAsTrustworthy(const GURL& url) const;
39
Lily Chenab36a112019-09-19 20:17:2840 // Gets the access semantics to apply to |cookie|, based on its domain (i.e.,
41 // whether a policy specifies that legacy access semantics should apply).
42 virtual CookieAccessSemantics GetAccessSemantics(
43 const CanonicalCookie& cookie) const = 0;
44
Lily Chen0db055b2019-11-15 20:29:0245 // Returns whether a cookie should be attached regardless of its SameSite
46 // value vs the request context.
47 virtual bool ShouldIgnoreSameSiteRestrictions(
48 const GURL& url,
Maks Orlovich8be0e252019-12-09 18:35:4949 const SiteForCookies& site_for_cookies) const = 0;
Lily Chen0db055b2019-11-15 20:29:0250
cfredricb7ae6d32022-01-05 22:08:3151 // Returns the metadata indicating whether `site` is same-party with
52 // `party_context` and `top_frame_site`; and `site`'s owner, if applicable..
53 // If `top_frame_site` is nullptr, then `site` will be checked only against
54 // `party_context`.
55 virtual FirstPartySetMetadata ComputeFirstPartySetMetadata(
cfredric716f3f802020-12-14 22:19:5056 const net::SchemefulSite& site,
cfredric362c4a02021-07-09 22:40:4057 const net::SchemefulSite* top_frame_site,
cfredric716f3f802020-12-14 22:19:5058 const std::set<net::SchemefulSite>& party_context) const = 0;
59
Dylan Cutler69a51c92021-12-08 16:32:0160 // Returns the owner of a `site`'s First-Party Set if `site` is in a
61 // non-trivial set. Returns nullopt otherwise.
62 virtual absl::optional<net::SchemefulSite> FindFirstPartySetOwner(
63 const net::SchemefulSite& site) const = 0;
64
65 // Creates a CookiePartitionKey that takes whether the top-frame site is in a
66 // First-Party Set into account. If FPS are not enabled, it returns a cookie
67 // partition key that does not take FPS into account.
68 //
69 // Should always return nullopt if partitioned cookies are disabled or if
70 // the NIK has no top-frame site.
71 static absl::optional<CookiePartitionKey> CreateCookiePartitionKey(
72 const CookieAccessDelegate* delegate,
73 const NetworkIsolationKey& network_isolation_key);
74
75 // Converts the CookiePartitionKey's site to its First-Party Set owner if
76 // the site is in a nontrivial set.
77 static absl::optional<CookiePartitionKey> FirstPartySetifyPartitionKey(
78 const CookieAccessDelegate* delegate,
79 const CookiePartitionKey& cookie_partition_key);
80
cfredriccee97492021-01-29 18:48:4581 // Returns the First-Party Sets.
82 virtual base::flat_map<net::SchemefulSite, std::set<net::SchemefulSite>>
83 RetrieveFirstPartySets() const = 0;
Lily Chenab36a112019-09-19 20:17:2884};
85
86} // namespace net
87
88#endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_