Chromium Code Reviews| Index: chrome/browser/ui/autofill/autofill_dialog_common.cc |
| diff --git a/chrome/browser/ui/autofill/autofill_dialog_common.cc b/chrome/browser/ui/autofill/autofill_dialog_common.cc |
| index 753104e8b31182ef8867c52eb06c64085945683a..b92aaa7d5cdc6b45415027ba77b72c811eaf00a0 100644 |
| --- a/chrome/browser/ui/autofill/autofill_dialog_common.cc |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_common.cc |
| @@ -13,6 +13,11 @@ |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources.h" |
| #include "grit/webkit_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +#if !defined(OS_ANDROID) |
| +#include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| +#endif // !defined(OS_ANDROID) |
| namespace autofill { |
| namespace common { |
| @@ -71,79 +76,107 @@ void BuildInputs(const DetailInput* input_template, |
| } |
| } |
| +bool IsI18nInputEnabled() { |
| +#if defined(OS_ANDROID) |
| + return false; |
| +#else |
| + return i18ninput::Enabled(); |
| +#endif |
| +} |
| + |
| +void BuildI18nAddressInputs(AddressType address_type, |
| + const std::string& country_code, |
| + DetailInputs* inputs) { |
| +#if defined(OS_ANDROID) |
| + NOTREACHED(); |
| +#else |
| + i18ninput::BuildAddressInputs(address_type, country_code, inputs); |
| +#endif |
| +} |
| + |
| // Constructs |inputs| from template data for a given |dialog_section|. |
| void BuildInputsForSection(DialogSection dialog_section, |
| - DetailInputs* inputs) { |
| + DetailInputs* inputs, |
| + const std::string& country_code) { |
| + using l10n_util::GetStringUTF16; |
| + |
| const DetailInput kCCInputs[] = { |
| { DetailInput::LONG, |
| CREDIT_CARD_NUMBER, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER) }, |
| { DetailInput::SHORT, |
| CREDIT_CARD_EXP_MONTH, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH) }, |
| { DetailInput::SHORT, |
| CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, |
| - { DetailInput::SHORT, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR) }, |
| + { DetailInput::SHORT_EOL, |
| CREDIT_CARD_VERIFICATION_CODE, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC), |
| 1.5 }, |
| }; |
| const DetailInput kBillingInputs[] = { |
| { DetailInput::LONG, |
| NAME_BILLING_FULL, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME) }, |
| { DetailInput::LONG, |
| ADDRESS_BILLING_LINE1, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) }, |
| { DetailInput::LONG, |
| ADDRESS_BILLING_LINE2, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) }, |
| { DetailInput::LONG, |
| ADDRESS_BILLING_CITY, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
| - // TODO(estade): state placeholder should depend on locale. |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) }, |
| { DetailInput::SHORT, |
| ADDRESS_BILLING_STATE, |
| - IDS_AUTOFILL_FIELD_LABEL_STATE }, |
| - { DetailInput::SHORT, |
| + GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) }, |
| + { DetailInput::SHORT_EOL, |
| ADDRESS_BILLING_ZIP, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) }, |
| // We don't allow the user to change the country: http://crbug.com/247518 |
| - { DetailInput::NONE, ADDRESS_BILLING_COUNTRY, 0 }, |
| + { DetailInput::NONE, ADDRESS_BILLING_COUNTRY }, |
| + }; |
| + |
| + const DetailInput kBillingPhoneInputs[] = { |
| { DetailInput::LONG, |
| PHONE_BILLING_WHOLE_NUMBER, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) }, |
| }; |
| const DetailInput kEmailInputs[] = { |
| - { DetailInput::LONG, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
| + { DetailInput::LONG, |
| + EMAIL_ADDRESS, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL) }, |
| }; |
| const DetailInput kShippingInputs[] = { |
| { DetailInput::LONG, |
| NAME_FULL, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME) }, |
| { DetailInput::LONG, |
| ADDRESS_HOME_LINE1, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) }, |
| { DetailInput::LONG, |
| ADDRESS_HOME_LINE2, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) }, |
| { DetailInput::LONG, |
| ADDRESS_HOME_CITY, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) }, |
| { DetailInput::SHORT, |
| ADDRESS_HOME_STATE, |
| - IDS_AUTOFILL_FIELD_LABEL_STATE }, |
| - { DetailInput::SHORT, |
| + GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) }, |
| + { DetailInput::SHORT_EOL, |
| ADDRESS_HOME_ZIP, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
| - { DetailInput::NONE, ADDRESS_HOME_COUNTRY, 0 }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) }, |
| + { DetailInput::NONE, ADDRESS_HOME_COUNTRY }, |
| + }; |
| + |
| + const DetailInput kShippingPhoneInputs[] = { |
| { DetailInput::LONG, |
| PHONE_HOME_WHOLE_NUMBER, |
| - IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
| + GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) }, |
| }; |
| switch (dialog_section) { |
| @@ -152,17 +185,34 @@ void BuildInputsForSection(DialogSection dialog_section, |
| break; |
| case SECTION_BILLING: |
| - BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
| + if (IsI18nInputEnabled()) |
| + BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, country_code, inputs); |
| + else |
| + BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
| + |
| + BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
| BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); |
| break; |
| case SECTION_CC_BILLING: |
| BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
| - BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
| + |
| + if (IsI18nInputEnabled()) |
| + BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, country_code, inputs); |
| + else |
| + BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
| + |
| + BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
| break; |
| case SECTION_SHIPPING: |
| - BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); |
| + if (IsI18nInputEnabled()) |
| + BuildI18nAddressInputs(ADDRESS_TYPE_SHIPPING, country_code, inputs); |
| + else |
| + BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); |
| + |
| + BuildInputs( |
| + kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs); |
| break; |
| } |
| } |
| @@ -207,13 +257,13 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( |
| return AutofillMetrics::NUM_DIALOG_UI_EVENTS; |
| } |
| -string16 GetHardcodedValueForType(ServerFieldType type) { |
| +base::string16 GetInitialValueForType(ServerFieldType type, |
| + const std::string& country_code) { |
| if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { |
| - AutofillCountry country("US", g_browser_process->GetApplicationLocale()); |
|
Evan Stade
2013/12/05 03:09:18
seems like you're breaking the non-i18nized case (
Dan Beam
2013/12/05 08:55:57
We should just add back i18ninput::GuessCountry()
|
| - return country.name(); |
| + const std::string& ui_locale = g_browser_process->GetApplicationLocale(); |
| + return AutofillCountry(country_code, ui_locale).name(); |
| } |
| - |
| - return string16(); |
| + return base::string16(); |
| } |
| } // namespace common |