Replace SetContentSetting method of the content_settings::Provider interface...

Replace SetContentSetting method of the content_settings::Provider interface with GetWebsiteSetting.

This is part of a series of cleanup CLs to make all content settings Providers and the HostContentSetting map use only |Values| instead of |ContentSettings|. The HostContentSettingsMap should only contain conveniences methods that take |ContentSetting| parameters.

BUG=102637
TEST=HostContentSettingsMapTest*,
     PrefProviderTest*,
     PolicyProviderTest*,
     DefaultProviderTest*,
     ExtensionProviderTest*

Review URL: http://codereview.chromium.org/8539004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110500 0039d316-1c4b-4281-b951-d872f2087c98
parent 5656f8a3
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_ #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_
#define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_ #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_
#include <map>
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/linked_ptr.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "chrome/browser/content_settings/content_settings_observable_provider.h" #include "chrome/browser/content_settings/content_settings_observable_provider.h"
#include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/prefs/pref_change_registrar.h"
...@@ -37,12 +39,12 @@ class DefaultProvider : public ObservableProvider, ...@@ -37,12 +39,12 @@ class DefaultProvider : public ObservableProvider,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
bool incognito) const OVERRIDE; bool incognito) const OVERRIDE;
virtual void SetContentSetting( virtual bool SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern, const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern, const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting content_setting) OVERRIDE; Value* value) OVERRIDE;
virtual void ClearAllContentSettingsRules( virtual void ClearAllContentSettingsRules(
ContentSettingsType content_type) OVERRIDE; ContentSettingsType content_type) OVERRIDE;
...@@ -56,8 +58,7 @@ class DefaultProvider : public ObservableProvider, ...@@ -56,8 +58,7 @@ class DefaultProvider : public ObservableProvider,
private: private:
// Sets the fields of |settings| based on the values in |dictionary|. // Sets the fields of |settings| based on the values in |dictionary|.
void GetSettingsFromDictionary(const base::DictionaryValue* dictionary, void GetSettingsFromDictionary(const base::DictionaryValue* dictionary);
ContentSetting* settings);
// Forces the default settings to be explicitly set instead of themselves // Forces the default settings to be explicitly set instead of themselves
// being CONTENT_SETTING_DEFAULT. // being CONTENT_SETTING_DEFAULT.
...@@ -70,8 +71,10 @@ class DefaultProvider : public ObservableProvider, ...@@ -70,8 +71,10 @@ class DefaultProvider : public ObservableProvider,
void MigrateObsoleteNotificationPref(); void MigrateObsoleteNotificationPref();
void MigrateObsoleteGeolocationPref(); void MigrateObsoleteGeolocationPref();
typedef linked_ptr<base::Value> ValuePtr;
typedef std::map<ContentSettingsType, ValuePtr> ValueMap;
// Copies of the pref data, so that we can read it on the IO thread. // Copies of the pref data, so that we can read it on the IO thread.
ContentSetting default_content_settings_[CONTENT_SETTINGS_NUM_TYPES]; ValueMap default_settings_;
PrefService* prefs_; PrefService* prefs_;
......
...@@ -43,11 +43,12 @@ TEST_F(DefaultProviderTest, DefaultValues) { ...@@ -43,11 +43,12 @@ TEST_F(DefaultProviderTest, DefaultValues) {
CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTINGS_TYPE_COOKIES,
std::string(), std::string(),
false)); false));
provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), provider_.SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_COOKIES, ContentSettingsPattern::Wildcard(),
std::string(), CONTENT_SETTINGS_TYPE_COOKIES,
CONTENT_SETTING_BLOCK); std::string(),
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(&provider_, GetContentSetting(&provider_,
GURL(), GURL(),
...@@ -63,11 +64,12 @@ TEST_F(DefaultProviderTest, DefaultValues) { ...@@ -63,11 +64,12 @@ TEST_F(DefaultProviderTest, DefaultValues) {
CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTINGS_TYPE_GEOLOCATION,
std::string(), std::string(),
false)); false));
provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), provider_.SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_GEOLOCATION, ContentSettingsPattern::Wildcard(),
std::string(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
CONTENT_SETTING_BLOCK); std::string(),
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(&provider_, GetContentSetting(&provider_,
GURL(), GURL(),
...@@ -88,11 +90,15 @@ TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) { ...@@ -88,11 +90,15 @@ TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) {
CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTINGS_TYPE_COOKIES,
std::string(), std::string(),
false)); false));
provider_.SetContentSetting(ContentSettingsPattern::FromURL(primary_url), scoped_ptr<base::Value> value(
ContentSettingsPattern::FromURL(secondary_url), Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
CONTENT_SETTINGS_TYPE_COOKIES, bool owned = provider_.SetWebsiteSetting(
std::string(), ContentSettingsPattern::FromURL(primary_url),
CONTENT_SETTING_BLOCK); ContentSettingsPattern::FromURL(secondary_url),
CONTENT_SETTINGS_TYPE_COOKIES,
std::string(),
value.get());
EXPECT_FALSE(owned);
EXPECT_EQ(CONTENT_SETTING_ALLOW, EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(&provider_, GetContentSetting(&provider_,
primary_url, primary_url,
...@@ -108,20 +114,22 @@ TEST_F(DefaultProviderTest, Observer) { ...@@ -108,20 +114,22 @@ TEST_F(DefaultProviderTest, Observer) {
OnContentSettingChanged( OnContentSettingChanged(
_, _, CONTENT_SETTINGS_TYPE_IMAGES, "")); _, _, CONTENT_SETTINGS_TYPE_IMAGES, ""));
provider_.AddObserver(&mock_observer); provider_.AddObserver(&mock_observer);
provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), provider_.SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES, ContentSettingsPattern::Wildcard(),
std::string(), CONTENT_SETTINGS_TYPE_IMAGES,
CONTENT_SETTING_BLOCK); std::string(),
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_CALL(mock_observer, EXPECT_CALL(mock_observer,
OnContentSettingChanged( OnContentSettingChanged(
_, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), provider_.SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_GEOLOCATION, ContentSettingsPattern::Wildcard(),
std::string(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
CONTENT_SETTING_BLOCK); std::string(),
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
} }
...@@ -132,11 +140,12 @@ TEST_F(DefaultProviderTest, ObserveDefaultPref) { ...@@ -132,11 +140,12 @@ TEST_F(DefaultProviderTest, ObserveDefaultPref) {
scoped_ptr<Value> default_value(prefs->FindPreference( scoped_ptr<Value> default_value(prefs->FindPreference(
prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), provider_.SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_COOKIES, ContentSettingsPattern::Wildcard(),
std::string(), CONTENT_SETTINGS_TYPE_COOKIES,
CONTENT_SETTING_BLOCK); std::string(),
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(&provider_, GetContentSetting(&provider_,
GURL(), GURL(),
...@@ -189,11 +198,12 @@ TEST_F(DefaultProviderTest, OffTheRecord) { ...@@ -189,11 +198,12 @@ TEST_F(DefaultProviderTest, OffTheRecord) {
// Changing content settings on the main provider should also affect the // Changing content settings on the main provider should also affect the
// incognito map. // incognito map.
provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), provider_.SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_COOKIES, ContentSettingsPattern::Wildcard(),
std::string(), CONTENT_SETTINGS_TYPE_COOKIES,
CONTENT_SETTING_BLOCK); std::string(),
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(&provider_, GetContentSetting(&provider_,
GURL(), GURL(),
...@@ -211,11 +221,15 @@ TEST_F(DefaultProviderTest, OffTheRecord) { ...@@ -211,11 +221,15 @@ TEST_F(DefaultProviderTest, OffTheRecord) {
true)); true));
// Changing content settings on the incognito provider should be ignored. // Changing content settings on the incognito provider should be ignored.
otr_provider.SetContentSetting(ContentSettingsPattern::Wildcard(), scoped_ptr<base::Value> value(
ContentSettingsPattern::Wildcard(), Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
CONTENT_SETTINGS_TYPE_COOKIES, bool owned = otr_provider.SetWebsiteSetting(
std::string(), ContentSettingsPattern::Wildcard(),
CONTENT_SETTING_ALLOW); ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_COOKIES,
std::string(),
value.get());
EXPECT_FALSE(owned);
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(&provider_, GetContentSetting(&provider_,
GURL(), GURL(),
......
...@@ -31,6 +31,15 @@ RuleIterator* ExtensionProvider::GetRuleIterator( ...@@ -31,6 +31,15 @@ RuleIterator* ExtensionProvider::GetRuleIterator(
incognito); incognito);
} }
bool ExtensionProvider::SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
Value* value) {
return false;
}
void ExtensionProvider::ShutdownOnUIThread() { void ExtensionProvider::ShutdownOnUIThread() {
RemoveAllObservers(); RemoveAllObservers();
extensions_settings_->RemoveObserver(this); extensions_settings_->RemoveObserver(this);
......
...@@ -28,12 +28,12 @@ class ExtensionProvider : public ObservableProvider, ...@@ -28,12 +28,12 @@ class ExtensionProvider : public ObservableProvider,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
bool incognito) const OVERRIDE; bool incognito) const OVERRIDE;
virtual void SetContentSetting( virtual bool SetWebsiteSetting(
const ContentSettingsPattern& embedded_url_pattern, const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& top_level_url_pattern, const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting content_setting) OVERRIDE {} Value* value) OVERRIDE;
virtual void ClearAllContentSettingsRules(ContentSettingsType content_type) virtual void ClearAllContentSettingsRules(ContentSettingsType content_type)
OVERRIDE {} OVERRIDE {}
......
...@@ -33,20 +33,21 @@ RuleIterator* MockProvider::GetRuleIterator( ...@@ -33,20 +33,21 @@ RuleIterator* MockProvider::GetRuleIterator(
return value_map_.GetRuleIterator(content_type, resource_identifier, NULL); return value_map_.GetRuleIterator(content_type, resource_identifier, NULL);
} }
void MockProvider::SetContentSetting( bool MockProvider::SetWebsiteSetting(
const ContentSettingsPattern& requesting_url_pattern, const ContentSettingsPattern& requesting_url_pattern,
const ContentSettingsPattern& embedding_url_pattern, const ContentSettingsPattern& embedding_url_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting content_setting) { base::Value* value) {
if (read_only_) if (read_only_)
return; return false;
value_map_.clear(); value_map_.clear();
value_map_.SetValue(requesting_url_pattern, value_map_.SetValue(requesting_url_pattern,
embedding_url_pattern, embedding_url_pattern,
content_type, content_type,
resource_identifier, resource_identifier,
Value::CreateIntegerValue(content_setting)); value);
return true;
} }
void MockProvider::ShutdownOnUIThread() { void MockProvider::ShutdownOnUIThread() {
......
...@@ -35,12 +35,12 @@ class MockProvider : public ObservableProvider { ...@@ -35,12 +35,12 @@ class MockProvider : public ObservableProvider {
// The MockProvider is only able to store one content setting. So every time // The MockProvider is only able to store one content setting. So every time
// this method is called the previously set content settings is overwritten. // this method is called the previously set content settings is overwritten.
virtual void SetContentSetting( virtual bool SetWebsiteSetting(
const ContentSettingsPattern& requesting_url_pattern, const ContentSettingsPattern& requesting_url_pattern,
const ContentSettingsPattern& embedding_url_pattern, const ContentSettingsPattern& embedding_url_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting content_setting) OVERRIDE; base::Value* value) OVERRIDE;
virtual void ClearAllContentSettingsRules( virtual void ClearAllContentSettingsRules(
ContentSettingsType content_type) OVERRIDE {} ContentSettingsType content_type) OVERRIDE {}
......
...@@ -384,12 +384,13 @@ void PolicyProvider::ReadManagedContentSettings(bool overwrite) { ...@@ -384,12 +384,13 @@ void PolicyProvider::ReadManagedContentSettings(bool overwrite) {
// Since the PolicyProvider is a read only content settings provider, all // Since the PolicyProvider is a read only content settings provider, all
// methodes of the ProviderInterface that set or delete any settings do nothing. // methodes of the ProviderInterface that set or delete any settings do nothing.
void PolicyProvider::SetContentSetting( bool PolicyProvider::SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern, const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern, const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting content_setting) { Value* value) {
return false;
} }
void PolicyProvider::ClearAllContentSettingsRules( void PolicyProvider::ClearAllContentSettingsRules(
......
...@@ -35,12 +35,12 @@ class PolicyProvider : public ObservableProvider, ...@@ -35,12 +35,12 @@ class PolicyProvider : public ObservableProvider,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
bool incognito) const OVERRIDE; bool incognito) const OVERRIDE;
virtual void SetContentSetting( virtual bool SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern, const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern, const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting content_setting) OVERRIDE; Value* value) OVERRIDE;
virtual void ClearAllContentSettingsRules( virtual void ClearAllContentSettingsRules(
ContentSettingsType content_type) OVERRIDE; ContentSettingsType content_type) OVERRIDE;
......
...@@ -190,13 +190,16 @@ TEST_F(PolicyProviderTest, GettingManagedContentSettings) { ...@@ -190,13 +190,16 @@ TEST_F(PolicyProviderTest, GettingManagedContentSettings) {
// The PolicyProvider does not allow setting content settings as they are // The PolicyProvider does not allow setting content settings as they are
// enforced via policies and not set by the user or extension. So a call to // enforced via policies and not set by the user or extension. So a call to
// SetContentSetting does nothing. // SetWebsiteSetting does nothing.
provider.SetContentSetting( scoped_ptr<base::Value> value_block(
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
bool owned = provider.SetWebsiteSetting(
yt_url_pattern, yt_url_pattern,
yt_url_pattern, yt_url_pattern,
CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTINGS_TYPE_COOKIES,
"", "",
CONTENT_SETTING_BLOCK); value_block.get());
EXPECT_FALSE(owned);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, EXPECT_EQ(CONTENT_SETTING_DEFAULT,
GetContentSetting( GetContentSetting(
&provider, youtube_url, youtube_url, &provider, youtube_url, youtube_url,
......
...@@ -44,12 +44,12 @@ class PrefProvider : public ObservableProvider, ...@@ -44,12 +44,12 @@ class PrefProvider : public ObservableProvider,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
bool incognito) const OVERRIDE; bool incognito) const OVERRIDE;
virtual void SetContentSetting( virtual bool SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern, const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern, const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting content_setting) OVERRIDE; Value* value) OVERRIDE;
virtual void ClearAllContentSettingsRules( virtual void ClearAllContentSettingsRules(
ContentSettingsType content_type) OVERRIDE; ContentSettingsType content_type) OVERRIDE;
...@@ -77,7 +77,7 @@ class PrefProvider : public ObservableProvider, ...@@ -77,7 +77,7 @@ class PrefProvider : public ObservableProvider,
const ContentSettingsPattern& secondary_pattern, const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting setting); const base::Value* value);
// Updates the given |pattern_pairs_settings| dictionary value. // Updates the given |pattern_pairs_settings| dictionary value.
void UpdatePatternPairsSettings( void UpdatePatternPairsSettings(
...@@ -85,7 +85,7 @@ class PrefProvider : public ObservableProvider, ...@@ -85,7 +85,7 @@ class PrefProvider : public ObservableProvider,
const ContentSettingsPattern& secondary_pattern, const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting setting, const base::Value* value,
DictionaryValue* pattern_pairs_settings); DictionaryValue* pattern_pairs_settings);
// Updates the preferences prefs::kContentSettingsPatterns. This preferences // Updates the preferences prefs::kContentSettingsPatterns. This preferences
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "base/values.h"
#include "chrome/browser/content_settings/content_settings_mock_observer.h" #include "chrome/browser/content_settings/content_settings_mock_observer.h"
#include "chrome/browser/content_settings/content_settings_utils.h" #include "chrome/browser/content_settings/content_settings_utils.h"
#include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/browser_prefs.h"
...@@ -133,12 +134,12 @@ TEST_F(PrefProviderTest, Observer) { ...@@ -133,12 +134,12 @@ TEST_F(PrefProviderTest, Observer) {
pref_content_settings_provider.AddObserver(&mock_observer); pref_content_settings_provider.AddObserver(&mock_observer);
pref_content_settings_provider.SetContentSetting( pref_content_settings_provider.SetWebsiteSetting(
pattern, pattern,
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTINGS_TYPE_IMAGES,
"", "",
CONTENT_SETTING_ALLOW); Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
pref_content_settings_provider.ShutdownOnUIThread(); pref_content_settings_provider.ShutdownOnUIThread();
} }
...@@ -172,12 +173,12 @@ TEST_F(PrefProviderTest, Incognito) { ...@@ -172,12 +173,12 @@ TEST_F(PrefProviderTest, Incognito) {
PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); PrefProvider pref_content_settings_provider_incognito(otr_prefs, true);
ContentSettingsPattern pattern = ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com"); ContentSettingsPattern::FromString("[*.]example.com");
pref_content_settings_provider.SetContentSetting( pref_content_settings_provider.SetWebsiteSetting(
pattern, pattern,
pattern, pattern,
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTINGS_TYPE_IMAGES,
"", "",
CONTENT_SETTING_ALLOW); Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
GURL host("http://example.com/"); GURL host("http://example.com/");
// The value should of course be visible in the regular PrefProvider. // The value should of course be visible in the regular PrefProvider.
...@@ -214,11 +215,12 @@ TEST_F(PrefProviderTest, GetContentSettingsValue) { ...@@ -214,11 +215,12 @@ TEST_F(PrefProviderTest, GetContentSettingsValue) {
&provider, primary_url, primary_url, &provider, primary_url, primary_url,
CONTENT_SETTINGS_TYPE_IMAGES, "", false)); CONTENT_SETTINGS_TYPE_IMAGES, "", false));
provider.SetContentSetting(primary_pattern, provider.SetWebsiteSetting(
primary_pattern, primary_pattern,
CONTENT_SETTINGS_TYPE_IMAGES, primary_pattern,
"", CONTENT_SETTINGS_TYPE_IMAGES,
CONTENT_SETTING_BLOCK); "",
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(&provider, primary_url, primary_url, GetContentSetting(&provider, primary_url, primary_url,
CONTENT_SETTINGS_TYPE_IMAGES, "", false)); CONTENT_SETTINGS_TYPE_IMAGES, "", false));
...@@ -229,11 +231,11 @@ TEST_F(PrefProviderTest, GetContentSettingsValue) { ...@@ -229,11 +231,11 @@ TEST_F(PrefProviderTest, GetContentSettingsValue) {
value_ptr->GetAsInteger(&int_value); value_ptr->GetAsInteger(&int_value);
EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value));
provider.SetContentSetting(primary_pattern, provider.SetWebsiteSetting(primary_pattern,
primary_pattern, primary_pattern,
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTINGS_TYPE_IMAGES,
"", "",
CONTENT_SETTING_DEFAULT); NULL);
EXPECT_EQ(NULL, EXPECT_EQ(NULL,
GetContentSettingValue( GetContentSettingValue(
&provider, primary_url, primary_url, &provider, primary_url, primary_url,
...@@ -261,12 +263,12 @@ TEST_F(PrefProviderTest, Patterns) { ...@@ -261,12 +263,12 @@ TEST_F(PrefProviderTest, Patterns) {
GetContentSetting( GetContentSetting(
&pref_content_settings_provider, &pref_content_settings_provider,
host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, "", false));
pref_content_settings_provider.SetContentSetting( pref_content_settings_provider.SetWebsiteSetting(
pattern1, pattern1,
pattern1, pattern1,
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTINGS_TYPE_IMAGES,
"", "",
CONTENT_SETTING_BLOCK); Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting( GetContentSetting(
&pref_content_settings_provider, &pref_content_settings_provider,
...@@ -280,12 +282,12 @@ TEST_F(PrefProviderTest, Patterns) { ...@@ -280,12 +282,12 @@ TEST_F(PrefProviderTest, Patterns) {
GetContentSetting( GetContentSetting(
&pref_content_settings_provider, &pref_content_settings_provider,
host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, "", false));
pref_content_settings_provider.SetContentSetting( pref_content_settings_provider.SetWebsiteSetting(
pattern2, pattern2,
pattern2, pattern2,
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTINGS_TYPE_IMAGES,
"", "",
CONTENT_SETTING_BLOCK); Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting( GetContentSetting(
&pref_content_settings_provider, &pref_content_settings_provider,
...@@ -295,12 +297,12 @@ TEST_F(PrefProviderTest, Patterns) { ...@@ -295,12 +297,12 @@ TEST_F(PrefProviderTest, Patterns) {
GetContentSetting(&pref_content_settings_provider, GetContentSetting(&pref_content_settings_provider,
host4, host4, CONTENT_SETTINGS_TYPE_IMAGES, "", host4, host4, CONTENT_SETTINGS_TYPE_IMAGES, "",
false)); false));
pref_content_settings_provider.SetContentSetting( pref_content_settings_provider.SetWebsiteSetting(
pattern3, pattern3,
pattern3, pattern3,
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTINGS_TYPE_IMAGES,
"", "",
CONTENT_SETTING_BLOCK); Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting( GetContentSetting(
&pref_content_settings_provider, &pref_content_settings_provider,
...@@ -325,12 +327,12 @@ TEST_F(PrefProviderTest, ResourceIdentifier) { ...@@ -325,12 +327,12 @@ TEST_F(PrefProviderTest, ResourceIdentifier) {
&pref_content_settings_provider, &pref_content_settings_provider,
host, host, CONTENT_SETTINGS_TYPE_PLUGINS, host, host, CONTENT_SETTINGS_TYPE_PLUGINS,
resource1, false)); resource1, false));
pref_content_settings_provider.SetContentSetting( pref_content_settings_provider.SetWebsiteSetting(
pattern, pattern,
pattern, pattern,
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTINGS_TYPE_PLUGINS,
resource1, resource1,
CONTENT_SETTING_BLOCK); Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting( GetContentSetting(
&pref_content_settings_provider, &pref_content_settings_provider,
...@@ -413,11 +415,11 @@ TEST_F(PrefProviderTest, SyncObsoletePref) { ...@@ -413,11 +415,11 @@ TEST_F(PrefProviderTest, SyncObsoletePref) {
ContentSettingsPattern::FromString("[*.]example.com"); ContentSettingsPattern::FromString("[*.]example.com");
ContentSettingsPattern secondary_pattern = ContentSettingsPattern secondary_pattern =
ContentSettingsPattern::Wildcard(); ContentSettingsPattern::Wildcard();
provider.SetContentSetting(primary_pattern, provider.SetWebsiteSetting(primary_pattern,
secondary_pattern, secondary_pattern,
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string(), std::string(),
CONTENT_SETTING_BLOCK); Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
// Test whether the obsolete preference is synced correctly. // Test whether the obsolete preference is synced correctly.
patterns = prefs->GetDictionary(prefs::kContentSettingsPatterns); patterns = prefs->GetDictionary(prefs::kContentSettingsPatterns);
...@@ -679,12 +681,12 @@ TEST_F(PrefProviderTest, AutoSubmitCertificateContentSetting) { ...@@ -679,12 +681,12 @@ TEST_F(PrefProviderTest, AutoSubmitCertificateContentSetting) {
std::string(), std::string(),
false)); false));
provider.SetContentSetting( provider.SetWebsiteSetting(
ContentSettingsPattern::FromURL(primary_url), ContentSettingsPattern::FromURL(primary_url),
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
std::string(), std::string(),
CONTENT_SETTING_ALLOW); Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
EXPECT_EQ(CONTENT_SETTING_ALLOW, EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting( GetContentSetting(
&provider, &provider,
......
...@@ -42,19 +42,20 @@ class ProviderInterface { ...@@ -42,19 +42,20 @@ class ProviderInterface {
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
bool incognito) const = 0; bool incognito) const = 0;
// Sets the content setting for a particular |primary_pattern|, // Askes the provider to set the website setting for a particular
// |secondary_pattern|, |content_type| tuple. For ContentSettingsTypes that // |primary_pattern|, |secondary_pattern|, |content_type| tuple. If the
// require a resource identifier to be specified, the |resource_identifier| // provider accepts the setting it returns true and takes the ownership of the
// must be non-empty. // |value|. Otherwise false is returned and the ownership of the |value| stays
// with the caller.
// //
// This should only be called on the UI thread, and not after // This should only be called on the UI thread, and not after
// ShutdownOnUIThread has been called. // ShutdownOnUIThread has been called.
virtual void SetContentSetting( virtual bool SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern, const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern, const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
ContentSetting content_setting) = 0; Value* value) = 0;
// Resets all content settings for the given |content_type| and empty resource // Resets all content settings for the given |content_type| and empty resource
// identifier to CONTENT_SETTING_DEFAULT. // identifier to CONTENT_SETTING_DEFAULT.
......
...@@ -53,24 +53,28 @@ TEST(ContentSettingsProviderTest, Mock) { ...@@ -53,24 +53,28 @@ TEST(ContentSettingsProviderTest, Mock) {
CONTENT_SETTINGS_TYPE_GEOLOCATION, "", CONTENT_SETTINGS_TYPE_GEOLOCATION, "",
false)); false));
mock_provider.SetContentSetting( bool owned = mock_provider.SetWebsiteSetting(
pattern, pattern,
pattern, pattern,
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTINGS_TYPE_PLUGINS,
"java_plugin", "java_plugin",
CONTENT_SETTING_ALLOW); Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
EXPECT_TRUE(owned);
EXPECT_EQ(CONTENT_SETTING_ALLOW, EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(&mock_provider, url, url, GetContentSetting(&mock_provider, url, url,
CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin",
false)); false));
mock_provider.set_read_only(true); mock_provider.set_read_only(true);
mock_provider.SetContentSetting( scoped_ptr<base::Value> value(
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
owned = mock_provider.SetWebsiteSetting(
pattern, pattern,
pattern, pattern,
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTINGS_TYPE_PLUGINS,
"java_plugin", "java_plugin",
CONTENT_SETTING_BLOCK); value.get());
EXPECT_FALSE(owned);
EXPECT_EQ(CONTENT_SETTING_ALLOW, EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(&mock_provider, url, url, GetContentSetting(&mock_provider, url, url,
CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin",
...@@ -79,12 +83,13 @@ TEST(ContentSettingsProviderTest, Mock) { ...@@ -79,12 +83,13 @@ TEST(ContentSettingsProviderTest, Mock) {
EXPECT_TRUE(mock_provider.read_only()); EXPECT_TRUE(mock_provider.read_only());
mock_provider.set_read_only(false); mock_provider.set_read_only(false);
mock_provider.SetContentSetting( owned = mock_provider.SetWebsiteSetting(
pattern, pattern,
pattern, pattern,
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTINGS_TYPE_PLUGINS,
"java_plugin", "java_plugin",
CONTENT_SETTING_BLOCK); Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_TRUE(owned);
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(&mock_provider, url, url, GetContentSetting(&mock_provider, url, url,
CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin",
......
...@@ -210,34 +210,53 @@ void HostContentSettingsMap::SetDefaultContentSetting( ...@@ -210,34 +210,53 @@ void HostContentSettingsMap::SetDefaultContentSetting(
DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
DCHECK(IsSettingAllowedForType(setting, content_type)); DCHECK(IsSettingAllowedForType(setting, content_type));
content_settings_providers_[DEFAULT_PROVIDER]->SetContentSetting( base::Value* value = Value::CreateIntegerValue(setting);
content_settings_providers_[DEFAULT_PROVIDER]->SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
content_type, content_type,
std::string(), std::string(),
setting); value);
} }
void HostContentSettingsMap::SetContentSetting( void HostContentSettingsMap::SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern, const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern, const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type, ContentSettingsType content_type,
const std::string& resource_identifier, const std::string& resource_identifier,
ContentSetting setting) { base::Value* value) {
DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); DCHECK(IsValueAllowedForType(value, content_type));
DCHECK(IsSettingAllowedForType(setting, content_type));
DCHECK(content_settings::SupportsResourceIdentifier(content_type) || DCHECK(content_settings::SupportsResourceIdentifier(content_type) ||
resource_identifier.empty()); resource_identifier.empty());
for (ProviderIterator provider = content_settings_providers_.begin(); for (ProviderIterator provider = content_settings_providers_.begin();
provider != content_settings_providers_.end(); provider != content_settings_providers_.end();
++provider) { ++provider) {
provider->second->SetContentSetting( if (provider->second->SetWebsiteSetting(primary_pattern,
primary_pattern, secondary_pattern,
secondary_pattern, content_type,
content_type, resource_identifier,
resource_identifier, value)) {
setting); return;
}
} }
NOTREACHED();
}
void HostContentSettingsMap::SetContentSetting(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const std::string& resource_identifier,
ContentSetting setting) {
DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
base::Value* value = NULL;
if (setting != CONTENT_SETTING_DEFAULT)
value = Value::CreateIntegerValue(setting);
SetWebsiteSetting(primary_pattern,
secondary_pattern,
content_type,
resource_identifier,
value);
} }
void HostContentSettingsMap::AddExceptionForURL( void HostContentSettingsMap::AddExceptionForURL(
...@@ -274,6 +293,12 @@ void HostContentSettingsMap::ClearSettingsForOneType( ...@@ -274,6 +293,12 @@ void HostContentSettingsMap::ClearSettingsForOneType(
} }
} }
bool HostContentSettingsMap::IsValueAllowedForType(
const base::Value* value, ContentSettingsType type) {
return IsSettingAllowedForType(
content_settings::ValueToContentSetting(value), type);
}
// static // static
bool HostContentSettingsMap::IsSettingAllowedForType( bool HostContentSettingsMap::IsSettingAllowedForType(
ContentSetting setting, ContentSettingsType content_type) { ContentSetting setting, ContentSettingsType content_type) {
......
...@@ -109,11 +109,13 @@ class HostContentSettingsMap ...@@ -109,11 +109,13 @@ class HostContentSettingsMap
void SetDefaultContentSetting(ContentSettingsType content_type, void SetDefaultContentSetting(ContentSettingsType content_type,
ContentSetting setting); ContentSetting setting);
// Sets the content setting for the given patterns and content type. // Sets the content |setting| for the given patterns, |content_type| and
// Setting the value to CONTENT_SETTING_DEFAULT causes the default setting // |resource_identifier|. Setting the value to CONTENT_SETTING_DEFAULT causes
// for that type to be used when loading pages matching this pattern. For // the default setting for that type to be used when loading pages matching
// ContentSettingsTypes that require an resource identifier to be specified, // this pattern.
// the |resource_identifier| must be non-empty. // 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.
// //
// This should only be called on the UI thread. // This should only be called on the UI thread.
void SetContentSetting(const ContentSettingsPattern& primary_pattern, void SetContentSetting(const ContentSettingsPattern& primary_pattern,
...@@ -122,6 +124,17 @@ class HostContentSettingsMap ...@@ -122,6 +124,17 @@ class HostContentSettingsMap
const std::string& resource_identifier, const std::string& resource_identifier,
ContentSetting setting); 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.
//
// 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);
// Convenience method to add a content setting for the given URLs, making sure // Convenience method to add a content setting for the given URLs, making sure
// that there is no setting overriding it. For ContentSettingsTypes that // that there is no setting overriding it. For ContentSettingsTypes that
// require an resource identifier to be specified, the |resource_identifier| // require an resource identifier to be specified, the |resource_identifier|
...@@ -139,6 +152,8 @@ class HostContentSettingsMap ...@@ -139,6 +152,8 @@ class HostContentSettingsMap
// This should only be called on the UI thread. // This should only be called on the UI thread.
void ClearSettingsForOneType(ContentSettingsType content_type); void ClearSettingsForOneType(ContentSettingsType content_type);
static bool IsValueAllowedForType(const base::Value* value,
ContentSettingsType content_type);
static bool IsSettingAllowedForType(ContentSetting setting, static bool IsSettingAllowedForType(ContentSetting setting,
ContentSettingsType content_type); ContentSettingsType content_type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment