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 <optional> 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/first_party_sets_cache_filter.h" 21 #include "url/gurl.h" 22 23 namespace net { 24 25 class SchemefulSite; 26 class SiteForCookies; 27 28 class NET_EXPORT CookieAccessDelegate { 29 public: 30 CookieAccessDelegate(); 31 32 CookieAccessDelegate(const CookieAccessDelegate&) = delete; 33 CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete; 34 35 virtual ~CookieAccessDelegate(); 36 37 // Returns true if the passed in |url| should be permitted to access secure 38 // cookies in addition to URLs that normally do so. Returning false from this 39 // method on a URL that would already be treated as secure by default, e.g. an 40 // https:// one has no effect. 41 virtual bool ShouldTreatUrlAsTrustworthy(const GURL& url) const; 42 43 // Gets the access semantics to apply to |cookie|, based on its domain (i.e., 44 // whether a policy specifies that legacy access semantics should apply). 45 virtual CookieAccessSemantics GetAccessSemantics( 46 const CanonicalCookie& cookie) const = 0; 47 48 // Returns whether a cookie should be attached regardless of its SameSite 49 // value vs the request context. 50 virtual bool ShouldIgnoreSameSiteRestrictions( 51 const GURL& url, 52 const SiteForCookies& site_for_cookies) const = 0; 53 54 // Calls `callback` with First-Party Sets metadata about `site` and 55 // `top_frame_site`, and cache filter info for `site`. Cache filter info is 56 // used to determine if the existing HTTP cache entries for `site` are allowed 57 // to be accessed. 58 // 59 // This may return a result synchronously, or asynchronously invoke `callback` 60 // with the result. The callback will be invoked iff the return value is 61 // nullopt; i.e. a result will be provided via return value or callback, but 62 // not both, and not neither. 63 [[nodiscard]] virtual std::optional< 64 std::pair<FirstPartySetMetadata, FirstPartySetsCacheFilter::MatchInfo>> 65 ComputeFirstPartySetMetadataMaybeAsync( 66 const net::SchemefulSite& site, 67 const net::SchemefulSite* top_frame_site, 68 base::OnceCallback<void(FirstPartySetMetadata, 69 FirstPartySetsCacheFilter::MatchInfo)> callback) 70 const = 0; 71 72 // Returns the entries of a set of sites if the sites are in non-trivial sets. 73 // If a given site is not in a non-trivial set, the output does not contain a 74 // corresponding entry. 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]] virtual std::optional< 81 base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>> 82 FindFirstPartySetEntries( 83 const base::flat_set<net::SchemefulSite>& sites, 84 base::OnceCallback< 85 void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)> 86 callback) const = 0; 87 }; 88 89 } // namespace net 90 91 #endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_ 92