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 fcfe3c47eff386a66e100d3f3172f47c129be84c..7ed03a2eb2659e62fc303e657c65ce474f3cca9d 100644 |
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| @@ -29,6 +29,7 @@ |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
| +#include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| #if !defined(OS_ANDROID) |
| @@ -508,6 +509,9 @@ gfx::Image CvcIconForCreditCardType(const base::string16& credit_card_type) { |
| AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} |
| AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { |
| + billing_country_combobox_model_.RemoveObserver(this); |
| + shipping_country_combobox_model_.RemoveObserver(this); |
| + |
| if (popup_controller_) |
| popup_controller_->Hide(); |
| @@ -603,14 +607,26 @@ void AutofillDialogControllerImpl::Show() { |
| AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); |
| } |
| + // Fail if the author didn't specify autocomplete types. |
| + if (!has_types) { |
| + callback_.Run(NULL); |
| + delete this; |
| + return; |
| + } |
| + |
| + std::string country_code = GetManager()->GetDefaultCountryCodeForNewAddress(); |
| common::BuildInputsForSection(SECTION_CC, |
| - &requested_cc_fields_); |
| + &requested_cc_fields_, |
| + country_code); |
| common::BuildInputsForSection(SECTION_BILLING, |
| - &requested_billing_fields_); |
| + &requested_billing_fields_, |
| + country_code); |
| common::BuildInputsForSection(SECTION_CC_BILLING, |
| - &requested_cc_billing_fields_); |
| + &requested_cc_billing_fields_, |
| + country_code); |
| common::BuildInputsForSection(SECTION_SHIPPING, |
| - &requested_shipping_fields_); |
| + &requested_shipping_fields_, |
| + country_code); |
| // Test whether we need to show the shipping section. If filling that section |
| // would be a no-op, don't show it. |
| @@ -636,7 +652,10 @@ void AutofillDialogControllerImpl::Show() { |
| SubmitButtonDelayBegin(); |
| view_.reset(CreateView()); |
| view_->Show(); |
| + |
| GetManager()->AddObserver(this); |
| + billing_country_combobox_model_.AddObserver(this); |
| + shipping_country_combobox_model_.AddObserver(this); |
| if (!account_chooser_model_->WalletIsSelected()) |
| LogDialogLatencyToShow(); |
| @@ -1097,8 +1116,9 @@ void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { |
| SetEditingExistingData(section, false); |
| DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| + std::string country_code = GetCountryCodeForSection(section); |
| for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { |
| - it->initial_value = common::GetHardcodedValueForType(it->type); |
| + it->initial_value = common::GetInitialValueForType(it->type, country_code); |
|
Evan Stade
2014/01/02 22:59:26
Isn't the purpose of setting the default index on
|
| } |
| } |
| @@ -1119,7 +1139,7 @@ void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( |
| DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| if (wrapper && IsEditingExistingData(section)) |
| - wrapper->FillInputs(inputs); |
| + wrapper->FillInputs(inputs, GetCountryCodeForSection(section)); |
| } |
| bool AutofillDialogControllerImpl::InputWasEdited(ServerFieldType type, |
| @@ -1173,7 +1193,7 @@ void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( |
| continue; |
| DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| - wrapper.FillInputs(inputs); |
| + wrapper.FillInputs(inputs, GetCountryCodeForSection(section)); |
| for (size_t i = 0; i < inputs->size(); ++i) { |
| if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) { |
| @@ -1299,15 +1319,23 @@ ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( |
| case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| return &cc_exp_year_combobox_model_; |
| - case ADDRESS_HOME_COUNTRY: |
| case ADDRESS_BILLING_COUNTRY: |
| - return &country_combobox_model_; |
| + return &billing_country_combobox_model_; |
| + |
| + case ADDRESS_HOME_COUNTRY: |
| + return &shipping_country_combobox_model_; |
| default: |
| return NULL; |
| } |
| } |
| +bool AutofillDialogControllerImpl::IsCountryComboboxModel( |
| + const ui::ComboboxModel* model) const { |
| + return model == &billing_country_combobox_model_ || |
| + model == &shipping_country_combobox_model_; |
| +} |
| + |
| ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( |
| DialogSection section) { |
| SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| @@ -1695,6 +1723,7 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage( |
| return base::string16(); // Line 2 is optional - always valid. |
| case ADDRESS_HOME_CITY: |
| + case ADDRESS_HOME_DEPENDENT_LOCALITY: |
| case ADDRESS_HOME_COUNTRY: |
| break; |
| @@ -1712,6 +1741,9 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage( |
| } |
| break; |
| + case ADDRESS_HOME_SORTING_CODE: |
| + break; |
| + |
| case NAME_FULL: |
| // Wallet requires a first and last billing name. |
| if (section == SECTION_CC_BILLING && !value.empty() && |
| @@ -1722,6 +1754,9 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage( |
| } |
| break; |
| + case COMPANY_NAME: |
| + break; |
| + |
| case PHONE_HOME_WHOLE_NUMBER: // Used in shipping section. |
| break; |
| @@ -1754,7 +1789,7 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
| // always has a value. If the individual field does not have validation |
| // errors, assume it to be valid unless later proven otherwise. |
| bool sure = InputWasEdited(type, iter->second) || |
| - ComboboxModelForAutofillType(type) == &country_combobox_model_; |
| + IsCountryComboboxModel(ComboboxModelForAutofillType(type)); |
| // Consider only individually valid fields for inter-field validation. |
| if (text.empty()) { |
| @@ -1927,6 +1962,13 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput( |
| popup_ids); |
| } |
| +void AutofillDialogControllerImpl::ComboboxItemSelected(ServerFieldType type, |
| + int index) { |
| + ui::ComboboxModel* model = ComboboxModelForAutofillType(type); |
| + if (IsCountryComboboxModel(model)) |
|
Evan Stade
2014/01/02 22:59:26
imo avoid the cast by doing:
if (type == ADDRESS_
|
| + static_cast<CountryComboboxModel*>(model)->SetDefaultIndex(index); |
|
Evan Stade
2014/01/02 22:59:26
can you call OnComboboxModelChanged from here inst
|
| +} |
| + |
| void AutofillDialogControllerImpl::FocusMoved() { |
| HidePopup(); |
| } |
| @@ -2163,7 +2205,8 @@ void AutofillDialogControllerImpl::DidAcceptSuggestion( |
| for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| DialogSection section = static_cast<DialogSection>(i); |
| - wrapper->FillInputs(MutableRequestedFieldsForSection(section)); |
| + wrapper->FillInputs(MutableRequestedFieldsForSection(section), |
| + GetCountryCodeForSection(section)); |
| view_->FillSection(section, *input_showing_popup_); |
| } |
| @@ -2524,7 +2567,10 @@ AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
| wallet_items_requested_(false), |
| handling_use_wallet_link_click_(false), |
| passive_failed_(false), |
| - country_combobox_model_(*GetManager()), |
| + billing_country_combobox_model_( |
| + GetManager()->GetDefaultCountryCodeForNewAddress()), |
| + shipping_country_combobox_model_( |
| + GetManager()->GetDefaultCountryCodeForNewAddress()), |
| suggested_cc_(this), |
| suggested_billing_(this), |
| suggested_cc_billing_(this), |
| @@ -2759,7 +2805,6 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| std::vector<base::string16> labels; |
| AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); |
| DCHECK_EQ(labels.size(), profiles.size()); |
| - const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| for (size_t i = 0; i < profiles.size(); ++i) { |
| const AutofillProfile& profile = *profiles[i]; |
| if (!HasCompleteAndVerifiedData(profile, requested_shipping_fields_) || |
| @@ -2845,11 +2890,10 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
| DialogSection section, |
| const InputFieldComparator& compare) { |
| - const DetailInputs& inputs = RequestedFieldsForSection(section); |
| - |
| if (!SectionIsActive(section)) |
| return; |
| + const DetailInputs& inputs = RequestedFieldsForSection(section); |
| scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| if (wrapper) { |
| // Only fill in data that is associated with this section. |
| @@ -2996,6 +3040,44 @@ DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
| return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| } |
| +std::string AutofillDialogControllerImpl::GetCountryCodeForSection( |
| + DialogSection section) const { |
| + if (section == SECTION_BILLING || section == SECTION_CC_BILLING) |
| + return billing_country_combobox_model_.GetDefaultCountryCode(); |
| + if (section == SECTION_SHIPPING) |
| + return shipping_country_combobox_model_.GetDefaultCountryCode(); |
| + return "US"; |
| +} |
| + |
| +void AutofillDialogControllerImpl::OnComboboxModelChanged( |
| + ui::ComboboxModel* model) { |
| + DCHECK(IsCountryComboboxModel(model)); |
| + |
| + ScopedViewUpdates updates(view_.get()); |
| + const FieldValueMap snapshot = TakeUserInputSnapshot(); |
| + |
| + const bool is_shipping = model == &shipping_country_combobox_model_; |
| + const std::string country_code = |
| + static_cast<CountryComboboxModel*>(model)->GetDefaultCountryCode(); |
| + for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| + DialogSection section = static_cast<DialogSection>(i); |
| + |
| + if ((is_shipping && section != SECTION_SHIPPING) || |
| + !(section == SECTION_BILLING || section == SECTION_CC_BILLING)) { |
| + continue; |
| + } |
| + |
| + DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| + inputs->clear(); |
| + common::BuildInputsForSection(section, inputs, country_code); |
| + } |
| + |
| + RestoreUserInputFromSnapshot(snapshot); |
| + |
| + UpdateSection(is_shipping ? SECTION_SHIPPING : |
| + IsPayingWithWallet() ? SECTION_CC_BILLING : SECTION_BILLING); |
| +} |
| + |
| void AutofillDialogControllerImpl::HidePopup() { |
| if (popup_controller_.get()) |
| popup_controller_->Hide(); |