Index: chrome/browser/content_settings/host_content_settings_map.cc |
diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc |
index fba2d9ac628830df83a307800db94810df0baab4..11ba444e138e78aaf68dd44f4b7c2b714d2d75e3 100644 |
--- a/chrome/browser/content_settings/host_content_settings_map.cc |
+++ b/chrome/browser/content_settings/host_content_settings_map.cc |
@@ -82,14 +82,15 @@ bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
} // namespace |
-HostContentSettingsMap::HostContentSettingsMap( |
- PrefService* prefs, |
- bool incognito) : |
+HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
+ bool incognito) |
+ : |
#ifndef NDEBUG |
used_from_thread_id_(base::PlatformThread::CurrentId()), |
#endif |
prefs_(prefs), |
- is_off_the_record_(incognito) { |
+ is_off_the_record_(incognito), |
+ override_(prefs_, is_off_the_record_) { |
content_settings::ObservableProvider* policy_provider = |
new content_settings::PolicyProvider(prefs_); |
policy_provider->AddObserver(this); |
@@ -165,6 +166,7 @@ void HostContentSettingsMap::RegisterProfilePrefs( |
content_settings::DefaultProvider::RegisterProfilePrefs(registry); |
content_settings::PrefProvider::RegisterProfilePrefs(registry); |
content_settings::PolicyProvider::RegisterProfilePrefs(registry); |
+ content_settings::OverrideProvider::RegisterProfilePrefs(registry); |
} |
ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( |
@@ -218,8 +220,8 @@ ContentSetting HostContentSettingsMap::GetContentSetting( |
ContentSettingsType content_type, |
const std::string& resource_identifier) const { |
DCHECK(!ContentTypeHasCompoundValue(content_type)); |
- scoped_ptr<base::Value> value(GetWebsiteSetting( |
- primary_url, secondary_url, content_type, resource_identifier, NULL)); |
+ scoped_ptr<base::Value> value = GetWebsiteSetting( |
+ primary_url, secondary_url, content_type, resource_identifier, NULL); |
return content_settings::ValueToContentSetting(value.get()); |
} |
@@ -410,6 +412,70 @@ base::Time HostContentSettingsMap::GetLastUsageByPattern( |
primary_pattern, secondary_pattern, content_type); |
} |
+ContentSetting HostContentSettingsMap::GetContentSettingWithoutOverride( |
+ const GURL& primary_url, |
+ const GURL& secondary_url, |
+ ContentSettingsType content_type, |
+ const std::string& resource_identifier) { |
+ scoped_ptr<base::Value> value(GetWebsiteSettingWithoutOverride( |
+ primary_url, secondary_url, content_type, resource_identifier, NULL)); |
+ return content_settings::ValueToContentSetting(value.get()); |
+} |
+ |
+scoped_ptr<base::Value> |
+HostContentSettingsMap::GetWebsiteSettingWithoutOverride( |
+ const GURL& primary_url, |
+ const GURL& secondary_url, |
+ ContentSettingsType content_type, |
+ const std::string& resource_identifier, |
+ content_settings::SettingInfo* info) const { |
+ ContentSettingsPattern* primary_pattern = NULL; |
+ ContentSettingsPattern* secondary_pattern = NULL; |
+ if (info) { |
+ primary_pattern = &info->primary_pattern; |
+ secondary_pattern = &info->secondary_pattern; |
+ } |
+ |
+ // The list of |content_settings_providers_| is ordered according to their |
+ // precedence. |
+ for (ConstProviderIterator provider = content_settings_providers_.begin(); |
+ provider != content_settings_providers_.end(); |
+ ++provider) { |
+ scoped_ptr<base::Value> value( |
+ content_settings::GetContentSettingValueAndPatterns(provider->second, |
+ primary_url, |
+ secondary_url, |
+ content_type, |
+ resource_identifier, |
+ is_off_the_record_, |
+ primary_pattern, |
+ secondary_pattern)); |
+ if (value) { |
+ if (info) |
+ info->source = kProviderSourceMap[provider->first]; |
+ return value.Pass(); |
+ } |
+ } |
+ |
+ if (info) { |
+ info->source = content_settings::SETTING_SOURCE_NONE; |
+ info->primary_pattern = ContentSettingsPattern(); |
+ info->secondary_pattern = ContentSettingsPattern(); |
+ } |
+ return scoped_ptr<base::Value>(); |
+} |
+ |
+void HostContentSettingsMap::SetContentSettingOverride( |
+ ContentSettingsType content_type, |
+ bool is_enabled) { |
+ override_.SetContentSetting(content_type, is_enabled); |
+} |
+ |
+bool HostContentSettingsMap::GetContentSettingOverride( |
+ ContentSettingsType content_type) { |
+ return override_.IsEnabled(content_type); |
+} |
+ |
void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) { |
observers_.AddObserver(observer); |
} |
@@ -696,7 +762,7 @@ bool HostContentSettingsMap::ShouldAllowAllContent( |
primary_url.SchemeIs(content::kChromeUIScheme); |
} |
-base::Value* HostContentSettingsMap::GetWebsiteSetting( |
+scoped_ptr<base::Value> HostContentSettingsMap::GetWebsiteSetting( |
const GURL& primary_url, |
const GURL& secondary_url, |
ContentSettingsType content_type, |
@@ -712,44 +778,28 @@ base::Value* HostContentSettingsMap::GetWebsiteSetting( |
info->primary_pattern = ContentSettingsPattern::Wildcard(); |
info->secondary_pattern = ContentSettingsPattern::Wildcard(); |
} |
- return new base::FundamentalValue(CONTENT_SETTING_ALLOW); |
- } |
- |
- ContentSettingsPattern* primary_pattern = NULL; |
- ContentSettingsPattern* secondary_pattern = NULL; |
- if (info) { |
- primary_pattern = &info->primary_pattern; |
- secondary_pattern = &info->secondary_pattern; |
+ return scoped_ptr<base::Value>( |
+ new base::FundamentalValue(CONTENT_SETTING_ALLOW)); |
} |
- // The list of |content_settings_providers_| is ordered according to their |
- // precedence. |
- for (ConstProviderIterator provider = content_settings_providers_.begin(); |
- provider != content_settings_providers_.end(); |
- ++provider) { |
- base::Value* value = content_settings::GetContentSettingValueAndPatterns( |
- provider->second, primary_url, secondary_url, content_type, |
- resource_identifier, is_off_the_record_, |
- primary_pattern, secondary_pattern); |
- if (value) { |
- if (info) |
- info->source = kProviderSourceMap[provider->first]; |
- return value; |
+ // Check if the content setting is globally disabled. |
+ if (!override_.IsEnabled(content_type)) { |
+ if (info) { |
+ info->source = content_settings::SETTING_SOURCE_USER; |
+ info->primary_pattern = ContentSettingsPattern::Wildcard(); |
+ info->secondary_pattern = ContentSettingsPattern::Wildcard(); |
} |
+ return scoped_ptr<base::Value>( |
+ new base::FundamentalValue(CONTENT_SETTING_BLOCK)); |
} |
- if (info) { |
- info->source = content_settings::SETTING_SOURCE_NONE; |
- info->primary_pattern = ContentSettingsPattern(); |
- info->secondary_pattern = ContentSettingsPattern(); |
- } |
- return NULL; |
+ return GetWebsiteSettingWithoutOverride( |
+ primary_url, secondary_url, content_type, resource_identifier, info); |
} |
// static |
HostContentSettingsMap::ProviderType |
- HostContentSettingsMap::GetProviderTypeFromSource( |
- const std::string& source) { |
+HostContentSettingsMap::GetProviderTypeFromSource(const std::string& source) { |
for (size_t i = 0; i < arraysize(kProviderNames); ++i) { |
if (source == kProviderNames[i]) |
return static_cast<ProviderType>(i); |