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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_common.cc

Issue 63053003: Ask libaddressinput for address components to use in requestAutocomplete(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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/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 4391a6b0d18d94711069617aaa590d3ce8457c76..1a1c7f0aa848e33b0cd92cfa046bda9c9250a714 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,50 +76,94 @@ void BuildInputs(const DetailInput* input_template,
}
}
+bool IsI18nAddressInputEnabledForPlatform() {
+#if defined(OS_ANDROID)
+ return false;
+#else
+ return i18ninput::IsI18nAddressInputEnabled();
+#endif
+}
+
+void BuildI18nInputs(i18ninput::AddressType address_type,
+ const std::string& country_code,
+ DetailInputs* inputs) {
+#if defined(OS_ANDROID)
+ NOTREACHED();
+#else
+ i18ninput::BuildI18nInputsForCountry(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;
+
+ // Row ids are segmented as follows:
+ // <= 0: invisible fields (e.g. country when i18n is off)
+ // 0-99: visible fields before address inputs (e.g. credit card)
+ // 100-199: visible address inputs (e.g. street, country)
+ // >= 200: visible fields after address inputs (e.g. email, phone number)
Evan Stade 2013/12/03 02:32:49 no magic numbers
Dan Beam 2013/12/03 07:38:07 Done.
+
const DetailInput kCCInputs[] = {
- { 1, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER },
- { 2, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH },
+ { 1, CREDIT_CARD_NUMBER,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER) },
+ { 2, CREDIT_CARD_EXP_MONTH,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH) },
{ 2, CREDIT_CARD_EXP_4_DIGIT_YEAR,
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR },
- { 2, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR) },
+ { 2, CREDIT_CARD_VERIFICATION_CODE,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC),
1.5 },
};
const DetailInput kBillingInputs[] = {
- { 3, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME },
- { 4, ADDRESS_BILLING_LINE1,
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
- { 5, ADDRESS_BILLING_LINE2,
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
- { 6, ADDRESS_BILLING_CITY,
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
- // TODO(estade): state placeholder should depend on locale.
- { 7, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
- { 7, ADDRESS_BILLING_ZIP,
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
+ { 101, NAME_BILLING_FULL,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME) },
+ { 102, ADDRESS_BILLING_LINE1,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) },
+ { 103, ADDRESS_BILLING_LINE2,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) },
+ { 104, ADDRESS_BILLING_CITY,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) },
+ { 105, ADDRESS_BILLING_STATE,
+ GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) },
+ { 105, ADDRESS_BILLING_ZIP,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) },
// We don't allow the user to change the country: http://crbug.com/247518
- { -1, ADDRESS_BILLING_COUNTRY, 0 },
- { 9, PHONE_BILLING_WHOLE_NUMBER,
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
+ { -1, ADDRESS_BILLING_COUNTRY, base::string16() },
+ };
+
+ const DetailInput kBillingPhoneInputs[] = {
+ { 201, PHONE_BILLING_WHOLE_NUMBER,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) },
};
const DetailInput kEmailInputs[] = {
- { 10, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL },
+ { 202, EMAIL_ADDRESS,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL) },
};
const DetailInput kShippingInputs[] = {
- { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME },
- { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
- { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
- { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
- { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
- { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
- { -1, ADDRESS_HOME_COUNTRY, 0 },
- { 17, PHONE_HOME_WHOLE_NUMBER,
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
+ { 101, NAME_FULL,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME) },
+ { 102, ADDRESS_HOME_LINE1,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) },
+ { 103, ADDRESS_HOME_LINE2,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) },
+ { 104, ADDRESS_HOME_CITY,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) },
+ { 105, ADDRESS_HOME_STATE,
+ GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) },
+ { 106, ADDRESS_HOME_ZIP,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) },
+ { -1, ADDRESS_HOME_COUNTRY, base::string16() },
+ };
+
+ const DetailInput kShippingPhoneInputs[] = {
+ { 201, PHONE_HOME_WHOLE_NUMBER,
+ GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) },
};
switch (dialog_section) {
@@ -123,17 +172,34 @@ void BuildInputsForSection(DialogSection dialog_section,
break;
case SECTION_BILLING:
- BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs);
+ if (IsI18nAddressInputEnabledForPlatform())
+ BuildI18nInputs(i18ninput::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 (IsI18nAddressInputEnabledForPlatform())
+ BuildI18nInputs(i18ninput::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 (IsI18nAddressInputEnabledForPlatform())
+ BuildI18nInputs(i18ninput::ADDRESS_TYPE_SHIPPING, country_code, inputs);
+ else
+ BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs);
+
+ BuildInputs(
+ kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs);
break;
}
}
@@ -178,13 +244,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());
- 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
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_common.h ('k') | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698