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