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

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

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial. Created 6 years, 7 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_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 5585aba9f98480fbd3766f7922d17431965e7948..2e93edaa50512e5ecee3d7bca55cb5a7627963c3 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,10 @@
#include "grit/component_scaled_resources.h"
#include "grit/component_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 "ui/base/base_window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/combobox_model.h"
@@ -95,12 +92,20 @@
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/skia_util.h"
+#define I18N_ADDRESSINPUT_UTIL_BASICTYPES_H_ // base/basictypes.h
+#include "third_party/libaddressinput/chromium/chrome_downloader_impl.h"
+#include "third_party/libaddressinput/chromium/chrome_storage_impl.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/address_validator.h"
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h"
+
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 +519,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 +829,13 @@ 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 PreloadAddressValidator(
+ scoped_ptr< ::i18n::addressinput::Downloader>(
+ new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())),
ValidationRulesStorageFactory::CreateStorage(),
- this);
+ scoped_ptr< ::i18n::addressinput::Downloader>(
+ new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())),
+ ValidationRulesStorageFactory::CreateStorage()));
SuggestionsUpdated();
SubmitButtonDelayBegin();
@@ -1303,8 +1309,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 +1909,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 +1947,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 +1960,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 +1969,20 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
profile, g_browser_process->GetApplicationLocale());
address_data->language_code = AddressLanguageCodeForSection(section);
- AddressProblems problems;
- status = GetValidator()->ValidateAddress(*address_data,
- AddressProblemFilter(),
- &problems);
+ 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;
+#if 0
+ base::string16 text = l10n_util::GetStringUTF16(
+ IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); // TODO!!!
+#else
+ base::string16 text = base::ASCIIToUTF16("Placeholder Error. TODO.");
please use gerrit instead 2014/05/23 14:44:54 Need Keghani's error message strings.
+#endif
+ 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_)

Powered by Google App Engine
This is Rietveld 408576698