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 |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/linked_ptr.h" | 18 #include "base/linked_ptr.h" |
19 #include "base/ref_counted.h" | 19 #include "base/ref_counted.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 #include "chrome/browser/browser_thread.h" | 21 #include "chrome/browser/browser_thread.h" |
22 #include "chrome/browser/content_settings/content_settings_pattern.h" | 22 #include "chrome/browser/content_settings/content_settings_pattern.h" |
23 #include "chrome/browser/prefs/pref_change_registrar.h" | 23 #include "chrome/browser/prefs/pref_change_registrar.h" |
24 #include "chrome/common/content_settings.h" | 24 #include "chrome/common/content_settings.h" |
25 #include "chrome/common/notification_observer.h" | 25 #include "chrome/common/notification_observer.h" |
26 #include "chrome/common/notification_registrar.h" | 26 #include "chrome/common/notification_registrar.h" |
27 | 27 |
28 namespace content_settings { | 28 namespace content_settings { |
29 class DefaultProviderInterface; | 29 class DefaultProviderInterface; |
| 30 class ProviderInterface; |
30 } // namespace content_settings | 31 } // namespace content_settings |
31 | 32 |
32 class ContentSettingsDetails; | 33 class ContentSettingsDetails; |
33 class DictionaryValue; | 34 class DictionaryValue; |
34 class GURL; | 35 class GURL; |
35 class PrefService; | 36 class PrefService; |
36 class Profile; | 37 class Profile; |
37 | 38 |
38 class HostContentSettingsMap | 39 class HostContentSettingsMap |
39 : public NotificationObserver, | 40 : public NotificationObserver, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 void AddExceptionForURL(const GURL& url, | 132 void AddExceptionForURL(const GURL& url, |
132 ContentSettingsType content_type, | 133 ContentSettingsType content_type, |
133 const std::string& resource_identifier, | 134 const std::string& resource_identifier, |
134 ContentSetting setting); | 135 ContentSetting setting); |
135 | 136 |
136 // Clears all host-specific settings for one content type. | 137 // Clears all host-specific settings for one content type. |
137 // | 138 // |
138 // This should only be called on the UI thread. | 139 // This should only be called on the UI thread. |
139 void ClearSettingsForOneType(ContentSettingsType content_type); | 140 void ClearSettingsForOneType(ContentSettingsType content_type); |
140 | 141 |
141 // Whether the |content_type| requires an additional resource identifier for | |
142 // accessing content settings. | |
143 bool RequiresResourceIdentifier(ContentSettingsType content_type) const; | |
144 | |
145 // This setting trumps any host-specific settings. | 142 // This setting trumps any host-specific settings. |
146 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; } | 143 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; } |
147 bool IsBlockThirdPartyCookiesManaged() const { | 144 bool IsBlockThirdPartyCookiesManaged() const { |
148 return is_block_third_party_cookies_managed_; | 145 return is_block_third_party_cookies_managed_; |
149 } | 146 } |
150 | 147 |
151 // Sets whether we block all third-party cookies. This method must not be | 148 // Sets whether we block all third-party cookies. This method must not be |
152 // invoked on an off-the-record map. | 149 // invoked on an off-the-record map. |
153 // | 150 // |
154 // This should only be called on the UI thread. | 151 // This should only be called on the UI thread. |
(...skipping 14 matching lines...) Expand all Loading... |
169 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; | 166 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; |
170 | 167 |
171 // NotificationObserver implementation. | 168 // NotificationObserver implementation. |
172 virtual void Observe(NotificationType type, | 169 virtual void Observe(NotificationType type, |
173 const NotificationSource& source, | 170 const NotificationSource& source, |
174 const NotificationDetails& details); | 171 const NotificationDetails& details); |
175 | 172 |
176 private: | 173 private: |
177 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 174 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
178 | 175 |
179 typedef std::pair<ContentSettingsType, std::string> | |
180 ContentSettingsTypeResourceIdentifierPair; | |
181 typedef std::map<ContentSettingsTypeResourceIdentifierPair, ContentSetting> | |
182 ResourceContentSettings; | |
183 | |
184 struct ExtendedContentSettings; | |
185 typedef std::map<std::string, ExtendedContentSettings> HostContentSettings; | |
186 | |
187 // Sets the fields of |settings| based on the values in |dictionary|. | |
188 void GetSettingsFromDictionary(const DictionaryValue* dictionary, | |
189 ContentSettings* settings); | |
190 | |
191 // Populates |settings| based on the values in |dictionary|. | |
192 void GetResourceSettingsFromDictionary(const DictionaryValue* dictionary, | |
193 ResourceContentSettings* settings); | |
194 | |
195 // Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT. | |
196 bool AllDefault(const ExtendedContentSettings& settings) const; | |
197 | |
198 // Reads the host exceptions from the prefereces service. If |overwrite| is | |
199 // true and the preference is missing, the local copy will be cleared as well. | |
200 void ReadExceptions(bool overwrite); | |
201 | |
202 // Informs observers that content settings have changed. Make sure that | 176 // Informs observers that content settings have changed. Make sure that |
203 // |lock_| is not held when calling this, as listeners will usually call one | 177 // |lock_| is not held when calling this, as listeners will usually call one |
204 // of the GetSettings functions in response, which would then lead to a | 178 // of the GetSettings functions in response, which would then lead to a |
205 // mutex deadlock. | 179 // mutex deadlock. |
206 void NotifyObservers(const ContentSettingsDetails& details); | 180 void NotifyObservers(const ContentSettingsDetails& details); |
207 | 181 |
208 void UnregisterObservers(); | 182 void UnregisterObservers(); |
209 | 183 |
210 // Various migration methods (old cookie, popup and per-host data gets | 184 // Various migration methods (old cookie, popup and per-host data gets |
211 // migrated to the new format). | 185 // migrated to the new format). |
212 void MigrateObsoleteCookiePref(PrefService* prefs); | 186 void MigrateObsoleteCookiePref(PrefService* prefs); |
213 void MigrateObsoletePopupsPref(PrefService* prefs); | |
214 void MigrateObsoletePerhostPref(PrefService* prefs); | |
215 | |
216 // Converts all exceptions that have non-canonicalized pattern into | |
217 // canonicalized pattern. If such pattern already exists, we just remove the | |
218 // old exception. | |
219 void CanonicalizeContentSettingsExceptions(DictionaryValue* settings); | |
220 | 187 |
221 // The profile we're associated with. | 188 // The profile we're associated with. |
222 Profile* profile_; | 189 Profile* profile_; |
223 | 190 |
224 NotificationRegistrar notification_registrar_; | 191 NotificationRegistrar notification_registrar_; |
225 PrefChangeRegistrar pref_change_registrar_; | 192 PrefChangeRegistrar pref_change_registrar_; |
226 | 193 |
227 // Whether this settings map is for an OTR session. | 194 // Whether this settings map is for an OTR session. |
228 bool is_off_the_record_; | 195 bool is_off_the_record_; |
229 | 196 |
230 // Whether we are currently updating preferences, this is used to ignore | 197 // Whether we are currently updating preferences, this is used to ignore |
231 // notifications from the preferences service that we triggered ourself. | 198 // notifications from the preferences service that we triggered ourself. |
232 bool updating_preferences_; | 199 bool updating_preferences_; |
233 | 200 |
234 // Content setting providers. | 201 // Default content setting providers. |
235 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > | 202 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > |
236 default_content_settings_providers_; | 203 default_content_settings_providers_; |
237 | 204 |
| 205 // Content setting providers. |
| 206 std::vector<linked_ptr<content_settings::ProviderInterface> > |
| 207 content_settings_providers_; |
| 208 |
238 // Used around accesses to the following objects to guarantee thread safety. | 209 // Used around accesses to the following objects to guarantee thread safety. |
239 mutable base::Lock lock_; | 210 mutable base::Lock lock_; |
240 | 211 |
241 // Copies of the pref data, so that we can read it on threads other than the | |
242 // UI thread. | |
243 HostContentSettings host_content_settings_; | |
244 | |
245 // Differences to the preference-stored host content settings for | |
246 // off-the-record settings. | |
247 HostContentSettings off_the_record_settings_; | |
248 | |
249 // Misc global settings. | 212 // Misc global settings. |
250 bool block_third_party_cookies_; | 213 bool block_third_party_cookies_; |
251 bool is_block_third_party_cookies_managed_; | 214 bool is_block_third_party_cookies_managed_; |
252 bool block_nonsandboxed_plugins_; | 215 bool block_nonsandboxed_plugins_; |
253 | 216 |
254 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 217 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
255 }; | 218 }; |
256 | 219 |
257 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 220 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
OLD | NEW |