summaryrefslogtreecommitdiffstats
path: root/chrome/browser/content_settings/host_content_settings_map.cc
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 09:06:52 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 09:06:52 +0000
commit019cd156ad264d0d9d677d7dd62b84a1026f8b7c (patch)
treec020ce3ff5efadf9e96810e40318062ab0379dda /chrome/browser/content_settings/host_content_settings_map.cc
parentb0ebe8d147f0be7b36e7a9ab4206cf7cc8cc6a10 (diff)
downloadchromium_src-019cd156ad264d0d9d677d7dd62b84a1026f8b7c.zip
chromium_src-019cd156ad264d0d9d677d7dd62b84a1026f8b7c.tar.gz
chromium_src-019cd156ad264d0d9d677d7dd62b84a1026f8b7c.tar.bz2
Refactoring: Iterating content setting rules.
Unify the logic behind HostContentSettingsMap::GetSettingsForOneType and HostContentSettingsMap::GetContentSetting. BUG=63656 TEST=NONE Review URL: http://codereview.chromium.org/7982028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105781 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/content_settings/host_content_settings_map.cc')
-rw-r--r--chrome/browser/content_settings/host_content_settings_map.cc125
1 files changed, 73 insertions, 52 deletions
diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc
index faeb325..93eea27 100644
--- a/chrome/browser/content_settings/host_content_settings_map.cc
+++ b/chrome/browser/content_settings/host_content_settings_map.cc
@@ -67,12 +67,14 @@ bool ContentTypeHasCompoundValue(ContentSettingsType type) {
return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE;
}
-ContentSetting GetDefaultSetting(Rules rules) {
+ContentSetting GetDefaultSetting(
+ content_settings::RuleIterator* rule_iterator) {
ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
- for (Rules::iterator rule = rules.begin(); rule != rules.end(); ++rule) {
- if (rule->primary_pattern == wildcard &&
- rule->secondary_pattern == wildcard) {
- return rule->content_setting;
+ 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;
@@ -158,9 +160,9 @@ ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider(
ConstProviderIterator it = content_settings_providers_.find(provider_type);
if (it == content_settings_providers_.end())
return CONTENT_SETTING_DEFAULT;
- Rules rules;
- it->second->GetAllContentSettingsRules(content_type, std::string(), &rules);
- return GetDefaultSetting(rules);
+ scoped_ptr<content_settings::RuleIterator> rule_iterator(
+ it->second->GetRuleIterator(content_type, "", false));
+ return GetDefaultSetting(rule_iterator.get());
}
ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
@@ -208,11 +210,12 @@ ContentSetting HostContentSettingsMap::GetCookieContentSetting(
if (provider->first == DEFAULT_PROVIDER)
continue;
- setting = provider->second->GetContentSetting(
- url,
- first_party_url,
- CONTENT_SETTINGS_TYPE_COOKIES,
- std::string());
+ setting = content_settings::GetContentSetting(provider->second,
+ url,
+ first_party_url,
+ CONTENT_SETTINGS_TYPE_COOKIES,
+ std::string(),
+ is_off_the_record_);
if (setting != CONTENT_SETTING_DEFAULT)
break;
}
@@ -254,13 +257,14 @@ ContentSetting HostContentSettingsMap::GetContentSetting(
if (ShouldAllowAllContent(secondary_url, content_type))
return CONTENT_SETTING_ALLOW;
- // Iterate through the list of providers and break when the first non default
- // setting is found.
+ // Iterate through the list of providers and return the first non-NULL value
+ // that matches |primary_url| and |secondary_url|.
for (ConstProviderIterator provider = content_settings_providers_.begin();
provider != content_settings_providers_.end();
++provider) {
- ContentSetting provided_setting = provider->second->GetContentSetting(
- primary_url, secondary_url, content_type, resource_identifier);
+ ContentSetting provided_setting = content_settings::GetContentSetting(
+ provider->second, primary_url, secondary_url, content_type,
+ resource_identifier, is_off_the_record_);
if (provided_setting != CONTENT_SETTING_DEFAULT)
return provided_setting;
}
@@ -282,8 +286,14 @@ Value* HostContentSettingsMap::GetContentSettingValue(
for (ConstProviderIterator provider = content_settings_providers_.begin();
provider != content_settings_providers_.end();
++provider) {
- Value* value = provider->second->GetContentSettingValue(
- primary_url, secondary_url, content_type, resource_identifier);
+ // TODO(marja): Make DefaultProvider return NULL for
+ // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, un-skip default provider
+ // here and remove the code below this loop.
+ if (provider->first == DEFAULT_PROVIDER)
+ continue;
+ base::Value* value = content_settings::GetContentSettingValue(
+ provider->second, primary_url, secondary_url, content_type,
+ resource_identifier, is_off_the_record_);
if (value)
return value;
}
@@ -333,40 +343,22 @@ void HostContentSettingsMap::GetSettingsForOneType(
for (ConstProviderIterator provider = content_settings_providers_.begin();
provider != content_settings_providers_.end();
++provider) {
- Rules rules;
- provider->second->GetAllContentSettingsRules(content_type,
- resource_identifier,
- &rules);
- // Sort rules according to their primary-secondary pattern string pairs
- // using a map.
- std::map<StringPair, PatternSettingSourceTuple> settings_map;
- for (Rules::iterator rule = rules.begin();
- rule != rules.end();
- ++rule) {
- // Filter out default settings.
- if (rule->primary_pattern == ContentSettingsPattern::Wildcard() &&
- rule->secondary_pattern == ContentSettingsPattern::Wildcard() &&
- (provider->first == POLICY_PROVIDER ||
- provider->first == DEFAULT_PROVIDER)) {
- continue;
- }
-
- StringPair sort_key(rule->primary_pattern.ToString(),
- rule->secondary_pattern.ToString());
- settings_map[sort_key] = PatternSettingSourceTuple(
- rule->primary_pattern,
- rule->secondary_pattern,
- rule->content_setting,
- kProviderNames[provider->first]);
- }
-
- // TODO(markusheintz): Only the rules that are applied should be added.
- for (std::map<StringPair, PatternSettingSourceTuple>::iterator i(
- settings_map.begin());
- i != settings_map.end();
- ++i) {
- settings->push_back(i->second);
+ // For each provider, iterate first the incognito-specific rules, then the
+ // normal rules.
+ if (is_off_the_record_) {
+ AddSettingsForOneType(provider->second,
+ provider->first,
+ content_type,
+ resource_identifier,
+ settings,
+ true);
}
+ AddSettingsForOneType(provider->second,
+ provider->first,
+ content_type,
+ resource_identifier,
+ settings,
+ false);
}
}
@@ -578,3 +570,32 @@ void HostContentSettingsMap::MigrateObsoleteCookiePref() {
}
}
}
+
+void HostContentSettingsMap::AddSettingsForOneType(
+ const content_settings::ProviderInterface* provider,
+ ProviderType provider_type,
+ ContentSettingsType content_type,
+ const std::string& resource_identifier,
+ SettingsForOneType* settings,
+ bool incognito) const {
+ scoped_ptr<content_settings::RuleIterator> rule_iterator(
+ provider->GetRuleIterator(content_type,
+ resource_identifier,
+ incognito));
+ ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
+ while (rule_iterator->HasNext()) {
+ const content_settings::Rule& rule = rule_iterator->Next();
+ // Filter out default settings.
+ if (rule.primary_pattern == wildcard &&
+ rule.secondary_pattern == wildcard &&
+ (provider_type == POLICY_PROVIDER ||
+ provider_type == DEFAULT_PROVIDER)) {
+ continue;
+ }
+ settings->push_back(PatternSettingSourceTuple(
+ rule.primary_pattern, rule.secondary_pattern,
+ content_settings::ValueToContentSetting(rule.value.get()),
+ kProviderNames[provider_type],
+ incognito));
+ }
+}