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/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 // Returns true if the |content_type| supports a resource identifier. | 77 // Returns true if the |content_type| supports a resource identifier. |
78 // Resource identifiers are supported (but not required) for plug-ins. | 78 // Resource identifiers are supported (but not required) for plug-ins. |
79 bool SupportsResourceIdentifier(ContentSettingsType content_type) { | 79 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
80 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 80 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
81 } | 81 } |
82 | 82 |
83 } // namespace | 83 } // namespace |
84 | 84 |
85 HostContentSettingsMap::HostContentSettingsMap( | 85 HostContentSettingsMap::HostContentSettingsMap( |
86 PrefService* prefs, | 86 PrefService* prefs, |
87 bool incognito) : | 87 bool incognito) : |
88 #ifndef NDEBUG | 88 #ifndef NDEBUG |
89 used_from_thread_id_(base::PlatformThread::CurrentId()), | 89 used_from_thread_id_(base::PlatformThread::CurrentId()), |
90 #endif | 90 #endif |
91 prefs_(prefs), | 91 prefs_(prefs), |
92 is_off_the_record_(incognito) { | 92 is_off_the_record_(incognito), |
| 93 override_(prefs_, is_off_the_record_) { |
93 content_settings::ObservableProvider* policy_provider = | 94 content_settings::ObservableProvider* policy_provider = |
94 new content_settings::PolicyProvider(prefs_); | 95 new content_settings::PolicyProvider(prefs_); |
95 policy_provider->AddObserver(this); | 96 policy_provider->AddObserver(this); |
96 content_settings_providers_[POLICY_PROVIDER] = policy_provider; | 97 content_settings_providers_[POLICY_PROVIDER] = policy_provider; |
97 | 98 |
98 content_settings::ObservableProvider* pref_provider = | 99 content_settings::ObservableProvider* pref_provider = |
99 new content_settings::PrefProvider(prefs_, is_off_the_record_); | 100 new content_settings::PrefProvider(prefs_, is_off_the_record_); |
100 pref_provider->AddObserver(this); | 101 pref_provider->AddObserver(this); |
101 content_settings_providers_[PREF_PROVIDER] = pref_provider; | 102 content_settings_providers_[PREF_PROVIDER] = pref_provider; |
102 | 103 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 159 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
159 registry->RegisterBooleanPref( | 160 registry->RegisterBooleanPref( |
160 prefs::kContentSettingsClearOnExitMigrated, | 161 prefs::kContentSettingsClearOnExitMigrated, |
161 false, | 162 false, |
162 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 163 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
163 | 164 |
164 // Register the prefs for the content settings providers. | 165 // Register the prefs for the content settings providers. |
165 content_settings::DefaultProvider::RegisterProfilePrefs(registry); | 166 content_settings::DefaultProvider::RegisterProfilePrefs(registry); |
166 content_settings::PrefProvider::RegisterProfilePrefs(registry); | 167 content_settings::PrefProvider::RegisterProfilePrefs(registry); |
167 content_settings::PolicyProvider::RegisterProfilePrefs(registry); | 168 content_settings::PolicyProvider::RegisterProfilePrefs(registry); |
| 169 content_settings::OverrideProvider::RegisterProfilePrefs(registry); |
168 } | 170 } |
169 | 171 |
170 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( | 172 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( |
171 ContentSettingsType content_type, | 173 ContentSettingsType content_type, |
172 content_settings::ProviderInterface* provider) const { | 174 content_settings::ProviderInterface* provider) const { |
173 scoped_ptr<content_settings::RuleIterator> rule_iterator( | 175 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
174 provider->GetRuleIterator(content_type, std::string(), false)); | 176 provider->GetRuleIterator(content_type, std::string(), false)); |
175 | 177 |
176 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 178 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
177 while (rule_iterator->HasNext()) { | 179 while (rule_iterator->HasNext()) { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 base::Time HostContentSettingsMap::GetLastUsageByPattern( | 405 base::Time HostContentSettingsMap::GetLastUsageByPattern( |
404 const ContentSettingsPattern& primary_pattern, | 406 const ContentSettingsPattern& primary_pattern, |
405 const ContentSettingsPattern& secondary_pattern, | 407 const ContentSettingsPattern& secondary_pattern, |
406 ContentSettingsType content_type) { | 408 ContentSettingsType content_type) { |
407 UsedContentSettingsProviders(); | 409 UsedContentSettingsProviders(); |
408 | 410 |
409 return GetPrefProvider()->GetLastUsage( | 411 return GetPrefProvider()->GetLastUsage( |
410 primary_pattern, secondary_pattern, content_type); | 412 primary_pattern, secondary_pattern, content_type); |
411 } | 413 } |
412 | 414 |
| 415 ContentSetting HostContentSettingsMap::GetContentSettingWithoutOverride( |
| 416 const GURL& primary_url, |
| 417 const GURL& secondary_url, |
| 418 ContentSettingsType content_type, |
| 419 const std::string& resource_identifier) { |
| 420 scoped_ptr<base::Value> value(GetWebsiteSettingWithoutOverride( |
| 421 primary_url, secondary_url, content_type, resource_identifier, NULL)); |
| 422 return content_settings::ValueToContentSetting(value.get()); |
| 423 } |
| 424 |
| 425 base::Value* HostContentSettingsMap::GetWebsiteSettingWithoutOverride( |
| 426 const GURL& primary_url, |
| 427 const GURL& secondary_url, |
| 428 ContentSettingsType content_type, |
| 429 const std::string& resource_identifier, |
| 430 content_settings::SettingInfo* info) const { |
| 431 ContentSettingsPattern* primary_pattern = NULL; |
| 432 ContentSettingsPattern* secondary_pattern = NULL; |
| 433 if (info) { |
| 434 primary_pattern = &info->primary_pattern; |
| 435 secondary_pattern = &info->secondary_pattern; |
| 436 } |
| 437 |
| 438 // The list of |content_settings_providers_| is ordered according to their |
| 439 // precedence. |
| 440 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 441 provider != content_settings_providers_.end(); |
| 442 ++provider) { |
| 443 base::Value* value = content_settings::GetContentSettingValueAndPatterns( |
| 444 provider->second, primary_url, secondary_url, content_type, |
| 445 resource_identifier, is_off_the_record_, |
| 446 primary_pattern, secondary_pattern); |
| 447 if (value) { |
| 448 if (info) |
| 449 info->source = kProviderSourceMap[provider->first]; |
| 450 return value; |
| 451 } |
| 452 } |
| 453 |
| 454 if (info) { |
| 455 info->source = content_settings::SETTING_SOURCE_NONE; |
| 456 info->primary_pattern = ContentSettingsPattern(); |
| 457 info->secondary_pattern = ContentSettingsPattern(); |
| 458 } |
| 459 return NULL; |
| 460 } |
| 461 |
| 462 void HostContentSettingsMap::SetContentSettingOverride( |
| 463 ContentSettingsType content_type, |
| 464 bool is_enabled) { |
| 465 override_.SetContentSetting(content_type, is_enabled); |
| 466 } |
| 467 |
| 468 bool HostContentSettingsMap::GetContentSettingOverride( |
| 469 ContentSettingsType content_type) { |
| 470 return override_.IsEnabled(content_type); |
| 471 } |
| 472 |
413 void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) { | 473 void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) { |
414 observers_.AddObserver(observer); | 474 observers_.AddObserver(observer); |
415 } | 475 } |
416 | 476 |
417 void HostContentSettingsMap::RemoveObserver( | 477 void HostContentSettingsMap::RemoveObserver( |
418 content_settings::Observer* observer) { | 478 content_settings::Observer* observer) { |
419 observers_.RemoveObserver(observer); | 479 observers_.RemoveObserver(observer); |
420 } | 480 } |
421 | 481 |
422 void HostContentSettingsMap::SetPrefClockForTesting( | 482 void HostContentSettingsMap::SetPrefClockForTesting( |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 // Check if the scheme of the requesting url is whitelisted. | 768 // Check if the scheme of the requesting url is whitelisted. |
709 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { | 769 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { |
710 if (info) { | 770 if (info) { |
711 info->source = content_settings::SETTING_SOURCE_WHITELIST; | 771 info->source = content_settings::SETTING_SOURCE_WHITELIST; |
712 info->primary_pattern = ContentSettingsPattern::Wildcard(); | 772 info->primary_pattern = ContentSettingsPattern::Wildcard(); |
713 info->secondary_pattern = ContentSettingsPattern::Wildcard(); | 773 info->secondary_pattern = ContentSettingsPattern::Wildcard(); |
714 } | 774 } |
715 return new base::FundamentalValue(CONTENT_SETTING_ALLOW); | 775 return new base::FundamentalValue(CONTENT_SETTING_ALLOW); |
716 } | 776 } |
717 | 777 |
718 ContentSettingsPattern* primary_pattern = NULL; | 778 // Check if the content setting is globally disabled. |
719 ContentSettingsPattern* secondary_pattern = NULL; | 779 if (!override_.IsEnabled(content_type)) { |
720 if (info) { | 780 if (info) { |
721 primary_pattern = &info->primary_pattern; | 781 info->source = content_settings::SETTING_SOURCE_USER; |
722 secondary_pattern = &info->secondary_pattern; | 782 info->primary_pattern = ContentSettingsPattern::Wildcard(); |
| 783 info->secondary_pattern = ContentSettingsPattern::Wildcard(); |
| 784 } |
| 785 return new base::FundamentalValue(CONTENT_SETTING_BLOCK); |
723 } | 786 } |
724 | 787 |
725 // The list of |content_settings_providers_| is ordered according to their | 788 return GetWebsiteSettingWithoutOverride( |
726 // precedence. | 789 primary_url, secondary_url, content_type, resource_identifier, info); |
727 for (ConstProviderIterator provider = content_settings_providers_.begin(); | |
728 provider != content_settings_providers_.end(); | |
729 ++provider) { | |
730 base::Value* value = content_settings::GetContentSettingValueAndPatterns( | |
731 provider->second, primary_url, secondary_url, content_type, | |
732 resource_identifier, is_off_the_record_, | |
733 primary_pattern, secondary_pattern); | |
734 if (value) { | |
735 if (info) | |
736 info->source = kProviderSourceMap[provider->first]; | |
737 return value; | |
738 } | |
739 } | |
740 | |
741 if (info) { | |
742 info->source = content_settings::SETTING_SOURCE_NONE; | |
743 info->primary_pattern = ContentSettingsPattern(); | |
744 info->secondary_pattern = ContentSettingsPattern(); | |
745 } | |
746 return NULL; | |
747 } | 790 } |
748 | 791 |
749 // static | 792 // static |
750 HostContentSettingsMap::ProviderType | 793 HostContentSettingsMap::ProviderType |
751 HostContentSettingsMap::GetProviderTypeFromSource( | 794 HostContentSettingsMap::GetProviderTypeFromSource(const std::string& source) { |
752 const std::string& source) { | |
753 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { | 795 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { |
754 if (source == kProviderNames[i]) | 796 if (source == kProviderNames[i]) |
755 return static_cast<ProviderType>(i); | 797 return static_cast<ProviderType>(i); |
756 } | 798 } |
757 | 799 |
758 NOTREACHED(); | 800 NOTREACHED(); |
759 return DEFAULT_PROVIDER; | 801 return DEFAULT_PROVIDER; |
760 } | 802 } |
761 | 803 |
762 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { | 804 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { |
763 return static_cast<content_settings::PrefProvider*>( | 805 return static_cast<content_settings::PrefProvider*>( |
764 content_settings_providers_[PREF_PROVIDER]); | 806 content_settings_providers_[PREF_PROVIDER]); |
765 } | 807 } |
OLD | NEW |