| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // upper layers may call |GetAllContentSettingRules| which acquires |lock_| | 216 // upper layers may call |GetAllContentSettingRules| which acquires |lock_| |
| 217 // again. | 217 // again. |
| 218 DictionaryPrefUpdate update(prefs_, prefs::kDefaultContentSettings); | 218 DictionaryPrefUpdate update(prefs_, prefs::kDefaultContentSettings); |
| 219 base::DictionaryValue* default_settings_dictionary = update.Get(); | 219 base::DictionaryValue* default_settings_dictionary = update.Get(); |
| 220 base::AutoLock lock(lock_); | 220 base::AutoLock lock(lock_); |
| 221 if (value.get() == NULL || | 221 if (value.get() == NULL || |
| 222 ValueToContentSetting(value.get()) == kDefaultSettings[content_type]) { | 222 ValueToContentSetting(value.get()) == kDefaultSettings[content_type]) { |
| 223 // If |value| is NULL we need to reset the default setting the the | 223 // If |value| is NULL we need to reset the default setting the the |
| 224 // hardcoded default. | 224 // hardcoded default. |
| 225 default_settings_[content_type].reset( | 225 default_settings_[content_type].reset( |
| 226 base::Value::CreateIntegerValue(kDefaultSettings[content_type])); | 226 new base::FundamentalValue(kDefaultSettings[content_type])); |
| 227 | 227 |
| 228 // Remove the corresponding pref entry since the hardcoded default value | 228 // Remove the corresponding pref entry since the hardcoded default value |
| 229 // is used. | 229 // is used. |
| 230 default_settings_dictionary->RemoveWithoutPathExpansion( | 230 default_settings_dictionary->RemoveWithoutPathExpansion( |
| 231 GetTypeName(content_type), NULL); | 231 GetTypeName(content_type), NULL); |
| 232 } else { | 232 } else { |
| 233 default_settings_[content_type].reset(value->DeepCopy()); | 233 default_settings_[content_type].reset(value->DeepCopy()); |
| 234 // Transfer ownership of |value| to the |default_settings_dictionary|. | 234 // Transfer ownership of |value| to the |default_settings_dictionary|. |
| 235 default_settings_dictionary->SetWithoutPathExpansion( | 235 default_settings_dictionary->SetWithoutPathExpansion( |
| 236 GetTypeName(content_type), value.release()); | 236 GetTypeName(content_type), value.release()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 308 |
| 309 ForceDefaultsToBeExplicit(); | 309 ForceDefaultsToBeExplicit(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void DefaultProvider::ForceDefaultsToBeExplicit() { | 312 void DefaultProvider::ForceDefaultsToBeExplicit() { |
| 313 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 313 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 314 ContentSettingsType type = ContentSettingsType(i); | 314 ContentSettingsType type = ContentSettingsType(i); |
| 315 if (!default_settings_[type].get() && | 315 if (!default_settings_[type].get() && |
| 316 kDefaultSettings[i] != CONTENT_SETTING_DEFAULT) { | 316 kDefaultSettings[i] != CONTENT_SETTING_DEFAULT) { |
| 317 default_settings_[type].reset( | 317 default_settings_[type].reset( |
| 318 base::Value::CreateIntegerValue(kDefaultSettings[i])); | 318 new base::FundamentalValue(kDefaultSettings[i])); |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 | 322 |
| 323 void DefaultProvider::GetSettingsFromDictionary( | 323 void DefaultProvider::GetSettingsFromDictionary( |
| 324 const base::DictionaryValue* dictionary) { | 324 const base::DictionaryValue* dictionary) { |
| 325 for (base::DictionaryValue::Iterator i(*dictionary); | 325 for (base::DictionaryValue::Iterator i(*dictionary); |
| 326 !i.IsAtEnd(); i.Advance()) { | 326 !i.IsAtEnd(); i.Advance()) { |
| 327 const std::string& content_type(i.key()); | 327 const std::string& content_type(i.key()); |
| 328 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 328 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
| 329 if (content_type == GetTypeName(ContentSettingsType(type))) { | 329 if (content_type == GetTypeName(ContentSettingsType(type))) { |
| 330 int int_value = CONTENT_SETTING_DEFAULT; | 330 int int_value = CONTENT_SETTING_DEFAULT; |
| 331 bool is_integer = i.value().GetAsInteger(&int_value); | 331 bool is_integer = i.value().GetAsInteger(&int_value); |
| 332 DCHECK(is_integer); | 332 DCHECK(is_integer); |
| 333 default_settings_[ContentSettingsType(type)].reset( | 333 default_settings_[ContentSettingsType(type)].reset( |
| 334 base::Value::CreateIntegerValue(int_value)); | 334 new base::FundamentalValue(int_value)); |
| 335 break; | 335 break; |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 // Migrate obsolete cookie prompt mode. | 339 // Migrate obsolete cookie prompt mode. |
| 340 if (ValueToContentSetting( | 340 if (ValueToContentSetting( |
| 341 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].get()) == | 341 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].get()) == |
| 342 CONTENT_SETTING_ASK) { | 342 CONTENT_SETTING_ASK) { |
| 343 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].reset( | 343 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].reset( |
| 344 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 344 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 } // namespace content_settings | 348 } // namespace content_settings |
| OLD | NEW |