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 // These constructors do no validation or canonicalization of their inputs; | |
27 // the resulting CanonicalCookies should not be relied on to be canonical | |
28 // unless the caller has done appropriate validation and canonicalization | |
29 // themselves. | |
30 CanonicalCookie(); | 26 CanonicalCookie(); |
31 // TODO(mmenke): Remove |url|, as it's not used. | |
32 CanonicalCookie(const GURL& url, | |
33 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 | |
45 CanonicalCookie(const CanonicalCookie& other); | 27 CanonicalCookie(const CanonicalCookie& other); |
46 | 28 |
47 ~CanonicalCookie(); | 29 ~CanonicalCookie(); |
48 | 30 |
49 // Supports the default copy constructor. | 31 // Supports the default copy constructor. |
50 | 32 |
51 // Creates a new |CanonicalCookie| from the |cookie_line| and the | 33 // Creates a new |CanonicalCookie| from the |cookie_line| and the |
52 // |creation_time|. Canonicalizes and validates inputs. May return NULL if | 34 // |creation_time|. Canonicalizes and validates inputs. May return NULL if |
53 // an attribute value is invalid. | 35 // an attribute value is invalid. |
54 static std::unique_ptr<CanonicalCookie> Create( | 36 static std::unique_ptr<CanonicalCookie> Create( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // https://tools.ietf.org/html/draft-west-cookie-prefixes | 157 // https://tools.ietf.org/html/draft-west-cookie-prefixes |
176 // | 158 // |
177 // This enum is being histogrammed; do not reorder or remove values. | 159 // This enum is being histogrammed; do not reorder or remove values. |
178 enum CookiePrefix { | 160 enum CookiePrefix { |
179 COOKIE_PREFIX_NONE = 0, | 161 COOKIE_PREFIX_NONE = 0, |
180 COOKIE_PREFIX_SECURE, | 162 COOKIE_PREFIX_SECURE, |
181 COOKIE_PREFIX_HOST, | 163 COOKIE_PREFIX_HOST, |
182 COOKIE_PREFIX_LAST | 164 COOKIE_PREFIX_LAST |
183 }; | 165 }; |
184 | 166 |
| 167 // This constructor does not validate or canonicalize their inputs; |
| 168 // the resulting CanonicalCookies should not be relied on to be canonical |
| 169 // unless the caller has done appropriate validation and canonicalization |
| 170 // themselves. |
| 171 // TODO(mmenke): Remove |url|, as it's not used. |
| 172 CanonicalCookie(const GURL& url, |
| 173 const std::string& name, |
| 174 const std::string& value, |
| 175 const std::string& domain, |
| 176 const std::string& path, |
| 177 const base::Time& creation, |
| 178 const base::Time& expiration, |
| 179 const base::Time& last_access, |
| 180 bool secure, |
| 181 bool httponly, |
| 182 CookieSameSite same_site, |
| 183 CookiePriority priority); |
| 184 |
185 // Returns the CookiePrefix (or COOKIE_PREFIX_NONE if none) that | 185 // Returns the CookiePrefix (or COOKIE_PREFIX_NONE if none) that |
186 // applies to the given cookie |name|. | 186 // applies to the given cookie |name|. |
187 static CookiePrefix GetCookiePrefix(const std::string& name); | 187 static CookiePrefix GetCookiePrefix(const std::string& name); |
188 // Records histograms to measure how often cookie prefixes appear in | 188 // Records histograms to measure how often cookie prefixes appear in |
189 // the wild and how often they would be blocked. | 189 // the wild and how often they would be blocked. |
190 static void RecordCookiePrefixMetrics(CookiePrefix prefix, | 190 static void RecordCookiePrefixMetrics(CookiePrefix prefix, |
191 bool is_cookie_valid); | 191 bool is_cookie_valid); |
192 // Returns true if a prefixed cookie does not violate any of the rules | 192 // Returns true if a prefixed cookie does not violate any of the rules |
193 // for that cookie. | 193 // for that cookie. |
194 static bool IsCookiePrefixValid(CookiePrefix prefix, | 194 static bool IsCookiePrefixValid(CookiePrefix prefix, |
(...skipping 14 matching lines...) Expand all Loading... |
209 bool httponly_; | 209 bool httponly_; |
210 CookieSameSite same_site_; | 210 CookieSameSite same_site_; |
211 CookiePriority priority_; | 211 CookiePriority priority_; |
212 }; | 212 }; |
213 | 213 |
214 typedef std::vector<CanonicalCookie> CookieList; | 214 typedef std::vector<CanonicalCookie> CookieList; |
215 | 215 |
216 } // namespace net | 216 } // namespace net |
217 | 217 |
218 #endif // NET_COOKIES_CANONICAL_COOKIE_H_ | 218 #endif // NET_COOKIES_CANONICAL_COOKIE_H_ |
OLD | NEW |