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 db0ef1073aeb0762c2bab5f090ec49d47f918635..54baddf3fd41ff4d988ea29946d30503fa0acdd7 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
@@ -13,9 +13,11 @@ |
#include "apps/ui/native_app_window.h" |
#include "base/base64.h" |
#include "base/bind.h" |
+#include "base/files/file_path.h" |
#include "base/i18n/case_conversion.h" |
#include "base/i18n/rtl.h" |
#include "base/logging.h" |
+#include "base/prefs/pref_filter.h" |
#include "base/prefs/pref_registry_simple.h" |
#include "base/prefs/pref_service.h" |
#include "base/prefs/scoped_user_pref_update.h" |
@@ -25,6 +27,7 @@ |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
+#include "chrome/browser/autofill/address_storage_factory.h" |
#include "chrome/browser/autofill/personal_data_manager_factory.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -38,6 +41,7 @@ |
#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/browser_navigator.h" |
#include "chrome/browser/ui/browser_window.h" |
+#include "chrome/common/chrome_constants.h" |
#include "chrome/common/chrome_version_info.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/render_messages.h" |
@@ -79,6 +83,9 @@ |
#include "grit/theme_resources.h" |
#include "grit/webkit_resources.h" |
#include "net/cert/cert_status_flags.h" |
+#include "third_party/libaddressinput/chromium/chrome_downloader_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" |
@@ -88,6 +95,12 @@ |
#include "ui/gfx/image/image_skia_operations.h" |
#include "ui/gfx/skia_util.h" |
+using ::i18n::addressinput::AddressData; |
+using ::i18n::addressinput::AddressProblem; |
+using ::i18n::addressinput::AddressProblemFilter; |
+using ::i18n::addressinput::AddressProblems; |
+using ::i18n::addressinput::AddressValidator; |
+ |
namespace autofill { |
namespace { |
@@ -480,9 +493,10 @@ gfx::Image CvcIconForCreditCardType(const base::string16& credit_card_type) { |
return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); |
} |
-ServerFieldType CountryTypeForSection(DialogSection section) { |
- return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : |
- ADDRESS_BILLING_COUNTRY; |
+ServerFieldType TypeForSection(DialogSection section, ServerFieldType type) { |
+ return section == SECTION_SHIPPING ? |
+ AutofillType(type).GetStorableType() : |
+ AutofillType::GetEquivalentBillingFieldType(type); |
} |
} // namespace |
@@ -1107,8 +1121,8 @@ void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( |
} |
if (wrapper && IsEditingExistingData(section)) { |
- base::string16 country = |
- wrapper->GetInfo(AutofillType(CountryTypeForSection(section))); |
+ base::string16 country = wrapper->GetInfo(AutofillType( |
+ TypeForSection(section, ADDRESS_HOME_COUNTRY))); |
if (!country.empty()) { |
// There's no user input to restore here as this is only called after |
// resetting all section input. |
@@ -1700,7 +1714,8 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage( |
break; |
case ADDRESS_HOME_STATE: |
- if (!value.empty() && !autofill::IsValidState(value) && |
+ if (!i18ninput::Enabled() && !value.empty() && |
+ !autofill::IsValidState(value) && |
CountryCodeForSection(section) == "US") { |
return l10n_util::GetStringUTF16( |
IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); |
@@ -1708,7 +1723,8 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage( |
break; |
case ADDRESS_HOME_ZIP: |
- if (!value.empty() && !autofill::IsValidZip(value) && |
+ if (!i18ninput::Enabled() && !value.empty() && |
+ !autofill::IsValidZip(value) && |
CountryCodeForSection(section) == "US") { |
return l10n_util::GetStringUTF16( |
IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); |
@@ -1747,9 +1763,59 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
const FieldValueMap& inputs) { |
ValidityMessages messages; |
FieldValueMap field_values; |
+ |
+ if (section != SECTION_CC) { |
+ FieldValueMap values = inputs; |
+ |
+ AddressData address_data; |
+ address_data.language_code = g_browser_process->GetApplicationLocale(); |
+ address_data.country_code = AutofillCountry::GetCountryCode( |
+ values[TypeForSection(section, ADDRESS_HOME_COUNTRY)], |
+ g_browser_process->GetApplicationLocale()); |
+ address_data.administrative_area = UTF16ToUTF8( |
+ values[TypeForSection(section, ADDRESS_HOME_STATE)]); |
+ address_data.locality = UTF16ToUTF8( |
+ values[TypeForSection(section, ADDRESS_HOME_CITY)]); |
+ address_data.dependent_locality = UTF16ToUTF8( |
+ values[TypeForSection(section, ADDRESS_HOME_DEPENDENT_LOCALITY)]); |
+ address_data.sorting_code = UTF16ToUTF8( |
+ values[TypeForSection(section, ADDRESS_HOME_SORTING_CODE)]); |
+ address_data.postal_code = UTF16ToUTF8( |
+ values[TypeForSection(section, ADDRESS_HOME_ZIP)]); |
+ address_data.recipient = UTF16ToUTF8( |
+ values[TypeForSection(section, NAME_FULL)]); |
+ |
+ base::string16 street_line1 = |
+ values[TypeForSection(section, ADDRESS_HOME_LINE1)]; |
+ if (!street_line1.empty()) |
+ address_data.address_lines.push_back(UTF16ToUTF8(street_line1)); |
+ |
+ base::string16 street_line2 = |
+ values[TypeForSection(section, ADDRESS_HOME_LINE2)]; |
+ if (!street_line2.empty()) |
+ address_data.address_lines.push_back(UTF16ToUTF8(street_line2)); |
+ |
+ AddressProblems problems; |
+ AddressValidator::Status status = validator_->ValidateAddress( |
+ address_data, AddressProblemFilter(), &problems); |
+ if (status == AddressValidator::SUCCESS) { |
+ 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), |
+ ValidityMessage(text, sure)); |
+ } |
+ } |
+ } |
+ |
for (FieldValueMap::const_iterator iter = inputs.begin(); |
iter != inputs.end(); ++iter) { |
const ServerFieldType type = iter->first; |
+ if (messages.HasSureError(type)) |
+ continue; |
base::string16 text = InputValidityMessage(section, type, iter->second); |
@@ -2580,7 +2646,6 @@ AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
suggested_shipping_(this), |
cares_about_shipping_(true), |
popup_input_type_(UNKNOWN_TYPE), |
- weak_ptr_factory_(this), |
waiting_for_explicit_sign_in_response_(false), |
has_accepted_legal_documents_(false), |
is_submitting_(false), |
@@ -2588,9 +2653,22 @@ AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
wallet_server_validation_recoverable_(true), |
data_was_passed_back_(false), |
was_ui_latency_logged_(false), |
- card_generated_animation_(2000, 60, this) { |
+ card_generated_animation_(2000, 60, this), |
+ weak_ptr_factory_(this) { |
// TODO(estade): remove duplicates from |form_structure|? |
DCHECK(!callback_.is_null()); |
+ |
+ scoped_ptr<autofill::ChromeDownloaderImpl> downloader( |
Evan Stade
2014/01/27 23:11:15
change this type then you don't have to PassAs (I
Dan Beam
2014/01/28 02:22:36
Done.
|
+ new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())); |
+ validator_ = AddressValidator::Build( |
+ downloader.PassAs< ::i18n::addressinput::Downloader>(), |
+ AddressStorageFactory::CreateStorage(), |
+ this); |
+ |
+ validator_->LoadRules( |
+ billing_country_combobox_model_.GetDefaultCountryCode()); |
Evan Stade
2014/01/27 23:11:15
I think you could just make this:
validator_->Loa
Dan Beam
2014/01/28 02:22:36
Done.
|
+ validator_->LoadRules( |
+ shipping_country_combobox_model_.GetDefaultCountryCode()); |
} |
AutofillDialogView* AutofillDialogControllerImpl::CreateView() { |
@@ -3075,7 +3153,8 @@ std::string AutofillDialogControllerImpl::CountryCodeForSection( |
scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
if (wrapper) { |
return AutofillCountry::GetCountryCode( |
- wrapper->GetInfo(AutofillType(CountryTypeForSection(section))), |
+ wrapper->GetInfo( |
+ AutofillType(TypeForSection(section, ADDRESS_HOME_COUNTRY))), |
g_browser_process->GetApplicationLocale()); |
} |
@@ -3094,7 +3173,7 @@ bool AutofillDialogControllerImpl::RebuildInputsForCountry( |
view_->GetUserInput(section, &outputs); |
// If |country_name| is the same as the view, no-op and let the caller know. |
- if (outputs[CountryTypeForSection(section)] == country_name) |
+ if (outputs[TypeForSection(section, ADDRESS_HOME_COUNTRY)] == country_name) |
return false; |
} |
@@ -3397,6 +3476,12 @@ void AutofillDialogControllerImpl::AnimationEnded( |
DoFinishSubmit(); |
} |
+void AutofillDialogControllerImpl::OnAddressValidationRulesLoaded( |
+ const std::string& country_code, |
+ bool success) { |
+ // TODO(dbeam): ask |view_| to re-validate its contents if necessary. |
+} |
+ |
void AutofillDialogControllerImpl::DoFinishSubmit() { |
FillOutputForSection(SECTION_CC); |
FillOutputForSection(SECTION_BILLING); |