Index: chrome/browser/content_settings/host_content_settings_map.cc |
diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc |
index 2077066c56215b32c5f66045b4147fc1d90586aa..a24b67544c42f1cc695f63294b710f6f0dd97843 100644 |
--- a/chrome/browser/content_settings/host_content_settings_map.cc |
+++ b/chrome/browser/content_settings/host_content_settings_map.cc |
@@ -28,41 +28,6 @@ |
namespace { |
-// The preference keys where resource identifiers are stored for |
-// ContentSettingsType values that support resource identifiers. |
-const char* kResourceTypeNames[CONTENT_SETTINGS_NUM_TYPES] = { |
- NULL, |
- NULL, |
- NULL, |
- "per_plugin", |
- NULL, |
- NULL, // Not used for Geolocation |
- NULL, // Not used for Notifications |
-}; |
- |
-// The names of the ContentSettingsType values, for use with dictionary prefs. |
-const char* kTypeNames[CONTENT_SETTINGS_NUM_TYPES] = { |
- "cookies", |
- "images", |
- "javascript", |
- "plugins", |
- "popups", |
- NULL, // Not used for Geolocation |
- NULL, // Not used for Notifications |
-}; |
- |
-// True if a given content settings type requires additional resource |
-// identifiers. |
-const bool kRequiresResourceIdentifier[CONTENT_SETTINGS_NUM_TYPES] = { |
- false, // CONTENT_SETTINGS_TYPE_COOKIES |
- false, // CONTENT_SETTINGS_TYPE_IMAGES |
- false, // CONTENT_SETTINGS_TYPE_JAVASCRIPT |
- true, // CONTENT_SETTINGS_TYPE_PLUGINS |
- false, // CONTENT_SETTINGS_TYPE_POPUPS |
- false, // Not used for Geolocation |
- false, // Not used for Notifications |
-}; |
- |
// Returns true if we should allow all content types for this URL. This is |
// true for various internal objects like chrome:// URLs, so UI and other |
// things users think of as "not webpages" don't break. |
@@ -75,33 +40,24 @@ static bool ShouldAllowAllContent(const GURL& url) { |
url.SchemeIs(chrome::kUserScriptScheme); |
} |
-// Map ASK for the plugins content type to BLOCK if click-to-play is |
-// not enabled. |
-ContentSetting ClickToPlayFixup(ContentSettingsType content_type, |
- ContentSetting setting) { |
- if (setting == CONTENT_SETTING_ASK && |
- content_type == CONTENT_SETTINGS_TYPE_PLUGINS && |
- !CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kEnableClickToPlay)) { |
- return CONTENT_SETTING_BLOCK; |
- } |
- return setting; |
-} |
- |
typedef linked_ptr<content_settings::DefaultProviderInterface> |
DefaultContentSettingsProviderPtr; |
typedef std::vector<DefaultContentSettingsProviderPtr>::iterator |
- provider_iterator; |
+ default_provider_iterator; |
typedef std::vector<DefaultContentSettingsProviderPtr>::const_iterator |
- const_provider_iterator; |
+ const_default_provider_iterator; |
-} // namespace |
+typedef linked_ptr<content_settings::ProviderInterface> ProviderPtr; |
+typedef std::vector<ProviderPtr>::iterator provider_iterator; |
Bernhard Bauer
2011/02/07 09:46:46
Please use CamelCase for the type, lowercase types
markusheintz_
2011/02/07 15:57:10
Agree. Done. I just tried to follow the style I sa
|
+typedef std::vector<ProviderPtr>::const_iterator const_provider_iterator; |
+typedef content_settings::ProviderInterface::Rules Rules; |
+typedef content_settings::ProviderInterface::Rules::iterator |
+ rules_iterator; |
+typedef content_settings::ProviderInterface::Rules::const_iterator |
+ const_rules_iterator; |
-struct HostContentSettingsMap::ExtendedContentSettings { |
- ContentSettings content_settings; |
- ResourceContentSettings content_settings_for_resources; |
-}; |
+} // namespace |
HostContentSettingsMap::HostContentSettingsMap(Profile* profile) |
: profile_(profile), |
@@ -109,9 +65,9 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile) |
updating_preferences_(false), |
block_third_party_cookies_(false), |
is_block_third_party_cookies_managed_(false) { |
- // The order in which the content settings providers are created is critical, |
- // as providers that are further down in the list (i.e. added later) override |
- // providers further up. |
+ // The order in which the default content settings providers are created is |
+ // critical, as providers that are further down in the list (i.e. added later) |
+ // override providers further up. |
default_content_settings_providers_.push_back( |
DefaultContentSettingsProviderPtr( |
new content_settings::PrefDefaultProvider(profile))); |
@@ -121,12 +77,10 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile) |
PrefService* prefs = profile_->GetPrefs(); |
+ // TODO(markusheintz): Discuss whether it is sensible to move migration code |
+ // to PrefContentSettingsProvider. |
MigrateObsoleteCookiePref(prefs); |
- MigrateObsoletePopupsPref(prefs); |
- |
- MigrateObsoletePerhostPref(prefs); |
- |
// Read misc. global settings. |
block_third_party_cookies_ = |
prefs->GetBoolean(prefs::kBlockThirdPartyCookies); |
@@ -135,22 +89,14 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile) |
block_nonsandboxed_plugins_ = |
prefs->GetBoolean(prefs::kBlockNonsandboxedPlugins); |
- // Verify preferences version. |
- if (!prefs->HasPrefPath(prefs::kContentSettingsVersion)) { |
- prefs->SetInteger(prefs::kContentSettingsVersion, |
- ContentSettingsPattern::kContentSettingsPatternVersion); |
- } |
- if (prefs->GetInteger(prefs::kContentSettingsVersion) > |
- ContentSettingsPattern::kContentSettingsPatternVersion) { |
- LOG(ERROR) << "Unknown content settings version in preferences."; |
- return; |
- } |
- |
- // Read exceptions. |
- ReadExceptions(false); |
+ // User defined non default content settings are provided by the PrefProvider. |
+ // The order in which the content settings providers are created is critical, |
+ // as providers that are further up in the list (i.e. added earlier) override |
+ // providers further down. |
+ content_settings_providers_.push_back(ProviderPtr( |
+ new content_settings::PrefProvider(profile))); |
pref_change_registrar_.Init(prefs); |
- pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); |
pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this); |
pref_change_registrar_.Add(prefs::kBlockNonsandboxedPlugins, this); |
notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
@@ -159,9 +105,6 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile) |
// static |
void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { |
- prefs->RegisterIntegerPref(prefs::kContentSettingsVersion, |
- ContentSettingsPattern::kContentSettingsPatternVersion); |
- prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns); |
prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, false); |
prefs->RegisterBooleanPref(prefs::kBlockNonsandboxedPlugins, false); |
prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
@@ -169,18 +112,17 @@ void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { |
// Obsolete prefs, for migration: |
prefs->RegisterIntegerPref(prefs::kCookieBehavior, |
net::StaticCookiePolicy::ALLOW_ALL_COOKIES); |
- prefs->RegisterListPref(prefs::kPopupWhitelistedHosts); |
- prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings); |
// Register the prefs for the content settings providers. |
content_settings::PrefDefaultProvider::RegisterUserPrefs(prefs); |
content_settings::PolicyDefaultProvider::RegisterUserPrefs(prefs); |
+ content_settings::PrefProvider::RegisterUserPrefs(prefs); |
} |
ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
ContentSettingsType content_type) const { |
ContentSetting setting = CONTENT_SETTING_DEFAULT; |
- for (const_provider_iterator provider = |
+ for (const_default_provider_iterator provider = |
default_content_settings_providers_.begin(); |
provider != default_content_settings_providers_.end(); ++provider) { |
ContentSetting provided_setting = |
@@ -216,74 +158,18 @@ ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( |
if (ShouldAllowAllContent(url)) |
return CONTENT_SETTING_ALLOW; |
- if (!RequiresResourceIdentifier(content_type)) |
- return GetNonDefaultContentSettings(url).settings[content_type]; |
- |
- if (CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kEnableResourceContentSettings)) { |
- DCHECK(!resource_identifier.empty()); |
- } |
- |
- // Host content settings are ignored if the default_content_setting is |
- // managed. |
- if (IsDefaultContentSettingManaged(content_type)) { |
- return GetDefaultContentSetting(content_type); |
- } |
- |
- base::AutoLock auto_lock(lock_); |
- |
- const std::string host(net::GetHostOrSpecFromURL(url)); |
- ContentSettingsTypeResourceIdentifierPair |
- requested_setting(content_type, resource_identifier); |
- |
- // Check for exact matches first. |
- HostContentSettings::const_iterator i(host_content_settings_.find(host)); |
- if (i != host_content_settings_.end() && |
- i->second.content_settings_for_resources.find(requested_setting) != |
- i->second.content_settings_for_resources.end()) { |
- return i->second.content_settings_for_resources.find( |
- requested_setting)->second; |
- } |
- |
- // If this map is not for an off-the-record profile, these searches will never |
- // match. The additional off-the-record exceptions always overwrite the |
- // regular ones. |
- i = off_the_record_settings_.find(host); |
- if (i != off_the_record_settings_.end() && |
- i->second.content_settings_for_resources.find(requested_setting) != |
- i->second.content_settings_for_resources.end()) { |
- return i->second.content_settings_for_resources.find( |
- requested_setting)->second; |
- } |
- |
- // Match patterns starting with the most concrete pattern match. |
- for (std::string key = |
- std::string(ContentSettingsPattern::kDomainWildcard) + host; ; ) { |
- HostContentSettings::const_iterator i(off_the_record_settings_.find(key)); |
- if (i != off_the_record_settings_.end() && |
- i->second.content_settings_for_resources.find(requested_setting) != |
- i->second.content_settings_for_resources.end()) { |
- return i->second.content_settings_for_resources.find( |
- requested_setting)->second; |
- } |
- |
- i = host_content_settings_.find(key); |
- if (i != host_content_settings_.end() && |
- i->second.content_settings_for_resources.find(requested_setting) != |
- i->second.content_settings_for_resources.end()) { |
- return i->second.content_settings_for_resources.find( |
- requested_setting)->second; |
- } |
- |
- const size_t next_dot = |
- key.find('.', ContentSettingsPattern::kDomainWildcardLength); |
- if (next_dot == std::string::npos) |
+ // Iterate through the list of providers and break when the first non default |
+ // setting is found. |
+ ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); |
+ for (const_provider_iterator provider = content_settings_providers_.begin(); |
+ provider != content_settings_providers_.end(); |
+ ++provider) { |
+ provided_setting = (*provider)->GetContentSetting( |
+ url, url, content_type, resource_identifier); |
+ if (provided_setting != CONTENT_SETTING_DEFAULT) |
break; |
- key.erase(ContentSettingsPattern::kDomainWildcardLength, |
- next_dot - ContentSettingsPattern::kDomainWildcardLength + 1); |
} |
- |
- return CONTENT_SETTING_DEFAULT; |
+ return provided_setting; |
} |
ContentSettings HostContentSettingsMap::GetContentSettings( |
@@ -293,16 +179,12 @@ ContentSettings HostContentSettingsMap::GetContentSettings( |
// If we require a resource identifier, set the content settings to default, |
// otherwise make the defaults explicit. |
for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
- if (RequiresResourceIdentifier(ContentSettingsType(j))) { |
- output.settings[j] = CONTENT_SETTING_DEFAULT; |
- } else { |
- // A managed default content setting has the highest priority and hence |
- // will overwrite any previously set value. |
- if ((output.settings[j] == CONTENT_SETTING_DEFAULT && |
- j != CONTENT_SETTINGS_TYPE_PLUGINS) || |
- IsDefaultContentSettingManaged(ContentSettingsType(j))) { |
- output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); |
- } |
+ // A managed default content setting has the highest priority and hence |
+ // will overwrite any previously set value. |
+ if ((output.settings[j] == CONTENT_SETTING_DEFAULT && |
+ j != CONTENT_SETTINGS_TYPE_PLUGINS) || |
+ IsDefaultContentSettingManaged(ContentSettingsType(j))) { |
+ output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); |
} |
} |
return output; |
@@ -313,53 +195,11 @@ ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( |
if (ShouldAllowAllContent(url)) |
return ContentSettings(CONTENT_SETTING_ALLOW); |
- base::AutoLock auto_lock(lock_); |
- |
- const std::string host(net::GetHostOrSpecFromURL(url)); |
- ContentSettings output; |
- for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) |
- output.settings[j] = CONTENT_SETTING_DEFAULT; |
- |
- // Check for exact matches first. |
- HostContentSettings::const_iterator i(host_content_settings_.find(host)); |
- if (i != host_content_settings_.end()) |
- output = i->second.content_settings; |
- |
- // If this map is not for an off-the-record profile, these searches will never |
- // match. The additional off-the-record exceptions always overwrite the |
- // regular ones. |
- i = off_the_record_settings_.find(host); |
- if (i != off_the_record_settings_.end()) { |
- for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) |
- if (i->second.content_settings.settings[j] != CONTENT_SETTING_DEFAULT) |
- output.settings[j] = i->second.content_settings.settings[j]; |
- } |
- |
- // Match patterns starting with the most concrete pattern match. |
- for (std::string key = |
- std::string(ContentSettingsPattern::kDomainWildcard) + host; ; ) { |
- HostContentSettings::const_iterator i(off_the_record_settings_.find(key)); |
- if (i != off_the_record_settings_.end()) { |
- for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
- if (output.settings[j] == CONTENT_SETTING_DEFAULT) |
- output.settings[j] = i->second.content_settings.settings[j]; |
- } |
- } |
- i = host_content_settings_.find(key); |
- if (i != host_content_settings_.end()) { |
- for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
- if (output.settings[j] == CONTENT_SETTING_DEFAULT) |
- output.settings[j] = i->second.content_settings.settings[j]; |
- } |
- } |
- const size_t next_dot = |
- key.find('.', ContentSettingsPattern::kDomainWildcardLength); |
- if (next_dot == std::string::npos) |
- break; |
- key.erase(ContentSettingsPattern::kDomainWildcardLength, |
- next_dot - ContentSettingsPattern::kDomainWildcardLength + 1); |
+ ContentSettings output(CONTENT_SETTING_DEFAULT); |
+ for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
+ output.settings[j] = GetNonDefaultContentSetting( |
+ url, ContentSettingsType(j) , ""); |
} |
- |
return output; |
} |
@@ -367,43 +207,36 @@ void HostContentSettingsMap::GetSettingsForOneType( |
ContentSettingsType content_type, |
const std::string& resource_identifier, |
SettingsForOneType* settings) const { |
- DCHECK(RequiresResourceIdentifier(content_type) != |
- resource_identifier.empty()); |
DCHECK(settings); |
settings->clear(); |
- const HostContentSettings* map_to_return = |
- is_off_the_record_ ? &off_the_record_settings_ : &host_content_settings_; |
- ContentSettingsTypeResourceIdentifierPair |
- requested_setting(content_type, resource_identifier); |
- |
- base::AutoLock auto_lock(lock_); |
- for (HostContentSettings::const_iterator i(map_to_return->begin()); |
- i != map_to_return->end(); ++i) { |
- ContentSetting setting; |
- if (RequiresResourceIdentifier(content_type)) { |
- if (i->second.content_settings_for_resources.find(requested_setting) != |
- i->second.content_settings_for_resources.end()) |
- setting = i->second.content_settings_for_resources.find( |
- requested_setting)->second; |
- else |
- setting = CONTENT_SETTING_DEFAULT; |
- } else { |
- setting = i->second.content_settings.settings[content_type]; |
- } |
- if (setting != CONTENT_SETTING_DEFAULT) { |
- // Use of push_back() relies on the map iterator traversing in order of |
- // ascending keys. |
- settings->push_back( |
- std::make_pair(ContentSettingsPattern(i->first), setting)); |
- } |
+ // Collect content_settings::Rules for the given content_type and |
+ // resource_identifier from the content settings providers. |
+ Rules content_settings_rules; |
+ for (const_provider_iterator provider = content_settings_providers_.begin(); |
+ provider != content_settings_providers_.end(); |
+ ++provider) { |
+ // TODO(markusheintz): Only the rules that are applied should be collected. |
+ // Merge rules. |
+ (*provider)->GetAllContentSettingsRules( |
+ content_type, resource_identifier, &content_settings_rules); |
+ } |
+ |
+ // convert Rules to SettingsForOneType |
+ for (const_rules_iterator rule_iterator = |
+ content_settings_rules.begin(); |
+ rule_iterator != content_settings_rules.end(); |
+ ++rule_iterator) { |
+ settings->push_back(std::make_pair(ContentSettingsPattern( |
+ rule_iterator->requesting_url_pattern), |
+ rule_iterator->content_setting)); |
} |
} |
void HostContentSettingsMap::SetDefaultContentSetting( |
ContentSettingsType content_type, |
ContentSetting setting) { |
- for (provider_iterator provider = |
+ for (default_provider_iterator provider = |
default_content_settings_providers_.begin(); |
provider != default_content_settings_providers_.end(); ++provider) { |
(*provider)->UpdateDefaultSetting(content_type, setting); |
@@ -411,109 +244,16 @@ void HostContentSettingsMap::SetDefaultContentSetting( |
} |
void HostContentSettingsMap::SetContentSetting( |
- const ContentSettingsPattern& original_pattern, |
+ const ContentSettingsPattern& pattern, |
ContentSettingsType content_type, |
const std::string& resource_identifier, |
ContentSetting setting) { |
- DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DCHECK_NE(RequiresResourceIdentifier(content_type), |
- resource_identifier.empty()); |
- DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS || |
- setting != CONTENT_SETTING_ASK || |
- CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kEnableClickToPlay)); |
- |
- const ContentSettingsPattern pattern(original_pattern.CanonicalizePattern()); |
- |
- bool early_exit = false; |
- std::string pattern_str(pattern.AsString()); |
- PrefService* prefs = NULL; |
- DictionaryValue* all_settings_dictionary = NULL; |
- HostContentSettings* map_to_modify = &off_the_record_settings_; |
- if (!is_off_the_record_) { |
- prefs = profile_->GetPrefs(); |
- all_settings_dictionary = |
- prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); |
- map_to_modify = &host_content_settings_; |
- } |
- |
- { |
- base::AutoLock auto_lock(lock_); |
- if (!map_to_modify->count(pattern_str)) |
- (*map_to_modify)[pattern_str].content_settings = ContentSettings(); |
- HostContentSettings::iterator |
- i(map_to_modify->find(pattern_str)); |
- ContentSettings& settings = i->second.content_settings; |
- if (RequiresResourceIdentifier(content_type)) { |
- settings.settings[content_type] = CONTENT_SETTING_DEFAULT; |
- if (setting != CONTENT_SETTING_DEFAULT) { |
- i->second.content_settings_for_resources[ |
- ContentSettingsTypeResourceIdentifierPair(content_type, |
- resource_identifier)] = setting; |
- } else { |
- i->second.content_settings_for_resources.erase( |
- ContentSettingsTypeResourceIdentifierPair(content_type, |
- resource_identifier)); |
- } |
- } else { |
- settings.settings[content_type] = setting; |
- } |
- if (AllDefault(i->second)) { |
- map_to_modify->erase(i); |
- if (all_settings_dictionary) |
- all_settings_dictionary->RemoveWithoutPathExpansion(pattern_str, NULL); |
- |
- // We can't just return because |NotifyObservers()| needs to be called, |
- // without |lock_| being held. |
- early_exit = true; |
- } |
- } |
- |
- if (!early_exit && all_settings_dictionary) { |
- DictionaryValue* host_settings_dictionary = NULL; |
- bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
- pattern_str, &host_settings_dictionary); |
- if (!found) { |
- host_settings_dictionary = new DictionaryValue; |
- all_settings_dictionary->SetWithoutPathExpansion( |
- pattern_str, host_settings_dictionary); |
- DCHECK_NE(setting, CONTENT_SETTING_DEFAULT); |
- } |
- if (RequiresResourceIdentifier(content_type)) { |
- std::string dictionary_path(kResourceTypeNames[content_type]); |
- DictionaryValue* resource_dictionary = NULL; |
- found = host_settings_dictionary->GetDictionary( |
- dictionary_path, &resource_dictionary); |
- if (!found) { |
- resource_dictionary = new DictionaryValue; |
- host_settings_dictionary->Set(dictionary_path, resource_dictionary); |
- } |
- if (setting == CONTENT_SETTING_DEFAULT) { |
- resource_dictionary->RemoveWithoutPathExpansion(resource_identifier, |
- NULL); |
- } else { |
- resource_dictionary->SetWithoutPathExpansion( |
- resource_identifier, Value::CreateIntegerValue(setting)); |
- } |
- } else { |
- std::string dictionary_path(kTypeNames[content_type]); |
- if (setting == CONTENT_SETTING_DEFAULT) { |
- host_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, |
- NULL); |
- } else { |
- host_settings_dictionary->SetWithoutPathExpansion( |
- dictionary_path, Value::CreateIntegerValue(setting)); |
- } |
- } |
+ for (provider_iterator provider = content_settings_providers_.begin(); |
+ provider != content_settings_providers_.end(); |
+ ++provider) { |
+ (*provider)->SetContentSetting( |
+ pattern, pattern, content_type, resource_identifier, setting); |
} |
- |
- updating_preferences_ = true; |
- if (!is_off_the_record_) |
- ScopedPrefUpdate update(prefs, prefs::kContentSettingsPatterns); |
- updating_preferences_ = false; |
- |
- NotifyObservers(ContentSettingsDetails(pattern, content_type, "")); |
} |
void HostContentSettingsMap::AddExceptionForURL( |
@@ -535,68 +275,10 @@ void HostContentSettingsMap::AddExceptionForURL( |
void HostContentSettingsMap::ClearSettingsForOneType( |
ContentSettingsType content_type) { |
- DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
- |
- PrefService* prefs = NULL; |
- DictionaryValue* all_settings_dictionary = NULL; |
- HostContentSettings* map_to_modify = &off_the_record_settings_; |
- |
- if (!is_off_the_record_) { |
- prefs = profile_->GetPrefs(); |
- all_settings_dictionary = |
- prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); |
- map_to_modify = &host_content_settings_; |
- } |
- |
- { |
- base::AutoLock auto_lock(lock_); |
- for (HostContentSettings::iterator i(map_to_modify->begin()); |
- i != map_to_modify->end(); ) { |
- if (RequiresResourceIdentifier(content_type) || |
- i->second.content_settings.settings[content_type] != |
- CONTENT_SETTING_DEFAULT) { |
- if (RequiresResourceIdentifier(content_type)) |
- i->second.content_settings_for_resources.clear(); |
- i->second.content_settings.settings[content_type] = |
- CONTENT_SETTING_DEFAULT; |
- std::string host(i->first); |
- if (AllDefault(i->second)) { |
- if (all_settings_dictionary) |
- all_settings_dictionary-> |
- RemoveWithoutPathExpansion(host, NULL); |
- map_to_modify->erase(i++); |
- } else if (all_settings_dictionary) { |
- DictionaryValue* host_settings_dictionary; |
- bool found = |
- all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
- host, &host_settings_dictionary); |
- DCHECK(found); |
- host_settings_dictionary->RemoveWithoutPathExpansion( |
- kTypeNames[content_type], NULL); |
- ++i; |
- } |
- } else { |
- ++i; |
- } |
- } |
- } |
- |
- updating_preferences_ = true; |
- if (!is_off_the_record_) |
- ScopedPrefUpdate update(prefs, prefs::kContentSettingsPatterns); |
- updating_preferences_ = false; |
- |
- NotifyObservers( |
- ContentSettingsDetails(ContentSettingsPattern(), content_type, "")); |
-} |
- |
-bool HostContentSettingsMap::RequiresResourceIdentifier( |
- ContentSettingsType content_type) const { |
- if (CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kEnableResourceContentSettings)) { |
- return kRequiresResourceIdentifier[content_type]; |
- } else { |
- return false; |
+ for (provider_iterator provider = content_settings_providers_.begin(); |
+ provider != content_settings_providers_.end(); |
+ ++provider) { |
+ (*provider)->ClearAllContentSettingsRules(content_type); |
} |
} |
@@ -644,7 +326,6 @@ void HostContentSettingsMap::SetBlockNonsandboxedPlugins(bool block) { |
block_nonsandboxed_plugins_ = block; |
} |
- |
PrefService* prefs = profile_->GetPrefs(); |
if (block) { |
UserMetrics::RecordAction( |
@@ -662,13 +343,18 @@ void HostContentSettingsMap::ResetToDefaults() { |
{ |
base::AutoLock auto_lock(lock_); |
- for (provider_iterator provider = |
+ for (default_provider_iterator provider = |
default_content_settings_providers_.begin(); |
provider != default_content_settings_providers_.end(); ++provider) { |
(*provider)->ResetToDefaults(); |
} |
- host_content_settings_.clear(); |
- off_the_record_settings_.clear(); |
+ |
+ for (provider_iterator provider = content_settings_providers_.begin(); |
+ provider != content_settings_providers_.end(); |
+ ++provider) { |
+ (*provider)->ResetToDefaults(); |
+ } |
+ |
// Don't reset block third party cookies if they are managed. |
if (!IsBlockThirdPartyCookiesManaged()) |
block_third_party_cookies_ = false; |
@@ -678,7 +364,6 @@ void HostContentSettingsMap::ResetToDefaults() { |
if (!is_off_the_record_) { |
PrefService* prefs = profile_->GetPrefs(); |
updating_preferences_ = true; |
- prefs->ClearPref(prefs::kContentSettingsPatterns); |
// If the block third party cookies preference is managed we still must |
// clear it in order to restore the default value for later when the |
// preference is not managed anymore. |
@@ -702,9 +387,7 @@ void HostContentSettingsMap::Observe(NotificationType type, |
return; |
std::string* name = Details<std::string>(details).ptr(); |
- if (*name == prefs::kContentSettingsPatterns) { |
- ReadExceptions(true); |
- } else if (*name == prefs::kBlockThirdPartyCookies) { |
+ if (*name == prefs::kBlockThirdPartyCookies) { |
base::AutoLock auto_lock(lock_); |
block_third_party_cookies_ = profile_->GetPrefs()->GetBoolean( |
prefs::kBlockThirdPartyCookies); |
@@ -737,77 +420,9 @@ HostContentSettingsMap::~HostContentSettingsMap() { |
UnregisterObservers(); |
} |
-void HostContentSettingsMap::GetSettingsFromDictionary( |
- const DictionaryValue* dictionary, |
- ContentSettings* settings) { |
- for (DictionaryValue::key_iterator i(dictionary->begin_keys()); |
- i != dictionary->end_keys(); ++i) { |
- const std::string& content_type(*i); |
- for (size_t type = 0; type < arraysize(kTypeNames); ++type) { |
- if ((kTypeNames[type] != NULL) && (kTypeNames[type] == content_type)) { |
- int setting = CONTENT_SETTING_DEFAULT; |
- bool found = dictionary->GetIntegerWithoutPathExpansion(content_type, |
- &setting); |
- DCHECK(found); |
- settings->settings[type] = IntToContentSetting(setting); |
- break; |
- } |
- } |
- } |
- // Migrate obsolete cookie prompt mode. |
- if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == |
- CONTENT_SETTING_ASK) |
- settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; |
- |
- settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS] = |
- ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, |
- settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]); |
-} |
- |
-void HostContentSettingsMap::GetResourceSettingsFromDictionary( |
- const DictionaryValue* dictionary, |
- ResourceContentSettings* settings) { |
- for (DictionaryValue::key_iterator i(dictionary->begin_keys()); |
- i != dictionary->end_keys(); ++i) { |
- const std::string& content_type(*i); |
- for (size_t type = 0; type < arraysize(kResourceTypeNames); ++type) { |
- if ((kResourceTypeNames[type] != NULL) && |
- (kResourceTypeNames[type] == content_type)) { |
- DictionaryValue* resource_dictionary = NULL; |
- bool found = dictionary->GetDictionary(content_type, |
- &resource_dictionary); |
- DCHECK(found); |
- for (DictionaryValue::key_iterator j(resource_dictionary->begin_keys()); |
- j != resource_dictionary->end_keys(); ++j) { |
- const std::string& resource_identifier(*j); |
- int setting = CONTENT_SETTING_DEFAULT; |
- bool found = resource_dictionary->GetIntegerWithoutPathExpansion( |
- resource_identifier, &setting); |
- DCHECK(found); |
- (*settings)[ContentSettingsTypeResourceIdentifierPair( |
- ContentSettingsType(type), resource_identifier)] = |
- ClickToPlayFixup(ContentSettingsType(type), |
- ContentSetting(setting)); |
- } |
- |
- break; |
- } |
- } |
- } |
-} |
- |
-bool HostContentSettingsMap::AllDefault( |
- const ExtendedContentSettings& settings) const { |
- for (size_t i = 0; i < arraysize(settings.content_settings.settings); ++i) { |
- if (settings.content_settings.settings[i] != CONTENT_SETTING_DEFAULT) |
- return false; |
- } |
- return settings.content_settings_for_resources.empty(); |
-} |
- |
bool HostContentSettingsMap::IsDefaultContentSettingManaged( |
ContentSettingsType content_type) const { |
- for (const_provider_iterator provider = |
+ for (const_default_provider_iterator provider = |
default_content_settings_providers_.begin(); |
provider != default_content_settings_providers_.end(); ++provider) { |
if ((*provider)->DefaultSettingIsManaged(content_type)) |
@@ -816,40 +431,6 @@ bool HostContentSettingsMap::IsDefaultContentSettingManaged( |
return false; |
} |
-void HostContentSettingsMap::ReadExceptions(bool overwrite) { |
- base::AutoLock lock(lock_); |
- |
- PrefService* prefs = profile_->GetPrefs(); |
- DictionaryValue* all_settings_dictionary = |
- prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); |
- |
- if (overwrite) |
- host_content_settings_.clear(); |
- |
- // Careful: The returned value could be NULL if the pref has never been set. |
- if (all_settings_dictionary != NULL) { |
- // Convert all Unicode patterns into punycode form, then read. |
- CanonicalizeContentSettingsExceptions(all_settings_dictionary); |
- |
- for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); |
- i != all_settings_dictionary->end_keys(); ++i) { |
- const std::string& pattern(*i); |
- if (!ContentSettingsPattern(pattern).IsValid()) |
- LOG(WARNING) << "Invalid pattern stored in content settings"; |
- DictionaryValue* pattern_settings_dictionary = NULL; |
- bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
- pattern, &pattern_settings_dictionary); |
- DCHECK(found); |
- ContentSettings settings; |
- GetSettingsFromDictionary(pattern_settings_dictionary, &settings); |
- host_content_settings_[pattern].content_settings = settings; |
- GetResourceSettingsFromDictionary( |
- pattern_settings_dictionary, |
- &host_content_settings_[pattern].content_settings_for_resources); |
- } |
- } |
-} |
- |
void HostContentSettingsMap::NotifyObservers( |
const ContentSettingsDetails& details) { |
NotificationService::current()->Notify( |
@@ -883,90 +464,3 @@ void HostContentSettingsMap::MigrateObsoleteCookiePref(PrefService* prefs) { |
} |
} |
} |
- |
-void HostContentSettingsMap::MigrateObsoletePopupsPref(PrefService* prefs) { |
- if (prefs->HasPrefPath(prefs::kPopupWhitelistedHosts)) { |
- const ListValue* whitelist_pref = |
- prefs->GetList(prefs::kPopupWhitelistedHosts); |
- for (ListValue::const_iterator i(whitelist_pref->begin()); |
- i != whitelist_pref->end(); ++i) { |
- std::string host; |
- (*i)->GetAsString(&host); |
- SetContentSetting(ContentSettingsPattern(host), |
- CONTENT_SETTINGS_TYPE_POPUPS, |
- "", |
- CONTENT_SETTING_ALLOW); |
- } |
- prefs->ClearPref(prefs::kPopupWhitelistedHosts); |
- } |
-} |
- |
-void HostContentSettingsMap::MigrateObsoletePerhostPref(PrefService* prefs) { |
- if (prefs->HasPrefPath(prefs::kPerHostContentSettings)) { |
- const DictionaryValue* all_settings_dictionary = |
- prefs->GetDictionary(prefs::kPerHostContentSettings); |
- for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); |
- i != all_settings_dictionary->end_keys(); ++i) { |
- const std::string& host(*i); |
- ContentSettingsPattern pattern( |
- std::string(ContentSettingsPattern::kDomainWildcard) + host); |
- DictionaryValue* host_settings_dictionary = NULL; |
- bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
- host, &host_settings_dictionary); |
- DCHECK(found); |
- ContentSettings settings; |
- GetSettingsFromDictionary(host_settings_dictionary, &settings); |
- for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
- if (settings.settings[j] != CONTENT_SETTING_DEFAULT && |
- !RequiresResourceIdentifier(ContentSettingsType(j))) |
- SetContentSetting( |
- pattern, ContentSettingsType(j), "", settings.settings[j]); |
- } |
- } |
- prefs->ClearPref(prefs::kPerHostContentSettings); |
- } |
-} |
- |
-void HostContentSettingsMap::CanonicalizeContentSettingsExceptions( |
- DictionaryValue* all_settings_dictionary) { |
- DCHECK(all_settings_dictionary); |
- |
- std::vector<std::string> remove_items; |
- std::vector<std::pair<std::string, std::string> > move_items; |
- for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); |
- i != all_settings_dictionary->end_keys(); ++i) { |
- const std::string& pattern(*i); |
- const std::string canonicalized_pattern = |
- ContentSettingsPattern(pattern).CanonicalizePattern(); |
- |
- if (canonicalized_pattern.empty() || canonicalized_pattern == pattern) |
- continue; |
- |
- // Clear old pattern if prefs already have canonicalized pattern. |
- DictionaryValue* new_pattern_settings_dictionary = NULL; |
- if (all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
- canonicalized_pattern, &new_pattern_settings_dictionary)) { |
- remove_items.push_back(pattern); |
- continue; |
- } |
- |
- // Move old pattern to canonicalized pattern. |
- DictionaryValue* old_pattern_settings_dictionary = NULL; |
- if (all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
- pattern, &old_pattern_settings_dictionary)) { |
- move_items.push_back(std::make_pair(pattern, canonicalized_pattern)); |
- } |
- } |
- |
- for (size_t i = 0; i < remove_items.size(); ++i) { |
- all_settings_dictionary->RemoveWithoutPathExpansion(remove_items[i], NULL); |
- } |
- |
- for (size_t i = 0; i < move_items.size(); ++i) { |
- Value* pattern_settings_dictionary = NULL; |
- all_settings_dictionary->RemoveWithoutPathExpansion( |
- move_items[i].first, &pattern_settings_dictionary); |
- all_settings_dictionary->SetWithoutPathExpansion( |
- move_items[i].second, pattern_settings_dictionary); |
- } |
-} |