Chromium Code Reviews| Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| index ce0e728bd95a8ad6daa31d6a165fcf9538c7403d..2a78395e187e900a3fe2d23bcec8c6532ceef3c7 100644 |
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| @@ -79,14 +79,17 @@ |
| #include "grit/component_scaled_resources.h" |
| #include "grit/components_strings.h" |
| #include "grit/generated_resources.h" |
| -#include "grit/libaddressinput_strings.h" |
| +#include "grit/libaddressinput/messages.h" |
| #include "grit/platform_locale_settings.h" |
| #include "grit/theme_resources.h" |
| #include "net/cert/cert_status_flags.h" |
| #include "third_party/libaddressinput/chromium/chrome_downloader_impl.h" |
| #include "third_party/libaddressinput/chromium/chrome_storage_impl.h" |
| -#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_data.h" |
| -#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_problem.h" |
| +#include "third_party/libaddressinput/chromium/preload_address_validator.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_problem.h" |
| +#include "third_party/libaddressinput/src/cpp/include/libaddressinput/localization.h" |
| #include "ui/base/base_window.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/models/combobox_model.h" |
| @@ -98,9 +101,7 @@ |
| using ::i18n::addressinput::AddressData; |
| using ::i18n::addressinput::AddressField; |
| using ::i18n::addressinput::AddressProblem; |
| -using ::i18n::addressinput::AddressProblemFilter; |
| -using ::i18n::addressinput::AddressProblems; |
| -using ::i18n::addressinput::AddressValidator; |
| +using ::i18n::addressinput::FieldProblemMap; |
| namespace autofill { |
| @@ -824,12 +825,12 @@ void AutofillDialogControllerImpl::Show() { |
| if (account_chooser_model_->WalletIsSelected()) |
| FetchWalletCookie(); |
| - scoped_ptr< ::i18n::addressinput::Downloader> downloader( |
| - new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())); |
| - validator_ = AddressValidator::Build( |
| - downloader.Pass(), |
| + validator_.reset(new AddressValidator( |
| + I18N_ADDRESS_VALIDATION_DATA_URL, |
| + scoped_ptr< ::i18n::addressinput::Downloader>( |
| + new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())), |
| ValidationRulesStorageFactory::CreateStorage(), |
| - this); |
| + this)); |
| SuggestionsUpdated(); |
| SubmitButtonDelayBegin(); |
| @@ -1901,14 +1902,14 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage( |
| case CREDIT_CARD_EXP_MONTH: |
| if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) { |
| return l10n_util::GetStringUTF16( |
| - IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); |
| + IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD); |
| } |
| break; |
| case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) { |
| return l10n_util::GetStringUTF16( |
| - IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); |
| + IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD); |
| } |
| break; |
| @@ -1940,7 +1941,7 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage( |
| } |
| return value.empty() ? l10n_util::GetStringUTF16( |
| - IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD) : |
| + IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD) : |
| base::string16(); |
| } |
| @@ -1961,17 +1962,24 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
| profile, g_browser_process->GetApplicationLocale()); |
| address_data->language_code = AddressLanguageCodeForSection(section); |
| - AddressProblems problems; |
| - status = GetValidator()->ValidateAddress(*address_data, |
| - AddressProblemFilter(), |
| - &problems); |
| + ::i18n::addressinput::Localization localization; |
| + localization.SetGetter( |
| + l10n_util::GetStringUTF8, g_browser_process->GetApplicationLocale()); |
|
Evan Stade
2014/06/12 00:18:08
I don't understand the purpose of passing the appl
please use gerrit instead
2014/06/13 19:22:09
Improved the comment in https://codereview.appspot
Evan Stade
2014/06/13 20:07:08
still don't get it. You don't need the locale here
|
| + |
| + FieldProblemMap problems; |
| + status = GetValidator()->ValidateAddress(*address_data, NULL, &problems); |
| common::AddressType address_type = section == SECTION_SHIPPING ? |
| common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; |
| - for (size_t i = 0; i < problems.size(); ++i) { |
| - const AddressProblem& problem = problems[i]; |
| - bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; |
| - base::string16 text = l10n_util::GetStringUTF16(problem.description_id); |
| - messages.Set(i18ninput::TypeForField(problem.field, address_type), |
| + for (FieldProblemMap::const_iterator iter = problems.begin(); |
| + iter != problems.end(); ++iter) { |
| + bool sure = iter->second != ::i18n::addressinput::MISSING_REQUIRED_FIELD; |
| + base::string16 text = base::UTF8ToUTF16( |
| + localization.GetErrorMessage(*address_data, |
| + /*field*/ iter->first, |
|
Evan Stade
2014/06/12 00:18:08
nit: remove inline comments
please use gerrit instead
2014/06/13 19:22:08
I removed the inline comments, but replaced them w
Evan Stade
2014/06/13 20:07:08
if you must document the parameters here, you can
please use gerrit instead
2014/06/16 19:02:24
Done.
|
| + /*problem*/ iter->second, |
| + /*enable_examples*/ true, |
| + /*enable_links*/ false)); |
| + messages.Set(i18ninput::TypeForField(iter->first, address_type), |
| ValidityMessage(text, sure)); |
| } |
| } |
| @@ -3546,9 +3554,9 @@ bool AutofillDialogControllerImpl::SectionIsValid( |
| bool AutofillDialogControllerImpl::RulesAreLoaded(DialogSection section) { |
| AddressData address_data; |
| - address_data.country_code = CountryCodeForSection(section); |
| + address_data.region_code = CountryCodeForSection(section); |
| AddressValidator::Status status = GetValidator()->ValidateAddress( |
| - address_data, AddressProblemFilter(), NULL); |
| + address_data, NULL, NULL); |
| return status == AddressValidator::SUCCESS; |
| } |
| @@ -3600,10 +3608,8 @@ bool AutofillDialogControllerImpl::HasInvalidAddress( |
| i18n::CreateAddressDataFromAutofillProfile( |
| profile, g_browser_process->GetApplicationLocale()); |
| - AddressProblems problems; |
| - GetValidator()->ValidateAddress(*address_data, |
| - AddressProblemFilter(), |
| - &problems); |
| + FieldProblemMap problems; |
| + GetValidator()->ValidateAddress(*address_data, NULL, &problems); |
| return !problems.empty(); |
| } |