static_cookie_policy.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_COOKIES_STATIC_COOKIE_POLICY_H_
  5. #define NET_COOKIES_STATIC_COOKIE_POLICY_H_
  6. #include "net/base/net_export.h"
  7. class GURL;
  8. namespace net {
  9. class SiteForCookies;
  10. // The StaticCookiePolicy class implements a static cookie policy that supports
  11. // three modes: allow all, deny all, or block third-party cookies.
  12. class NET_EXPORT StaticCookiePolicy {
  13. public:
  14. // Do not change the order of these types as they are persisted in
  15. // preferences.
  16. enum Type {
  17. // Do not perform any cookie blocking.
  18. ALLOW_ALL_COOKIES = 0,
  19. // Block all cookies (third-party or not) from begin set or read.
  20. BLOCK_ALL_COOKIES,
  21. // Prevent only third-party cookies from being set or read.
  22. BLOCK_ALL_THIRD_PARTY_COOKIES
  23. };
  24. StaticCookiePolicy() : type_(StaticCookiePolicy::ALLOW_ALL_COOKIES) {}
  25. explicit StaticCookiePolicy(Type type) : type_(type) {}
  26. StaticCookiePolicy(const StaticCookiePolicy&) = delete;
  27. StaticCookiePolicy& operator=(const StaticCookiePolicy&) = delete;
  28. // Sets the current policy to enforce. This should be called when the user's
  29. // preferences change.
  30. void set_type(Type type) { type_ = type; }
  31. Type type() const { return type_; }
  32. // Consults the user's third-party cookie blocking preferences to determine
  33. // whether the URL's cookies can be accessed (i.e., can be get or set).
  34. int CanAccessCookies(const GURL& url,
  35. const net::SiteForCookies& site_for_cookies) const;
  36. private:
  37. Type type_;
  38. };
  39. } // namespace net
  40. #endif // NET_COOKIES_STATIC_COOKIE_POLICY_H_