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