Home | History | Annotate | Download | only in base
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_BASE_STATIC_COOKIE_POLICY_H_
      6 #define NET_BASE_STATIC_COOKIE_POLICY_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "net/base/cookie_policy.h"
     10 
     11 class GURL;
     12 
     13 namespace net {
     14 
     15 // The StaticCookiePolicy class implements a static cookie policy that supports
     16 // three modes: allow all, deny all, or block third-party cookies.
     17 //
     18 // NOTE: This CookiePolicy implementation always completes synchronously.  The
     19 // callback parameter will be ignored if specified.  Just pass NULL.
     20 //
     21 class StaticCookiePolicy : public CookiePolicy {
     22  public:
     23   enum Type {
     24     ALLOW_ALL_COOKIES = 0,      // Do not perform any cookie blocking.
     25     BLOCK_THIRD_PARTY_COOKIES,  // Prevent third-party cookies from being set.
     26     BLOCK_ALL_COOKIES           // Disable cookies.
     27   };
     28 
     29   StaticCookiePolicy()
     30       : type_(StaticCookiePolicy::ALLOW_ALL_COOKIES) {
     31   }
     32 
     33   explicit StaticCookiePolicy(Type type)
     34       : type_(type) {
     35   }
     36 
     37   // Sets the current policy to enforce. This should be called when the user's
     38   // preferences change.
     39   void set_type(Type type) { type_ = type; }
     40   Type type() const { return type_; }
     41 
     42   // CookiePolicy methods:
     43 
     44   // Consults the user's third-party cookie blocking preferences to determine
     45   // whether the URL's cookies can be read.
     46   virtual int CanGetCookies(const GURL& url,
     47                             const GURL& first_party_for_cookies,
     48                             CompletionCallback* callback);
     49 
     50   // Consults the user's third-party cookie blocking preferences to determine
     51   // whether the URL's cookies can be set.
     52   virtual int CanSetCookie(const GURL& url,
     53                            const GURL& first_party_for_cookies,
     54                            const std::string& cookie_line,
     55                            CompletionCallback* callback);
     56 
     57  private:
     58   Type type_;
     59 
     60   DISALLOW_COPY_AND_ASSIGN(StaticCookiePolicy);
     61 };
     62 
     63 }  // namespace net
     64 
     65 #endif  // NET_BASE_STATIC_COOKIE_POLICY_H_
     66