| 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..1568b6c219180cfaa9edd2752ea84c245ba6e1c9 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"
|
| @@ -11,11 +12,13 @@
|
| #include "components/autofill/core/browser/autofill_profile.h"
|
| #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 "grit/component_strings.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,44 @@ bool AddressHasCompleteAndVerifiedData(const AutofillProfile& profile,
|
| if (!profile.IsVerified())
|
| return false;
|
|
|
| - if (!i18n::CreateAddressDataFromAutofillProfile(profile, app_locale)->
|
| - HasAllRequiredFields()) {
|
| + 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::ADMIN_AREA,
|
| + ::i18n::addressinput::LOCALITY,
|
| + ::i18n::addressinput::DEPENDENT_LOCALITY,
|
| + ::i18n::addressinput::SORTING_CODE,
|
| + ::i18n::addressinput::POSTAL_CODE,
|
| + ::i18n::addressinput::STREET_ADDRESS,
|
| + ::i18n::addressinput::RECIPIENT
|
| + };
|
| +
|
| + // TODO: Make libaddressinput always flag COUNTRY as required.
|
| + if (address->IsFieldEmpty(::i18n::addressinput::COUNTRY)) {
|
| return false;
|
| }
|
|
|
| - const ServerFieldType more_required_fields[] = {
|
| + for (size_t i = 0; i < arraysize(kFields); ++i) {
|
| + AddressField field = kFields[i];
|
| + if (::i18n::addressinput::IsFieldRequired(field, address->region_code) &&
|
| + address->IsFieldEmpty(field)) {
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + 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 +161,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 +209,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;
|
| case NAME_BILLING_FULL:
|
| case NAME_FULL:
|
| @@ -198,9 +223,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;
|
| 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;
|
|
|