[go: nahoru, domu]

blob: 835aa8b7cabddbc1fe6c4435d35f44b777870b23 [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2018 The Chromium Authors
Chris Mumfordd8ed9f82018-05-01 15:43:132// 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_DELETION_INFO_H_
6#define NET_COOKIES_COOKIE_DELETION_INFO_H_
7
8#include <set>
9#include <string>
10
Chris Mumfordd8ed9f82018-05-01 15:43:1311#include "base/time/time.h"
12#include "net/cookies/canonical_cookie.h"
Lily Chencdd5777122019-10-14 20:45:5413#include "net/cookies/cookie_constants.h"
Dylan Cutler108a41922022-01-05 18:16:2314#include "net/cookies/cookie_partition_key_collection.h"
Anton Bikineev068d2912021-05-15 20:43:5215#include "third_party/abseil-cpp/absl/types/optional.h"
Chris Mumfordd8ed9f82018-05-01 15:43:1316
17namespace net {
18
19// Used to specify which cookies to delete. All members are ANDed together.
20struct NET_EXPORT CookieDeletionInfo {
21 // TODO(cmumford): Combine with
22 // network::mojom::CookieDeletionSessionControl.
23 enum SessionControl {
24 IGNORE_CONTROL,
25 SESSION_COOKIES,
26 PERSISTENT_COOKIES,
27 };
28
29 // Define a range of time from [start, end) where start is inclusive and end
30 // is exclusive. There is a special case where |start| == |end| (matching a
31 // single time) where |end| is inclusive. This special case is for iOS that
32 // will be removed in the future.
33 //
34 // TODO(crbug.com/830689): Delete the start=end special case.
35 class NET_EXPORT TimeRange {
36 public:
37 // Default constructor matches any non-null time.
38 TimeRange();
39 TimeRange(const TimeRange& other);
40 TimeRange(base::Time start, base::Time end);
41 TimeRange& operator=(const TimeRange& rhs);
42
43 // Is |time| within this time range?
44 //
45 // Will return true if:
46 //
47 // |start_| <= |time| < |end_|
48 //
49 // If |start_| is null then the range is unbounded on the lower range.
50 // If |end_| is null then the range is unbounded on the upper range.
51 //
52 // Note 1: |time| cannot be null.
53 // Note 2: If |start_| == |end_| then end_ is inclusive.
54 //
55 bool Contains(const base::Time& time) const;
56
57 // Set the range start time. Set to null (i.e. Time()) to indicated an
58 // unbounded lower range.
59 void SetStart(base::Time value);
60
61 // Set the range end time. Set to null (i.e. Time()) to indicated an
62 // unbounded upper range.
63 void SetEnd(base::Time value);
64
65 // Return the start time.
66 base::Time start() const { return start_; }
67
68 // Return the end time.
69 base::Time end() const { return end_; }
70
71 private:
72 // The inclusive start time of this range.
73 base::Time start_;
74 // The exclusive end time of this range.
75 base::Time end_;
76 };
77
78 CookieDeletionInfo();
79 CookieDeletionInfo(CookieDeletionInfo&& other);
80 CookieDeletionInfo(const CookieDeletionInfo& other);
81 CookieDeletionInfo(base::Time start_time, base::Time end_time);
82 ~CookieDeletionInfo();
83
84 CookieDeletionInfo& operator=(CookieDeletionInfo&& rhs);
85 CookieDeletionInfo& operator=(const CookieDeletionInfo& rhs);
86
87 // Return true if |cookie| matches all members of this instance. All members
88 // are ANDed together. For example: if the |cookie| creation date is within
89 // |creation_range| AND the |cookie| name is equal to |name|, etc. then true
90 // will be returned. If not false.
91 //
cfredric571a1082020-11-18 18:07:3792 // |params.access_semantics| is the access semantics mode of the cookie at the
93 // time of the attempted match. This is used to determine whether the cookie
Lily Chencdd5777122019-10-14 20:45:5494 // matches a particular URL based on effective SameSite mode. (But the value
95 // should not matter because the CookieOptions used for this check includes
96 // all cookies for a URL regardless of SameSite).
97 //
cfredric571a1082020-11-18 18:07:3798 // |params.delegate_treats_url_as_trustworthy| should be set to true if |url|
99 // was granted access to secure cookies by the CookieAccessDelegate.
Maks Orlovichbd04d782020-11-17 21:23:34100 //
Chris Mumfordd8ed9f82018-05-01 15:43:13101 // All members are used. See comments above other members for specifics
102 // about how checking is done for that value.
Lily Chencdd5777122019-10-14 20:45:54103 bool Matches(const CanonicalCookie& cookie,
cfredric571a1082020-11-18 18:07:37104 const CookieAccessParams& params) const;
Chris Mumfordd8ed9f82018-05-01 15:43:13105
106 // See comment above for TimeRange::Contains() for more info.
107 TimeRange creation_range;
108
109 // By default ignore session type and delete both session and persistent
110 // cookies.
111 SessionControl session_control = SessionControl::IGNORE_CONTROL;
112
113 // If has a value then cookie.Host() must equal |host|.
Anton Bikineev068d2912021-05-15 20:43:52114 absl::optional<std::string> host;
Chris Mumfordd8ed9f82018-05-01 15:43:13115
116 // If has a value then cookie.Name() must equal |name|.
Anton Bikineev068d2912021-05-15 20:43:52117 absl::optional<std::string> name;
Chris Mumfordd8ed9f82018-05-01 15:43:13118
119 // If has a value then will match if the cookie being evaluated would be
120 // included for a request of |url|.
Anton Bikineev068d2912021-05-15 20:43:52121 absl::optional<GURL> url;
Chris Mumfordd8ed9f82018-05-01 15:43:13122
Chris Mumfordd8ed9f82018-05-01 15:43:13123 // If this is not empty then any cookie with a domain/ip contained in this
124 // will be deleted (assuming other fields match).
125 // Domains must not have a leading period. e.g "example.com" and not
126 // ".example.com".
127 //
128 // Note: |domains_and_ips_to_ignore| takes precedence. For example if this
129 // has a value of ["A", "B"] and |domains_and_ips_to_ignore| is ["B", "C"]
130 // then only "A" will be deleted.
131 std::set<std::string> domains_and_ips_to_delete;
132
133 // If this is not empty then any cookie with a domain/ip contained in this
134 // will be ignored (and not deleted).
135 // Domains must not have a leading period. e.g "example.com" and not
136 // ".example.com".
137 //
138 // See precedence note above.
139 std::set<std::string> domains_and_ips_to_ignore;
140
141 // Used only for testing purposes.
Anton Bikineev068d2912021-05-15 20:43:52142 absl::optional<std::string> value_for_testing;
Dylan Cutler108a41922022-01-05 18:16:23143
Dylan Cutler70af8802022-05-24 17:14:38144 // Cookie partition collection. Partitioned cookies are not deleted if their
145 // partition key is not in the collection. By default, it clears cookies in
146 // all partitions.
Dylan Cutler108a41922022-01-05 18:16:23147 CookiePartitionKeyCollection cookie_partition_key_collection =
148 CookiePartitionKeyCollection::ContainsAll();
Dylan Cutler72ac55092023-03-20 20:54:05149
150 // If true, third-party cookie blocking applies to the context that triggered
151 // the deletion. In this case, we should only delete partitioned cookies.
152 bool partitioned_state_only = false;
Chris Mumfordd8ed9f82018-05-01 15:43:13153};
154
155} // namespace net
156
157#endif // NET_COOKIES_COOKIE_DELETION_INFO_H_