Chromium Code Reviews| 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" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 const char kLastUsed[] = "last_used"; | 26 const char kLastUsed[] = "last_used"; |
| 27 | 27 |
| 28 // If the given content type supports resource identifiers in user preferences, | 28 // If the given content type supports resource identifiers in user preferences, |
| 29 // 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 |
| 30 // dictionary under which per-resource content settings are stored. | 30 // dictionary under which per-resource content settings are stored. |
| 31 // Otherwise, returns false. | 31 // Otherwise, returns false. |
| 32 bool SupportsResourceIdentifiers(ContentSettingsType content_type) { | 32 bool SupportsResourceIdentifiers(ContentSettingsType content_type) { |
| 33 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 33 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
| 34 } | 34 } |
| 35 | 35 |
| 36 bool IsValueAllowedForType(const base::Value* value, ContentSettingsType type) { | |
| 37 const content_settings::ContentSettingsInfo* info = | |
| 38 content_settings::ContentSettingsRegistry::GetInstance()->Get(type); | |
| 39 if (info) { | |
| 40 int setting; | |
| 41 if (!value->GetAsInteger(&setting)) | |
| 42 return false; | |
| 43 if (setting == CONTENT_SETTING_DEFAULT) | |
| 44 return false; | |
| 45 return info->IsSettingValid(IntToContentSetting(setting)); | |
| 46 } else { | |
|
Bernhard Bauer
2015/09/28 18:46:09
You don't need the else if you return in the previ
raymes
2015/09/29 05:51:26
Done.
| |
| 47 // TODO(raymes): We should permit different types of base::Value for | |
| 48 // website settings. | |
| 49 return value->GetType() == base::Value::TYPE_DICTIONARY; | |
| 50 } | |
| 51 } | |
| 52 | |
| 36 } // namespace | 53 } // namespace |
| 37 | 54 |
| 38 namespace content_settings { | 55 namespace content_settings { |
| 39 | 56 |
| 40 ContentSettingsPref::ContentSettingsPref( | 57 ContentSettingsPref::ContentSettingsPref( |
| 41 ContentSettingsType content_type, | 58 ContentSettingsType content_type, |
| 42 PrefService* prefs, | 59 PrefService* prefs, |
| 43 PrefChangeRegistrar* registrar, | 60 PrefChangeRegistrar* registrar, |
| 44 const std::string& pref_name, | 61 const std::string& pref_name, |
| 45 bool incognito, | 62 bool incognito, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 71 resource_identifier, | 88 resource_identifier, |
| 72 &lock_); | 89 &lock_); |
| 73 return value_map_.GetRuleIterator(content_type_, resource_identifier, &lock_); | 90 return value_map_.GetRuleIterator(content_type_, resource_identifier, &lock_); |
| 74 } | 91 } |
| 75 | 92 |
| 76 bool ContentSettingsPref::SetWebsiteSetting( | 93 bool ContentSettingsPref::SetWebsiteSetting( |
| 77 const ContentSettingsPattern& primary_pattern, | 94 const ContentSettingsPattern& primary_pattern, |
| 78 const ContentSettingsPattern& secondary_pattern, | 95 const ContentSettingsPattern& secondary_pattern, |
| 79 const ResourceIdentifier& resource_identifier, | 96 const ResourceIdentifier& resource_identifier, |
| 80 base::Value* in_value) { | 97 base::Value* in_value) { |
| 98 DCHECK(!in_value || IsValueAllowedForType(in_value, content_type_)); | |
| 81 DCHECK(thread_checker_.CalledOnValidThread()); | 99 DCHECK(thread_checker_.CalledOnValidThread()); |
| 82 DCHECK(prefs_); | 100 DCHECK(prefs_); |
| 83 DCHECK(primary_pattern != ContentSettingsPattern::Wildcard() || | 101 DCHECK(primary_pattern != ContentSettingsPattern::Wildcard() || |
| 84 secondary_pattern != ContentSettingsPattern::Wildcard() || | 102 secondary_pattern != ContentSettingsPattern::Wildcard() || |
| 85 !resource_identifier.empty()); | 103 !resource_identifier.empty()); |
| 86 | 104 |
| 87 // At this point take the ownership of the |in_value|. | 105 // At this point take the ownership of the |in_value|. |
| 88 scoped_ptr<base::Value> value(in_value); | 106 scoped_ptr<base::Value> value(in_value); |
| 89 | 107 |
| 90 // Update in memory value map. | 108 // Update in memory value map. |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 resource_identifier, | 314 resource_identifier, |
| 297 setting_ptr->DeepCopy()); | 315 setting_ptr->DeepCopy()); |
| 298 } | 316 } |
| 299 } | 317 } |
| 300 } | 318 } |
| 301 | 319 |
| 302 const base::Value* value = nullptr; | 320 const base::Value* value = nullptr; |
| 303 settings_dictionary->GetWithoutPathExpansion(kSettingPath, &value); | 321 settings_dictionary->GetWithoutPathExpansion(kSettingPath, &value); |
| 304 | 322 |
| 305 if (value) { | 323 if (value) { |
| 306 DCHECK(HostContentSettingsMap::IsValueAllowedForType(value, | 324 DCHECK(IsValueAllowedForType(value, content_type_)); |
| 307 content_type_)); | |
| 308 value_map_.SetValue(pattern_pair.first, | 325 value_map_.SetValue(pattern_pair.first, |
| 309 pattern_pair.second, | 326 pattern_pair.second, |
| 310 content_type_, | 327 content_type_, |
| 311 ResourceIdentifier(), | 328 ResourceIdentifier(), |
| 312 value->DeepCopy()); | 329 value->DeepCopy()); |
| 313 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { | 330 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 314 ContentSetting s = ValueToContentSetting(value); | 331 ContentSetting s = ValueToContentSetting(value); |
| 315 switch (s) { | 332 switch (s) { |
| 316 case CONTENT_SETTING_ALLOW : | 333 case CONTENT_SETTING_ALLOW : |
| 317 ++cookies_allow_exception_count; | 334 ++cookies_allow_exception_count; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 | 501 |
| 485 void ContentSettingsPref::AssertLockNotHeld() const { | 502 void ContentSettingsPref::AssertLockNotHeld() const { |
| 486 #if !defined(NDEBUG) | 503 #if !defined(NDEBUG) |
| 487 // |Lock::Acquire()| will assert if the lock is held by this thread. | 504 // |Lock::Acquire()| will assert if the lock is held by this thread. |
| 488 lock_.Acquire(); | 505 lock_.Acquire(); |
| 489 lock_.Release(); | 506 lock_.Release(); |
| 490 #endif | 507 #endif |
| 491 } | 508 } |
| 492 | 509 |
| 493 } // namespace content_settings | 510 } // namespace content_settings |
| OLD | NEW |