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 edaee4f0f3801e79775f503cc84e10107103eafd..b3aedd2096eabec327ff3bf210326dd75004a3bb 100644 |
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| @@ -12,6 +12,7 @@ |
| #include "apps/app_window_registry.h" |
| #include "apps/ui/native_app_window.h" |
| #include "base/base64.h" |
| +#include "base/basictypes.h" |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/i18n/case_conversion.h" |
| @@ -79,14 +80,18 @@ |
| #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/callback.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 +103,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 { |
| @@ -514,7 +517,7 @@ ServerFieldType CountryTypeForSection(DialogSection section) { |
| // Attempts to canonicalize the administrative area name in |profile| using the |
| // rules in |validator|. |
| -void CanonicalizeState(const AddressValidator* validator, |
| +void CanonicalizeState(const PreloadAddressValidator* validator, |
| AutofillProfile* profile) { |
| base::string16 administrative_area; |
| scoped_ptr<AddressData> address_data = |
| @@ -824,12 +827,11 @@ 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(), |
| - ValidationRulesStorageFactory::CreateStorage(), |
| - this); |
| + validator_.reset(new PreloadAddressValidator( |
| + I18N_ADDRESS_VALIDATION_DATA_URL, |
| + scoped_ptr< ::i18n::addressinput::Downloader>( |
| + new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())), |
| + ValidationRulesStorageFactory::CreateStorage())); |
| SuggestionsUpdated(); |
| SubmitButtonDelayBegin(); |
| @@ -1303,8 +1305,10 @@ void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { |
| } else if (!it->initial_value.empty() && |
| (it->type == ADDRESS_BILLING_COUNTRY || |
| it->type == ADDRESS_HOME_COUNTRY)) { |
| - GetValidator()->LoadRules(AutofillCountry::GetCountryCode( |
| - it->initial_value, g_browser_process->GetApplicationLocale())); |
| + GetValidator()->LoadRules( |
| + AutofillCountry::GetCountryCode( |
| + it->initial_value, g_browser_process->GetApplicationLocale()), |
| + *address_validation_rules_loaded_); |
| } |
| } |
| } |
| @@ -1901,14 +1905,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; |
| @@ -1939,9 +1943,9 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage( |
| break; |
| } |
| - return value.empty() ? l10n_util::GetStringUTF16( |
| - IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD) : |
| - base::string16(); |
| + return value.empty() ? |
| + l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD) : |
| + base::string16(); |
| } |
| // TODO(groby): Also add tests. |
| @@ -1952,7 +1956,7 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
| if (inputs.empty()) |
| return messages; |
| - AddressValidator::Status status = AddressValidator::SUCCESS; |
| + PreloadAddressValidator::Status status = PreloadAddressValidator::SUCCESS; |
| if (section != SECTION_CC) { |
| AutofillProfile profile; |
| FillFormGroupFromOutputs(inputs, &profile); |
| @@ -1961,17 +1965,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()); |
| + |
| + FieldProblemMap problems; |
| + status = GetValidator()->Validate(*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, |
| + iter->first, |
|
please use gerrit instead
2014/06/05 22:22:47
To reduce reviewer burden: add comment on what is
please use gerrit instead
2014/06/09 23:28:16
Done.
|
| + iter->second, |
| + /*enable_examples*/ true, |
| + /*enable_links*/ false)); |
| + messages.Set(i18ninput::TypeForField(iter->first, address_type), |
| ValidityMessage(text, sure)); |
| } |
| } |
| @@ -1986,7 +1997,7 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
| // otherwise. |
| bool sure = InputWasEdited(type, iter->second); |
| - if (sure && status == AddressValidator::RULES_NOT_READY && |
| + if (sure && status == PreloadAddressValidator::RULES_NOT_READY && |
| !ComboboxModelForAutofillType(type) && |
| (AutofillType(type).group() == ADDRESS_HOME || |
| AutofillType(type).group() == ADDRESS_BILLING)) { |
| @@ -2792,7 +2803,11 @@ AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
| data_was_passed_back_(false), |
| was_ui_latency_logged_(false), |
| card_generated_animation_(2000, 60, this), |
| - weak_ptr_factory_(this) { |
| + weak_ptr_factory_(this), |
| + address_validation_rules_loaded_( |
| + ::i18n::addressinput::BuildCallback( |
| + this, |
| + &AutofillDialogControllerImpl::AddressValidationRulesLoaded)) { |
| DCHECK(!callback_.is_null()); |
| } |
| @@ -2804,7 +2819,7 @@ PersonalDataManager* AutofillDialogControllerImpl::GetManager() const { |
| return PersonalDataManagerFactory::GetForProfile(profile_); |
| } |
| -AddressValidator* AutofillDialogControllerImpl::GetValidator() { |
| +PreloadAddressValidator* AutofillDialogControllerImpl::GetValidator() { |
| return validator_.get(); |
| } |
| @@ -3359,11 +3374,11 @@ void AutofillDialogControllerImpl::GetI18nValidatorSuggestions( |
| user_input->language_code = AddressLanguageCodeForSection(section); |
| static const size_t kSuggestionsLimit = 10; |
| - AddressValidator::Status status = GetValidator()->GetSuggestions( |
| + PreloadAddressValidator::Status status = GetValidator()->GetSuggestions( |
| *user_input, focused_field, kSuggestionsLimit, |
| &i18n_validator_suggestions_); |
| - if (status != AddressValidator::SUCCESS) |
| + if (status != PreloadAddressValidator::SUCCESS) |
| return; |
| for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { |
| @@ -3464,8 +3479,10 @@ bool AutofillDialogControllerImpl::RebuildInputsForCountry( |
| MutableAddressLanguageCodeForSection(section)); |
| if (!country_code.empty()) { |
| - GetValidator()->LoadRules(AutofillCountry::GetCountryCode( |
| - country_name, g_browser_process->GetApplicationLocale())); |
| + GetValidator()->LoadRules( |
| + AutofillCountry::GetCountryCode( |
| + country_name, g_browser_process->GetApplicationLocale()), |
| + *address_validation_rules_loaded_); |
| } |
| return true; |
| @@ -3547,10 +3564,11 @@ bool AutofillDialogControllerImpl::SectionIsValid( |
| bool AutofillDialogControllerImpl::RulesAreLoaded(DialogSection section) { |
| AddressData address_data; |
| - address_data.country_code = CountryCodeForSection(section); |
| - AddressValidator::Status status = GetValidator()->ValidateAddress( |
| - address_data, AddressProblemFilter(), NULL); |
| - return status == AddressValidator::SUCCESS; |
| + address_data.region_code = CountryCodeForSection(section); |
| + FieldProblemMap dummy; |
| + PreloadAddressValidator::Status status = GetValidator()->Validate( |
| + address_data, NULL, &dummy); |
| + return status == PreloadAddressValidator::SUCCESS; |
| } |
| bool AutofillDialogControllerImpl::IsCreditCardExpirationValid( |
| @@ -3601,10 +3619,8 @@ bool AutofillDialogControllerImpl::HasInvalidAddress( |
| i18n::CreateAddressDataFromAutofillProfile( |
| profile, g_browser_process->GetApplicationLocale()); |
| - AddressProblems problems; |
| - GetValidator()->ValidateAddress(*address_data, |
| - AddressProblemFilter(), |
| - &problems); |
| + FieldProblemMap problems; |
| + GetValidator()->Validate(*address_data, NULL, &problems); |
| return !problems.empty(); |
| } |
| @@ -3807,9 +3823,10 @@ void AutofillDialogControllerImpl::AnimationEnded( |
| DoFinishSubmit(); |
| } |
| -void AutofillDialogControllerImpl::OnAddressValidationRulesLoaded( |
| +void AutofillDialogControllerImpl::AddressValidationRulesLoaded( |
| + bool success, |
| const std::string& country_code, |
| - bool success) { |
| + const int& /*rule_count*/) { |
| // Rules may load instantly (during initialization, before the view is |
| // even ready). We'll validate when the view is created. |
| if (!view_) |