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

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

Issue 145553009: rAc: use libaddressinput to validate international addresses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 11 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/ui/autofill/autofill_dialog_i18n_input.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc b/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc
index 6e2f5fbc4dd3a6611c3f2ca3ffaf4a17b3c3a4b3..6539617ae16a178e5757f8e68a787bf88c43a97f 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc
@@ -24,33 +24,6 @@ namespace {
using ::i18n::addressinput::AddressField;
using ::i18n::addressinput::AddressUiComponent;
-ServerFieldType AddressFieldToServerFieldType(AddressField address_field,
- bool billing) {
- switch (address_field) {
- case ::i18n::addressinput::COUNTRY:
- return billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY;
- case ::i18n::addressinput::ADMIN_AREA:
- return billing ? ADDRESS_BILLING_STATE : ADDRESS_HOME_STATE;
- case ::i18n::addressinput::LOCALITY:
- return billing ? ADDRESS_BILLING_CITY : ADDRESS_HOME_CITY;
- case ::i18n::addressinput::DEPENDENT_LOCALITY:
- return billing ? ADDRESS_BILLING_DEPENDENT_LOCALITY :
- ADDRESS_HOME_DEPENDENT_LOCALITY;
- case ::i18n::addressinput::POSTAL_CODE:
- return billing ? ADDRESS_BILLING_ZIP : ADDRESS_HOME_ZIP;
- case ::i18n::addressinput::SORTING_CODE:
- return billing ? ADDRESS_BILLING_SORTING_CODE : ADDRESS_HOME_SORTING_CODE;
- case ::i18n::addressinput::STREET_ADDRESS:
- return billing ? ADDRESS_BILLING_LINE1 : ADDRESS_HOME_LINE1;
- case ::i18n::addressinput::RECIPIENT:
- return billing ? NAME_BILLING_FULL : NAME_FULL;
- case ::i18n::addressinput::ORGANIZATION:
- return COMPANY_NAME;
- }
- NOTREACHED();
- return UNKNOWN_TYPE;
-}
-
DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) {
if (hint == AddressUiComponent::HINT_SHORT)
return DetailInput::SHORT;
@@ -80,8 +53,7 @@ void BuildAddressInputs(common::AddressType address_type,
continue;
}
- ServerFieldType server_type = AddressFieldToServerFieldType(component.field,
- billing);
+ ServerFieldType server_type = TypeForField(component.field, address_type);
DetailInput::Length length = LengthFromHint(component.length_hint);
base::string16 placeholder = l10n_util::GetStringUTF16(component.name_id);
DetailInput input = { length, server_type, placeholder };
@@ -137,7 +109,7 @@ bool AddressHasCompleteAndVerifiedData(const AutofillProfile& profile) {
for (size_t i = 0; i < required_fields.size(); ++i) {
ServerFieldType type =
- AddressFieldToServerFieldType(required_fields[i], false);
+ TypeForField(required_fields[i], common::ADDRESS_TYPE_SHIPPING);
if (profile.GetRawInfo(type).empty())
return false;
}
@@ -156,5 +128,33 @@ bool AddressHasCompleteAndVerifiedData(const AutofillProfile& profile) {
return true;
}
+ServerFieldType TypeForField(AddressField address_field,
+ common::AddressType address_type) {
+ bool billing = address_type == common::ADDRESS_TYPE_BILLING;
+ switch (address_field) {
+ case ::i18n::addressinput::COUNTRY:
+ return billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY;
+ case ::i18n::addressinput::ADMIN_AREA:
+ return billing ? ADDRESS_BILLING_STATE : ADDRESS_HOME_STATE;
+ case ::i18n::addressinput::LOCALITY:
+ return billing ? ADDRESS_BILLING_CITY : ADDRESS_HOME_CITY;
+ case ::i18n::addressinput::DEPENDENT_LOCALITY:
+ return billing ? ADDRESS_BILLING_DEPENDENT_LOCALITY :
+ ADDRESS_HOME_DEPENDENT_LOCALITY;
+ case ::i18n::addressinput::POSTAL_CODE:
+ return billing ? ADDRESS_BILLING_ZIP : ADDRESS_HOME_ZIP;
+ case ::i18n::addressinput::SORTING_CODE:
+ return billing ? ADDRESS_BILLING_SORTING_CODE : ADDRESS_HOME_SORTING_CODE;
+ case ::i18n::addressinput::STREET_ADDRESS:
+ return billing ? ADDRESS_BILLING_LINE1 : ADDRESS_HOME_LINE1;
+ case ::i18n::addressinput::RECIPIENT:
+ return billing ? NAME_BILLING_FULL : NAME_FULL;
+ case ::i18n::addressinput::ORGANIZATION:
+ return COMPANY_NAME;
+ }
+ NOTREACHED();
+ return UNKNOWN_TYPE;
+}
+
} // namespace i18ninput
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698