summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/chrome_cookie_policy.h
blob: 88e698b81d6d6b79218eaff10aeabae2be32f7ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_NET_CHROME_COOKIE_POLICY_H_
#define CHROME_BROWSER_NET_CHROME_COOKIE_POLICY_H_

#include <map>
#include <string>

#include "base/basictypes.h"
#include "base/lock.h"
#include "chrome/common/content_permission_types.h"
#include "net/base/cookie_policy.h"

class GURL;
class PrefService;
class Profile;

// The ChromeCookiePolicy class implements per-domain cookie policies.
class ChromeCookiePolicy : public net::CookiePolicy {
 public:
  typedef std::map<std::string, ContentPermissionType> CookiePolicies;

  explicit ChromeCookiePolicy(Profile* profile);

  virtual ~ChromeCookiePolicy() {}

  static void RegisterUserPrefs(PrefService* prefs);

  void ResetToDefaults();

  // Consult the user's cookie blocking preferences to determine whether the
  // URL's cookies can be read.
  virtual bool CanGetCookies(const GURL& url,
                             const GURL& first_party_for_cookies);

  // Consult the user's cookie blocking preferences to determine whether the
  // URL's cookies can be set.
  virtual bool CanSetCookie(const GURL& url,
                            const GURL& first_party_for_cookies);

  // Sets per domain policies. A policy of type DEFAULT will erase the entry.
  //
  // This should be called only on the UI thread.
  void SetPerDomainPermission(const std::string& domain,
                              ContentPermissionType type);

  // Returns all per domain policies.
  //
  // This can be called on any thread.
  CookiePolicies GetAllPerDomainPermissions() const {
    return per_domain_policy_;
  }

  // Sets the current policy to enforce.
  //
  // This should be called only on the UI thread.
  void set_type(Type type);

  // This can be called on any thread.
  Type type() const {
    AutoLock auto_lock(lock_);
    return net::CookiePolicy::type();
  }

 protected:
  ContentPermissionType CheckPermissionForHost(const std::string& host) const;

  Profile* profile_;

  mutable Lock lock_;

  // Local copy of prefs.
  CookiePolicies per_domain_policy_;

 private:
  DISALLOW_COPY_AND_ASSIGN(ChromeCookiePolicy);
};

#endif  // CHROME_BROWSER_NET_CHROME_COOKIE_POLICY_H_