| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/content_settings/core/browser/content_settings_pref.h" | 5 #include "components/content_settings/core/browser/content_settings_pref.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/time/clock.h" | 13 #include "base/time/clock.h" |
| 14 #include "components/content_settings/core/browser/content_settings_rule.h" | 14 #include "components/content_settings/core/browser/content_settings_rule.h" |
| 15 #include "components/content_settings/core/browser/content_settings_utils.h" | 15 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 16 #include "components/content_settings/core/browser/host_content_settings_map.h" | 16 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 17 #include "components/content_settings/core/common/content_settings.h" | 17 #include "components/content_settings/core/common/content_settings.h" |
| 18 #include "components/content_settings/core/common/content_settings_pattern.h" | 18 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 19 #include "components/content_settings/core/common/pref_names.h" | 19 #include "components/content_settings/core/common/pref_names.h" |
| 20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const char kSettingPath[] = "setting"; | 24 const char kSettingPath[] = "setting"; |
| 25 const char kPerResourceIdentifierPrefName[] = "per_resource"; | 25 const char kPerResourceIdentifierPrefName[] = "per_resource"; |
| 26 const char kLastUsed[] = "last_used"; | 26 const char kLastUsed[] = "last_used"; |
| 27 | 27 |
| 28 ContentSetting FixObsoleteCookiePromptMode(ContentSettingsType content_type, | |
| 29 ContentSetting setting) { | |
| 30 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES && | |
| 31 setting == CONTENT_SETTING_ASK) { | |
| 32 return CONTENT_SETTING_BLOCK; | |
| 33 } | |
| 34 return setting; | |
| 35 } | |
| 36 | |
| 37 // If the given content type supports resource identifiers in user preferences, | 28 // If the given content type supports resource identifiers in user preferences, |
| 38 // returns true and sets |pref_key| to the key in the content settings | 29 // returns true and sets |pref_key| to the key in the content settings |
| 39 // dictionary under which per-resource content settings are stored. | 30 // dictionary under which per-resource content settings are stored. |
| 40 // Otherwise, returns false. | 31 // Otherwise, returns false. |
| 41 bool SupportsResourceIdentifiers(ContentSettingsType content_type) { | 32 bool SupportsResourceIdentifiers(ContentSettingsType content_type) { |
| 42 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 33 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
| 43 } | 34 } |
| 44 | 35 |
| 45 } // namespace | 36 } // namespace |
| 46 | 37 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 scoped_ptr<base::Value> setting_ptr( | 291 scoped_ptr<base::Value> setting_ptr( |
| 301 new base::FundamentalValue(setting)); | 292 new base::FundamentalValue(setting)); |
| 302 value_map_.SetValue(pattern_pair.first, | 293 value_map_.SetValue(pattern_pair.first, |
| 303 pattern_pair.second, | 294 pattern_pair.second, |
| 304 content_type_, | 295 content_type_, |
| 305 resource_identifier, | 296 resource_identifier, |
| 306 setting_ptr->DeepCopy()); | 297 setting_ptr->DeepCopy()); |
| 307 } | 298 } |
| 308 } | 299 } |
| 309 } | 300 } |
| 310 base::Value* value = NULL; | |
| 311 if (HostContentSettingsMap::ContentTypeHasCompoundValue(content_type_)) { | |
| 312 const base::DictionaryValue* setting = NULL; | |
| 313 // TODO(xians): Handle the non-dictionary types. | |
| 314 if (settings_dictionary->GetDictionaryWithoutPathExpansion( | |
| 315 kSettingPath, &setting)) { | |
| 316 DCHECK(!setting->empty()); | |
| 317 value = setting->DeepCopy(); | |
| 318 } | |
| 319 } else { | |
| 320 int setting = CONTENT_SETTING_DEFAULT; | |
| 321 if (settings_dictionary->GetIntegerWithoutPathExpansion( | |
| 322 kSettingPath, &setting)) { | |
| 323 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting); | |
| 324 setting = FixObsoleteCookiePromptMode(content_type_, | |
| 325 ContentSetting(setting)); | |
| 326 value = new base::FundamentalValue(setting); | |
| 327 } | |
| 328 } | |
| 329 | 301 |
| 330 if (value != NULL) { | 302 const base::Value* value = nullptr; |
| 331 scoped_ptr<base::Value> value_ptr(value); | 303 settings_dictionary->GetWithoutPathExpansion(kSettingPath, &value); |
| 304 |
| 305 if (value) { |
| 306 DCHECK( |
| 307 HostContentSettingsMap::IsValueAllowedForType(value, content_type_)); |
| 332 value_map_.SetValue(pattern_pair.first, | 308 value_map_.SetValue(pattern_pair.first, |
| 333 pattern_pair.second, | 309 pattern_pair.second, |
| 334 content_type_, | 310 content_type_, |
| 335 ResourceIdentifier(), | 311 ResourceIdentifier(), |
| 336 value->DeepCopy()); | 312 value->DeepCopy()); |
| 337 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { | 313 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 338 ContentSetting s = ValueToContentSetting(value); | 314 ContentSetting s = ValueToContentSetting(value); |
| 339 switch (s) { | 315 switch (s) { |
| 340 case CONTENT_SETTING_ALLOW : | 316 case CONTENT_SETTING_ALLOW : |
| 341 ++cookies_allow_exception_count; | 317 ++cookies_allow_exception_count; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 484 |
| 509 void ContentSettingsPref::AssertLockNotHeld() const { | 485 void ContentSettingsPref::AssertLockNotHeld() const { |
| 510 #if !defined(NDEBUG) | 486 #if !defined(NDEBUG) |
| 511 // |Lock::Acquire()| will assert if the lock is held by this thread. | 487 // |Lock::Acquire()| will assert if the lock is held by this thread. |
| 512 lock_.Acquire(); | 488 lock_.Acquire(); |
| 513 lock_.Release(); | 489 lock_.Release(); |
| 514 #endif | 490 #endif |
| 515 } | 491 } |
| 516 | 492 |
| 517 } // namespace content_settings | 493 } // namespace content_settings |
| OLD | NEW |