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

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: " Created 9 years, 5 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..487ee5a0f99873a88806e5ac6e0ce2c5c1fe6462 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,
@@ -83,6 +83,26 @@ void SetDefaultContentSettings(DictionaryValue* default_settings) {
}
}
+void CopyKeys(DictionaryValue* source,
Bernhard Bauer 2011/08/03 15:22:50 Not used?
markusheintz_ 2011/08/04 12:45:56 Sorry. Removed!
+ DictionaryValue* target,
+ const char** keys_to_copy,
+ size_t size) {
+ for (DictionaryValue::key_iterator i(source->begin_keys());
+ i != source->end_keys(); ++i) {
+ const std::string& key(*i);
+ for (size_t i = 0; i < size; ++i) {
+ if ((keys_to_copy[i] != NULL) && (keys_to_copy[i] == key)) {
+ Value* value;
+ bool found = source->GetWithoutPathExpansion(
+ key, &value);
+ DCHECK(found);
+ target->SetWithoutPathExpansion(key, value->DeepCopy());
+ break;
+ }
+ }
+ }
+}
+
ContentSetting ValueToContentSetting(Value* value) {
int int_value;
value->GetAsInteger(&int_value);
@@ -357,6 +377,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 +398,7 @@ PrefProvider::PrefProvider(PrefService* prefs,
MigrateObsoletePerhostPref();
MigrateObsoletePopupsPref();
MigrateObsoleteContentSettingsPatternPref();
+ MigrateObsoleteGeolocationPref();
}
// Verify preferences version.
@@ -399,6 +422,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 +489,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 +575,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 +619,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 +724,7 @@ void PrefProvider::ReadContentSettingsFromPref(bool overwrite) {
}
}
-void PrefProvider::UpdatePatternsPref(
+void PrefProvider::UpdateObsoletePatternsPref(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
@@ -1004,7 +1039,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 +1062,141 @@ 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 (DictionaryValue::key_iterator i(settings_dictionary->begin_keys());
+ i != settings_dictionary->end_keys();
+ ++i) {
+ const std::string& type_name(*i);
+ // Copy only the content settings types that were stored in the obsolete
+ // preference.
+ for (size_t i = 0; i <= CONTENT_SETTINGS_TYPE_POPUPS; ++i) {
Bernhard Bauer 2011/08/03 15:22:50 Can you start the iteration at CONTENT_SETTINGS_TY
markusheintz_ 2011/08/04 12:45:56 s/0/CONTENT_SETTINGS_TYPE_COOKIES/ and changed the
+ if ((kTypeNames[i] != NULL) && (kTypeNames[i] == type_name)) {
Bernhard Bauer 2011/08/03 15:22:50 kTypeNames[i] should never be NULL.
markusheintz_ 2011/08/04 12:45:56 I replaced the (kTypeNames[i] != NULL)with a DCHEC
+ Value* value;
Bernhard Bauer 2011/08/03 15:22:50 Initialize to NULL please.
markusheintz_ 2011/08/04 12:45:56 Done.
+ bool found = settings_dictionary->GetWithoutPathExpansion(
+ type_name, &value);
+ DCHECK(found);
+ settings_dictionary_copy->SetWithoutPathExpansion(
+ type_name, value->DeepCopy());
+ break;
+ }
+ }
+ }
+
+ // 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_dictionary =
+ prefs_->GetDictionary(prefs::kGeolocationContentSettings);
+ for (DictionaryValue::key_iterator i =
+ geolocation_settings_dictionary->begin_keys();
+ i != geolocation_settings_dictionary->end_keys();
+ ++i) {
+ const std::string& primary_key(*i);
+ GURL primary_url(primary_key);
+ DCHECK(primary_url.is_valid());
+
+ DictionaryValue* requesting_origin_settings_dictionary = NULL;
+ bool found =
+ geolocation_settings_dictionary->GetDictionaryWithoutPathExpansion(
Bernhard Bauer 2011/08/03 15:22:50 Maybe this is an indication to use a shorter varia
markusheintz_ 2011/08/04 12:45:56 I removed the trailing |_dictionary| from the name
+ primary_key, &requesting_origin_settings_dictionary);
+ DCHECK(found);
+
+ for (DictionaryValue::key_iterator j =
+ requesting_origin_settings_dictionary->begin_keys();
+ j != requesting_origin_settings_dictionary->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_dictionary->GetIntegerWithoutPathExpansion(
+ secondary_key, &setting_value);
+ 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* all_settings_dictionary =
+ prefs_->GetDictionary(prefs::kContentSettingsPatternPairs);
+ for (DictionaryValue::key_iterator i = all_settings_dictionary->begin_keys();
+ i != all_settings_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;
Bernhard Bauer 2011/08/03 15:22:50 Initialize with NULL please.
markusheintz_ 2011/08/04 12:45:56 Done.
+ bool found = all_settings_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;
Bernhard Bauer 2011/08/03 15:22:50 Initialize with NULL please (not as important here
markusheintz_ 2011/08/04 12:45:56 Done.
+ 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,
Bernhard Bauer 2011/08/03 15:22:50 Is there a reason you're not using a DictionaryPre
markusheintz_ 2011/08/04 12:45:56 I just found that shorter.
Bernhard Bauer 2011/08/05 10:08:46 OTOH, it makes a |DeepCopy| of the dictionary.
+ *obsolete_geolocation_settings);
}
} // namespace content_settings

Powered by Google App Engine
This is Rietveld 408576698