1 // Copyright 2019 The Chromium Authors 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 8 #include <set> 9 10 #include "base/containers/flat_map.h" 11 #include "base/containers/flat_set.h" 12 #include "base/functional/callback_forward.h" 13 #include "net/base/net_export.h" 14 #include "net/base/schemeful_site.h" 15 #include "net/cookies/canonical_cookie.h" 16 #include "net/cookies/cookie_constants.h" 17 #include "net/cookies/cookie_partition_key.h" 18 #include "net/first_party_sets/first_party_set_entry.h" 19 #include "net/first_party_sets/first_party_set_metadata.h" 20 #include "net/first_party_sets/same_party_context.h" 21 #include "third_party/abseil-cpp/absl/types/optional.h" 22 #include "url/gurl.h" 23 24 namespace net { 25 26 class SchemefulSite; 27 class SiteForCookies; 28 29 class NET_EXPORT CookieAccessDelegate { 30 public: 31 CookieAccessDelegate(); 32 33 CookieAccessDelegate(const CookieAccessDelegate&) = delete; 34 CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete; 35 36 virtual ~CookieAccessDelegate(); 37 38 // 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 44 // 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 49 // 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, 53 const SiteForCookies& site_for_cookies) const = 0; 54 55 // Calls `callback` with metadata indicating whether `site` is same-party with 56 // `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`. 59 // 60 // 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( 66 const net::SchemefulSite& site, 67 const net::SchemefulSite* top_frame_site, 68 const std::set<net::SchemefulSite>& party_context, 69 base::OnceCallback<void(FirstPartySetMetadata)> callback) const = 0; 70 71 // 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. 74 // 75 // 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< 80 base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>> 81 FindFirstPartySetEntries( 82 const base::flat_set<net::SchemefulSite>& sites, 83 base::OnceCallback< 84 void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)> 85 callback) const = 0; 86 }; 87 88 } // namespace net 89 90 #endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_ 91