Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map.cc

Issue 542253003: Add a global on/off switch for content settings and expose a toggle on the Website Settings options… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@global-settings
Patch Set: Forgot to clarify ownership comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 kProviderSourceMap_has_incorrect_size); 75 kProviderSourceMap_has_incorrect_size);
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(PrefService* prefs,
86 PrefService* prefs, 86 bool incognito)
87 bool incognito) : 87 :
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
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 NOTREACHED(); 213 NOTREACHED();
212 return CONTENT_SETTING_DEFAULT; 214 return CONTENT_SETTING_DEFAULT;
213 } 215 }
214 216
215 ContentSetting HostContentSettingsMap::GetContentSetting( 217 ContentSetting HostContentSettingsMap::GetContentSetting(
216 const GURL& primary_url, 218 const GURL& primary_url,
217 const GURL& secondary_url, 219 const GURL& secondary_url,
218 ContentSettingsType content_type, 220 ContentSettingsType content_type,
219 const std::string& resource_identifier) const { 221 const std::string& resource_identifier) const {
220 DCHECK(!ContentTypeHasCompoundValue(content_type)); 222 DCHECK(!ContentTypeHasCompoundValue(content_type));
221 scoped_ptr<base::Value> value(GetWebsiteSetting( 223 scoped_ptr<base::Value> value = GetWebsiteSetting(
222 primary_url, secondary_url, content_type, resource_identifier, NULL)); 224 primary_url, secondary_url, content_type, resource_identifier, NULL);
223 return content_settings::ValueToContentSetting(value.get()); 225 return content_settings::ValueToContentSetting(value.get());
224 } 226 }
225 227
226 void HostContentSettingsMap::GetSettingsForOneType( 228 void HostContentSettingsMap::GetSettingsForOneType(
227 ContentSettingsType content_type, 229 ContentSettingsType content_type,
228 const std::string& resource_identifier, 230 const std::string& resource_identifier,
229 ContentSettingsForOneType* settings) const { 231 ContentSettingsForOneType* settings) const {
230 DCHECK(SupportsResourceIdentifier(content_type) || 232 DCHECK(SupportsResourceIdentifier(content_type) ||
231 resource_identifier.empty()); 233 resource_identifier.empty());
232 DCHECK(settings); 234 DCHECK(settings);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 scoped_ptr<base::Value>
426 HostContentSettingsMap::GetWebsiteSettingWithoutOverride(
427 const GURL& primary_url,
428 const GURL& secondary_url,
429 ContentSettingsType content_type,
430 const std::string& resource_identifier,
431 content_settings::SettingInfo* info) const {
432 ContentSettingsPattern* primary_pattern = NULL;
433 ContentSettingsPattern* secondary_pattern = NULL;
434 if (info) {
435 primary_pattern = &info->primary_pattern;
436 secondary_pattern = &info->secondary_pattern;
437 }
438
439 // The list of |content_settings_providers_| is ordered according to their
440 // precedence.
441 for (ConstProviderIterator provider = content_settings_providers_.begin();
442 provider != content_settings_providers_.end();
443 ++provider) {
444 scoped_ptr<base::Value> value(
445 content_settings::GetContentSettingValueAndPatterns(provider->second,
446 primary_url,
447 secondary_url,
448 content_type,
449 resource_identifier,
450 is_off_the_record_,
451 primary_pattern,
452 secondary_pattern));
453 if (value) {
454 if (info)
455 info->source = kProviderSourceMap[provider->first];
456 return value.Pass();
457 }
458 }
459
460 if (info) {
461 info->source = content_settings::SETTING_SOURCE_NONE;
462 info->primary_pattern = ContentSettingsPattern();
463 info->secondary_pattern = ContentSettingsPattern();
464 }
465 return scoped_ptr<base::Value>();
466 }
467
468 void HostContentSettingsMap::SetContentSettingOverride(
469 ContentSettingsType content_type,
470 bool is_enabled) {
471 override_.SetContentSetting(content_type, is_enabled);
472 }
473
474 bool HostContentSettingsMap::GetContentSettingOverride(
475 ContentSettingsType content_type) {
476 return override_.IsEnabled(content_type);
477 }
478
413 void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) { 479 void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) {
414 observers_.AddObserver(observer); 480 observers_.AddObserver(observer);
415 } 481 }
416 482
417 void HostContentSettingsMap::RemoveObserver( 483 void HostContentSettingsMap::RemoveObserver(
418 content_settings::Observer* observer) { 484 content_settings::Observer* observer) {
419 observers_.RemoveObserver(observer); 485 observers_.RemoveObserver(observer);
420 } 486 }
421 487
422 void HostContentSettingsMap::SetPrefClockForTesting( 488 void HostContentSettingsMap::SetPrefClockForTesting(
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 return secondary_url.SchemeIs(extensions::kExtensionScheme); 755 return secondary_url.SchemeIs(extensions::kExtensionScheme);
690 default: 756 default:
691 return true; 757 return true;
692 } 758 }
693 } 759 }
694 #endif 760 #endif
695 return primary_url.SchemeIs(content::kChromeDevToolsScheme) || 761 return primary_url.SchemeIs(content::kChromeDevToolsScheme) ||
696 primary_url.SchemeIs(content::kChromeUIScheme); 762 primary_url.SchemeIs(content::kChromeUIScheme);
697 } 763 }
698 764
699 base::Value* HostContentSettingsMap::GetWebsiteSetting( 765 scoped_ptr<base::Value> HostContentSettingsMap::GetWebsiteSetting(
700 const GURL& primary_url, 766 const GURL& primary_url,
701 const GURL& secondary_url, 767 const GURL& secondary_url,
702 ContentSettingsType content_type, 768 ContentSettingsType content_type,
703 const std::string& resource_identifier, 769 const std::string& resource_identifier,
704 content_settings::SettingInfo* info) const { 770 content_settings::SettingInfo* info) const {
705 DCHECK(SupportsResourceIdentifier(content_type) || 771 DCHECK(SupportsResourceIdentifier(content_type) ||
706 resource_identifier.empty()); 772 resource_identifier.empty());
707 773
708 // Check if the scheme of the requesting url is whitelisted. 774 // Check if the scheme of the requesting url is whitelisted.
709 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { 775 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) {
710 if (info) { 776 if (info) {
711 info->source = content_settings::SETTING_SOURCE_WHITELIST; 777 info->source = content_settings::SETTING_SOURCE_WHITELIST;
712 info->primary_pattern = ContentSettingsPattern::Wildcard(); 778 info->primary_pattern = ContentSettingsPattern::Wildcard();
713 info->secondary_pattern = ContentSettingsPattern::Wildcard(); 779 info->secondary_pattern = ContentSettingsPattern::Wildcard();
714 } 780 }
715 return new base::FundamentalValue(CONTENT_SETTING_ALLOW); 781 return scoped_ptr<base::Value>(
782 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
716 } 783 }
717 784
718 ContentSettingsPattern* primary_pattern = NULL; 785 // Check if the content setting is globally disabled.
719 ContentSettingsPattern* secondary_pattern = NULL; 786 if (!override_.IsEnabled(content_type)) {
720 if (info) { 787 if (info) {
721 primary_pattern = &info->primary_pattern; 788 info->source = content_settings::SETTING_SOURCE_USER;
722 secondary_pattern = &info->secondary_pattern; 789 info->primary_pattern = ContentSettingsPattern::Wildcard();
790 info->secondary_pattern = ContentSettingsPattern::Wildcard();
791 }
792 return scoped_ptr<base::Value>(
793 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
723 } 794 }
724 795
725 // The list of |content_settings_providers_| is ordered according to their 796 return GetWebsiteSettingWithoutOverride(
726 // precedence. 797 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 } 798 }
748 799
749 // static 800 // static
750 HostContentSettingsMap::ProviderType 801 HostContentSettingsMap::ProviderType
751 HostContentSettingsMap::GetProviderTypeFromSource( 802 HostContentSettingsMap::GetProviderTypeFromSource(const std::string& source) {
752 const std::string& source) {
753 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { 803 for (size_t i = 0; i < arraysize(kProviderNames); ++i) {
754 if (source == kProviderNames[i]) 804 if (source == kProviderNames[i])
755 return static_cast<ProviderType>(i); 805 return static_cast<ProviderType>(i);
756 } 806 }
757 807
758 NOTREACHED(); 808 NOTREACHED();
759 return DEFAULT_PROVIDER; 809 return DEFAULT_PROVIDER;
760 } 810 }
761 811
762 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { 812 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() {
763 return static_cast<content_settings::PrefProvider*>( 813 return static_cast<content_settings::PrefProvider*>(
764 content_settings_providers_[PREF_PROVIDER]); 814 content_settings_providers_[PREF_PROVIDER]);
765 } 815 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698