1*6777b538SAndroid Build Coastguard Worker // Copyright 2018 The Chromium Authors 2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file. 4*6777b538SAndroid Build Coastguard Worker 5*6777b538SAndroid Build Coastguard Worker #ifndef NET_COOKIES_COOKIE_DELETION_INFO_H_ 6*6777b538SAndroid Build Coastguard Worker #define NET_COOKIES_COOKIE_DELETION_INFO_H_ 7*6777b538SAndroid Build Coastguard Worker 8*6777b538SAndroid Build Coastguard Worker #include <optional> 9*6777b538SAndroid Build Coastguard Worker #include <set> 10*6777b538SAndroid Build Coastguard Worker #include <string> 11*6777b538SAndroid Build Coastguard Worker 12*6777b538SAndroid Build Coastguard Worker #include "base/time/time.h" 13*6777b538SAndroid Build Coastguard Worker #include "net/cookies/canonical_cookie.h" 14*6777b538SAndroid Build Coastguard Worker #include "net/cookies/cookie_constants.h" 15*6777b538SAndroid Build Coastguard Worker #include "net/cookies/cookie_partition_key_collection.h" 16*6777b538SAndroid Build Coastguard Worker 17*6777b538SAndroid Build Coastguard Worker namespace net { 18*6777b538SAndroid Build Coastguard Worker 19*6777b538SAndroid Build Coastguard Worker // Used to specify which cookies to delete. All members are ANDed together. 20*6777b538SAndroid Build Coastguard Worker struct NET_EXPORT CookieDeletionInfo { 21*6777b538SAndroid Build Coastguard Worker // TODO(cmumford): Combine with 22*6777b538SAndroid Build Coastguard Worker // network::mojom::CookieDeletionSessionControl. 23*6777b538SAndroid Build Coastguard Worker enum SessionControl { 24*6777b538SAndroid Build Coastguard Worker IGNORE_CONTROL, 25*6777b538SAndroid Build Coastguard Worker SESSION_COOKIES, 26*6777b538SAndroid Build Coastguard Worker PERSISTENT_COOKIES, 27*6777b538SAndroid Build Coastguard Worker }; 28*6777b538SAndroid Build Coastguard Worker 29*6777b538SAndroid Build Coastguard Worker // Define a range of time from [start, end) where start is inclusive and end 30*6777b538SAndroid Build Coastguard Worker // is exclusive. There is a special case where |start| == |end| (matching a 31*6777b538SAndroid Build Coastguard Worker // single time) where |end| is inclusive. This special case is for iOS that 32*6777b538SAndroid Build Coastguard Worker // will be removed in the future. 33*6777b538SAndroid Build Coastguard Worker // 34*6777b538SAndroid Build Coastguard Worker // TODO(crbug.com/830689): Delete the start=end special case. 35*6777b538SAndroid Build Coastguard Worker class NET_EXPORT TimeRange { 36*6777b538SAndroid Build Coastguard Worker public: 37*6777b538SAndroid Build Coastguard Worker // Default constructor matches any non-null time. 38*6777b538SAndroid Build Coastguard Worker TimeRange(); 39*6777b538SAndroid Build Coastguard Worker TimeRange(const TimeRange& other); 40*6777b538SAndroid Build Coastguard Worker TimeRange(base::Time start, base::Time end); 41*6777b538SAndroid Build Coastguard Worker TimeRange& operator=(const TimeRange& rhs); 42*6777b538SAndroid Build Coastguard Worker 43*6777b538SAndroid Build Coastguard Worker // Is |time| within this time range? 44*6777b538SAndroid Build Coastguard Worker // 45*6777b538SAndroid Build Coastguard Worker // Will return true if: 46*6777b538SAndroid Build Coastguard Worker // 47*6777b538SAndroid Build Coastguard Worker // |start_| <= |time| < |end_| 48*6777b538SAndroid Build Coastguard Worker // 49*6777b538SAndroid Build Coastguard Worker // If |start_| is null then the range is unbounded on the lower range. 50*6777b538SAndroid Build Coastguard Worker // If |end_| is null then the range is unbounded on the upper range. 51*6777b538SAndroid Build Coastguard Worker // 52*6777b538SAndroid Build Coastguard Worker // Note 1: |time| cannot be null. 53*6777b538SAndroid Build Coastguard Worker // Note 2: If |start_| == |end_| then end_ is inclusive. 54*6777b538SAndroid Build Coastguard Worker // 55*6777b538SAndroid Build Coastguard Worker bool Contains(const base::Time& time) const; 56*6777b538SAndroid Build Coastguard Worker 57*6777b538SAndroid Build Coastguard Worker // Set the range start time. Set to null (i.e. Time()) to indicated an 58*6777b538SAndroid Build Coastguard Worker // unbounded lower range. 59*6777b538SAndroid Build Coastguard Worker void SetStart(base::Time value); 60*6777b538SAndroid Build Coastguard Worker 61*6777b538SAndroid Build Coastguard Worker // Set the range end time. Set to null (i.e. Time()) to indicated an 62*6777b538SAndroid Build Coastguard Worker // unbounded upper range. 63*6777b538SAndroid Build Coastguard Worker void SetEnd(base::Time value); 64*6777b538SAndroid Build Coastguard Worker 65*6777b538SAndroid Build Coastguard Worker // Return the start time. startCookieDeletionInfo66*6777b538SAndroid Build Coastguard Worker base::Time start() const { return start_; } 67*6777b538SAndroid Build Coastguard Worker 68*6777b538SAndroid Build Coastguard Worker // Return the end time. endCookieDeletionInfo69*6777b538SAndroid Build Coastguard Worker base::Time end() const { return end_; } 70*6777b538SAndroid Build Coastguard Worker 71*6777b538SAndroid Build Coastguard Worker private: 72*6777b538SAndroid Build Coastguard Worker // The inclusive start time of this range. 73*6777b538SAndroid Build Coastguard Worker base::Time start_; 74*6777b538SAndroid Build Coastguard Worker // The exclusive end time of this range. 75*6777b538SAndroid Build Coastguard Worker base::Time end_; 76*6777b538SAndroid Build Coastguard Worker }; 77*6777b538SAndroid Build Coastguard Worker 78*6777b538SAndroid Build Coastguard Worker CookieDeletionInfo(); 79*6777b538SAndroid Build Coastguard Worker CookieDeletionInfo(CookieDeletionInfo&& other); 80*6777b538SAndroid Build Coastguard Worker CookieDeletionInfo(const CookieDeletionInfo& other); 81*6777b538SAndroid Build Coastguard Worker CookieDeletionInfo(base::Time start_time, base::Time end_time); 82*6777b538SAndroid Build Coastguard Worker ~CookieDeletionInfo(); 83*6777b538SAndroid Build Coastguard Worker 84*6777b538SAndroid Build Coastguard Worker CookieDeletionInfo& operator=(CookieDeletionInfo&& rhs); 85*6777b538SAndroid Build Coastguard Worker CookieDeletionInfo& operator=(const CookieDeletionInfo& rhs); 86*6777b538SAndroid Build Coastguard Worker 87*6777b538SAndroid Build Coastguard Worker // Return true if |cookie| matches all members of this instance. All members 88*6777b538SAndroid Build Coastguard Worker // are ANDed together. For example: if the |cookie| creation date is within 89*6777b538SAndroid Build Coastguard Worker // |creation_range| AND the |cookie| name is equal to |name|, etc. then true 90*6777b538SAndroid Build Coastguard Worker // will be returned. If not false. 91*6777b538SAndroid Build Coastguard Worker // 92*6777b538SAndroid Build Coastguard Worker // |params.access_semantics| is the access semantics mode of the cookie at the 93*6777b538SAndroid Build Coastguard Worker // time of the attempted match. This is used to determine whether the cookie 94*6777b538SAndroid Build Coastguard Worker // matches a particular URL based on effective SameSite mode. (But the value 95*6777b538SAndroid Build Coastguard Worker // should not matter because the CookieOptions used for this check includes 96*6777b538SAndroid Build Coastguard Worker // all cookies for a URL regardless of SameSite). 97*6777b538SAndroid Build Coastguard Worker // 98*6777b538SAndroid Build Coastguard Worker // |params.delegate_treats_url_as_trustworthy| should be set to true if |url| 99*6777b538SAndroid Build Coastguard Worker // was granted access to secure cookies by the CookieAccessDelegate. 100*6777b538SAndroid Build Coastguard Worker // 101*6777b538SAndroid Build Coastguard Worker // All members are used. See comments above other members for specifics 102*6777b538SAndroid Build Coastguard Worker // about how checking is done for that value. 103*6777b538SAndroid Build Coastguard Worker bool Matches(const CanonicalCookie& cookie, 104*6777b538SAndroid Build Coastguard Worker const CookieAccessParams& params) const; 105*6777b538SAndroid Build Coastguard Worker 106*6777b538SAndroid Build Coastguard Worker // See comment above for TimeRange::Contains() for more info. 107*6777b538SAndroid Build Coastguard Worker TimeRange creation_range; 108*6777b538SAndroid Build Coastguard Worker 109*6777b538SAndroid Build Coastguard Worker // By default ignore session type and delete both session and persistent 110*6777b538SAndroid Build Coastguard Worker // cookies. 111*6777b538SAndroid Build Coastguard Worker SessionControl session_control = SessionControl::IGNORE_CONTROL; 112*6777b538SAndroid Build Coastguard Worker 113*6777b538SAndroid Build Coastguard Worker // If has a value then cookie.Host() must equal |host|. 114*6777b538SAndroid Build Coastguard Worker std::optional<std::string> host; 115*6777b538SAndroid Build Coastguard Worker 116*6777b538SAndroid Build Coastguard Worker // If has a value then cookie.Name() must equal |name|. 117*6777b538SAndroid Build Coastguard Worker std::optional<std::string> name; 118*6777b538SAndroid Build Coastguard Worker 119*6777b538SAndroid Build Coastguard Worker // If has a value then will match if the cookie being evaluated would be 120*6777b538SAndroid Build Coastguard Worker // included for a request of |url|. 121*6777b538SAndroid Build Coastguard Worker std::optional<GURL> url; 122*6777b538SAndroid Build Coastguard Worker 123*6777b538SAndroid Build Coastguard Worker // If has a value then any cookie with a domain/ip contained in this set 124*6777b538SAndroid Build Coastguard Worker // will be deleted (assuming other fields match). 125*6777b538SAndroid Build Coastguard Worker // Domains must not have a leading period. e.g "example.com" and not 126*6777b538SAndroid Build Coastguard Worker // ".example.com". 127*6777b538SAndroid Build Coastguard Worker // 128*6777b538SAndroid Build Coastguard Worker // Note: |domains_and_ips_to_ignore| takes precedence. For example if this 129*6777b538SAndroid Build Coastguard Worker // has a value of ["A", "B"] and |domains_and_ips_to_ignore| is ["B", "C"] 130*6777b538SAndroid Build Coastguard Worker // then only "A" will be deleted. 131*6777b538SAndroid Build Coastguard Worker std::optional<std::set<std::string>> domains_and_ips_to_delete; 132*6777b538SAndroid Build Coastguard Worker 133*6777b538SAndroid Build Coastguard Worker // If has a value then any cookie with a domain/ip contained in this set 134*6777b538SAndroid Build Coastguard Worker // will be ignored (and not deleted). 135*6777b538SAndroid Build Coastguard Worker // Domains must not have a leading period. e.g "example.com" and not 136*6777b538SAndroid Build Coastguard Worker // ".example.com". 137*6777b538SAndroid Build Coastguard Worker // 138*6777b538SAndroid Build Coastguard Worker // See precedence note above. 139*6777b538SAndroid Build Coastguard Worker std::optional<std::set<std::string>> domains_and_ips_to_ignore; 140*6777b538SAndroid Build Coastguard Worker 141*6777b538SAndroid Build Coastguard Worker // Used only for testing purposes. 142*6777b538SAndroid Build Coastguard Worker std::optional<std::string> value_for_testing; 143*6777b538SAndroid Build Coastguard Worker 144*6777b538SAndroid Build Coastguard Worker // Cookie partition collection. Partitioned cookies are not deleted if their 145*6777b538SAndroid Build Coastguard Worker // partition key is not in the collection. By default, it clears cookies in 146*6777b538SAndroid Build Coastguard Worker // all partitions. 147*6777b538SAndroid Build Coastguard Worker CookiePartitionKeyCollection cookie_partition_key_collection = 148*6777b538SAndroid Build Coastguard Worker CookiePartitionKeyCollection::ContainsAll(); 149*6777b538SAndroid Build Coastguard Worker 150*6777b538SAndroid Build Coastguard Worker // If true, third-party cookie blocking applies to the context that triggered 151*6777b538SAndroid Build Coastguard Worker // the deletion. In this case, we should only delete partitioned cookies. 152*6777b538SAndroid Build Coastguard Worker bool partitioned_state_only = false; 153*6777b538SAndroid Build Coastguard Worker }; 154*6777b538SAndroid Build Coastguard Worker 155*6777b538SAndroid Build Coastguard Worker } // namespace net 156*6777b538SAndroid Build Coastguard Worker 157*6777b538SAndroid Build Coastguard Worker #endif // NET_COOKIES_COOKIE_DELETION_INFO_H_ 158