OLD | NEW |
---|---|
(Empty) | |
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 | |
5 // Maps hostnames to cookie settings. Written on the UI thread and read on any | |
6 // thread. One instance per profile. | |
7 | |
8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | |
9 #define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | |
10 #pragma once | |
11 | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/synchronization/lock.h" | |
14 #include "chrome/browser/prefs/pref_change_registrar.h" | |
15 #include "chrome/common/content_settings.h" | |
16 #include "content/common/notification_observer.h" | |
17 | |
18 class ContentSettingsPattern; | |
19 class GURL; | |
20 class HostContentSettingsMap; | |
21 class Profile; | |
22 | |
23 // A frontend to the cookie-specific settings of HostContentSettingsMap. Handles | |
24 // cookie-specific logic such as blocking third-party cookies. | |
25 class CookieSettings | |
26 : public NotificationObserver, | |
27 public base::RefCountedThreadSafe<CookieSettings> { | |
28 public: | |
29 CookieSettings( | |
30 HostContentSettingsMap* host_content_settings_map, | |
31 PrefService* prefs, | |
32 bool incognito); | |
33 | |
34 virtual ~CookieSettings(); | |
35 | |
36 // Returns the CookieSettings associated with the profile. | |
37 // | |
38 // This should only be called on the UI thread. | |
39 static CookieSettings* GetForProfile(Profile* profile); | |
40 | |
41 // Returns the default content setting (CONTENT_SETTING_ALLOW, | |
42 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. | |
43 // | |
44 // This may be called on any thread. | |
45 ContentSetting GetDefaultSetting() const; | |
46 | |
47 // Returns true if the page identified by (url, first_party_url) is allowed to | |
48 // read cookies. | |
49 // | |
50 // This may be called on any thread. | |
51 bool IsReadingCookieAllowed(const GURL& url, | |
52 const GURL& first_party_url) const; | |
53 | |
54 // Returns true if the page identified by (url, first_party_url) is allowed to | |
55 // set a cookie (permanent or session only). | |
56 // | |
57 // This may be called on any thread. | |
58 bool IsSettingCookieAllowed(const GURL& url, | |
59 const GURL& first_party_url) const; | |
60 | |
61 // Returns true if the cookie set by a page identified by url should be | |
62 // session only. Querying this only makes sense if IsSettingCookieAllowed has | |
63 // returned true. | |
64 // | |
65 // This may be called on any thread. | |
66 bool IsCookieSessionOnly(const GURL& url) const; | |
67 | |
68 // Sets the default content setting (CONTENT_SETTING_ALLOW, | |
69 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. | |
70 // | |
71 // This should only be called on the UI thread. | |
72 void SetDefaultSetting(ContentSetting setting); | |
73 | |
74 // Sets the cookie setting to CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK or | |
75 // CONTENT_SETTING_SESSION_ONLY for (url, first_party_url) pairs where url | |
76 // matches primary_pattern. | |
77 // | |
78 // This should only be called on the UI thread. | |
79 void SetCookieSetting(const ContentSettingsPattern& primary_pattern, | |
80 ContentSetting setting); | |
81 | |
82 // Resets the cookie setting for (url, first_party_url) pais where url matches | |
83 // primary_pattern. | |
84 // | |
85 // This should only be called on the UI thread. | |
86 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern); | |
87 | |
88 // This setting trumps any host-specific settings. | |
89 // | |
90 // These may be called on any thread. | |
91 bool ShouldBlockThirdPartyCookies() const { | |
92 return block_third_party_cookies_; | |
Bernhard Bauer
2011/09/05 11:05:38
This isn't thread safe. You should wrap all access
marja
2011/09/06 08:30:15
Done.
| |
93 } | |
94 | |
95 // Sets whether we block all third-party cookies. This method must not be | |
96 // invoked on an incognito map. | |
97 // TODO(bauerb): Remove this and use PrefService directly. | |
98 // | |
99 // This should only be called on the UI thread. | |
100 void SetBlockThirdPartyCookies(bool block); | |
101 | |
102 // NotificationObserver implementation. | |
103 virtual void Observe(int type, | |
104 const NotificationSource& source, | |
105 const NotificationDetails& details); | |
106 | |
107 // Detaches the CookieSettings from all Profile-related objects like | |
108 // PrefService. This methods needs to be called before destroying the Profile. | |
109 // Afterwards, none of the methods above that should only be called on the UI | |
110 // thread should be called anymore. | |
111 void ShutdownOnUIThread(); | |
112 | |
113 private: | |
114 class Factory; | |
115 | |
116 // A helper for retrieving data for CONTENT_TYPE_COOKIES and | |
117 // CONTENT_TYPE_COOKIES_SESSION_ONLY. | |
118 ContentSetting GetCookieContentSetting(const GURL& url, | |
119 const GURL& first_party_url, | |
120 ContentSettingsType content_type, | |
121 bool setting_cookie) const; | |
122 | |
123 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | |
124 | |
125 // Weak; owned by the profile. | |
126 PrefService* prefs_; | |
127 PrefChangeRegistrar pref_change_registrar_; | |
128 | |
129 bool is_off_the_record_; | |
130 | |
131 // Used around accesses to the following objects to guarantee thread safety. | |
132 mutable base::Lock lock_; | |
133 | |
134 bool block_third_party_cookies_; | |
135 }; | |
136 | |
137 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | |
OLD | NEW |