OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Maps hostnames to custom content settings. Written on the UI thread and read | 5 // Maps hostnames to custom content settings. Written on the UI thread and read |
6 // on any thread. One instance per profile. | 6 // on any thread. One instance per profile. |
7 | 7 |
8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
10 #pragma once | 10 #pragma once |
(...skipping 21 matching lines...) Expand all Loading... |
32 } // namespace content_settings | 32 } // namespace content_settings |
33 | 33 |
34 class ContentSettingsDetails; | 34 class ContentSettingsDetails; |
35 class ExtensionService; | 35 class ExtensionService; |
36 class GURL; | 36 class GURL; |
37 class PrefService; | 37 class PrefService; |
38 class Profile; | 38 class Profile; |
39 | 39 |
40 class HostContentSettingsMap | 40 class HostContentSettingsMap |
41 : public content_settings::Observer, | 41 : public content_settings::Observer, |
42 public NotificationObserver, | |
43 public base::RefCountedThreadSafe<HostContentSettingsMap> { | 42 public base::RefCountedThreadSafe<HostContentSettingsMap> { |
44 public: | 43 public: |
45 // TODO(markusheintz): I sold my soul to the devil on order to add this tuple. | 44 // TODO(markusheintz): I sold my soul to the devil on order to add this tuple. |
46 // I really want my soul back, so I really will change this ASAP. | 45 // I really want my soul back, so I really will change this ASAP. |
47 typedef Tuple4<ContentSettingsPattern, | 46 typedef Tuple4<ContentSettingsPattern, |
48 ContentSettingsPattern, | 47 ContentSettingsPattern, |
49 ContentSetting, | 48 ContentSetting, |
50 std::string> PatternSettingSourceTuple; | 49 std::string> PatternSettingSourceTuple; |
51 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; | 50 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; |
52 | 51 |
(...skipping 19 matching lines...) Expand all Loading... |
72 // require an resource identifier to be specified, the |resource_identifier| | 71 // require an resource identifier to be specified, the |resource_identifier| |
73 // must be non-empty. | 72 // must be non-empty. |
74 // | 73 // |
75 // This may be called on any thread. | 74 // This may be called on any thread. |
76 ContentSetting GetContentSetting( | 75 ContentSetting GetContentSetting( |
77 const GURL& primary_url, | 76 const GURL& primary_url, |
78 const GURL& secondary_url, | 77 const GURL& secondary_url, |
79 ContentSettingsType content_type, | 78 ContentSettingsType content_type, |
80 const std::string& resource_identifier) const; | 79 const std::string& resource_identifier) const; |
81 | 80 |
82 // Gets the content setting for cookies. This takes the third party cookie | |
83 // flag into account, and therefore needs to know whether we read or write a | |
84 // cookie. | |
85 // | |
86 // This may be called on any thread. | |
87 ContentSetting GetCookieContentSetting( | |
88 const GURL& url, | |
89 const GURL& first_party_url, | |
90 bool setting_cookie) const; | |
91 | |
92 // Returns all ContentSettings which apply to the given URLs. For content | 81 // Returns all ContentSettings which apply to the given URLs. For content |
93 // setting types that require an additional resource identifier, the default | 82 // setting types that require an additional resource identifier, the default |
94 // content setting is returned. | 83 // content setting is returned. |
95 // | 84 // |
96 // This may be called on any thread. | 85 // This may be called on any thread. |
97 ContentSettings GetContentSettings( | 86 ContentSettings GetContentSettings( |
98 const GURL& primary_url, | 87 const GURL& primary_url, |
99 const GURL& secondary_url) const; | 88 const GURL& secondary_url) const; |
100 | 89 |
101 // For a given content type, returns all patterns with a non-default setting, | 90 // For a given content type, returns all patterns with a non-default setting, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 ContentSetting setting); | 132 ContentSetting setting); |
144 | 133 |
145 // Clears all host-specific settings for one content type. | 134 // Clears all host-specific settings for one content type. |
146 // | 135 // |
147 // This should only be called on the UI thread. | 136 // This should only be called on the UI thread. |
148 void ClearSettingsForOneType(ContentSettingsType content_type); | 137 void ClearSettingsForOneType(ContentSettingsType content_type); |
149 | 138 |
150 static bool IsSettingAllowedForType(ContentSetting setting, | 139 static bool IsSettingAllowedForType(ContentSetting setting, |
151 ContentSettingsType content_type); | 140 ContentSettingsType content_type); |
152 | 141 |
153 // This setting trumps any host-specific settings. | |
154 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; } | |
155 bool IsBlockThirdPartyCookiesManaged() const { | |
156 return is_block_third_party_cookies_managed_; | |
157 } | |
158 | |
159 // Sets whether we block all third-party cookies. This method must not be | |
160 // invoked on an incognito map. | |
161 // | |
162 // This should only be called on the UI thread. | |
163 void SetBlockThirdPartyCookies(bool block); | |
164 | |
165 // Returns true if the default setting for the |content_type| is managed. | 142 // Returns true if the default setting for the |content_type| is managed. |
166 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; | 143 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; |
167 | 144 |
168 // Detaches the HostContentSettingsMap from all Profile-related objects like | 145 // Detaches the HostContentSettingsMap from all Profile-related objects like |
169 // PrefService. This methods needs to be called before destroying the Profile. | 146 // PrefService. This methods needs to be called before destroying the Profile. |
170 // Afterwards, none of the methods above that should only be called on the UI | 147 // Afterwards, none of the methods above that should only be called on the UI |
171 // thread should be called anymore. | 148 // thread should be called anymore. |
172 void ShutdownOnUIThread(); | 149 void ShutdownOnUIThread(); |
173 | 150 |
174 // content_settings::Observer implementation. | 151 // content_settings::Observer implementation. |
175 virtual void OnContentSettingChanged( | 152 virtual void OnContentSettingChanged( |
176 ContentSettingsPattern primary_pattern, | 153 ContentSettingsPattern primary_pattern, |
177 ContentSettingsPattern secondary_pattern, | 154 ContentSettingsPattern secondary_pattern, |
178 ContentSettingsType content_type, | 155 ContentSettingsType content_type, |
179 std::string resource_identifier); | 156 std::string resource_identifier); |
180 | 157 |
181 // NotificationObserver implementation. | 158 static bool ShouldAllowAllContent(const GURL& url, |
182 virtual void Observe(int type, | 159 ContentSettingsType content_type); |
183 const NotificationSource& source, | |
184 const NotificationDetails& details); | |
185 | 160 |
186 private: | 161 private: |
187 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 162 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
| 163 friend class CookieSettings; |
188 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; | 164 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; |
189 | 165 |
190 virtual ~HostContentSettingsMap(); | 166 virtual ~HostContentSettingsMap(); |
191 | 167 |
192 // Returns all non-default ContentSettings which apply to the given URLs. For | 168 // Returns all non-default ContentSettings which apply to the given URLs. For |
193 // content setting types that require an additional resource identifier, | 169 // content setting types that require an additional resource identifier, |
194 // CONTENT_SETTING_DEFAULT is returned. | 170 // CONTENT_SETTING_DEFAULT is returned. |
195 // | 171 // |
196 // This may be called on any thread. | 172 // This may be called on any thread. |
197 ContentSettings GetNonDefaultContentSettings( | 173 ContentSettings GetNonDefaultContentSettings( |
(...skipping 12 matching lines...) Expand all Loading... |
210 const GURL& secondary_url, | 186 const GURL& secondary_url, |
211 ContentSettingsType content_type, | 187 ContentSettingsType content_type, |
212 const std::string& resource_identifier) const; | 188 const std::string& resource_identifier) const; |
213 | 189 |
214 ContentSetting GetContentSettingInternal( | 190 ContentSetting GetContentSettingInternal( |
215 const GURL& primary_url, | 191 const GURL& primary_url, |
216 const GURL& secondary_url, | 192 const GURL& secondary_url, |
217 ContentSettingsType content_type, | 193 ContentSettingsType content_type, |
218 const std::string& resource_identifier) const; | 194 const std::string& resource_identifier) const; |
219 | 195 |
220 // Various migration methods (old cookie, popup and per-host data gets | |
221 // migrated to the new format). | |
222 void MigrateObsoleteCookiePref(); | |
223 | |
224 // Weak; owned by the Profile. | 196 // Weak; owned by the Profile. |
225 PrefService* prefs_; | 197 PrefService* prefs_; |
226 | 198 |
227 PrefChangeRegistrar pref_change_registrar_; | |
228 | |
229 // Whether this settings map is for an OTR session. | 199 // Whether this settings map is for an OTR session. |
230 bool is_off_the_record_; | 200 bool is_off_the_record_; |
231 | 201 |
232 // Whether we are currently updating preferences, this is used to ignore | 202 // Whether we are currently updating preferences, this is used to ignore |
233 // notifications from the preferences service that we triggered ourself. | 203 // notifications from the preferences service that we triggered ourself. |
234 bool updating_preferences_; | 204 bool updating_preferences_; |
235 | 205 |
236 // Default content setting providers. | 206 // Default content setting providers. |
237 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > | 207 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > |
238 default_content_settings_providers_; | 208 default_content_settings_providers_; |
239 | 209 |
240 // Content setting providers. | 210 // Content setting providers. |
241 std::vector<linked_ptr<content_settings::ProviderInterface> > | 211 std::vector<linked_ptr<content_settings::ProviderInterface> > |
242 content_settings_providers_; | 212 content_settings_providers_; |
243 | 213 |
244 // Used around accesses to the following objects to guarantee thread safety. | |
245 mutable base::Lock lock_; | |
246 | |
247 // Misc global settings. | |
248 bool block_third_party_cookies_; | |
249 bool is_block_third_party_cookies_managed_; | |
250 | |
251 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 214 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
252 }; | 215 }; |
253 | 216 |
254 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 217 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
OLD | NEW |