Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1290)

Unified Diff: chrome/browser/content_settings/content_settings_pref_provider.cc

Issue 7484072: Migrate geolocation settings to host content settings map. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename variables Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/content_settings_pref_provider.cc
diff --git a/chrome/browser/content_settings/content_settings_pref_provider.cc b/chrome/browser/content_settings/content_settings_pref_provider.cc
index c7fe7fdcdc13715573fbf2f236926aa08a0cee62..516255d532d231c0f5a53ed12f286249273c2268 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider.cc
+++ b/chrome/browser/content_settings/content_settings_pref_provider.cc
@@ -38,7 +38,7 @@ const char* kResourceTypeNames[] = {
NULL,
"per_plugin",
NULL,
- NULL, // Not used for Geolocation
+ NULL,
NULL, // Not used for Notifications
};
COMPILE_ASSERT(arraysize(kResourceTypeNames) == CONTENT_SETTINGS_NUM_TYPES,
@@ -64,9 +64,9 @@ const char* kTypeNames[] = {
"javascript",
"plugins",
"popups",
+ "geolocation",
// TODO(markusheintz): Refactoring in progress. Content settings exceptions
- // for notifications and geolocation will be added next.
- "geolocation", // Only used for default Geolocation settings
+ // for notifications added next.
"notifications", // Only used for default Notifications settings.
};
COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES,
@@ -357,6 +357,8 @@ void PrefProvider::RegisterUserPrefs(PrefService* prefs) {
PrefService::SYNCABLE_PREF);
// Obsolete prefs, for migration:
+ prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings,
+ PrefService::SYNCABLE_PREF);
prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns,
PrefService::SYNCABLE_PREF);
prefs->RegisterListPref(prefs::kPopupWhitelistedHosts,
@@ -376,6 +378,7 @@ PrefProvider::PrefProvider(PrefService* prefs,
MigrateObsoletePerhostPref();
MigrateObsoletePopupsPref();
MigrateObsoleteContentSettingsPatternPref();
+ MigrateObsoleteGeolocationPref();
}
// Verify preferences version.
@@ -399,6 +402,7 @@ PrefProvider::PrefProvider(PrefService* prefs,
pref_change_registrar_.Init(prefs_);
pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this);
pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this);
+ pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this);
}
ContentSetting PrefProvider::GetContentSetting(
@@ -465,7 +469,7 @@ void PrefProvider::SetContentSetting(
ContentSetting setting) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(prefs_);
- DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation.
+ DCHECK(kTypeNames[content_type] != NULL);
// Update in memory value map.
OriginIdentifierValueMap* map_to_modify = &incognito_value_map_;
@@ -551,12 +555,17 @@ void PrefProvider::Observe(
std::string* name = Details<std::string>(details).ptr();
if (*name == prefs::kContentSettingsPatternPairs) {
- SyncObsoletePref();
+ SyncObsoletePatternPref();
+ SyncObsoleteGeolocationPref();
ReadContentSettingsFromPref(true);
} else if (*name == prefs::kContentSettingsPatterns) {
AutoReset<bool> auto_reset(&updating_preferences_, true);
MigrateObsoleteContentSettingsPatternPref();
ReadContentSettingsFromPref(true);
+ } else if (*name == prefs::kGeolocationContentSettings) {
+ AutoReset<bool> auto_reset(&updating_preferences_, true);
+ MigrateObsoleteGeolocationPref();
+ ReadContentSettingsFromPref(true);
} else {
NOTREACHED() << "Unexpected preference observed";
return;
@@ -590,11 +599,17 @@ void PrefProvider::UpdatePref(
content_type,
resource_identifier,
setting);
- UpdatePatternsPref(primary_pattern,
- secondary_pattern,
- content_type,
- resource_identifier,
- setting);
+ if (content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION &&
+ content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
+ UpdateObsoletePatternsPref(primary_pattern,
+ secondary_pattern,
+ content_type,
+ resource_identifier,
+ setting);
+ }
+ if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
+ SyncObsoleteGeolocationPref();
+ }
}
void PrefProvider::ReadContentSettingsFromPref(bool overwrite) {
@@ -689,7 +704,7 @@ void PrefProvider::ReadContentSettingsFromPref(bool overwrite) {
}
}
-void PrefProvider::UpdatePatternsPref(
+void PrefProvider::UpdateObsoletePatternsPref(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
@@ -964,14 +979,14 @@ void PrefProvider::MigrateObsoletePopupsPref() {
void PrefProvider::MigrateObsoleteContentSettingsPatternPref() {
if (prefs_->HasPrefPath(prefs::kContentSettingsPatterns) && !is_incognito_) {
- const DictionaryValue* all_settings_dictionary =
- prefs_->GetDictionary(prefs::kContentSettingsPatterns);
+ const DictionaryValue* patterns_dictionary =
+ prefs_->GetDictionary(prefs::kContentSettingsPatterns);
DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs);
DictionaryValue* exceptions_dictionary;
exceptions_dictionary = update.Get();
- for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys());
- i != all_settings_dictionary->end_keys();
+ for (DictionaryValue::key_iterator i(patterns_dictionary->begin_keys());
+ i != patterns_dictionary->end_keys();
++i) {
const std::string& key(*i);
if (key.empty())
@@ -989,7 +1004,7 @@ void PrefProvider::MigrateObsoleteContentSettingsPatternPref() {
// Copy dictionary value.
// Get old settings.
DictionaryValue* dictionary = NULL;
- bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion(
+ bool found = patterns_dictionary->GetDictionaryWithoutPathExpansion(
key, &dictionary);
DCHECK(found);
@@ -1004,7 +1019,7 @@ void PrefProvider::MigrateObsoleteContentSettingsPatternPref() {
}
}
-void PrefProvider::SyncObsoletePref() {
+void PrefProvider::SyncObsoletePatternPref() {
AutoReset<bool> auto_reset(&updating_preferences_, true);
if (prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs) &&
!is_incognito_) {
@@ -1027,17 +1042,135 @@ void PrefProvider::SyncObsoletePref() {
continue;
}
- // Copy dictionary
- DictionaryValue* dictionary = NULL;
+ DictionaryValue* settings_dictionary = NULL;
bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion(
- key, &dictionary);
+ key, &settings_dictionary);
DCHECK(found);
- std::string new_key = pattern_pair.first.ToString();
- // Existing values are overwritten.
- obsolete_settings_dictionary->SetWithoutPathExpansion(
- new_key, dictionary->DeepCopy());
+ scoped_ptr<DictionaryValue> settings_dictionary_copy(
+ new DictionaryValue());
+ for (size_t i = CONTENT_SETTINGS_TYPE_COOKIES;
+ i <= CONTENT_SETTINGS_TYPE_POPUPS;
+ ++i) {
+ DCHECK(kTypeNames[i]);
+ std::string type_name(kTypeNames[i]);
+ if (settings_dictionary->HasKey(type_name)) {
+ Value* value = NULL;
+ bool found = settings_dictionary->GetWithoutPathExpansion(
+ type_name, &value);
+ DCHECK(found);
+ settings_dictionary_copy->SetWithoutPathExpansion(
+ type_name, value->DeepCopy());
+ }
+ }
+
+ // Ignore empty dictionaryies.
+ if (!settings_dictionary_copy->empty()) {
+ std::string new_key = pattern_pair.first.ToString();
+ // Existing values are overwritten.
+ obsolete_settings_dictionary->SetWithoutPathExpansion(
+ new_key, settings_dictionary_copy.release());
+ }
}
}
}
+void PrefProvider::MigrateObsoleteGeolocationPref() {
+ if (!prefs_->HasPrefPath(prefs::kGeolocationContentSettings))
+ return;
+
+ const DictionaryValue* geolocation_settings =
+ prefs_->GetDictionary(prefs::kGeolocationContentSettings);
+ for (DictionaryValue::key_iterator i =
+ geolocation_settings->begin_keys();
+ i != geolocation_settings->end_keys();
+ ++i) {
+ const std::string& primary_key(*i);
+ GURL primary_url(primary_key);
+ DCHECK(primary_url.is_valid());
+
+ DictionaryValue* requesting_origin_settings = NULL;
+ bool found = geolocation_settings->GetDictionaryWithoutPathExpansion(
+ primary_key, &requesting_origin_settings);
Bernhard Bauer 2011/08/05 10:08:46 Nit: indent four spaces less now.
markusheintz_ 2011/08/09 13:45:48 Done.
+ DCHECK(found);
+
+ for (DictionaryValue::key_iterator j =
+ requesting_origin_settings->begin_keys();
+ j != requesting_origin_settings->end_keys();
+ ++j) {
+ const std::string& secondary_key(*j);
+ GURL secondary_url(secondary_key);
+ DCHECK(secondary_url.is_valid());
+
+ int setting_value;
+ found = requesting_origin_settings->GetIntegerWithoutPathExpansion(
+ secondary_key, &setting_value);
Bernhard Bauer 2011/08/05 10:08:46 Nit: indent four spaces less now.
markusheintz_ 2011/08/09 13:45:48 Done.
+ DCHECK(found);
+
+ ContentSettingsPattern primary_pattern =
+ ContentSettingsPattern::FromURLNoWildcard(primary_url);
+ ContentSettingsPattern secondary_pattern =
+ ContentSettingsPattern::FromURLNoWildcard(secondary_url);
+ DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid());
+
+ SetContentSetting(primary_pattern,
+ secondary_pattern,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string(),
+ IntToContentSetting(setting_value));
+ }
+ }
+}
+
+void PrefProvider::SyncObsoleteGeolocationPref() {
+ DCHECK(prefs_);
+ DCHECK(prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs));
+
+ scoped_ptr<DictionaryValue> obsolete_geolocation_settings(
+ new DictionaryValue());
+
+ const DictionaryValue* pattern_pairs_dictionary =
+ prefs_->GetDictionary(prefs::kContentSettingsPatternPairs);
+ for (DictionaryValue::key_iterator i = pattern_pairs_dictionary->begin_keys();
+ i != pattern_pairs_dictionary->end_keys();
+ ++i) {
+ const std::string& key(*i);
+ std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair =
+ ParsePatternString(key);
+ DCHECK(pattern_pair.first.IsValid() && pattern_pair.second.IsValid());
+
+ DictionaryValue* settings_dictionary = NULL;
+ bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion(
+ key, &settings_dictionary);
+ DCHECK(found);
+
+ if (settings_dictionary->HasKey(
+ kTypeNames[CONTENT_SETTINGS_TYPE_GEOLOCATION])) {
+ const GURL primary_url(pattern_pair.first.ToString());
+ const GURL secondary_url(pattern_pair.second.ToString());
+ DCHECK(primary_url.is_valid() && secondary_url.is_valid());
+
+ int setting_value;
+ settings_dictionary->GetInteger(
+ kTypeNames[CONTENT_SETTINGS_TYPE_GEOLOCATION], &setting_value);
+
+ // Add to obsolete pref.
+ DictionaryValue* one_origin_settings = NULL;
+ bool found =
+ obsolete_geolocation_settings->GetDictionaryWithoutPathExpansion(
+ primary_url.spec(), &one_origin_settings);
+ if (!found) {
+ one_origin_settings = new DictionaryValue();
+ obsolete_geolocation_settings->SetWithoutPathExpansion(
+ primary_url.spec(), one_origin_settings);
+ }
+
+ one_origin_settings->SetWithoutPathExpansion(
+ secondary_url.spec(), Value::CreateIntegerValue(setting_value));
+ }
+ }
+
+ prefs_->Set(prefs::kGeolocationContentSettings,
+ *obsolete_geolocation_settings);
+}
+
} // namespace content_settings

Powered by Google App Engine
This is Rietveld 408576698