blob: 1899a4d1b6b43940573a4d4b68fbdbfa756b1a49 [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"
cfredric362c4a02021-07-09 22:40:4014#include "net/cookies/same_party_context.h"
Lei Zhang698df03c2021-05-21 04:23:3415#include "third_party/abseil-cpp/absl/types/optional.h"
Lily Chen0db055b2019-11-15 20:29:0216#include "url/gurl.h"
Lily Chenab36a112019-09-19 20:17:2817
18namespace net {
19
cfredric716f3f802020-12-14 22:19:5020class SchemefulSite;
Maks Orlovich8be0e252019-12-09 18:35:4921class SiteForCookies;
22
Lily Chenab36a112019-09-19 20:17:2823class NET_EXPORT CookieAccessDelegate {
24 public:
25 CookieAccessDelegate();
Peter Boström293b1342021-09-22 17:31:4326
27 CookieAccessDelegate(const CookieAccessDelegate&) = delete;
28 CookieAccessDelegate& operator=(const CookieAccessDelegate&) = delete;
29
Lily Chenab36a112019-09-19 20:17:2830 virtual ~CookieAccessDelegate();
31
Maks Orlovichbd04d782020-11-17 21:23:3432 // Returns true if the passed in |url| should be permitted to access secure
33 // cookies in addition to URLs that normally do so. Returning false from this
34 // method on a URL that would already be treated as secure by default, e.g. an
35 // https:// one has no effect.
36 virtual bool ShouldTreatUrlAsTrustworthy(const GURL& url) const;
37
Lily Chenab36a112019-09-19 20:17:2838 // Gets the access semantics to apply to |cookie|, based on its domain (i.e.,
39 // whether a policy specifies that legacy access semantics should apply).
40 virtual CookieAccessSemantics GetAccessSemantics(
41 const CanonicalCookie& cookie) const = 0;
42
Lily Chen0db055b2019-11-15 20:29:0243 // Returns whether a cookie should be attached regardless of its SameSite
44 // value vs the request context.
45 virtual bool ShouldIgnoreSameSiteRestrictions(
46 const GURL& url,
Maks Orlovich8be0e252019-12-09 18:35:4947 const SiteForCookies& site_for_cookies) const = 0;
Lily Chen0db055b2019-11-15 20:29:0248
cfredric362c4a02021-07-09 22:40:4049 // Returns the SamePartyContext indicating whether `site` is same-party
50 // with `party_context` and `top_frame_site`. If `top_frame_site` is nullptr,
51 // then `site` will be checked only against `party_context`.
52 virtual SamePartyContext ComputeSamePartyContext(
cfredric716f3f802020-12-14 22:19:5053 const net::SchemefulSite& site,
cfredric362c4a02021-07-09 22:40:4054 const net::SchemefulSite* top_frame_site,
cfredric716f3f802020-12-14 22:19:5055 const std::set<net::SchemefulSite>& party_context) const = 0;
56
57 // Returns whether `site` belongs to a non-singleton First-Party Set.
58 virtual bool IsInNontrivialFirstPartySet(
59 const net::SchemefulSite& site) const = 0;
60
cfredric176f9e232021-05-12 20:20:1461 virtual FirstPartySetsContextType ComputeFirstPartySetsContextType(
62 const SchemefulSite& site,
Anton Bikineev068d2912021-05-15 20:43:5263 const absl::optional<SchemefulSite>& top_frame_site,
cfredric176f9e232021-05-12 20:20:1464 const std::set<SchemefulSite>& party_context) const = 0;
65
cfredriccee97492021-01-29 18:48:4566 // Returns the First-Party Sets.
67 virtual base::flat_map<net::SchemefulSite, std::set<net::SchemefulSite>>
68 RetrieveFirstPartySets() const = 0;
Lily Chenab36a112019-09-19 20:17:2869};
70
71} // namespace net
72
73#endif // NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_