OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_COOKIES_CANONICAL_COOKIE_H_ | 5 #ifndef NET_COOKIES_CANONICAL_COOKIE_H_ |
6 #define NET_COOKIES_CANONICAL_COOKIE_H_ | 6 #define NET_COOKIES_CANONICAL_COOKIE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const std::string& Value() const { return value_; } | 75 const std::string& Value() const { return value_; } |
76 const std::string& Domain() const { return domain_; } | 76 const std::string& Domain() const { return domain_; } |
77 const std::string& Path() const { return path_; } | 77 const std::string& Path() const { return path_; } |
78 const base::Time& CreationDate() const { return creation_date_; } | 78 const base::Time& CreationDate() const { return creation_date_; } |
79 const base::Time& LastAccessDate() const { return last_access_date_; } | 79 const base::Time& LastAccessDate() const { return last_access_date_; } |
80 bool IsPersistent() const { return !expiry_date_.is_null(); } | 80 bool IsPersistent() const { return !expiry_date_.is_null(); } |
81 const base::Time& ExpiryDate() const { return expiry_date_; } | 81 const base::Time& ExpiryDate() const { return expiry_date_; } |
82 bool IsSecure() const { return secure_; } | 82 bool IsSecure() const { return secure_; } |
83 bool IsHttpOnly() const { return httponly_; } | 83 bool IsHttpOnly() const { return httponly_; } |
84 CookiePriority Priority() const { return priority_; } | 84 CookiePriority Priority() const { return priority_; } |
85 bool IsDomainCookie() const { | 85 bool IsDomainCookie() const { return !domain_.empty() && domain_[0] == '.'; } |
86 return !domain_.empty() && domain_[0] == '.'; } | |
87 bool IsHostCookie() const { return !IsDomainCookie(); } | 86 bool IsHostCookie() const { return !IsDomainCookie(); } |
88 | 87 |
89 bool IsExpired(const base::Time& current) const { | 88 bool IsExpired(const base::Time& current) const { |
90 return !expiry_date_.is_null() && current >= expiry_date_; | 89 return !expiry_date_.is_null() && current >= expiry_date_; |
91 } | 90 } |
92 | 91 |
93 // Are the cookies considered equivalent in the eyes of RFC 2965. | 92 // Are the cookies considered equivalent in the eyes of RFC 2965. |
94 // The RFC says that name must match (case-sensitive), domain must | 93 // The RFC says that name must match (case-sensitive), domain must |
95 // match (case insensitive), and path must match (case sensitive). | 94 // match (case insensitive), and path must match (case sensitive). |
96 // For the case insensitive domain compare, we rely on the domain | 95 // For the case insensitive domain compare, we rely on the domain |
97 // having been canonicalized (in | 96 // having been canonicalized (in |
98 // GetCookieDomainWithString->CanonicalizeHost). | 97 // GetCookieDomainWithString->CanonicalizeHost). |
99 bool IsEquivalent(const CanonicalCookie& ecc) const { | 98 bool IsEquivalent(const CanonicalCookie& ecc) const { |
100 // It seems like it would make sense to take secure and httponly into | 99 // It seems like it would make sense to take secure and httponly into |
101 // account, but the RFC doesn't specify this. | 100 // account, but the RFC doesn't specify this. |
102 // NOTE: Keep this logic in-sync with TrimDuplicateCookiesForHost(). | 101 // NOTE: Keep this logic in-sync with TrimDuplicateCookiesForHost(). |
103 return (name_ == ecc.Name() && domain_ == ecc.Domain() | 102 return (name_ == ecc.Name() && domain_ == ecc.Domain() && |
104 && path_ == ecc.Path()); | 103 path_ == ecc.Path()); |
105 } | 104 } |
106 | 105 |
107 void SetLastAccessDate(const base::Time& date) { | 106 void SetLastAccessDate(const base::Time& date) { last_access_date_ = date; } |
108 last_access_date_ = date; | |
109 } | |
110 | 107 |
111 // Returns true if the given |url_path| path-matches the cookie-path as | 108 // Returns true if the given |url_path| path-matches the cookie-path as |
112 // described in section 5.1.4 in RFC 6265. | 109 // described in section 5.1.4 in RFC 6265. |
113 bool IsOnPath(const std::string& url_path) const; | 110 bool IsOnPath(const std::string& url_path) const; |
114 | 111 |
115 // Returns true if the cookie domain matches the given |host| as described in | 112 // Returns true if the cookie domain matches the given |host| as described in |
116 // section 5.1.3 of RFC 6265. | 113 // section 5.1.3 of RFC 6265. |
117 bool IsDomainMatch(const std::string& host) const; | 114 bool IsDomainMatch(const std::string& host) const; |
118 | 115 |
119 // Returns true if the cookie should be included for the given request |url|. | 116 // Returns true if the cookie should be included for the given request |url|. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 bool secure_; | 150 bool secure_; |
154 bool httponly_; | 151 bool httponly_; |
155 CookiePriority priority_; | 152 CookiePriority priority_; |
156 }; | 153 }; |
157 | 154 |
158 typedef std::vector<CanonicalCookie> CookieList; | 155 typedef std::vector<CanonicalCookie> CookieList; |
159 | 156 |
160 } // namespace net | 157 } // namespace net |
161 | 158 |
162 #endif // NET_COOKIES_CANONICAL_COOKIE_H_ | 159 #endif // NET_COOKIES_CANONICAL_COOKIE_H_ |
OLD | NEW |