- Remove unused includes

- Add missing includes
- Inline function.


BUG=63656
TEST=HostContentSettingsMapTest*, 
     ContentSettingsProviderTest*


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113610 0039d316-1c4b-4281-b951-d872f2087c98
parent c6c989f7
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "chrome/common/content_settings.h" #include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"
#include "chrome/common/content_settings_pattern.h" #include "chrome/common/content_settings_pattern.h"
// Details for the CONTENT_SETTINGS_CHANGED notification. This is sent when // Details for the CONTENT_SETTINGS_CHANGED notification. This is sent when
......
...@@ -9,19 +9,8 @@ namespace content_settings { ...@@ -9,19 +9,8 @@ namespace content_settings {
MockProvider::MockProvider() MockProvider::MockProvider()
: read_only_(false) {} : read_only_(false) {}
MockProvider::MockProvider(ContentSettingsPattern requesting_url_pattern, MockProvider::MockProvider(bool read_only)
ContentSettingsPattern embedding_url_pattern,
ContentSettingsType content_type,
ResourceIdentifier resource_identifier,
ContentSetting setting,
bool read_only,
bool is_managed)
: read_only_(read_only) { : read_only_(read_only) {
value_map_.SetValue(requesting_url_pattern,
embedding_url_pattern,
content_type,
resource_identifier,
Value::CreateIntegerValue(setting));
} }
MockProvider::~MockProvider() {} MockProvider::~MockProvider() {}
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/content_settings/content_settings_observable_provider.h" #include "chrome/browser/content_settings/content_settings_observable_provider.h"
#include "chrome/browser/content_settings/content_settings_origin_identifier_value_map.h" #include "chrome/browser/content_settings/content_settings_origin_identifier_value_map.h"
#include "chrome/common/content_settings_pattern.h" #include "chrome/common/content_settings_pattern.h"
#include "chrome/common/content_settings_types.h"
namespace content_settings { namespace content_settings {
...@@ -19,13 +20,7 @@ namespace content_settings { ...@@ -19,13 +20,7 @@ namespace content_settings {
class MockProvider : public ObservableProvider { class MockProvider : public ObservableProvider {
public: public:
MockProvider(); MockProvider();
MockProvider(ContentSettingsPattern requesting_url_pattern, explicit MockProvider(bool read_only);
ContentSettingsPattern embedding_url_pattern,
ContentSettingsType content_type,
ResourceIdentifier resource_identifier,
ContentSetting setting,
bool read_only,
bool is_managed);
virtual ~MockProvider(); virtual ~MockProvider();
virtual RuleIterator* GetRuleIterator( virtual RuleIterator* GetRuleIterator(
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <vector> #include <vector>
#include "base/values.h" #include "base/values.h"
#include "chrome/common/content_settings.h" #include "chrome/common/content_settings_types.h"
class ContentSettingsPattern; class ContentSettingsPattern;
......
...@@ -16,14 +16,14 @@ TEST(ContentSettingsProviderTest, Mock) { ...@@ -16,14 +16,14 @@ TEST(ContentSettingsProviderTest, Mock) {
ContentSettingsPattern::FromString("[*.]youtube.com"); ContentSettingsPattern::FromString("[*.]youtube.com");
GURL url("http://www.youtube.com"); GURL url("http://www.youtube.com");
MockProvider mock_provider( MockProvider mock_provider(false);
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));
false,
false);
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(&mock_provider, url, url, GetContentSetting(&mock_provider, url, url,
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_pattern.h" #include "chrome/common/content_settings_pattern.h"
namespace content_settings { namespace content_settings {
......
...@@ -49,10 +49,6 @@ std::string GetTypeName(ContentSettingsType type) { ...@@ -49,10 +49,6 @@ std::string GetTypeName(ContentSettingsType type) {
return std::string(kTypeNames[type]); return std::string(kTypeNames[type]);
} }
bool SupportsResourceIdentifier(ContentSettingsType content_type) {
return content_type == CONTENT_SETTINGS_TYPE_PLUGINS;
}
ContentSetting ClickToPlayFixup(ContentSettingsType content_type, ContentSetting ClickToPlayFixup(ContentSettingsType content_type,
ContentSetting setting) { ContentSetting setting) {
if (setting == CONTENT_SETTING_ASK && if (setting == CONTENT_SETTING_ASK &&
......
...@@ -28,10 +28,6 @@ typedef std::pair<ContentSettingsPattern, ContentSettingsPattern> PatternPair; ...@@ -28,10 +28,6 @@ typedef std::pair<ContentSettingsPattern, ContentSettingsPattern> PatternPair;
std::string GetTypeName(ContentSettingsType type); std::string GetTypeName(ContentSettingsType type);
// Returns true if the |content_type| supports a resource identifier.
// Resource identifiers are supported (but not required) for plug-ins.
bool SupportsResourceIdentifier(ContentSettingsType content_type);
// Maps CONTENT_SETTING_ASK for the CONTENT_SETTINGS_TYPE_PLUGINS to // Maps CONTENT_SETTING_ASK for the CONTENT_SETTINGS_TYPE_PLUGINS to
// CONTENT_SETTING_BLOCK if click-to-play is not enabled. // CONTENT_SETTING_BLOCK if click-to-play is not enabled.
ContentSetting ClickToPlayFixup(ContentSettingsType content_type, ContentSetting ClickToPlayFixup(ContentSettingsType content_type,
......
...@@ -68,17 +68,10 @@ bool ContentTypeHasCompoundValue(ContentSettingsType type) { ...@@ -68,17 +68,10 @@ bool ContentTypeHasCompoundValue(ContentSettingsType type) {
return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE; return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE;
} }
ContentSetting GetDefaultSetting( // Returns true if the |content_type| supports a resource identifier.
content_settings::RuleIterator* rule_iterator) { // Resource identifiers are supported (but not required) for plug-ins.
ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); bool SupportsResourceIdentifier(ContentSettingsType content_type) {
while (rule_iterator->HasNext()) { return content_type == CONTENT_SETTINGS_TYPE_PLUGINS;
content_settings::Rule rule = rule_iterator->Next();
if (rule.primary_pattern == wildcard &&
rule.secondary_pattern == wildcard) {
return content_settings::ValueToContentSetting(rule.value.get());
}
}
return CONTENT_SETTING_DEFAULT;
} }
} // namespace } // namespace
...@@ -132,7 +125,16 @@ ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( ...@@ -132,7 +125,16 @@ ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider(
content_settings::ProviderInterface* provider) const { content_settings::ProviderInterface* provider) const {
scoped_ptr<content_settings::RuleIterator> rule_iterator( scoped_ptr<content_settings::RuleIterator> rule_iterator(
provider->GetRuleIterator(content_type, "", false)); provider->GetRuleIterator(content_type, "", false));
return GetDefaultSetting(rule_iterator.get());
ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
while (rule_iterator->HasNext()) {
content_settings::Rule rule = rule_iterator->Next();
if (rule.primary_pattern == wildcard &&
rule.secondary_pattern == wildcard) {
return content_settings::ValueToContentSetting(rule.value.get());
}
}
return CONTENT_SETTING_DEFAULT;
} }
ContentSetting HostContentSettingsMap::GetDefaultContentSetting( ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
...@@ -168,6 +170,7 @@ ContentSetting HostContentSettingsMap::GetContentSetting( ...@@ -168,6 +170,7 @@ ContentSetting HostContentSettingsMap::GetContentSetting(
const GURL& secondary_url, const GURL& secondary_url,
ContentSettingsType content_type, ContentSettingsType content_type,
const std::string& resource_identifier) const { const std::string& resource_identifier) const {
DCHECK(!ContentTypeHasCompoundValue(content_type));
scoped_ptr<base::Value> value(GetWebsiteSetting( scoped_ptr<base::Value> value(GetWebsiteSetting(
primary_url, secondary_url, content_type, resource_identifier, NULL)); primary_url, secondary_url, content_type, resource_identifier, NULL));
return content_settings::ValueToContentSetting(value.get()); return content_settings::ValueToContentSetting(value.get());
...@@ -177,7 +180,7 @@ void HostContentSettingsMap::GetSettingsForOneType( ...@@ -177,7 +180,7 @@ void HostContentSettingsMap::GetSettingsForOneType(
ContentSettingsType content_type, ContentSettingsType content_type,
const std::string& resource_identifier, const std::string& resource_identifier,
ContentSettingsForOneType* settings) const { ContentSettingsForOneType* settings) const {
DCHECK(content_settings::SupportsResourceIdentifier(content_type) || DCHECK(SupportsResourceIdentifier(content_type) ||
resource_identifier.empty()); resource_identifier.empty());
DCHECK(settings); DCHECK(settings);
...@@ -207,7 +210,7 @@ void HostContentSettingsMap::GetSettingsForOneType( ...@@ -207,7 +210,7 @@ void HostContentSettingsMap::GetSettingsForOneType(
void HostContentSettingsMap::SetDefaultContentSetting( void HostContentSettingsMap::SetDefaultContentSetting(
ContentSettingsType content_type, ContentSettingsType content_type,
ContentSetting setting) { ContentSetting setting) {
DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); DCHECK(!ContentTypeHasCompoundValue(content_type));
DCHECK(IsSettingAllowedForType(setting, content_type)); DCHECK(IsSettingAllowedForType(setting, content_type));
base::Value* value = NULL; base::Value* value = NULL;
...@@ -228,7 +231,7 @@ void HostContentSettingsMap::SetWebsiteSetting( ...@@ -228,7 +231,7 @@ void HostContentSettingsMap::SetWebsiteSetting(
const std::string& resource_identifier, const std::string& resource_identifier,
base::Value* value) { base::Value* value) {
DCHECK(IsValueAllowedForType(value, content_type)); DCHECK(IsValueAllowedForType(value, content_type));
DCHECK(content_settings::SupportsResourceIdentifier(content_type) || DCHECK(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();
...@@ -250,7 +253,7 @@ void HostContentSettingsMap::SetContentSetting( ...@@ -250,7 +253,7 @@ void HostContentSettingsMap::SetContentSetting(
ContentSettingsType content_type, ContentSettingsType content_type,
const std::string& resource_identifier, const std::string& resource_identifier,
ContentSetting setting) { ContentSetting setting) {
DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); DCHECK(!ContentTypeHasCompoundValue(content_type));
base::Value* value = NULL; base::Value* value = NULL;
if (setting != CONTENT_SETTING_DEFAULT) if (setting != CONTENT_SETTING_DEFAULT)
value = Value::CreateIntegerValue(setting); value = Value::CreateIntegerValue(setting);
...@@ -270,6 +273,7 @@ void HostContentSettingsMap::AddExceptionForURL( ...@@ -270,6 +273,7 @@ void HostContentSettingsMap::AddExceptionForURL(
// TODO(markusheintz): Until the UI supports pattern pairs, both urls must // TODO(markusheintz): Until the UI supports pattern pairs, both urls must
// match. // match.
DCHECK(primary_url == secondary_url); DCHECK(primary_url == secondary_url);
DCHECK(!ContentTypeHasCompoundValue(content_type));
// Make sure there is no entry that would override the pattern we are about // Make sure there is no entry that would override the pattern we are about
// to insert for exactly this URL. // to insert for exactly this URL.
...@@ -415,7 +419,7 @@ base::Value* HostContentSettingsMap::GetWebsiteSetting( ...@@ -415,7 +419,7 @@ base::Value* HostContentSettingsMap::GetWebsiteSetting(
ContentSettingsType content_type, ContentSettingsType content_type,
const std::string& resource_identifier, const std::string& resource_identifier,
content_settings::SettingInfo* info) const { content_settings::SettingInfo* info) const {
DCHECK(content_settings::SupportsResourceIdentifier(content_type) || DCHECK(SupportsResourceIdentifier(content_type) ||
resource_identifier.empty()); resource_identifier.empty());
// Check if the scheme of the requesting url is whitelisted. // Check if the scheme of the requesting url is whitelisted.
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/content_settings/content_settings_observer.h" #include "chrome/browser/content_settings/content_settings_observer.h"
#include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/common/content_settings.h" #include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"
#include "chrome/common/content_settings_pattern.h" #include "chrome/common/content_settings_pattern.h"
namespace base { namespace base {
......
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