1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_
#define NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_
#include <optional>
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/functional/callback_forward.h"
#include "net/base/net_export.h"
#include "net/base/schemeful_site.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_partition_key.h"
#include "net/first_party_sets/first_party_set_entry.h"
#include "net/first_party_sets/first_party_set_metadata.h"
#include "net/first_party_sets/first_party_sets_cache_filter.h"
#include "url/gurl.h"
namespace net {
class SchemefulSite;
class SiteForCookies;
class NET_EXPORT CookieAccessDelegate {
public:
CookieAccessDelegate();
CookieAccessDelegate(const CookieAccessDelegate&) = delete;
CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete;
virtual ~CookieAccessDelegate();
// Returns true if the passed in |url| should be permitted to access secure
// cookies in addition to URLs that normally do so. Returning false from this
// method on a URL that would already be treated as secure by default, e.g. an
// https:// one has no effect.
virtual bool ShouldTreatUrlAsTrustworthy(const GURL& url) const;
// Gets the access semantics to apply to |cookie|, based on its domain (i.e.,
// whether a policy specifies that legacy access semantics should apply).
virtual CookieAccessSemantics GetAccessSemantics(
const CanonicalCookie& cookie) const = 0;
// Gets the scope semantics to apply to based on the given domain (i.e.,
// whether a policy specifies this legacy cookie scope should apply).
virtual CookieScopeSemantics GetScopeSemantics(
const std::string_view domain) const = 0;
// Returns whether a cookie should be attached regardless of its SameSite
// value vs the request context.
virtual bool ShouldIgnoreSameSiteRestrictions(
const GURL& url,
const SiteForCookies& site_for_cookies) const = 0;
// Calls `callback` with First-Party Sets metadata about `site` and
// `top_frame_site`, and cache filter info for `site`. Cache filter info is
// used to determine if the existing HTTP cache entries for `site` are allowed
// to be accessed.
//
// This may return a result synchronously, or asynchronously invoke `callback`
// with the result. The callback will be invoked iff the return value is
// nullopt; i.e. a result will be provided via return value or callback, but
// not both, and not neither.
[[nodiscard]] virtual std::optional<
std::pair<FirstPartySetMetadata, FirstPartySetsCacheFilter::MatchInfo>>
ComputeFirstPartySetMetadataMaybeAsync(
const net::SchemefulSite& site,
const net::SchemefulSite* top_frame_site,
base::OnceCallback<void(FirstPartySetMetadata,
FirstPartySetsCacheFilter::MatchInfo)> callback)
const = 0;
// Returns the entries of a set of sites if the sites are in non-trivial sets.
// If a given site is not in a non-trivial set, the output does not contain a
// corresponding entry.
//
// This may return a result synchronously, or asynchronously invoke `callback`
// with the result. The callback will be invoked iff the return value is
// nullopt; i.e. a result will be provided via return value or callback, but
// not both, and not neither.
[[nodiscard]] virtual std::optional<
base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>>
FindFirstPartySetEntries(
const base::flat_set<net::SchemefulSite>& sites,
base::OnceCallback<
void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)>
callback) const = 0;
};
} // namespace net
#endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_
|