| Index: components/content_settings/core/browser/host_content_settings_map.cc
|
| diff --git a/components/content_settings/core/browser/host_content_settings_map.cc b/components/content_settings/core/browser/host_content_settings_map.cc
|
| index 978aff41c2b478be224d5ca13d801825741151ce..e337ff247f26ee1545afc4bef6369106a7ddbed4 100644
|
| --- a/components/content_settings/core/browser/host_content_settings_map.cc
|
| +++ b/components/content_settings/core/browser/host_content_settings_map.cc
|
| @@ -147,20 +147,21 @@ HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs,
|
| prefs_(prefs),
|
| is_off_the_record_(is_incognito_profile || is_guest_profile) {
|
| DCHECK(!(is_incognito_profile && is_guest_profile));
|
| - content_settings::ObservableProvider* policy_provider =
|
| - new content_settings::PolicyProvider(prefs_);
|
| - policy_provider->AddObserver(this);
|
| - content_settings_providers_[POLICY_PROVIDER] = policy_provider;
|
| -
|
| - content_settings::PrefProvider* pref_provider =
|
| - new content_settings::PrefProvider(prefs_, is_off_the_record_);
|
| - pref_provider->AddObserver(this);
|
| - content_settings_providers_[PREF_PROVIDER] = pref_provider;
|
| + content_settings_providers_[POLICY_PROVIDER] =
|
| + policy_provider_ =
|
| + new content_settings::PolicyProvider(prefs_);
|
| + policy_provider_->AddObserver(this);
|
| +
|
| + content_settings_providers_[PREF_PROVIDER] =
|
| + pref_provider_ =
|
| + new content_settings::PrefProvider(prefs_, is_off_the_record_);
|
| +
|
| + pref_provider_->AddObserver(this);
|
| // This ensures that content settings are cleared for the guest profile. This
|
| // wouldn't be needed except that we used to allow settings to be stored for
|
| // the guest profile and so we need to ensure those get cleared.
|
| if (is_guest_profile)
|
| - pref_provider->ClearPrefs();
|
| + pref_provider_->ClearPrefs();
|
|
|
| content_settings::ObservableProvider* default_provider =
|
| new content_settings::DefaultProvider(prefs_, is_off_the_record_);
|
| @@ -219,9 +220,10 @@ ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider(
|
| return CONTENT_SETTING_DEFAULT;
|
| }
|
|
|
| -ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
|
| - ContentSettingsType content_type,
|
| - std::string* provider_id) const {
|
| +HostContentSettingsMap::ContentSettingWithProviderType
|
| +HostContentSettingsMap::GetDefaultContentSetting(
|
| + ContentSettingsType content_type) const {
|
| + ContentSettingWithProviderType ret; // Initialized.
|
| UsedContentSettingsProviders();
|
|
|
| // Iterate through the list of providers and return the first non-NULL value
|
| @@ -241,13 +243,45 @@ ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
|
| .get());
|
| }
|
| if (default_setting != CONTENT_SETTING_DEFAULT) {
|
| - if (provider_id)
|
| - *provider_id = kProviderNamesSourceMap[provider->first].provider_name;
|
| - return default_setting;
|
| + ret.content_setting = default_setting;
|
| + ret.provider_type = provider->first;
|
| + break;
|
| }
|
| }
|
|
|
| - return CONTENT_SETTING_DEFAULT;
|
| + return ret;
|
| +}
|
| +
|
| +// FIXME(huangs): Remove this and fix callers.
|
| +ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
|
| + ContentSettingsType content_type,
|
| + std::string* provider_name) const {
|
| + ContentSettingWithProviderType result =
|
| + GetDefaultContentSetting(content_type);
|
| + if (result.provider_type != NUM_PROVIDER_TYPES && provider_name) {
|
| + *provider_name = kProviderNamesSourceMap[
|
| + result.provider_type].provider_name;
|
| + }
|
| + return result.content_setting;
|
| +}
|
| +
|
| +bool HostContentSettingsMap::AreUserExceptionsAllowedForType(
|
| + ContentSettingsType content_type) const {
|
| + switch (policy_provider_->GetUserExceptionsUsageSettingForType(
|
| + content_type)) {
|
| + case USER_EXCEPTIONS_ALLOW:
|
| + return true;
|
| +
|
| + case USER_EXCEPTIONS_DEFAULT: {
|
| + // Disable if default setting came from policy provider.
|
| + ProviderType default_settings_provider =
|
| + GetDefaultContentSetting(content_type).provider_type;
|
| + return default_settings_provider != POLICY_PROVIDER;
|
| + }
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| + return false;
|
| }
|
|
|
| ContentSetting HostContentSettingsMap::GetContentSetting(
|
| @@ -520,7 +554,7 @@ void HostContentSettingsMap::UpdateLastUsageByPattern(
|
| ContentSettingsType content_type) {
|
| UsedContentSettingsProviders();
|
|
|
| - GetPrefProvider()->UpdateLastUsage(
|
| + pref_provider_->UpdateLastUsage(
|
| primary_pattern, secondary_pattern, content_type);
|
| }
|
|
|
| @@ -540,7 +574,7 @@ base::Time HostContentSettingsMap::GetLastUsageByPattern(
|
| ContentSettingsType content_type) {
|
| UsedContentSettingsProviders();
|
|
|
| - return GetPrefProvider()->GetLastUsage(
|
| + return pref_provider_->GetLastUsage(
|
| primary_pattern, secondary_pattern, content_type);
|
| }
|
|
|
| @@ -561,7 +595,7 @@ void HostContentSettingsMap::SetPrefClockForTesting(
|
| scoped_ptr<base::Clock> clock) {
|
| UsedContentSettingsProviders();
|
|
|
| - GetPrefProvider()->SetClockForTesting(std::move(clock));
|
| + pref_provider_->SetClockForTesting(std::move(clock));
|
| }
|
|
|
| void HostContentSettingsMap::ClearSettingsForOneType(
|
| @@ -726,11 +760,6 @@ HostContentSettingsMap::GetProviderTypeFromSource(const std::string& source) {
|
| 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,
|
| @@ -738,27 +767,59 @@ scoped_ptr<base::Value> HostContentSettingsMap::GetWebsiteSettingInternal(
|
| const std::string& resource_identifier,
|
| content_settings::SettingInfo* info) const {
|
| UsedContentSettingsProviders();
|
| - ContentSettingsPattern* primary_pattern = NULL;
|
| - ContentSettingsPattern* secondary_pattern = NULL;
|
| - if (info) {
|
| - primary_pattern = &info->primary_pattern;
|
| - secondary_pattern = &info->secondary_pattern;
|
| - }
|
| + ContentSettingsPattern primary_pattern;
|
| + ContentSettingsPattern secondary_pattern;
|
| +
|
| + scoped_ptr<base::Value> value_found;
|
| + ProviderType type_found = NUM_PROVIDER_TYPES;
|
| + const content_settings::ProviderInterface* provider_found = nullptr;
|
| +
|
| + ContentSettingsUserExceptionsUsage user_exceptions_allowed =
|
| + policy_provider_->GetUserExceptionsUsageSettingForType(content_type);
|
|
|
| // 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) {
|
| + for (ConstProviderIterator it = content_settings_providers_.begin();
|
| + it != content_settings_providers_.end();
|
| + ++it) {
|
| scoped_ptr<base::Value> value = GetContentSettingValueAndPatterns(
|
| - provider->second, primary_url, secondary_url, content_type,
|
| - resource_identifier, is_off_the_record_, primary_pattern,
|
| - secondary_pattern);
|
| + it->second, primary_url, secondary_url, content_type,
|
| + resource_identifier, is_off_the_record_, &primary_pattern,
|
| + &secondary_pattern);
|
| if (value) {
|
| - if (info)
|
| - info->source = kProviderNamesSourceMap[provider->first].provider_source;
|
| - return value;
|
| + provider_found = it->second;
|
| + type_found = it->first;
|
| + value_found = std::move(value);
|
| + break;
|
| + }
|
| + }
|
| +
|
| + if (value_found) {
|
| + // If we match a PolicyProvider that allows user to specify exceptions,
|
| + // and that we hit the default setting of the PolicyProvider, then use
|
| + // the test
|
| + if (type_found == POLICY_PROVIDER) {
|
| + DCHECK_EQ(policy_provider_, provider_found);
|
| + if (user_exceptions_allowed == USER_EXCEPTIONS_ALLOW &&
|
| + primary_pattern == ContentSettingsPattern::Wildcard() &&
|
| + secondary_pattern == ContentSettingsPattern::Wildcard()) {
|
| + scoped_ptr<base::Value> value = GetContentSettingValueAndPatterns(
|
| + pref_provider_, primary_url, secondary_url, content_type,
|
| + resource_identifier, is_off_the_record_, &primary_pattern,
|
| + &secondary_pattern);
|
| + if (value) {
|
| + type_found = PREF_PROVIDER;
|
| + value_found.reset(value.release());
|
| + }
|
| + }
|
| + }
|
| +
|
| + if (info) {
|
| + info->source = kProviderNamesSourceMap[type_found].provider_source;
|
| + info->primary_pattern = primary_pattern;
|
| + info->secondary_pattern = secondary_pattern;
|
| }
|
| + return value_found;
|
| }
|
|
|
| if (info) {
|
|
|