| 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 #include "chrome/browser/content_settings/content_settings_default_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_default_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 DefaultProvider::DefaultProvider(PrefService* prefs, bool incognito) | 102 DefaultProvider::DefaultProvider(PrefService* prefs, bool incognito) |
| 103 : prefs_(prefs), | 103 : prefs_(prefs), |
| 104 is_incognito_(incognito), | 104 is_incognito_(incognito), |
| 105 updating_preferences_(false) { | 105 updating_preferences_(false) { |
| 106 DCHECK(prefs_); | 106 DCHECK(prefs_); |
| 107 MigrateObsoleteNotificationPref(); | 107 MigrateObsoleteNotificationPref(); |
| 108 MigrateObsoleteGeolocationPref(); | 108 MigrateObsoleteGeolocationPref(); |
| 109 | 109 |
| 110 // Read global defaults. | 110 // Read global defaults. |
| 111 ReadDefaultSettings(true); | 111 ReadDefaultSettings(true); |
| 112 if (default_content_settings_.settings[CONTENT_SETTINGS_TYPE_COOKIES] == | 112 if (default_content_settings_[CONTENT_SETTINGS_TYPE_COOKIES] == |
| 113 CONTENT_SETTING_BLOCK) { | 113 CONTENT_SETTING_BLOCK) { |
| 114 UserMetrics::RecordAction( | 114 UserMetrics::RecordAction( |
| 115 UserMetricsAction("CookieBlockingEnabledPerDefault")); | 115 UserMetricsAction("CookieBlockingEnabledPerDefault")); |
| 116 } else { | 116 } else { |
| 117 UserMetrics::RecordAction( | 117 UserMetrics::RecordAction( |
| 118 UserMetricsAction("CookieBlockingDisabledPerDefault")); | 118 UserMetricsAction("CookieBlockingDisabledPerDefault")); |
| 119 } | 119 } |
| 120 | 120 |
| 121 pref_change_registrar_.Init(prefs_); | 121 pref_change_registrar_.Init(prefs_); |
| 122 pref_change_registrar_.Add(prefs::kDefaultContentSettings, this); | 122 pref_change_registrar_.Add(prefs::kDefaultContentSettings, this); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 // |DefaultProvider| should not send any notifications when holding | 155 // |DefaultProvider| should not send any notifications when holding |
| 156 // |lock_|. |DictionaryPrefUpdate| destructor and | 156 // |lock_|. |DictionaryPrefUpdate| destructor and |
| 157 // |PrefService::SetInteger()| send out notifications. As a response, the | 157 // |PrefService::SetInteger()| send out notifications. As a response, the |
| 158 // upper layers may call |GetAllContentSettingRules| which acquires |lock_| | 158 // upper layers may call |GetAllContentSettingRules| which acquires |lock_| |
| 159 // again. | 159 // again. |
| 160 { | 160 { |
| 161 base::AutoLock lock(lock_); | 161 base::AutoLock lock(lock_); |
| 162 if (setting == CONTENT_SETTING_DEFAULT || | 162 if (setting == CONTENT_SETTING_DEFAULT || |
| 163 setting == kDefaultSettings[content_type]) { | 163 setting == kDefaultSettings[content_type]) { |
| 164 default_content_settings_.settings[content_type] = | 164 default_content_settings_[content_type] = |
| 165 kDefaultSettings[content_type]; | 165 kDefaultSettings[content_type]; |
| 166 default_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, | 166 default_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, |
| 167 NULL); | 167 NULL); |
| 168 } else { | 168 } else { |
| 169 default_content_settings_.settings[content_type] = setting; | 169 default_content_settings_[content_type] = setting; |
| 170 default_settings_dictionary->SetWithoutPathExpansion( | 170 default_settings_dictionary->SetWithoutPathExpansion( |
| 171 dictionary_path, Value::CreateIntegerValue(setting)); | 171 dictionary_path, Value::CreateIntegerValue(setting)); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Keep the obsolete pref in sync as long as backwards compatibility is | 175 // Keep the obsolete pref in sync as long as backwards compatibility is |
| 176 // required. This is required to keep sync working correctly. | 176 // required. This is required to keep sync working correctly. |
| 177 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 177 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 178 prefs_->SetInteger(prefs::kGeolocationDefaultContentSetting, | 178 prefs_->SetInteger(prefs::kGeolocationDefaultContentSetting, |
| 179 setting == CONTENT_SETTING_DEFAULT ? | 179 setting == CONTENT_SETTING_DEFAULT ? |
| 180 kDefaultSettings[content_type] : setting); | 180 kDefaultSettings[content_type] : setting); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 NotifyObservers(ContentSettingsPattern(), | 184 NotifyObservers(ContentSettingsPattern(), |
| 185 ContentSettingsPattern(), | 185 ContentSettingsPattern(), |
| 186 content_type, | 186 content_type, |
| 187 std::string()); | 187 std::string()); |
| 188 } | 188 } |
| 189 | 189 |
| 190 RuleIterator* DefaultProvider::GetRuleIterator( | 190 RuleIterator* DefaultProvider::GetRuleIterator( |
| 191 ContentSettingsType content_type, | 191 ContentSettingsType content_type, |
| 192 const ResourceIdentifier& resource_identifier, | 192 const ResourceIdentifier& resource_identifier, |
| 193 bool incognito) const { | 193 bool incognito) const { |
| 194 base::AutoLock lock(lock_); | 194 base::AutoLock lock(lock_); |
| 195 if (resource_identifier.empty()) { | 195 if (resource_identifier.empty()) { |
| 196 return new DefaultRuleIterator( | 196 return new DefaultRuleIterator( |
| 197 default_content_settings_.settings[content_type]); | 197 default_content_settings_[content_type]); |
| 198 } else { | 198 } else { |
| 199 return new EmptyRuleIterator(); | 199 return new EmptyRuleIterator(); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 void DefaultProvider::ClearAllContentSettingsRules( | 203 void DefaultProvider::ClearAllContentSettingsRules( |
| 204 ContentSettingsType content_type) { | 204 ContentSettingsType content_type) { |
| 205 // TODO(markusheintz): This method is only called when the | 205 // TODO(markusheintz): This method is only called when the |
| 206 // |DesktopNotificationService| calls |ClearAllSettingsForType| method on the | 206 // |DesktopNotificationService| calls |ClearAllSettingsForType| method on the |
| 207 // |HostContentSettingsMap|. Don't implement this method yet, otherwise the | 207 // |HostContentSettingsMap|. Don't implement this method yet, otherwise the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } else { | 247 } else { |
| 248 NOTREACHED() << "Unexpected notification"; | 248 NOTREACHED() << "Unexpected notification"; |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 void DefaultProvider::ReadDefaultSettings(bool overwrite) { | 252 void DefaultProvider::ReadDefaultSettings(bool overwrite) { |
| 253 base::AutoLock lock(lock_); | 253 base::AutoLock lock(lock_); |
| 254 const DictionaryValue* default_settings_dictionary = | 254 const DictionaryValue* default_settings_dictionary = |
| 255 prefs_->GetDictionary(prefs::kDefaultContentSettings); | 255 prefs_->GetDictionary(prefs::kDefaultContentSettings); |
| 256 | 256 |
| 257 if (overwrite) | 257 if (overwrite) { |
| 258 default_content_settings_ = ContentSettings(); | 258 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) |
| 259 default_content_settings_[i] = CONTENT_SETTING_DEFAULT; |
| 260 } |
| 259 | 261 |
| 260 // Careful: The returned value could be NULL if the pref has never been set. | 262 // Careful: The returned value could be NULL if the pref has never been set. |
| 261 if (default_settings_dictionary) { | 263 if (default_settings_dictionary) { |
| 262 GetSettingsFromDictionary(default_settings_dictionary, | 264 GetSettingsFromDictionary(default_settings_dictionary, |
| 263 &default_content_settings_); | 265 default_content_settings_); |
| 264 } | 266 } |
| 265 ForceDefaultsToBeExplicit(); | 267 ForceDefaultsToBeExplicit(); |
| 266 } | 268 } |
| 267 | 269 |
| 268 void DefaultProvider::ForceDefaultsToBeExplicit() { | 270 void DefaultProvider::ForceDefaultsToBeExplicit() { |
| 269 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 271 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 270 if (default_content_settings_.settings[i] == CONTENT_SETTING_DEFAULT) | 272 if (default_content_settings_[i] == CONTENT_SETTING_DEFAULT) |
| 271 default_content_settings_.settings[i] = kDefaultSettings[i]; | 273 default_content_settings_[i] = kDefaultSettings[i]; |
| 272 } | 274 } |
| 273 } | 275 } |
| 274 | 276 |
| 275 void DefaultProvider::GetSettingsFromDictionary( | 277 void DefaultProvider::GetSettingsFromDictionary( |
| 276 const DictionaryValue* dictionary, | 278 const DictionaryValue* dictionary, |
| 277 ContentSettings* settings) { | 279 ContentSetting* settings) { |
| 278 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); | 280 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); |
| 279 i != dictionary->end_keys(); ++i) { | 281 i != dictionary->end_keys(); ++i) { |
| 280 const std::string& content_type(*i); | 282 const std::string& content_type(*i); |
| 281 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 283 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
| 282 if (content_type == GetTypeName(ContentSettingsType(type))) { | 284 if (content_type == GetTypeName(ContentSettingsType(type))) { |
| 283 int setting = CONTENT_SETTING_DEFAULT; | 285 int setting = CONTENT_SETTING_DEFAULT; |
| 284 bool found = dictionary->GetIntegerWithoutPathExpansion(content_type, | 286 bool found = dictionary->GetIntegerWithoutPathExpansion(content_type, |
| 285 &setting); | 287 &setting); |
| 286 DCHECK(found); | 288 DCHECK(found); |
| 287 settings->settings[type] = IntToContentSetting(setting); | 289 settings[type] = IntToContentSetting(setting); |
| 288 break; | 290 break; |
| 289 } | 291 } |
| 290 } | 292 } |
| 291 } | 293 } |
| 292 // Migrate obsolete cookie prompt mode/ | 294 // Migrate obsolete cookie prompt mode/ |
| 293 if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == | 295 if (settings[CONTENT_SETTINGS_TYPE_COOKIES] == CONTENT_SETTING_ASK) |
| 294 CONTENT_SETTING_ASK) | 296 settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; |
| 295 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; | |
| 296 | 297 |
| 297 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS] = | 298 settings[CONTENT_SETTINGS_TYPE_PLUGINS] = |
| 298 ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, | 299 ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 299 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]); | 300 settings[CONTENT_SETTINGS_TYPE_PLUGINS]); |
| 300 } | 301 } |
| 301 | 302 |
| 302 void DefaultProvider::MigrateObsoleteNotificationPref() { | 303 void DefaultProvider::MigrateObsoleteNotificationPref() { |
| 303 if (prefs_->HasPrefPath(prefs::kDesktopNotificationDefaultContentSetting)) { | 304 if (prefs_->HasPrefPath(prefs::kDesktopNotificationDefaultContentSetting)) { |
| 304 ContentSetting setting = IntToContentSetting( | 305 ContentSetting setting = IntToContentSetting( |
| 305 prefs_->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); | 306 prefs_->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); |
| 306 SetContentSetting( | 307 SetContentSetting( |
| 307 ContentSettingsPattern::Wildcard(), | 308 ContentSettingsPattern::Wildcard(), |
| 308 ContentSettingsPattern::Wildcard(), | 309 ContentSettingsPattern::Wildcard(), |
| 309 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 310 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 322 SetContentSetting( | 323 SetContentSetting( |
| 323 ContentSettingsPattern::Wildcard(), | 324 ContentSettingsPattern::Wildcard(), |
| 324 ContentSettingsPattern::Wildcard(), | 325 ContentSettingsPattern::Wildcard(), |
| 325 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 326 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 326 std::string(), | 327 std::string(), |
| 327 setting); | 328 setting); |
| 328 } | 329 } |
| 329 } | 330 } |
| 330 | 331 |
| 331 } // namespace content_settings | 332 } // namespace content_settings |
| OLD | NEW |