[go: nahoru, domu]

blob: 1d824985f66a7ca15e056e48b658f9b256641076 [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
Arthur Sonzogni4787fce2024-02-08 13:42:488#include <optional>
Chris Mumfordd8ed9f82018-05-01 15:43:139#include <set>
10#include <string>
11
Chris Mumfordd8ed9f82018-05-01 15:43:1312#include "base/time/time.h"
13#include "net/cookies/canonical_cookie.h"
Lily Chencdd5777122019-10-14 20:45:5414#include "net/cookies/cookie_constants.h"
Dylan Cutler108a41922022-01-05 18:16:2315#include "net/cookies/cookie_partition_key_collection.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 //
Alison Gale59c007a2024-04-20 03:05:4034 // TODO(crbug.com/40570811): Delete the start=end special case.
Chris Mumfordd8ed9f82018-05-01 15:43:1335 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|.
Arthur Sonzogni4787fce2024-02-08 13:42:48114 std::optional<std::string> host;
Chris Mumfordd8ed9f82018-05-01 15:43:13115
116 // If has a value then cookie.Name() must equal |name|.
Arthur Sonzogni4787fce2024-02-08 13:42:48117 std::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|.
Arthur Sonzogni4787fce2024-02-08 13:42:48121 std::optional<GURL> url;
Chris Mumfordd8ed9f82018-05-01 15:43:13122
Christian Dullwebereca439f2023-06-26 15:21:24123 // If has a value then any cookie with a domain/ip contained in this set
Chris Mumfordd8ed9f82018-05-01 15:43:13124 // 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.
Arthur Sonzogni4787fce2024-02-08 13:42:48131 std::optional<std::set<std::string>> domains_and_ips_to_delete;
Chris Mumfordd8ed9f82018-05-01 15:43:13132
Christian Dullwebereca439f2023-06-26 15:21:24133 // If has a value then any cookie with a domain/ip contained in this set
Chris Mumfordd8ed9f82018-05-01 15:43:13134 // 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.
Arthur Sonzogni4787fce2024-02-08 13:42:48139 std::optional<std::set<std::string>> domains_and_ips_to_ignore;
Chris Mumfordd8ed9f82018-05-01 15:43:13140
141 // Used only for testing purposes.
Arthur Sonzogni4787fce2024-02-08 13:42:48142 std::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_