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

Unified 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: Rebase. 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 side-by-side diff with in-line comments
Download patch
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 9c85abff35d0d10ea819b7f8e8bbb9e6776bfa7d..f17e2683b748359489b9946f901280c91c263216 100644
--- a/chrome/browser/content_settings/host_content_settings_map.cc
+++ b/chrome/browser/content_settings/host_content_settings_map.cc
@@ -49,6 +49,7 @@ const char* kProviderNames[] = {
"platform_app",
"policy",
"extension",
+ "override",
"preference",
"default"
};
@@ -59,6 +60,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,
@@ -72,9 +74,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
@@ -95,6 +97,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();
@@ -117,6 +122,7 @@ void HostContentSettingsMap::RegisterProfilePrefs(
content_settings::DefaultProvider::RegisterProfilePrefs(registry);
content_settings::PrefProvider::RegisterProfilePrefs(registry);
content_settings::PolicyProvider::RegisterProfilePrefs(registry);
+ content_settings::OverrideProvider::RegisterProfilePrefs(registry);
}
void HostContentSettingsMap::RegisterProvider(
@@ -164,7 +170,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);
@@ -184,8 +191,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());
}
@@ -202,6 +209,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_) {
@@ -376,6 +385,52 @@ 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]);
+ override->SetOverrideSetting(content_type, is_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);
}
@@ -662,7 +717,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,
@@ -678,9 +733,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) {
@@ -693,14 +782,22 @@ 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 (info)
info->source = kProviderSourceMap[provider->first];
- return value;
+ return value.Pass();
}
}
@@ -709,23 +806,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>();
}

Powered by Google App Engine
This is Rietveld 408576698