| 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 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_PREF_CONTENT_SETTINGS_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_PREF_CONTENT_SETTINGS_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_CONTENT_SETTINGS_PREF_CONTENT_SETTINGS_PROVIDER_H_ | 6 #define CHROME_BROWSER_CONTENT_SETTINGS_PREF_CONTENT_SETTINGS_PROVIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // A content settings provider that takes its settings out of the pref service. | 9 // A content settings provider that takes its settings out of the pref service. |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "chrome/browser/content_settings/content_settings_base_provider.h" |
| 17 #include "chrome/browser/content_settings/content_settings_provider.h" | 18 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 18 #include "chrome/browser/prefs/pref_change_registrar.h" | 19 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 19 #include "chrome/common/notification_observer.h" | 20 #include "chrome/common/notification_observer.h" |
| 20 #include "chrome/common/notification_registrar.h" | 21 #include "chrome/common/notification_registrar.h" |
| 21 | 22 |
| 22 class ContentSettingsDetails; | 23 class ContentSettingsDetails; |
| 23 class DictionaryValue; | 24 class DictionaryValue; |
| 24 class PrefService; | 25 class PrefService; |
| 25 class Profile; | 26 class Profile; |
| 26 | 27 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 PrefChangeRegistrar pref_change_registrar_; | 84 PrefChangeRegistrar pref_change_registrar_; |
| 84 NotificationRegistrar notification_registrar_; | 85 NotificationRegistrar notification_registrar_; |
| 85 | 86 |
| 86 // Whether we are currently updating preferences, this is used to ignore | 87 // Whether we are currently updating preferences, this is used to ignore |
| 87 // notifications from the preferences service that we triggered ourself. | 88 // notifications from the preferences service that we triggered ourself. |
| 88 bool updating_preferences_; | 89 bool updating_preferences_; |
| 89 | 90 |
| 90 DISALLOW_COPY_AND_ASSIGN(PrefDefaultProvider); | 91 DISALLOW_COPY_AND_ASSIGN(PrefDefaultProvider); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 class PrefProvider : public ProviderInterface, | 94 // Content-settings-provider that provides content-settings from the user |
| 95 // preference. |
| 96 class PrefProvider : public BaseProvider, |
| 94 public NotificationObserver { | 97 public NotificationObserver { |
| 95 public: | 98 public: |
| 96 static void RegisterUserPrefs(PrefService* prefs); | 99 static void RegisterUserPrefs(PrefService* prefs); |
| 97 | 100 |
| 98 explicit PrefProvider(Profile* profile); | 101 explicit PrefProvider(Profile* profile); |
| 99 virtual ~PrefProvider(); | 102 virtual ~PrefProvider(); |
| 100 | 103 |
| 101 // ContentSettingsProvider implementation. | 104 // ContentSettingsProvider implementation. |
| 102 virtual bool ContentSettingsTypeIsManaged( | 105 virtual bool ContentSettingsTypeIsManaged( |
| 103 ContentSettingsType content_type); | 106 ContentSettingsType content_type); |
| 104 | 107 |
| 105 virtual ContentSetting GetContentSetting( | |
| 106 const GURL& requesting_url, | |
| 107 const GURL& embedding_url, | |
| 108 ContentSettingsType content_type, | |
| 109 const ResourceIdentifier& resource_identifier) const; | |
| 110 | |
| 111 virtual void SetContentSetting( | 108 virtual void SetContentSetting( |
| 112 const ContentSettingsPattern& requesting_pattern, | 109 const ContentSettingsPattern& requesting_pattern, |
| 113 const ContentSettingsPattern& embedding_pattern, | 110 const ContentSettingsPattern& embedding_pattern, |
| 114 ContentSettingsType content_type, | 111 ContentSettingsType content_type, |
| 115 const ResourceIdentifier& resource_identifier, | 112 const ResourceIdentifier& resource_identifier, |
| 116 ContentSetting content_setting); | 113 ContentSetting content_setting); |
| 117 | 114 |
| 118 virtual void GetAllContentSettingsRules( | |
| 119 ContentSettingsType content_type, | |
| 120 const ResourceIdentifier& resource_identifier, | |
| 121 Rules* content_setting_rules) const; | |
| 122 | |
| 123 virtual void ClearAllContentSettingsRules( | 115 virtual void ClearAllContentSettingsRules( |
| 124 ContentSettingsType content_type); | 116 ContentSettingsType content_type); |
| 125 | 117 |
| 126 virtual void ResetToDefaults(); | 118 virtual void ResetToDefaults(); |
| 127 | 119 |
| 120 // BaseProvider implementations. |
| 121 virtual void Init(); |
| 122 |
| 128 // NotificationObserver implementation. | 123 // NotificationObserver implementation. |
| 129 virtual void Observe(NotificationType type, | 124 virtual void Observe(NotificationType type, |
| 130 const NotificationSource& source, | 125 const NotificationSource& source, |
| 131 const NotificationDetails& details); | 126 const NotificationDetails& details); |
| 132 | 127 |
| 133 private: | 128 private: |
| 134 typedef std::pair<ContentSettingsType, std::string> | 129 void ReadExceptions(bool overwrite); |
| 135 ContentSettingsTypeResourceIdentifierPair; | |
| 136 typedef std::map<ContentSettingsTypeResourceIdentifierPair, ContentSetting> | |
| 137 ResourceContentSettings; | |
| 138 | |
| 139 struct ExtendedContentSettings; | |
| 140 | |
| 141 typedef std::map<std::string, ExtendedContentSettings> HostContentSettings; | |
| 142 | 130 |
| 143 // Various migration methods (old cookie, popup and per-host data gets | 131 // Various migration methods (old cookie, popup and per-host data gets |
| 144 // migrated to the new format). | 132 // migrated to the new format). |
| 145 void MigrateObsoletePerhostPref(PrefService* prefs); | 133 void MigrateObsoletePerhostPref(PrefService* prefs); |
| 146 void MigrateObsoletePopupsPref(PrefService* prefs); | 134 void MigrateObsoletePopupsPref(PrefService* prefs); |
| 147 | 135 |
| 148 bool AllDefault(const ExtendedContentSettings& settings) const; | |
| 149 | |
| 150 void ReadExceptions(bool overwrite); | |
| 151 | |
| 152 bool RequiresResourceIdentifier( | |
| 153 ContentSettingsType content_type) const; | |
| 154 | |
| 155 void CanonicalizeContentSettingsExceptions( | 136 void CanonicalizeContentSettingsExceptions( |
| 156 DictionaryValue* all_settings_dictionary); | 137 DictionaryValue* all_settings_dictionary); |
| 157 | 138 |
| 158 void GetSettingsFromDictionary( | 139 void GetSettingsFromDictionary( |
| 159 const DictionaryValue* dictionary, | 140 const DictionaryValue* dictionary, |
| 160 ContentSettings* settings); | 141 ContentSettings* settings); |
| 161 | 142 |
| 162 void GetResourceSettingsFromDictionary( | 143 void GetResourceSettingsFromDictionary( |
| 163 const DictionaryValue* dictionary, | 144 const DictionaryValue* dictionary, |
| 164 ResourceContentSettings* settings); | 145 ResourceContentSettings* settings); |
| 165 | 146 |
| 166 void NotifyObservers(const ContentSettingsDetails& details); | 147 void NotifyObservers(const ContentSettingsDetails& details); |
| 167 | 148 |
| 168 void UnregisterObservers(); | 149 void UnregisterObservers(); |
| 169 | 150 |
| 170 Profile* profile_; | 151 Profile* profile_; |
| 171 | 152 |
| 172 // Whether this settings map is for an OTR session. | |
| 173 bool is_off_the_record_; | |
| 174 | |
| 175 // Used around accesses to the content_settings_ object to guarantee | |
| 176 // thread safety. | |
| 177 mutable base::Lock lock_; | |
| 178 | |
| 179 PrefChangeRegistrar pref_change_registrar_; | 153 PrefChangeRegistrar pref_change_registrar_; |
| 180 NotificationRegistrar notification_registrar_; | 154 NotificationRegistrar notification_registrar_; |
| 181 | 155 |
| 182 // Copies of the pref data, so that we can read it on threads other than the | |
| 183 // UI thread. | |
| 184 HostContentSettings host_content_settings_; | |
| 185 | |
| 186 // Differences to the preference-stored host content settings for | |
| 187 // off-the-record settings. | |
| 188 HostContentSettings off_the_record_settings_; | |
| 189 | |
| 190 // Whether we are currently updating preferences, this is used to ignore | 156 // Whether we are currently updating preferences, this is used to ignore |
| 191 // notifications from the preferences service that we triggered ourself. | 157 // notifications from the preferences service that we triggered ourself. |
| 192 bool updating_preferences_; | 158 bool updating_preferences_; |
| 193 | 159 |
| 194 // Do not fire any Notifications as long as we are in the constructor. | 160 // Do not fire any Notifications as long as we are in the constructor. |
| 195 bool initializing_; | 161 bool initializing_; |
| 196 | 162 |
| 197 // LEGACY: TBR | |
| 198 ContentSettings GetNonDefaultContentSettings(const GURL& url) const; | |
| 199 | |
| 200 DISALLOW_COPY_AND_ASSIGN(PrefProvider); | 163 DISALLOW_COPY_AND_ASSIGN(PrefProvider); |
| 201 }; | 164 }; |
| 202 | 165 |
| 203 } // namespace content_settings | 166 } // namespace content_settings |
| 204 | 167 |
| 205 #endif // CHROME_BROWSER_CONTENT_SETTINGS_PREF_CONTENT_SETTINGS_PROVIDER_H_ | 168 #endif // CHROME_BROWSER_CONTENT_SETTINGS_PREF_CONTENT_SETTINGS_PROVIDER_H_ |
| OLD | NEW |