| 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/linked_ptr.h" |
| 18 #include "base/lock.h" | 19 #include "base/lock.h" |
| 19 #include "base/ref_counted.h" | 20 #include "base/ref_counted.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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 typedef std::map<std::string, ExtendedContentSettings> HostContentSettings; | 182 typedef std::map<std::string, ExtendedContentSettings> HostContentSettings; |
| 181 | 183 |
| 182 // Sets the fields of |settings| based on the values in |dictionary|. | 184 // Sets the fields of |settings| based on the values in |dictionary|. |
| 183 void GetSettingsFromDictionary(const DictionaryValue* dictionary, | 185 void GetSettingsFromDictionary(const DictionaryValue* dictionary, |
| 184 ContentSettings* settings); | 186 ContentSettings* settings); |
| 185 | 187 |
| 186 // Populates |settings| based on the values in |dictionary|. | 188 // Populates |settings| based on the values in |dictionary|. |
| 187 void GetResourceSettingsFromDictionary(const DictionaryValue* dictionary, | 189 void GetResourceSettingsFromDictionary(const DictionaryValue* dictionary, |
| 188 ResourceContentSettings* settings); | 190 ResourceContentSettings* settings); |
| 189 | 191 |
| 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. | 192 // Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT. |
| 195 bool AllDefault(const ExtendedContentSettings& settings) const; | 193 bool AllDefault(const ExtendedContentSettings& settings) const; |
| 196 | 194 |
| 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 | 195 // 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. | 196 // true and the preference is missing, the local copy will be cleared as well. |
| 216 void ReadExceptions(bool overwrite); | 197 void ReadExceptions(bool overwrite); |
| 217 | 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 |
| 243 // Copies of the pref data, so that we can read it on the IO thread. | 224 // Whether this settings map is for an OTR session. |
| 244 ContentSettings default_content_settings_; | 225 bool is_off_the_record_; |
| 245 ContentSettings managed_default_content_settings_; | 226 |
| 227 // Whether we are currently updating preferences, this is used to ignore |
| 228 // notifications from the preferences service that we triggered ourself. |
| 229 bool updating_preferences_; |
| 230 |
| 231 // Content setting providers. |
| 232 std::vector<linked_ptr<ContentSettingsProviderInterface> > |
| 233 content_settings_providers_; |
| 234 |
| 235 // Used around accesses to the following objects to guarantee thread safety. |
| 236 mutable Lock lock_; |
| 237 |
| 238 // Copies of the pref data, so that we can read it on threads other than the |
| 239 // UI thread. |
| 246 HostContentSettings host_content_settings_; | 240 HostContentSettings host_content_settings_; |
| 247 | 241 |
| 248 // Differences to the preference-stored host content settings for | 242 // Differences to the preference-stored host content settings for |
| 249 // off-the-record settings. | 243 // off-the-record settings. |
| 250 HostContentSettings off_the_record_settings_; | 244 HostContentSettings off_the_record_settings_; |
| 251 | 245 |
| 252 // Misc global settings. | 246 // Misc global settings. |
| 253 bool block_third_party_cookies_; | 247 bool block_third_party_cookies_; |
| 254 bool is_block_third_party_cookies_managed_; | 248 bool is_block_third_party_cookies_managed_; |
| 255 bool block_nonsandboxed_plugins_; | 249 bool block_nonsandboxed_plugins_; |
| 256 | 250 |
| 257 // Used around accesses to the settings objects to guarantee thread safety. | |
| 258 mutable Lock lock_; | |
| 259 | |
| 260 // Whether this settings map is for an OTR session. | |
| 261 bool is_off_the_record_; | |
| 262 | |
| 263 // Whether we are currently updating preferences, this is used to ignore | |
| 264 // notifications from the preferences service that we triggered ourself. | |
| 265 bool updating_preferences_; | |
| 266 | |
| 267 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 251 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
| 268 }; | 252 }; |
| 269 | 253 |
| 270 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 254 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |