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

Unified Diff: chrome/browser/webui/options/autofill_options_handler.cc

Issue 6484022: Autofill i18n: Set postal code and state field labels based on the selected country. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Properly merged with ToT Created 9 years, 10 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
« no previous file with comments | « chrome/browser/webdata/web_database_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/webui/options/autofill_options_handler.cc
diff --git a/chrome/browser/webui/options/autofill_options_handler.cc b/chrome/browser/webui/options/autofill_options_handler.cc
index 1ffdad5cda60cfc815fc360f6ab560bff8223cb2..3e6ec60f1e2a4792cd3469ba7feae9ccc4ecad07 100644
--- a/chrome/browser/webui/options/autofill_options_handler.cc
+++ b/chrome/browser/webui/options/autofill_options_handler.cc
@@ -11,6 +11,7 @@
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/browser/autofill/autofill_country.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/profiles/profile.h"
@@ -46,6 +47,27 @@ int CreditCardTypeToResourceID(const string16& type16) {
return 0;
}
+// Returns a dictionary that maps country codes to data for the country.
+DictionaryValue* GetCountryData() {
+ std::string app_locale = AutoFillCountry::ApplicationLocale();
+ std::vector<std::string> country_codes;
+ AutoFillCountry::GetAvailableCountries(&country_codes);
+
+ DictionaryValue* country_data = new DictionaryValue();
+ for (size_t i = 0; i < country_codes.size(); ++i) {
+ const AutoFillCountry country(country_codes[i], app_locale);
+
+ DictionaryValue* details = new DictionaryValue();
+ details->SetString("name", country.name());
+ details->SetString("postalCodeLabel", country.postal_code_label());
+ details->SetString("stateLabel", country.state_label());
+
+ country_data->Set(country.country_code(), details);
+ }
+
+ return country_data;
+}
+
} // namespace
AutoFillOptionsHandler::AutoFillOptionsHandler()
@@ -145,12 +167,6 @@ void AutoFillOptionsHandler::SetAddressOverlayStrings(
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2));
localized_strings->SetString("cityLabel",
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY));
- localized_strings->SetString("stateLabel",
- l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE));
- localized_strings->SetString("zipCodeLabel",
- l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE));
- localized_strings->SetString("countryLabel",
- l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY));
localized_strings->SetString("countryLabel",
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY));
localized_strings->SetString("phoneLabel",
@@ -159,6 +175,12 @@ void AutoFillOptionsHandler::SetAddressOverlayStrings(
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX));
localized_strings->SetString("emailLabel",
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL));
+
+ std::string app_locale = AutoFillCountry::ApplicationLocale();
+ std::string default_country_code =
+ AutoFillCountry::CountryCodeForLocale(app_locale);
+ localized_strings->SetString("defaultCountryCode", default_country_code);
+ localized_strings->Set("autofillCountryData", GetCountryData());
}
void AutoFillOptionsHandler::SetCreditCardOverlayStrings(
@@ -264,10 +286,10 @@ void AutoFillOptionsHandler::LoadAddressEditor(const ListValue* args) {
profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY)));
address.SetString("state",
profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE)));
- address.SetString("zipCode",
+ address.SetString("postalCode",
profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)));
address.SetString("country",
- profile->GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY)));
+ profile->CountryCode());
address.SetString(
"phone",
profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER)));
@@ -332,6 +354,7 @@ void AutoFillOptionsHandler::SetAddress(const ListValue* args) {
AutoFillProfile profile(guid);
+ std::string country_code;
string16 value;
if (args->GetString(1, &value))
profile.SetInfo(AutoFillType(NAME_FULL), value);
@@ -347,8 +370,8 @@ void AutoFillOptionsHandler::SetAddress(const ListValue* args) {
profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), value);
if (args->GetString(7, &value))
profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), value);
- if (args->GetString(8, &value))
- profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), value);
+ if (args->GetString(8, &country_code))
+ profile.SetCountryCode(country_code);
if (args->GetString(9, &value))
profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), value);
if (args->GetString(10, &value))
« no previous file with comments | « chrome/browser/webdata/web_database_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698