Chromium Code Reviews| 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 303ec9855df7551c4c7d78eabbf5190e8278c968..edfe39436eef4bf9494077d58b40dd2630c23b01 100644 |
| --- a/components/content_settings/core/browser/host_content_settings_map.cc |
| +++ b/components/content_settings/core/browser/host_content_settings_map.cc |
| @@ -34,6 +34,8 @@ |
| #include "net/base/static_cookie_policy.h" |
| #include "url/gurl.h" |
| +using content_settings::WebsiteSettingsInfo; |
| + |
| namespace { |
| typedef std::vector<content_settings::Rule> Rules; |
| @@ -106,6 +108,38 @@ scoped_ptr<base::Value> ProcessIncognitoInheritanceBehavior( |
| return value; |
| } |
| +struct PatternPair { |
|
raymes
2016/03/02 04:22:51
nit: it looks like there is already a content_sett
lshang
2016/03/02 05:21:56
Done.
Good catch! Yeah I think we'd better use the
|
| + ContentSettingsPattern primary_pattern; |
| + ContentSettingsPattern secondary_pattern; |
| +}; |
| + |
| +PatternPair GetPatternsFromScopingType( |
| + WebsiteSettingsInfo::ScopingType scoping_type, |
| + const GURL& primary_url, |
| + const GURL& secondary_url) { |
| + PatternPair patterns; |
| + |
| + switch (scoping_type) { |
| + case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: |
| + case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE: |
| + patterns.primary_pattern = ContentSettingsPattern::FromURL(primary_url); |
| + patterns.secondary_pattern = ContentSettingsPattern::Wildcard(); |
| + break; |
| + case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: |
| + patterns.primary_pattern = |
| + ContentSettingsPattern::FromURLNoWildcard(primary_url); |
| + patterns.secondary_pattern = ContentSettingsPattern::Wildcard(); |
| + break; |
| + case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: |
| + patterns.primary_pattern = |
| + ContentSettingsPattern::FromURLNoWildcard(primary_url); |
| + patterns.secondary_pattern = |
| + ContentSettingsPattern::FromURLNoWildcard(secondary_url); |
| + break; |
| + } |
| + return patterns; |
| +} |
| + |
| } // namespace |
| HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
| @@ -283,39 +317,16 @@ void HostContentSettingsMap::SetWebsiteSettingDefaultScope( |
| ContentSettingsType content_type, |
| const std::string& resource_identifier, |
| base::Value* value) { |
| - using content_settings::WebsiteSettingsInfo; |
| - |
| const WebsiteSettingsInfo* info = |
| content_settings::WebsiteSettingsRegistry::GetInstance()->Get( |
| content_type); |
| - ContentSettingsPattern primary_pattern; |
| - ContentSettingsPattern secondary_pattern; |
| - switch (info->scoping_type()) { |
| - case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: |
| - primary_pattern = ContentSettingsPattern::FromURL(top_level_url); |
| - secondary_pattern = ContentSettingsPattern::Wildcard(); |
| - DCHECK(requesting_url.is_empty()); |
| - break; |
| - case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE: |
| - primary_pattern = ContentSettingsPattern::FromURL(requesting_url); |
| - secondary_pattern = ContentSettingsPattern::Wildcard(); |
| - DCHECK(top_level_url.is_empty()); |
| - break; |
| - case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: |
| - primary_pattern = |
| - ContentSettingsPattern::FromURLNoWildcard(requesting_url); |
| - secondary_pattern = ContentSettingsPattern::Wildcard(); |
| - DCHECK(top_level_url.is_empty()); |
| - break; |
| - case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: |
| - primary_pattern = |
| - ContentSettingsPattern::FromURLNoWildcard(requesting_url); |
| - secondary_pattern = |
| - ContentSettingsPattern::FromURLNoWildcard(top_level_url); |
| - break; |
| - } |
| + PatternPair patterns = GetPatternsFromScopingType( |
| + info->scoping_type(), requesting_url, top_level_url); |
| + ContentSettingsPattern primary_pattern = patterns.primary_pattern; |
| + ContentSettingsPattern secondary_pattern = patterns.secondary_pattern; |
| if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) |
| return; |
| + |
| SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type, |
| resource_identifier, make_scoped_ptr(value)); |
| } |
| @@ -437,6 +448,30 @@ void HostContentSettingsMap::SetContentSetting( |
| resource_identifier, std::move(value)); |
| } |
| +void HostContentSettingsMap::SetContentSettingDefaultScope( |
| + const GURL& primary_url, |
| + const GURL& secondary_url, |
| + ContentSettingsType content_type, |
| + const std::string& resource_identifier, |
| + ContentSetting setting) { |
| + using content_settings::ContentSettingsInfo; |
| + const ContentSettingsInfo* info = |
| + content_settings::ContentSettingsRegistry::GetInstance()->Get( |
| + content_type); |
| + DCHECK(info); |
| + |
| + PatternPair patterns = |
| + GetPatternsFromScopingType(info->website_settings_info()->scoping_type(), |
| + primary_url, secondary_url); |
| + ContentSettingsPattern primary_pattern = patterns.primary_pattern; |
| + ContentSettingsPattern secondary_pattern = patterns.secondary_pattern; |
| + if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) |
| + return; |
| + |
| + SetContentSetting(primary_pattern, secondary_pattern, content_type, |
| + resource_identifier, setting); |
| +} |
| + |
| ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
| const GURL& primary_url, |
| const GURL& secondary_url, |