xref: /aosp_15_r20/external/cronet/net/cookies/static_cookie_policy.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2011 The Chromium Authors
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_COOKIES_STATIC_COOKIE_POLICY_H_
6 #define NET_COOKIES_STATIC_COOKIE_POLICY_H_
7 
8 #include "net/base/net_export.h"
9 
10 class GURL;
11 
12 namespace net {
13 
14 class SiteForCookies;
15 
16 // The StaticCookiePolicy class implements a static cookie policy that supports
17 // three modes: allow all, deny all, or block third-party cookies.
18 class NET_EXPORT StaticCookiePolicy {
19  public:
20   // Do not change the order of these types as they are persisted in
21   // preferences.
22   enum Type {
23     // Do not perform any cookie blocking.
24     ALLOW_ALL_COOKIES = 0,
25     // Block all cookies (third-party or not) from begin set or read.
26     BLOCK_ALL_COOKIES,
27     // Prevent only third-party cookies from being set or read.
28     BLOCK_ALL_THIRD_PARTY_COOKIES
29   };
30 
StaticCookiePolicy()31   StaticCookiePolicy() : type_(StaticCookiePolicy::ALLOW_ALL_COOKIES) {}
32 
StaticCookiePolicy(Type type)33   explicit StaticCookiePolicy(Type type) : type_(type) {}
34 
35   StaticCookiePolicy(const StaticCookiePolicy&) = delete;
36   StaticCookiePolicy& operator=(const StaticCookiePolicy&) = delete;
37 
38   // Sets the current policy to enforce. This should be called when the user's
39   // preferences change.
set_type(Type type)40   void set_type(Type type) { type_ = type; }
type()41   Type type() const { return type_; }
42 
43   // Consults the user's third-party cookie blocking preferences to determine
44   // whether the URL's cookies can be accessed (i.e., can be get or set).
45   int CanAccessCookies(const GURL& url,
46                        const net::SiteForCookies& site_for_cookies) const;
47 
48  private:
49   Type type_;
50 };
51 
52 }  // namespace net
53 
54 #endif  // NET_COOKIES_STATIC_COOKIE_POLICY_H_
55