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 <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
15 #include "net/cookies/cookie_constants.h" | 15 #include "net/cookies/cookie_constants.h" |
16 #include "net/cookies/cookie_options.h" | 16 #include "net/cookies/cookie_options.h" |
17 | 17 |
18 class GURL; | 18 class GURL; |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 class ParsedCookie; | 22 class ParsedCookie; |
23 | 23 |
24 class NET_EXPORT CanonicalCookie { | 24 class NET_EXPORT CanonicalCookie { |
25 public: | 25 public: |
26 CanonicalCookie(); | 26 CanonicalCookie(); |
27 CanonicalCookie(const CanonicalCookie& other); | 27 CanonicalCookie(const CanonicalCookie& other); |
28 | 28 |
| 29 // This constructor does not validate or canonicalize their inputs; |
| 30 // the resulting CanonicalCookies should not be relied on to be canonical |
| 31 // unless the caller has done appropriate validation and canonicalization |
| 32 // themselves. |
| 33 CanonicalCookie(const std::string& name, |
| 34 const std::string& value, |
| 35 const std::string& domain, |
| 36 const std::string& path, |
| 37 const base::Time& creation, |
| 38 const base::Time& expiration, |
| 39 const base::Time& last_access, |
| 40 bool secure, |
| 41 bool httponly, |
| 42 CookieSameSite same_site, |
| 43 CookiePriority priority); |
| 44 |
29 ~CanonicalCookie(); | 45 ~CanonicalCookie(); |
30 | 46 |
31 // Supports the default copy constructor. | 47 // Supports the default copy constructor. |
32 | 48 |
33 // Creates a new |CanonicalCookie| from the |cookie_line| and the | 49 // Creates a new |CanonicalCookie| from the |cookie_line| and the |
34 // |creation_time|. Canonicalizes and validates inputs. May return NULL if | 50 // |creation_time|. Canonicalizes and validates inputs. May return NULL if |
35 // an attribute value is invalid. | 51 // an attribute value is invalid. |
36 static std::unique_ptr<CanonicalCookie> Create( | 52 static std::unique_ptr<CanonicalCookie> Create( |
37 const GURL& url, | 53 const GURL& url, |
38 const std::string& cookie_line, | 54 const std::string& cookie_line, |
39 const base::Time& creation_time, | 55 const base::Time& creation_time, |
40 const CookieOptions& options); | 56 const CookieOptions& options); |
41 | 57 |
42 // Creates a canonical cookie from unparsed attribute values. | |
43 // It does not do any canonicalization. | |
44 // |name| and |path| must not be empty. | |
45 static std::unique_ptr<CanonicalCookie> Create(const std::string& name, | |
46 const std::string& value, | |
47 const std::string& domain, | |
48 const std::string& path, | |
49 const base::Time& creation, | |
50 const base::Time& expiration, | |
51 const base::Time& last_access, | |
52 bool secure, | |
53 bool http_only, | |
54 CookieSameSite same_site, | |
55 CookiePriority priority); | |
56 | |
57 const std::string& Name() const { return name_; } | 58 const std::string& Name() const { return name_; } |
58 const std::string& Value() const { return value_; } | 59 const std::string& Value() const { return value_; } |
59 const std::string& Domain() const { return domain_; } | 60 const std::string& Domain() const { return domain_; } |
60 const std::string& Path() const { return path_; } | 61 const std::string& Path() const { return path_; } |
61 const base::Time& CreationDate() const { return creation_date_; } | 62 const base::Time& CreationDate() const { return creation_date_; } |
62 const base::Time& LastAccessDate() const { return last_access_date_; } | 63 const base::Time& LastAccessDate() const { return last_access_date_; } |
63 bool IsPersistent() const { return !expiry_date_.is_null(); } | 64 bool IsPersistent() const { return !expiry_date_.is_null(); } |
64 const base::Time& ExpiryDate() const { return expiry_date_; } | 65 const base::Time& ExpiryDate() const { return expiry_date_; } |
65 bool IsSecure() const { return secure_; } | 66 bool IsSecure() const { return secure_; } |
66 bool IsHttpOnly() const { return httponly_; } | 67 bool IsHttpOnly() const { return httponly_; } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // https://tools.ietf.org/html/draft-west-cookie-prefixes | 151 // https://tools.ietf.org/html/draft-west-cookie-prefixes |
151 // | 152 // |
152 // This enum is being histogrammed; do not reorder or remove values. | 153 // This enum is being histogrammed; do not reorder or remove values. |
153 enum CookiePrefix { | 154 enum CookiePrefix { |
154 COOKIE_PREFIX_NONE = 0, | 155 COOKIE_PREFIX_NONE = 0, |
155 COOKIE_PREFIX_SECURE, | 156 COOKIE_PREFIX_SECURE, |
156 COOKIE_PREFIX_HOST, | 157 COOKIE_PREFIX_HOST, |
157 COOKIE_PREFIX_LAST | 158 COOKIE_PREFIX_LAST |
158 }; | 159 }; |
159 | 160 |
160 // This constructor does not validate or canonicalize their inputs; | |
161 // the resulting CanonicalCookies should not be relied on to be canonical | |
162 // unless the caller has done appropriate validation and canonicalization | |
163 // themselves. | |
164 CanonicalCookie(const std::string& name, | |
165 const std::string& value, | |
166 const std::string& domain, | |
167 const std::string& path, | |
168 const base::Time& creation, | |
169 const base::Time& expiration, | |
170 const base::Time& last_access, | |
171 bool secure, | |
172 bool httponly, | |
173 CookieSameSite same_site, | |
174 CookiePriority priority); | |
175 | |
176 // Returns the CookiePrefix (or COOKIE_PREFIX_NONE if none) that | 161 // Returns the CookiePrefix (or COOKIE_PREFIX_NONE if none) that |
177 // applies to the given cookie |name|. | 162 // applies to the given cookie |name|. |
178 static CookiePrefix GetCookiePrefix(const std::string& name); | 163 static CookiePrefix GetCookiePrefix(const std::string& name); |
179 // Records histograms to measure how often cookie prefixes appear in | 164 // Records histograms to measure how often cookie prefixes appear in |
180 // the wild and how often they would be blocked. | 165 // the wild and how often they would be blocked. |
181 static void RecordCookiePrefixMetrics(CookiePrefix prefix, | 166 static void RecordCookiePrefixMetrics(CookiePrefix prefix, |
182 bool is_cookie_valid); | 167 bool is_cookie_valid); |
183 // Returns true if a prefixed cookie does not violate any of the rules | 168 // Returns true if a prefixed cookie does not violate any of the rules |
184 // for that cookie. | 169 // for that cookie. |
185 static bool IsCookiePrefixValid(CookiePrefix prefix, | 170 static bool IsCookiePrefixValid(CookiePrefix prefix, |
(...skipping 14 matching lines...) Expand all Loading... |
200 bool httponly_; | 185 bool httponly_; |
201 CookieSameSite same_site_; | 186 CookieSameSite same_site_; |
202 CookiePriority priority_; | 187 CookiePriority priority_; |
203 }; | 188 }; |
204 | 189 |
205 typedef std::vector<CanonicalCookie> CookieList; | 190 typedef std::vector<CanonicalCookie> CookieList; |
206 | 191 |
207 } // namespace net | 192 } // namespace net |
208 | 193 |
209 #endif // NET_COOKIES_CANONICAL_COOKIE_H_ | 194 #endif // NET_COOKIES_CANONICAL_COOKIE_H_ |
OLD | NEW |