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