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 47856d71641dea74888e29e131c4e8624f653fc1..624417f05c948628bfb8a30b1c47d886235e8078 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc |
@@ -4,6 +4,7 @@ |
#include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
+#include "base/macros.h" |
#include "base/strings/string_split.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/browser_process.h" |
@@ -12,10 +13,12 @@ |
#include "components/autofill/core/browser/credit_card.h" |
#include "components/autofill/core/browser/field_types.h" |
#include "grit/components_strings.h" |
-#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_data.h" |
-#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_field.h" |
-#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_ui.h" |
-#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_ui_component.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_metadata.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui_component.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/localization.h" |
#include "ui/base/l10n/l10n_util.h" |
namespace autofill { |
@@ -41,23 +44,23 @@ void BuildAddressInputs(common::AddressType address_type, |
const std::string& country_code, |
DetailInputs* inputs, |
std::string* language_code) { |
+ DCHECK(inputs); |
+ DCHECK(language_code); |
+ |
+ ::i18n::addressinput::Localization localization; |
+ localization.SetGetter( |
+ l10n_util::GetStringUTF8, g_browser_process->GetApplicationLocale()); |
std::vector<AddressUiComponent> components( |
::i18n::addressinput::BuildComponents( |
- country_code, g_browser_process->GetApplicationLocale(), |
- language_code)); |
+ country_code, localization, language_code)); |
const bool billing = address_type == common::ADDRESS_TYPE_BILLING; |
for (size_t i = 0; i < components.size(); ++i) { |
const AddressUiComponent& component = components[i]; |
- if (component.field == ::i18n::addressinput::ORGANIZATION) { |
- // TODO(dbeam): figure out when we actually need this. |
- continue; |
- } |
- |
ServerFieldType server_type = TypeForField(component.field, address_type); |
DetailInput::Length length = LengthFromHint(component.length_hint); |
- base::string16 placeholder = l10n_util::GetStringUTF16(component.name_id); |
+ base::string16 placeholder = base::UTF8ToUTF16(component.name); |
DetailInput input = { length, server_type, placeholder }; |
inputs->push_back(input); |
} |
@@ -93,19 +96,40 @@ bool AddressHasCompleteAndVerifiedData(const AutofillProfile& profile, |
if (!profile.IsVerified()) |
return false; |
- if (!i18n::CreateAddressDataFromAutofillProfile(profile, app_locale)-> |
- HasAllRequiredFields()) { |
please use gerrit instead
2014/06/05 22:22:48
To reduce reviewer burden: make a HasAllRequiredFi
please use gerrit instead
2014/06/09 23:28:16
Done.
|
- return false; |
+ scoped_ptr<AddressData> address( |
+ i18n::CreateAddressDataFromAutofillProfile(profile, app_locale)); |
+ |
+ // TODO: Think about whether it makes sense to do this special check here in |
+ // Chromium, instead of just using the regular address validation feature of |
+ // libaddressinput. |
+ static const AddressField kFields[] = { |
+ ::i18n::addressinput::COUNTRY, |
+ ::i18n::addressinput::ADMIN_AREA, |
+ ::i18n::addressinput::LOCALITY, |
+ ::i18n::addressinput::DEPENDENT_LOCALITY, |
+ ::i18n::addressinput::SORTING_CODE, |
+ ::i18n::addressinput::POSTAL_CODE, |
+ ::i18n::addressinput::STREET_ADDRESS, |
+ ::i18n::addressinput::RECIPIENT |
+ }; |
+ |
+ for (size_t i = 0; i < arraysize(kFields); ++i) { |
+ AddressField field = kFields[i]; |
+ if (address->IsFieldEmpty(field) && |
+ ::i18n::addressinput::IsFieldRequired(field, address->region_code)) { |
+ return false; |
+ } |
} |
- const ServerFieldType more_required_fields[] = { |
+ static const ServerFieldType more_required_fields[] = { |
NAME_FULL, |
PHONE_HOME_WHOLE_NUMBER |
}; |
for (size_t i = 0; i < arraysize(more_required_fields); ++i) { |
- if (profile.GetRawInfo(more_required_fields[i]).empty()) |
+ if (profile.GetRawInfo(more_required_fields[i]).empty()) { |
return false; |
+ } |
} |
return true; |
@@ -133,8 +157,6 @@ ServerFieldType TypeForField(AddressField address_field, |
ADDRESS_HOME_STREET_ADDRESS; |
case ::i18n::addressinput::RECIPIENT: |
return billing ? NAME_BILLING_FULL : NAME_FULL; |
- case ::i18n::addressinput::ORGANIZATION: |
- return COMPANY_NAME; |
} |
NOTREACHED(); |
return UNKNOWN_TYPE; |
@@ -183,8 +205,7 @@ bool FieldForType(ServerFieldType server_type, |
*field = ::i18n::addressinput::STREET_ADDRESS; |
return true; |
case COMPANY_NAME: |
- if (field) |
- *field = ::i18n::addressinput::ORGANIZATION; |
+ // Ignored. |
return true; |
please use gerrit instead
2014/06/05 22:22:48
Investigate: this might have to return false due t
please use gerrit instead
2014/06/09 23:28:16
Done.
|
case NAME_BILLING_FULL: |
case NAME_FULL: |
@@ -198,9 +219,13 @@ bool FieldForType(ServerFieldType server_type, |
bool CountryIsFullySupported(const std::string& country_code) { |
DCHECK_EQ(2U, country_code.size()); |
+ ::i18n::addressinput::Localization localization; |
+ localization.SetGetter( |
+ l10n_util::GetStringUTF8, g_browser_process->GetApplicationLocale()); |
+ std::string best_address_language; |
please use gerrit instead
2014/06/05 22:22:47
To reduce reviewer burden: put this into a functio
please use gerrit instead
2014/06/09 23:28:16
Done.
|
std::vector< ::i18n::addressinput::AddressUiComponent> components = |
::i18n::addressinput::BuildComponents( |
- country_code, g_browser_process->GetApplicationLocale(), NULL); |
+ country_code, localization, &best_address_language); |
for (size_t i = 0; i < components.size(); ++i) { |
if (components[i].field == ::i18n::addressinput::DEPENDENT_LOCALITY) |
return false; |