| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_BASE_COOKIE_POLICY_H_ | 5 #ifndef NET_BASE_STATIC_COOKIE_POLICY_H_ |
| 6 #define NET_BASE_COOKIE_POLICY_H_ | 6 #define NET_BASE_STATIC_COOKIE_POLICY_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "net/base/cookie_policy.h" |
| 9 | 10 |
| 10 class GURL; | 11 class GURL; |
| 11 | 12 |
| 12 namespace net { | 13 namespace net { |
| 13 | 14 |
| 14 // The CookiePolicy class implements third-party cookie blocking. | 15 // The StaticCookiePolicy class implements a static cookie policy that supports |
| 15 class CookiePolicy { | 16 // three modes: allow all, deny all, or block third-party cookies. |
| 17 class StaticCookiePolicy : public CookiePolicy { |
| 16 public: | 18 public: |
| 17 // Consult the user's third-party cookie blocking preferences to determine | 19 // Consult the user's third-party cookie blocking preferences to determine |
| 18 // whether the URL's cookies can be read. | 20 // whether the URL's cookies can be read. |
| 19 bool CanGetCookies(const GURL& url, const GURL& first_party_for_cookies); | 21 bool CanGetCookies(const GURL& url, const GURL& first_party_for_cookies); |
| 20 | 22 |
| 21 // Consult the user's third-party cookie blocking preferences to determine | 23 // Consult the user's third-party cookie blocking preferences to determine |
| 22 // whether the URL's cookies can be set. | 24 // whether the URL's cookies can be set. |
| 23 bool CanSetCookie(const GURL& url, const GURL& first_party_for_cookies); | 25 bool CanSetCookie(const GURL& url, const GURL& first_party_for_cookies); |
| 24 | 26 |
| 25 enum Type { | 27 enum Type { |
| 26 ALLOW_ALL_COOKIES = 0, // Do not perform any cookie blocking. | 28 ALLOW_ALL_COOKIES = 0, // Do not perform any cookie blocking. |
| 27 BLOCK_THIRD_PARTY_COOKIES, // Prevent third-party cookies from being set. | 29 BLOCK_THIRD_PARTY_COOKIES, // Prevent third-party cookies from being set. |
| 28 BLOCK_ALL_COOKIES // Disable cookies. | 30 BLOCK_ALL_COOKIES // Disable cookies. |
| 29 }; | 31 }; |
| 30 | 32 |
| 31 static bool ValidType(int32 type) { | |
| 32 return type >= ALLOW_ALL_COOKIES && type <= BLOCK_ALL_COOKIES; | |
| 33 } | |
| 34 | |
| 35 static Type FromInt(int32 type) { | |
| 36 return static_cast<Type>(type); | |
| 37 } | |
| 38 | |
| 39 // Sets the current policy to enforce. This should be called when the user's | 33 // Sets the current policy to enforce. This should be called when the user's |
| 40 // preferences change. | 34 // preferences change. |
| 41 void set_type(Type type) { type_ = type; } | 35 void set_type(Type type) { type_ = type; } |
| 42 | 36 |
| 43 Type type() const { | 37 Type type() const { |
| 44 return type_; | 38 return type_; |
| 45 } | 39 } |
| 46 | 40 |
| 47 CookiePolicy(); | 41 StaticCookiePolicy() |
| 42 : type_(StaticCookiePolicy::ALLOW_ALL_COOKIES) { |
| 43 } |
| 44 |
| 45 explicit StaticCookiePolicy(Type type) |
| 46 : type_(type) { |
| 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 Type type_; | 50 Type type_; |
| 51 | 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(CookiePolicy); | 52 DISALLOW_COPY_AND_ASSIGN(StaticCookiePolicy); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 } // namespace net | 55 } // namespace net |
| 56 | 56 |
| 57 #endif // NET_BASE_COOKIE_POLICY_H_ | 57 #endif // NET_BASE_STATIC_COOKIE_POLICY_H_ |
| OLD | NEW |