Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/lock.h" | 18 #include "base/lock.h" |
| 19 #include "base/ref_counted.h" | 19 #include "base/ref_counted.h" |
| 20 #include "base/stl_util-inl.h" | |
| 20 #include "chrome/browser/browser_thread.h" | 21 #include "chrome/browser/browser_thread.h" |
| 21 #include "chrome/browser/content_settings/content_settings_pattern.h" | 22 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 22 #include "chrome/browser/prefs/pref_change_registrar.h" | 23 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 23 #include "chrome/common/content_settings.h" | 24 #include "chrome/common/content_settings.h" |
| 24 #include "chrome/common/notification_observer.h" | 25 #include "chrome/common/notification_observer.h" |
| 25 #include "chrome/common/notification_registrar.h" | 26 #include "chrome/common/notification_registrar.h" |
| 26 | 27 |
| 27 class ContentSettingsDetails; | 28 class ContentSettingsDetails; |
| 29 class ContentSettingsProviderInterface; | |
| 28 class DictionaryValue; | 30 class DictionaryValue; |
| 29 class GURL; | 31 class GURL; |
| 30 class PrefService; | 32 class PrefService; |
| 31 class Profile; | 33 class Profile; |
| 32 | 34 |
| 33 class HostContentSettingsMap | 35 class HostContentSettingsMap |
| 34 : public NotificationObserver, | 36 : public NotificationObserver, |
| 35 public base::RefCountedThreadSafe<HostContentSettingsMap, | 37 public base::RefCountedThreadSafe<HostContentSettingsMap, |
| 36 BrowserThread::DeleteOnUIThread> { | 38 BrowserThread::DeleteOnUIThread> { |
| 37 public: | 39 public: |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 void SetBlockThirdPartyCookies(bool block); | 152 void SetBlockThirdPartyCookies(bool block); |
| 151 | 153 |
| 152 bool GetBlockNonsandboxedPlugins() const { | 154 bool GetBlockNonsandboxedPlugins() const { |
| 153 return block_nonsandboxed_plugins_; | 155 return block_nonsandboxed_plugins_; |
| 154 } | 156 } |
| 155 | 157 |
| 156 void SetBlockNonsandboxedPlugins(bool block); | 158 void SetBlockNonsandboxedPlugins(bool block); |
| 157 | 159 |
| 158 // Resets all settings levels. | 160 // Resets all settings levels. |
| 159 // | 161 // |
| 160 // This should only be called on the UI thread. | 162 // This should only be called on the UI thread. |
|
gfeher
2010/12/08 13:59:17
I know this was already here, but please document
gfeher
2010/12/08 14:13:54
Sorry, this is not true.
jochen (gone - plz use gerrit)
2010/12/08 14:54:01
right :)
| |
| 161 void ResetToDefaults(); | 163 void ResetToDefaults(); |
| 162 | 164 |
| 163 // Returns true if the default setting for the |content_type| is managed. | 165 // Returns true if the default setting for the |content_type| is managed. |
| 164 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; | 166 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; |
| 165 | 167 |
| 166 // NotificationObserver implementation. | |
| 167 virtual void Observe(NotificationType type, | |
| 168 const NotificationSource& source, | |
| 169 const NotificationDetails& details); | |
| 170 | |
| 171 private: | 168 private: |
| 172 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 169 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
| 173 | 170 |
| 174 typedef std::pair<ContentSettingsType, std::string> | 171 typedef std::pair<ContentSettingsType, std::string> |
| 175 ContentSettingsTypeResourceIdentifierPair; | 172 ContentSettingsTypeResourceIdentifierPair; |
| 176 typedef std::map<ContentSettingsTypeResourceIdentifierPair, ContentSetting> | 173 typedef std::map<ContentSettingsTypeResourceIdentifierPair, ContentSetting> |
| 177 ResourceContentSettings; | 174 ResourceContentSettings; |
| 178 | 175 |
| 179 struct ExtendedContentSettings; | 176 struct ExtendedContentSettings; |
| 180 typedef std::map<std::string, ExtendedContentSettings> HostContentSettings; | 177 typedef std::map<std::string, ExtendedContentSettings> HostContentSettings; |
| 181 | 178 |
| 182 // Sets the fields of |settings| based on the values in |dictionary|. | 179 // Sets the fields of |settings| based on the values in |dictionary|. |
| 183 void GetSettingsFromDictionary(const DictionaryValue* dictionary, | 180 void GetSettingsFromDictionary(const DictionaryValue* dictionary, |
| 184 ContentSettings* settings); | 181 ContentSettings* settings); |
| 185 | 182 |
| 186 // Populates |settings| based on the values in |dictionary|. | 183 // Populates |settings| based on the values in |dictionary|. |
| 187 void GetResourceSettingsFromDictionary(const DictionaryValue* dictionary, | 184 void GetResourceSettingsFromDictionary(const DictionaryValue* dictionary, |
| 188 ResourceContentSettings* settings); | 185 ResourceContentSettings* settings); |
| 189 | 186 |
| 190 // Forces the default settings to be explicitly set instead of themselves | |
| 191 // being CONTENT_SETTING_DEFAULT. | |
| 192 void ForceDefaultsToBeExplicit(); | |
| 193 | |
| 194 // Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT. | 187 // Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT. |
| 195 bool AllDefault(const ExtendedContentSettings& settings) const; | 188 bool AllDefault(const ExtendedContentSettings& settings) const; |
| 196 | 189 |
| 197 // Reads the default settings from the prefereces service. If |overwrite| is | |
| 198 // true and the preference is missing, the local copy will be cleared as well. | |
| 199 void ReadDefaultSettings(bool overwrite); | |
| 200 | |
| 201 // Reads managed default content settings from the preference service |prefs|. | |
| 202 // |settings| is set to the respective content setting for managed settings, | |
| 203 // and to CONTENT_SETTING_DEFAULT for other settings. | |
| 204 void ReadManagedDefaultSettings(const PrefService* prefs, | |
| 205 ContentSettings* settings); | |
| 206 | |
| 207 // Updates the managed setting of the default-content-settings-type |type|. | |
| 208 // The updated setting is read from the preference service |prefs| and written | |
| 209 // to |settings|. | |
| 210 void UpdateManagedDefaultSetting(ContentSettingsType type, | |
| 211 const PrefService* prefs, | |
| 212 ContentSettings* settings); | |
| 213 | |
| 214 // Reads the host exceptions from the prefereces service. If |overwrite| is | 190 // Reads the host exceptions from the prefereces service. If |overwrite| is |
| 215 // true and the preference is missing, the local copy will be cleared as well. | 191 // true and the preference is missing, the local copy will be cleared as well. |
| 216 void ReadExceptions(bool overwrite); | 192 void ReadExceptions(bool overwrite); |
| 217 | 193 |
| 194 // NotificationObserver implementation. | |
| 195 virtual void Observe(NotificationType type, | |
| 196 const NotificationSource& source, | |
| 197 const NotificationDetails& details); | |
| 198 | |
| 218 // Informs observers that content settings have changed. Make sure that | 199 // Informs observers that content settings have changed. Make sure that |
| 219 // |lock_| is not held when calling this, as listeners will usually call one | 200 // |lock_| is not held when calling this, as listeners will usually call one |
| 220 // of the GetSettings functions in response, which would then lead to a | 201 // of the GetSettings functions in response, which would then lead to a |
| 221 // mutex deadlock. | 202 // mutex deadlock. |
| 222 void NotifyObservers(const ContentSettingsDetails& details); | 203 void NotifyObservers(const ContentSettingsDetails& details); |
| 223 | 204 |
| 224 void UnregisterObservers(); | 205 void UnregisterObservers(); |
| 225 | 206 |
| 226 // Various migration methods (old cookie, popup and per-host data gets | 207 // Various migration methods (old cookie, popup and per-host data gets |
| 227 // migrated to the new format). | 208 // migrated to the new format). |
| 228 void MigrateObsoleteCookiePref(PrefService* prefs); | 209 void MigrateObsoleteCookiePref(PrefService* prefs); |
| 229 void MigrateObsoletePopupsPref(PrefService* prefs); | 210 void MigrateObsoletePopupsPref(PrefService* prefs); |
| 230 void MigrateObsoletePerhostPref(PrefService* prefs); | 211 void MigrateObsoletePerhostPref(PrefService* prefs); |
| 231 | 212 |
| 232 // Converts all exceptions that have non-canonicalized pattern into | 213 // Converts all exceptions that have non-canonicalized pattern into |
| 233 // canonicalized pattern. If such pattern already exists, we just remove the | 214 // canonicalized pattern. If such pattern already exists, we just remove the |
| 234 // old exception. | 215 // old exception. |
| 235 void CanonicalizeContentSettingsExceptions(DictionaryValue* settings); | 216 void CanonicalizeContentSettingsExceptions(DictionaryValue* settings); |
| 236 | 217 |
| 237 // The profile we're associated with. | 218 // The profile we're associated with. |
| 238 Profile* profile_; | 219 Profile* profile_; |
| 239 | 220 |
| 240 NotificationRegistrar notification_registrar_; | 221 NotificationRegistrar notification_registrar_; |
| 241 PrefChangeRegistrar pref_change_registrar_; | 222 PrefChangeRegistrar pref_change_registrar_; |
| 242 | 223 |
| 224 // Content setting providers. | |
| 225 std::vector<ContentSettingsProviderInterface*> content_settings_providers_; | |
| 226 STLElementDeleter<std::vector<ContentSettingsProviderInterface*> > | |
| 227 content_settings_providers_deleter_; | |
|
gfeher
2010/12/08 13:59:17
What was the reason for not using linked_ptr or so
jochen (gone - plz use gerrit)
2010/12/08 14:54:01
Done.
| |
| 228 | |
| 243 // Copies of the pref data, so that we can read it on the IO thread. | 229 // Copies of the pref data, so that we can read it on the IO thread. |
| 244 ContentSettings default_content_settings_; | |
| 245 ContentSettings managed_default_content_settings_; | 230 ContentSettings managed_default_content_settings_; |
| 246 HostContentSettings host_content_settings_; | 231 HostContentSettings host_content_settings_; |
| 247 | 232 |
| 248 // Differences to the preference-stored host content settings for | 233 // Differences to the preference-stored host content settings for |
| 249 // off-the-record settings. | 234 // off-the-record settings. |
| 250 HostContentSettings off_the_record_settings_; | 235 HostContentSettings off_the_record_settings_; |
| 251 | 236 |
| 252 // Misc global settings. | 237 // Misc global settings. |
| 253 bool block_third_party_cookies_; | 238 bool block_third_party_cookies_; |
| 254 bool is_block_third_party_cookies_managed_; | 239 bool is_block_third_party_cookies_managed_; |
| 255 bool block_nonsandboxed_plugins_; | 240 bool block_nonsandboxed_plugins_; |
| 256 | 241 |
| 257 // Used around accesses to the settings objects to guarantee thread safety. | 242 // Used around accesses to the settings objects to guarantee thread safety. |
|
gfeher
2010/12/08 13:59:17
Please list here what members are protected with t
jochen (gone - plz use gerrit)
2010/12/08 14:54:01
Done.
| |
| 258 mutable Lock lock_; | 243 mutable Lock lock_; |
| 259 | 244 |
| 260 // Whether this settings map is for an OTR session. | 245 // Whether this settings map is for an OTR session. |
| 261 bool is_off_the_record_; | 246 bool is_off_the_record_; |
| 262 | 247 |
| 263 // Whether we are currently updating preferences, this is used to ignore | 248 // Whether we are currently updating preferences, this is used to ignore |
| 264 // notifications from the preferences service that we triggered ourself. | 249 // notifications from the preferences service that we triggered ourself. |
| 265 bool updating_preferences_; | 250 bool updating_preferences_; |
| 266 | 251 |
| 267 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 252 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
| 268 }; | 253 }; |
| 269 | 254 |
| 270 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 255 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |