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 // Brought to you by number 42. | 5 // Brought to you by number 42. |
6 | 6 |
7 #ifndef NET_COOKIES_COOKIE_OPTIONS_H_ | 7 #ifndef NET_COOKIES_COOKIE_OPTIONS_H_ |
8 #define NET_COOKIES_COOKIE_OPTIONS_H_ | 8 #define NET_COOKIES_COOKIE_OPTIONS_H_ |
9 | 9 |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 #include "url/origin.h" | |
14 | 13 |
15 namespace net { | 14 namespace net { |
16 | 15 |
17 class NET_EXPORT CookieOptions { | 16 class NET_EXPORT CookieOptions { |
18 public: | 17 public: |
19 // Default is to exclude httponly completely, and exclude first-party from | 18 // Creates a CookieOptions object which: |
20 // being read, which means: | |
21 // - reading operations will not return httponly or first-party cookies. | |
22 // - writing operations will not write httponly cookies (first-party will be | |
23 // written). | |
24 // | 19 // |
25 // If a first-party URL is set, then first-party cookies which match that URL | 20 // * Excludes HttpOnly cookies |
26 // will be returned. | 21 // * Excludes First-Party-Only cookies |
| 22 // * Does not enforce prefix restrictions (e.g. "$Secure-*") |
| 23 // |
| 24 // These settings can be altered by calling: |
| 25 // |
| 26 // * |set_{include,exclude}_httponly()| |
| 27 // * |set_include_first_party_only_cookies()| |
| 28 // * |set_enforce_prefixes()| |
27 CookieOptions(); | 29 CookieOptions(); |
28 | 30 |
29 void set_exclude_httponly() { exclude_httponly_ = true; } | 31 void set_exclude_httponly() { exclude_httponly_ = true; } |
30 void set_include_httponly() { exclude_httponly_ = false; } | 32 void set_include_httponly() { exclude_httponly_ = false; } |
31 bool exclude_httponly() const { return exclude_httponly_; } | 33 bool exclude_httponly() const { return exclude_httponly_; } |
32 | 34 |
33 void set_include_first_party_only() { include_first_party_only_ = true; } | 35 // Default is to exclude 'first-party-only' cookies. |
34 bool include_first_party_only() const { return include_first_party_only_; } | 36 void set_include_first_party_only_cookies() { |
35 | 37 include_first_party_only_cookies_ = true; |
36 void set_first_party(const url::Origin& origin) { first_party_ = origin; } | 38 } |
37 const url::Origin& first_party() const { return first_party_; } | 39 bool include_first_party_only_cookies() const { |
| 40 return include_first_party_only_cookies_; |
| 41 } |
38 | 42 |
39 // TODO(jww): Remove once we decide whether to ship modifying 'secure' cookies | 43 // TODO(jww): Remove once we decide whether to ship modifying 'secure' cookies |
40 // only from secure schemes. https://crbug.com/546820 | 44 // only from secure schemes. https://crbug.com/546820 |
41 void set_enforce_strict_secure() { enforce_strict_secure_ = true; } | 45 void set_enforce_strict_secure() { enforce_strict_secure_ = true; } |
42 bool enforce_strict_secure() const { return enforce_strict_secure_; } | 46 bool enforce_strict_secure() const { return enforce_strict_secure_; } |
43 | 47 |
44 // |server_time| indicates what the server sending us the Cookie thought the | 48 // |server_time| indicates what the server sending us the Cookie thought the |
45 // current time was when the cookie was produced. This is used to adjust for | 49 // current time was when the cookie was produced. This is used to adjust for |
46 // clock skew between server and host. | 50 // clock skew between server and host. |
47 void set_server_time(const base::Time& server_time) { | 51 void set_server_time(const base::Time& server_time) { |
48 server_time_ = server_time; | 52 server_time_ = server_time; |
49 } | 53 } |
50 bool has_server_time() const { return !server_time_.is_null(); } | 54 bool has_server_time() const { return !server_time_.is_null(); } |
51 base::Time server_time() const { return server_time_; } | 55 base::Time server_time() const { return server_time_; } |
52 | 56 |
53 private: | 57 private: |
54 bool exclude_httponly_; | 58 bool exclude_httponly_; |
55 bool include_first_party_only_; | 59 bool include_first_party_only_cookies_; |
56 url::Origin first_party_; | |
57 bool enforce_strict_secure_; | 60 bool enforce_strict_secure_; |
58 base::Time server_time_; | 61 base::Time server_time_; |
59 }; | 62 }; |
60 | 63 |
61 } // namespace net | 64 } // namespace net |
62 | 65 |
63 #endif // NET_COOKIES_COOKIE_OPTIONS_H_ | 66 #endif // NET_COOKIES_COOKIE_OPTIONS_H_ |
OLD | NEW |