cookie_access_delegate.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_
  5. #define NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_
  6. #include <set>
  7. #include "base/callback_forward.h"
  8. #include "base/containers/flat_map.h"
  9. #include "base/containers/flat_set.h"
  10. #include "net/base/net_export.h"
  11. #include "net/base/schemeful_site.h"
  12. #include "net/cookies/canonical_cookie.h"
  13. #include "net/cookies/cookie_constants.h"
  14. #include "net/cookies/cookie_partition_key.h"
  15. #include "net/cookies/first_party_set_entry.h"
  16. #include "net/cookies/first_party_set_metadata.h"
  17. #include "net/cookies/same_party_context.h"
  18. #include "third_party/abseil-cpp/absl/types/optional.h"
  19. #include "url/gurl.h"
  20. namespace net {
  21. class SchemefulSite;
  22. class SiteForCookies;
  23. class NET_EXPORT CookieAccessDelegate {
  24. public:
  25. CookieAccessDelegate();
  26. CookieAccessDelegate(const CookieAccessDelegate&) = delete;
  27. CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete;
  28. virtual ~CookieAccessDelegate();
  29. // Returns true if the passed in |url| should be permitted to access secure
  30. // cookies in addition to URLs that normally do so. Returning false from this
  31. // method on a URL that would already be treated as secure by default, e.g. an
  32. // https:// one has no effect.
  33. virtual bool ShouldTreatUrlAsTrustworthy(const GURL& url) const;
  34. // Gets the access semantics to apply to |cookie|, based on its domain (i.e.,
  35. // whether a policy specifies that legacy access semantics should apply).
  36. virtual CookieAccessSemantics GetAccessSemantics(
  37. const CanonicalCookie& cookie) const = 0;
  38. // Returns whether a cookie should be attached regardless of its SameSite
  39. // value vs the request context.
  40. virtual bool ShouldIgnoreSameSiteRestrictions(
  41. const GURL& url,
  42. const SiteForCookies& site_for_cookies) const = 0;
  43. // Calls `callback` with metadata indicating whether `site` is same-party with
  44. // `party_context` and `top_frame_site`; and `site`'s owner, if applicable..
  45. // If `top_frame_site` is nullptr, then `site` will be checked only against
  46. // `party_context`.
  47. //
  48. // This may return a result synchronously, or asynchronously invoke `callback`
  49. // with the result. The callback will be invoked iff the return value is
  50. // nullopt; i.e. a result will be provided via return value or callback, but
  51. // not both, and not neither.
  52. [[nodiscard]] virtual absl::optional<FirstPartySetMetadata>
  53. ComputeFirstPartySetMetadataMaybeAsync(
  54. const net::SchemefulSite& site,
  55. const net::SchemefulSite* top_frame_site,
  56. const std::set<net::SchemefulSite>& party_context,
  57. base::OnceCallback<void(FirstPartySetMetadata)> callback) const = 0;
  58. // Returns the entries of a set of sites if the sites are in non-trivial sets.
  59. // If a given site is not in a non-trivial set, the output does not contain a
  60. // corresponding entry.
  61. //
  62. // This may return a result synchronously, or asynchronously invoke `callback`
  63. // with the result. The callback will be invoked iff the return value is
  64. // nullopt; i.e. a result will be provided via return value or callback, but
  65. // not both, and not neither.
  66. [[nodiscard]] virtual absl::optional<
  67. base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>>
  68. FindFirstPartySetOwners(
  69. const base::flat_set<net::SchemefulSite>& sites,
  70. base::OnceCallback<
  71. void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)>
  72. callback) const = 0;
  73. // Converts the CookiePartitionKey's site to its First-Party Set owner if
  74. // the site is in a nontrivial set.
  75. //
  76. // This may return a result synchronously, or asynchronously invoke `callback`
  77. // with the result. The callback will be invoked iff the return value is
  78. // nullopt; i.e. a result will be provided via return value or callback, but
  79. // not both, and not neither.
  80. [[nodiscard]] static absl::optional<CookiePartitionKey>
  81. FirstPartySetifyPartitionKey(
  82. const CookieAccessDelegate* delegate,
  83. const CookiePartitionKey& cookie_partition_key,
  84. base::OnceCallback<void(CookiePartitionKey)> callback);
  85. };
  86. } // namespace net
  87. #endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_