summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraymes <raymes@chromium.org>2015-11-25 18:16:04 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-26 02:16:49 +0000
commit5592f3cdc930a676c72f78e290011e28792abe21 (patch)
treee0dc6e0df70966121586ae8d345244a84f90b73e
parent5c70b66b1b9b5488460c8c048ff7c32542d4c36f (diff)
downloadchromium_src-5592f3cdc930a676c72f78e290011e28792abe21.zip
chromium_src-5592f3cdc930a676c72f78e290011e28792abe21.tar.gz
chromium_src-5592f3cdc930a676c72f78e290011e28792abe21.tar.bz2
Change HostContentSettingsMap::SetWebsiteSetting to use GURLs instead of patterns
This changes SetWebsiteSetting to accept GURLs instead of patterns. The pattern is determined by the WebsiteSettingsInfo::ScopingType instead of directly passed in. BUG=551747 Review URL: https://codereview.chromium.org/1437083002 Cr-Commit-Position: refs/heads/master@{#361791}
-rw-r--r--chrome/browser/banners/app_banner_settings_helper.cc30
-rw-r--r--chrome/browser/engagement/site_engagement_service.cc28
-rw-r--r--chrome/browser/permissions/chooser_context_base.cc11
-rw-r--r--chrome/browser/ssl/chrome_ssl_host_state_delegate.cc22
-rw-r--r--chrome/browser/ssl/ssl_browser_tests.cc10
-rw-r--r--chrome/browser/ui/webui/options/content_settings_handler.cc12
-rw-r--r--components/content_settings/core/browser/host_content_settings_map.cc99
-rw-r--r--components/content_settings/core/browser/host_content_settings_map.h36
-rw-r--r--components/content_settings/core/browser/website_settings_info.h6
9 files changed, 132 insertions, 122 deletions
diff --git a/chrome/browser/banners/app_banner_settings_helper.cc b/chrome/browser/banners/app_banner_settings_helper.cc
index bae9b55..2f0bb43 100644
--- a/chrome/browser/banners/app_banner_settings_helper.cc
+++ b/chrome/browser/banners/app_banner_settings_helper.cc
@@ -168,13 +168,9 @@ void AppBannerSettingsHelper::ClearHistoryForURLs(
HostContentSettingsMap* settings =
HostContentSettingsMapFactory::GetForProfile(profile);
for (const GURL& origin_url : origin_urls) {
- ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url));
- if (!pattern.IsValid())
- continue;
-
- settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(),
- CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(),
- nullptr);
+ settings->SetWebsiteSettingDefaultScope(origin_url, GURL(),
+ CONTENT_SETTINGS_TYPE_APP_BANNER,
+ std::string(), nullptr);
settings->FlushLossyWebsiteSettings();
}
}
@@ -230,10 +226,6 @@ void AppBannerSettingsHelper::RecordBannerEvent(
if (profile->IsOffTheRecord() || package_name_or_start_url.empty())
return;
- ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url));
- if (!pattern.IsValid())
- return;
-
HostContentSettingsMap* settings =
HostContentSettingsMapFactory::GetForProfile(profile);
scoped_ptr<base::DictionaryValue> origin_dict =
@@ -251,9 +243,9 @@ void AppBannerSettingsHelper::RecordBannerEvent(
std::string event_key(kBannerEventKeys[event]);
app_dict->SetDouble(event_key, time.ToInternalValue());
- settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(),
- CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(),
- origin_dict.release());
+ settings->SetWebsiteSettingDefaultScope(origin_url, GURL(),
+ CONTENT_SETTINGS_TYPE_APP_BANNER,
+ std::string(), origin_dict.release());
// App banner content settings are lossy, meaning they will not cause the
// prefs to become dirty. This is fine for most events, as if they are lost it
@@ -275,10 +267,6 @@ void AppBannerSettingsHelper::RecordBannerCouldShowEvent(
if (profile->IsOffTheRecord() || package_name_or_start_url.empty())
return;
- ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url));
- if (!pattern.IsValid())
- return;
-
HostContentSettingsMap* settings =
HostContentSettingsMapFactory::GetForProfile(profile);
scoped_ptr<base::DictionaryValue> origin_dict =
@@ -348,9 +336,9 @@ void AppBannerSettingsHelper::RecordBannerCouldShowEvent(
value->SetDouble(kBannerEngagementKey, engagement);
could_show_list->Append(value.Pass());
- settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(),
- CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(),
- origin_dict.release());
+ settings->SetWebsiteSettingDefaultScope(origin_url, GURL(),
+ CONTENT_SETTINGS_TYPE_APP_BANNER,
+ std::string(), origin_dict.release());
}
bool AppBannerSettingsHelper::ShouldShowBanner(
diff --git a/chrome/browser/engagement/site_engagement_service.cc b/chrome/browser/engagement/site_engagement_service.cc
index 9198efc..b875eb6 100644
--- a/chrome/browser/engagement/site_engagement_service.cc
+++ b/chrome/browser/engagement/site_engagement_service.cc
@@ -421,14 +421,9 @@ void SiteEngagementService::AddPoints(const GURL& url, double points) {
score.AddPoints(points);
if (score.UpdateScoreDict(score_dict.get())) {
- ContentSettingsPattern pattern(
- ContentSettingsPattern::FromURLNoWildcard(url));
- if (!pattern.IsValid())
- return;
-
- settings_map->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(),
- CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
- std::string(), score_dict.release());
+ settings_map->SetWebsiteSettingDefaultScope(
+ url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
+ score_dict.release());
}
}
@@ -453,9 +448,9 @@ void SiteEngagementService::CleanupEngagementScores() {
continue;
}
- settings_map->SetWebsiteSetting(
- site.primary_pattern, ContentSettingsPattern::Wildcard(),
- CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), nullptr);
+ settings_map->SetWebsiteSettingDefaultScope(
+ origin, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
+ nullptr);
}
}
@@ -556,13 +551,8 @@ void SiteEngagementService::GetCountsForOriginsComplete(
if (origin_to_count.second != 0)
continue;
- ContentSettingsPattern pattern(
- ContentSettingsPattern::FromURLNoWildcard(origin_to_count.first));
- if (!pattern.IsValid())
- continue;
-
- settings_map->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(),
- CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
- std::string(), nullptr);
+ settings_map->SetWebsiteSettingDefaultScope(
+ origin_to_count.first, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
+ std::string(), nullptr);
}
}
diff --git a/chrome/browser/permissions/chooser_context_base.cc b/chrome/browser/permissions/chooser_context_base.cc
index 22f043e..16ca2c1 100644
--- a/chrome/browser/permissions/chooser_context_base.cc
+++ b/chrome/browser/permissions/chooser_context_base.cc
@@ -99,14 +99,7 @@ scoped_ptr<base::DictionaryValue> ChooserContextBase::GetWebsiteSetting(
void ChooserContextBase::SetWebsiteSetting(const GURL& requesting_origin,
const GURL& embedding_origin,
scoped_ptr<base::Value> value) {
- ContentSettingsPattern primary_pattern(
- ContentSettingsPattern::FromURLNoWildcard(requesting_origin));
- ContentSettingsPattern secondary_pattern(
- ContentSettingsPattern::FromURLNoWildcard(embedding_origin));
- if (!primary_pattern.IsValid() || !secondary_pattern.IsValid())
- return;
-
- host_content_settings_map_->SetWebsiteSetting(
- primary_pattern, secondary_pattern, data_content_settings_type_,
+ host_content_settings_map_->SetWebsiteSettingDefaultScope(
+ requesting_origin, embedding_origin, data_content_settings_type_,
std::string(), value.release());
}
diff --git a/chrome/browser/ssl/chrome_ssl_host_state_delegate.cc b/chrome/browser/ssl/chrome_ssl_host_state_delegate.cc
index 9de74c8..75b150a 100644
--- a/chrome/browser/ssl/chrome_ssl_host_state_delegate.cc
+++ b/chrome/browser/ssl/chrome_ssl_host_state_delegate.cc
@@ -235,8 +235,6 @@ void ChromeSSLHostStateDelegate::AllowCert(const std::string& host,
const net::X509Certificate& cert,
net::CertStatus error) {
GURL url = GetSecureGURLForHost(host);
- const ContentSettingsPattern pattern =
- ContentSettingsPattern::FromURLNoWildcard(url);
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile_);
scoped_ptr<base::Value> value(map->GetWebsiteSetting(
@@ -263,12 +261,10 @@ void ChromeSSLHostStateDelegate::AllowCert(const std::string& host,
cert_dict->SetIntegerWithoutPathExpansion(GetKey(cert, error), ALLOWED);
// The map takes ownership of the value, so it is released in the call to
- // SetWebsiteSetting.
- map->SetWebsiteSetting(pattern,
- pattern,
- CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS,
- std::string(),
- value.release());
+ // SetWebsiteSettingDefaultScope.
+ map->SetWebsiteSettingDefaultScope(url, GURL(),
+ CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS,
+ std::string(), value.release());
}
void ChromeSSLHostStateDelegate::Clear() {
@@ -331,16 +327,12 @@ ChromeSSLHostStateDelegate::QueryPolicy(const std::string& host,
void ChromeSSLHostStateDelegate::RevokeUserAllowExceptions(
const std::string& host) {
GURL url = GetSecureGURLForHost(host);
- const ContentSettingsPattern pattern =
- ContentSettingsPattern::FromURLNoWildcard(url);
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile_);
- map->SetWebsiteSetting(pattern,
- pattern,
- CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS,
- std::string(),
- NULL);
+ map->SetWebsiteSettingDefaultScope(url, GURL(),
+ CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS,
+ std::string(), NULL);
}
// TODO(jww): This will revoke all of the decisions in the browser context.
diff --git a/chrome/browser/ssl/ssl_browser_tests.cc b/chrome/browser/ssl/ssl_browser_tests.cc
index a348065..3aad838 100644
--- a/chrome/browser/ssl/ssl_browser_tests.cc
+++ b/chrome/browser/ssl/ssl_browser_tests.cc
@@ -1170,12 +1170,10 @@ IN_PROC_BROWSER_TEST_F(SSLUITestWithClientCert, TestWSSClientCert) {
DCHECK(profile);
scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
dict->SetString("ISSUER.CN", "pywebsocket");
- HostContentSettingsMapFactory::GetForProfile(profile)->SetWebsiteSetting(
- ContentSettingsPattern::FromURL(url),
- ContentSettingsPattern::FromURL(url),
- CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
- std::string(),
- dict.release());
+ HostContentSettingsMapFactory::GetForProfile(profile)
+ ->SetWebsiteSettingDefaultScope(
+ url, GURL(), CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
+ std::string(), dict.release());
// Visit a HTTPS page which requires client certs.
ui_test_utils::NavigateToURL(browser(), url);
diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc
index 10ce23a..0ecb0dc 100644
--- a/chrome/browser/ui/webui/options/content_settings_handler.cc
+++ b/chrome/browser/ui/webui/options/content_settings_handler.cc
@@ -1354,14 +1354,12 @@ void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap(
mode == "normal" ? GetContentSettingsMap() :
GetOTRContentSettingsMap();
if (settings_map) {
- settings_map->SetWebsiteSetting(
+ settings_map->SetContentSetting(
ContentSettingsPattern::FromString(pattern),
- secondary_pattern.empty() ?
- ContentSettingsPattern::Wildcard() :
- ContentSettingsPattern::FromString(secondary_pattern),
- type,
- std::string(),
- NULL);
+ secondary_pattern.empty()
+ ? ContentSettingsPattern::Wildcard()
+ : ContentSettingsPattern::FromString(secondary_pattern),
+ type, std::string(), CONTENT_SETTING_DEFAULT);
}
}
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 660cefa..3887bb5 100644
--- a/components/content_settings/core/browser/host_content_settings_map.cc
+++ b/components/content_settings/core/browser/host_content_settings_map.cc
@@ -23,6 +23,7 @@
#include "components/content_settings/core/browser/content_settings_registry.h"
#include "components/content_settings/core/browser/content_settings_rule.h"
#include "components/content_settings/core/browser/content_settings_utils.h"
+#include "components/content_settings/core/browser/website_settings_registry.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
@@ -213,42 +214,58 @@ void HostContentSettingsMap::GetSettingsForOneType(
void HostContentSettingsMap::SetDefaultContentSetting(
ContentSettingsType content_type,
ContentSetting setting) {
- base::Value* value = NULL;
+ scoped_ptr<base::Value> value;
// A value of CONTENT_SETTING_DEFAULT implies deleting the content setting.
if (setting != CONTENT_SETTING_DEFAULT) {
DCHECK(IsDefaultSettingAllowedForType(setting, content_type));
- value = new base::FundamentalValue(setting);
+ value.reset(new base::FundamentalValue(setting));
}
- SetWebsiteSetting(
- ContentSettingsPattern::Wildcard(),
- ContentSettingsPattern::Wildcard(),
- content_type,
- std::string(),
- value);
+ SetWebsiteSettingCustomScope(ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::Wildcard(), content_type,
+ std::string(), value.Pass());
}
-void HostContentSettingsMap::SetWebsiteSetting(
- const ContentSettingsPattern& primary_pattern,
- const ContentSettingsPattern& secondary_pattern,
+void HostContentSettingsMap::SetWebsiteSettingDefaultScope(
+ const GURL& requesting_url,
+ const GURL& top_level_url,
ContentSettingsType content_type,
const std::string& resource_identifier,
base::Value* value) {
- DCHECK(SupportsResourceIdentifier(content_type) ||
- resource_identifier.empty());
- UsedContentSettingsProviders();
+ using content_settings::WebsiteSettingsInfo;
- for (ProviderIterator provider = content_settings_providers_.begin();
- provider != content_settings_providers_.end();
- ++provider) {
- if (provider->second->SetWebsiteSetting(primary_pattern,
- secondary_pattern,
- content_type,
- resource_identifier,
- value)) {
- return;
- }
+ 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;
}
- NOTREACHED();
+ if (!primary_pattern.IsValid() || !secondary_pattern.IsValid())
+ return;
+ SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type,
+ resource_identifier, make_scoped_ptr(value));
}
void HostContentSettingsMap::SetNarrowestContentSetting(
@@ -331,19 +348,16 @@ void HostContentSettingsMap::SetContentSetting(
UpdateLastUsageByPattern(primary_pattern, secondary_pattern, content_type);
}
- base::Value* value = NULL;
+ scoped_ptr<base::Value> value;
// A value of CONTENT_SETTING_DEFAULT implies deleting the content setting.
if (setting != CONTENT_SETTING_DEFAULT) {
DCHECK(content_settings::ContentSettingsRegistry::GetInstance()
->Get(content_type)
->IsSettingValid(setting));
- value = new base::FundamentalValue(setting);
+ value.reset(new base::FundamentalValue(setting));
}
- SetWebsiteSetting(primary_pattern,
- secondary_pattern,
- content_type,
- resource_identifier,
- value);
+ SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type,
+ resource_identifier, value.Pass());
}
ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage(
@@ -497,6 +511,27 @@ void HostContentSettingsMap::ShutdownOnUIThread() {
}
}
+void HostContentSettingsMap::SetWebsiteSettingCustomScope(
+ const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type,
+ const std::string& resource_identifier,
+ scoped_ptr<base::Value> value) {
+ DCHECK(SupportsResourceIdentifier(content_type) ||
+ resource_identifier.empty());
+ UsedContentSettingsProviders();
+
+ base::Value* val = value.release();
+ for (auto& provider_pair : content_settings_providers_) {
+ if (provider_pair.second->SetWebsiteSetting(primary_pattern,
+ secondary_pattern, content_type,
+ resource_identifier, val)) {
+ return;
+ }
+ }
+ NOTREACHED();
+}
+
void HostContentSettingsMap::AddSettingsForOneType(
const content_settings::ProviderInterface* provider,
ProviderType provider_type,
diff --git a/components/content_settings/core/browser/host_content_settings_map.h b/components/content_settings/core/browser/host_content_settings_map.h
index e7a1a49..d493589 100644
--- a/components/content_settings/core/browser/host_content_settings_map.h
+++ b/components/content_settings/core/browser/host_content_settings_map.h
@@ -132,25 +132,30 @@ class HostContentSettingsMap : public content_settings::Observer,
// this pattern.
// NOTICE: This is just a convenience method for content types that use
// |CONTENT_SETTING| as their data type. For content types that use other
- // data types please use the method SetWebsiteSetting.
+ // data types please use the method SetWebsiteSettingDefaultScope().
//
// This should only be called on the UI thread.
+ // TODO(raymes): Create a version of this function which uses the default
+ // scope.
void SetContentSetting(const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const std::string& resource_identifier,
ContentSetting setting);
- // Sets the |value| for the given patterns, |content_type| and
- // |resource_identifier|. Setting the value to NULL causes the default value
- // for that type to be used when loading pages matching this pattern.
+ // Sets the |value| for the default scope of the url that is appropriate for
+ // the given |content_type| and |resource_identifier|. Setting the value to
+ // null removes the default pattern pair for this content type.
//
- // Takes ownership of the passed value.
- void SetWebsiteSetting(const ContentSettingsPattern& primary_pattern,
- const ContentSettingsPattern& secondary_pattern,
- ContentSettingsType content_type,
- const std::string& resource_identifier,
- base::Value* value);
+ // Internally this will call SetWebsiteSettingCustomScope() with the default
+ // scope patterns for the given |content_type|. Developers will generally want
+ // to use this function instead of SetWebsiteSettingCustomScope() unless they
+ // need to specify custom scoping.
+ void SetWebsiteSettingDefaultScope(const GURL& requesting_url,
+ const GURL& top_level_url,
+ ContentSettingsType content_type,
+ const std::string& resource_identifier,
+ base::Value* value);
// Sets the most specific rule that currently defines the setting for the
// given content type. TODO(raymes): Remove this once all content settings
@@ -246,6 +251,17 @@ class HostContentSettingsMap : public content_settings::Observer,
~HostContentSettingsMap() override;
+ // Sets a rule to apply the |value| for all sites matching |pattern|,
+ // |content_type| and |resource_identifier|. Setting the value to null removes
+ // the given pattern pair. Unless adding a custom-scoped setting, most
+ // developers will want to use SetWebsiteSettingDefaultScope() instead.
+ void SetWebsiteSettingCustomScope(
+ const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type,
+ const std::string& resource_identifier,
+ scoped_ptr<base::Value> value);
+
ContentSetting GetDefaultContentSettingFromProvider(
ContentSettingsType content_type,
content_settings::ProviderInterface* provider) const;
diff --git a/components/content_settings/core/browser/website_settings_info.h b/components/content_settings/core/browser/website_settings_info.h
index 532878e..51016ea 100644
--- a/components/content_settings/core/browser/website_settings_info.h
+++ b/components/content_settings/core/browser/website_settings_info.h
@@ -28,13 +28,13 @@ class WebsiteSettingsInfo {
// Settings scoped to the domain of the main frame only.
TOP_LEVEL_DOMAIN_ONLY_SCOPE,
- // Settings scoped to the origin of the requesting frame only.
- REQUESTING_ORIGIN_ONLY_SCOPE,
-
// Settings scoped to the domain of the requesting frame only. This should
// not generally be used.
REQUESTING_DOMAIN_ONLY_SCOPE,
+ // Settings scoped to the origin of the requesting frame only.
+ REQUESTING_ORIGIN_ONLY_SCOPE,
+
// Settings scoped to the combination of the origin of the requesting
// frame and the origin of the top level frame.
REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE