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 40b6fe1be7a169aa97e859c6fa75061111824b90..fb6e04708953e359ceafe1147fa4a57db1ff50ad 100644 |
--- a/chrome/browser/content_settings/host_content_settings_map.cc |
+++ b/chrome/browser/content_settings/host_content_settings_map.cc |
@@ -59,6 +59,7 @@ const char* kProviderNames[] = { |
"platform_app", |
"policy", |
"extension", |
+ "override", |
"preference", |
"default" |
}; |
@@ -69,6 +70,7 @@ content_settings::SettingSource kProviderSourceMap[] = { |
content_settings::SETTING_SOURCE_EXTENSION, |
content_settings::SETTING_SOURCE_USER, |
content_settings::SETTING_SOURCE_USER, |
+ content_settings::SETTING_SOURCE_USER, |
}; |
COMPILE_ASSERT(arraysize(kProviderSourceMap) == |
HostContentSettingsMap::NUM_PROVIDER_TYPES, |
@@ -82,9 +84,9 @@ 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 |
@@ -105,6 +107,9 @@ HostContentSettingsMap::HostContentSettingsMap( |
default_provider->AddObserver(this); |
content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
+ content_settings_providers_[OVERRIDE_PROVIDER] = |
+ new content_settings::OverrideProvider(prefs_, is_off_the_record_); |
+ |
if (!is_off_the_record_) { |
// Migrate obsolete preferences. |
MigrateObsoleteClearOnExitPref(); |
@@ -161,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( |
@@ -190,7 +196,8 @@ ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
for (ConstProviderIterator provider = content_settings_providers_.begin(); |
provider != content_settings_providers_.end(); |
++provider) { |
- if (provider->first == PREF_PROVIDER) |
+ if (provider->first == PREF_PROVIDER || |
+ provider->first == OVERRIDE_PROVIDER) |
continue; |
ContentSetting default_setting = |
GetDefaultContentSettingFromProvider(content_type, provider->second); |
@@ -214,8 +221,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()); |
} |
@@ -232,6 +239,8 @@ void HostContentSettingsMap::GetSettingsForOneType( |
for (ConstProviderIterator provider = content_settings_providers_.begin(); |
provider != content_settings_providers_.end(); |
++provider) { |
+ if (provider->first == OVERRIDE_PROVIDER) |
+ continue; |
// For each provider, iterate first the incognito-specific rules, then the |
// normal rules. |
if (is_off_the_record_) { |
@@ -281,6 +290,8 @@ void HostContentSettingsMap::SetWebsiteSetting( |
for (ProviderIterator provider = content_settings_providers_.begin(); |
provider != content_settings_providers_.end(); |
++provider) { |
+ if (provider->first == OVERRIDE_PROVIDER) |
Bernhard Bauer
2014/09/11 16:49:56
If you use a new method to change overrides, you c
Daniel Nishi
2014/09/11 20:58:12
Done.
|
+ continue; |
if (provider->second->SetWebsiteSetting(primary_pattern, |
secondary_pattern, |
content_type, |
@@ -406,6 +417,58 @@ 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 { |
+ return GetWebsiteSettingInternal(primary_url, |
+ secondary_url, |
+ content_type, |
+ resource_identifier, |
+ info, |
+ false); |
+} |
+ |
+void HostContentSettingsMap::SetContentSettingOverride( |
+ ContentSettingsType content_type, |
+ bool is_enabled) { |
+ UsedContentSettingsProviders(); |
+ |
+ content_settings::OverrideProvider* override = |
+ static_cast<content_settings::OverrideProvider*>( |
+ content_settings_providers_[OVERRIDE_PROVIDER]); |
+ ContentSetting enabled = |
+ is_enabled ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
+ override->SetWebsiteSetting(ContentSettingsPattern::Wildcard(), |
Bernhard Bauer
2014/09/11 16:49:56
If you already cast to OverrideProvider, you can a
Daniel Nishi
2014/09/11 20:58:12
Done.
|
+ ContentSettingsPattern::Wildcard(), |
+ content_type, |
+ std::string(), |
+ new base::FundamentalValue(enabled)); |
+} |
+ |
+bool HostContentSettingsMap::GetContentSettingOverride( |
+ ContentSettingsType content_type) { |
+ UsedContentSettingsProviders(); |
+ |
+ content_settings::OverrideProvider* override = |
+ static_cast<content_settings::OverrideProvider*>( |
+ content_settings_providers_[OVERRIDE_PROVIDER]); |
+ return override->IsEnabled(content_type); |
+} |
+ |
void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) { |
observers_.AddObserver(observer); |
} |
@@ -692,7 +755,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, |
@@ -708,9 +771,43 @@ base::Value* HostContentSettingsMap::GetWebsiteSetting( |
info->primary_pattern = ContentSettingsPattern::Wildcard(); |
info->secondary_pattern = ContentSettingsPattern::Wildcard(); |
} |
- return new base::FundamentalValue(CONTENT_SETTING_ALLOW); |
+ return scoped_ptr<base::Value>( |
+ new base::FundamentalValue(CONTENT_SETTING_ALLOW)); |
+ } |
+ |
+ return GetWebsiteSettingInternal(primary_url, |
+ secondary_url, |
+ content_type, |
+ resource_identifier, |
+ info, |
+ true); |
+} |
+ |
+// static |
+HostContentSettingsMap::ProviderType |
+HostContentSettingsMap::GetProviderTypeFromSource(const std::string& source) { |
+ for (size_t i = 0; i < arraysize(kProviderNames); ++i) { |
+ if (source == kProviderNames[i]) |
+ return static_cast<ProviderType>(i); |
} |
+ NOTREACHED(); |
+ return DEFAULT_PROVIDER; |
+} |
+ |
+content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { |
+ return static_cast<content_settings::PrefProvider*>( |
+ content_settings_providers_[PREF_PROVIDER]); |
+} |
+ |
+scoped_ptr<base::Value> HostContentSettingsMap::GetWebsiteSettingInternal( |
+ const GURL& primary_url, |
+ const GURL& secondary_url, |
+ ContentSettingsType content_type, |
+ const std::string& resource_identifier, |
+ content_settings::SettingInfo* info, |
+ bool get_override) const { |
+ UsedContentSettingsProviders(); |
ContentSettingsPattern* primary_pattern = NULL; |
ContentSettingsPattern* secondary_pattern = NULL; |
if (info) { |
@@ -723,14 +820,27 @@ base::Value* HostContentSettingsMap::GetWebsiteSetting( |
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 (!get_override && provider->first == OVERRIDE_PROVIDER) |
+ continue; |
+ |
+ 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 (provider->first == OVERRIDE_PROVIDER && |
+ content_settings::ValueToContentSetting(value.get()) == |
+ CONTENT_SETTING_ALLOW) { |
Bernhard Bauer
2014/09/11 16:49:56
I think you can avoid this by not storing a value
Daniel Nishi
2014/09/11 20:58:12
Done.
|
+ continue; |
+ } |
if (info) |
info->source = kProviderSourceMap[provider->first]; |
- return value; |
+ return value.Pass(); |
} |
} |
@@ -739,23 +849,5 @@ base::Value* HostContentSettingsMap::GetWebsiteSetting( |
info->primary_pattern = ContentSettingsPattern(); |
info->secondary_pattern = ContentSettingsPattern(); |
} |
- return NULL; |
-} |
- |
-// static |
-HostContentSettingsMap::ProviderType |
- HostContentSettingsMap::GetProviderTypeFromSource( |
- const std::string& source) { |
- for (size_t i = 0; i < arraysize(kProviderNames); ++i) { |
- if (source == kProviderNames[i]) |
- return static_cast<ProviderType>(i); |
- } |
- |
- NOTREACHED(); |
- return DEFAULT_PROVIDER; |
-} |
- |
-content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { |
- return static_cast<content_settings::PrefProvider*>( |
- content_settings_providers_[PREF_PROVIDER]); |
+ return scoped_ptr<base::Value>(); |
} |