Chromium Code Reviews| Index: chrome/browser/ui/autofill/autofill_dialog_controller.cc |
| diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller.cc b/chrome/browser/ui/autofill/autofill_dialog_controller.cc |
| index 4fd02ffabd5ee5bc080b3b97e3ee91996bbc66f2..560684a67052986c2888ecc7c510b9d758b072ec 100644 |
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller.cc |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller.cc |
| @@ -18,6 +18,23 @@ namespace autofill { |
| namespace { |
| +// Returns true if |input| should be shown when |field| has been requeted. |
|
Ilya Sherman
2012/11/30 01:01:32
nit: "requeted" -> "requested"
Evan Stade
2012/11/30 22:55:25
Done.
|
| +bool InputMatchesField(const DetailInput& input, |
| + const AutofillField& field) { |
| + // If any credit card expiration info is asked for, show both month and year |
| + // inputs. |
| + if (field.type() == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
| + field.type() == CREDIT_CARD_EXP_2_DIGIT_YEAR || |
| + field.type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || |
| + field.type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || |
| + field.type() == CREDIT_CARD_EXP_MONTH) { |
| + return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
| + input.type == CREDIT_CARD_EXP_MONTH; |
| + } |
| + |
| + return input.type == field.type(); |
| +} |
| + |
| // Returns true if |input| should be used for a site-requested |field|. If |
| // non-empty, |section_suffix| overrides the section specified by |input|. |
| bool DetailInputMatchesFieldWithSection(const std::string& section_suffix, |
| @@ -25,7 +42,7 @@ bool DetailInputMatchesFieldWithSection(const std::string& section_suffix, |
| const AutofillField& field) { |
| bool right_section = section_suffix.empty() || |
| EndsWith(field.section(), section_suffix, false); |
| - return input.type == field.type() && right_section; |
| + return InputMatchesField(input, field) && right_section; |
| } |
| // Returns true if |input| should be used for a site-requested |field|. |
| @@ -142,7 +159,8 @@ void AutofillDialogController::Show() { |
| const DetailInput kCCInputs[] = { |
| { ++row_id, CREDIT_CARD_NUMBER, "Card number" }, |
| - { ++row_id, CREDIT_CARD_EXP_2_DIGIT_YEAR, "Expiration MM/YY" }, |
| + { ++row_id, CREDIT_CARD_EXP_MONTH }, |
| + { row_id, CREDIT_CARD_EXP_4_DIGIT_YEAR }, |
| { row_id, CREDIT_CARD_VERIFICATION_CODE, "CVC" }, |
| { ++row_id, CREDIT_CARD_NAME, "Cardholder name" }, |
| }; |
| @@ -271,6 +289,24 @@ const DetailInputs& AutofillDialogController::RequestedFieldsForSection( |
| return requested_shipping_fields_; |
| } |
| +ui::ComboboxModel* AutofillDialogController::ComboboxModelForAutofillType( |
| + AutofillFieldType type) { |
| + switch (type) { |
| + case CREDIT_CARD_EXP_MONTH: |
| + if (!cc_exp_month_combobox_model_.get()) |
| + cc_exp_month_combobox_model_.reset(new MonthComboboxModel()); |
|
Ilya Sherman
2012/11/30 01:01:32
nit: Why lazy-init and heap-allocate rather than j
Evan Stade
2012/11/30 22:55:25
good point
|
| + return cc_exp_month_combobox_model_.get(); |
| + |
| + case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| + if (!cc_exp_year_combobox_model_.get()) |
| + cc_exp_year_combobox_model_.reset(new YearComboboxModel()); |
| + return cc_exp_year_combobox_model_.get(); |
| + |
| + default: |
| + return NULL; |
| + } |
| +} |
| + |
| ui::ComboboxModel* AutofillDialogController::ComboboxModelForSection( |
| DialogSection section) { |
| return SuggestionsModelForSection(section); |
| @@ -299,21 +335,21 @@ void AutofillDialogController::GenerateComboboxModels() { |
| PersonalDataManagerFactory::GetForProfile(profile_); |
| const std::vector<CreditCard*>& cards = manager->credit_cards(); |
| for (size_t i = 0; i < cards.size(); ++i) { |
| - suggested_cc_.AddItem(cards[i]->Label(), cards[i]->guid()); |
| + suggested_cc_.AddItem(cards[i]->guid(), cards[i]->Label()); |
| } |
| - suggested_cc_.AddItem(ASCIIToUTF16("Enter new card"), ""); |
| + suggested_cc_.AddItem("", ASCIIToUTF16("Enter new card")); |
| const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
| for (size_t i = 0; i < profiles.size(); ++i) { |
| string16 email = profiles[i]->GetCanonicalizedInfo(EMAIL_ADDRESS); |
| if (!email.empty()) |
| - suggested_email_.AddItem(email, profiles[i]->guid()); |
| - suggested_billing_.AddItem(profiles[i]->Label(), profiles[i]->guid()); |
| - suggested_shipping_.AddItem(profiles[i]->Label(), profiles[i]->guid()); |
| + suggested_email_.AddItem(profiles[i]->guid(), email); |
| + suggested_billing_.AddItem(profiles[i]->guid(), profiles[i]->Label()); |
| + suggested_shipping_.AddItem(profiles[i]->guid(), profiles[i]->Label()); |
| } |
| - suggested_billing_.AddItem(ASCIIToUTF16("Enter new billing"), ""); |
| - suggested_email_.AddItem(ASCIIToUTF16("Enter new email"), ""); |
| - suggested_shipping_.AddItem(ASCIIToUTF16("Enter new shipping"), ""); |
| + suggested_billing_.AddItem("", ASCIIToUTF16("Enter new billing")); |
| + suggested_email_.AddItem("", ASCIIToUTF16("Enter new email")); |
| + suggested_shipping_.AddItem("", ASCIIToUTF16("Enter new shipping")); |
| } |
| void AutofillDialogController::PopulateInputsWithGuesses() { |
| @@ -407,8 +443,8 @@ void AutofillDialogController::FillOutputForSection(DialogSection section) { |
| base::Bind(DetailInputMatchesField)); |
| } |
| -AutofillDialogController::SuggestionsComboboxModel* AutofillDialogController:: |
| - SuggestionsModelForSection(DialogSection section) { |
| +SuggestionsComboboxModel* AutofillDialogController::SuggestionsModelForSection( |
| + DialogSection section) { |
| switch (section) { |
| case SECTION_EMAIL: |
| return &suggested_email_; |
| @@ -424,32 +460,4 @@ AutofillDialogController::SuggestionsComboboxModel* AutofillDialogController:: |
| return NULL; |
| } |
| -// SuggestionsComboboxModel ---------------------------------------------------- |
| - |
| -AutofillDialogController::SuggestionsComboboxModel::SuggestionsComboboxModel() { |
| -} |
| - |
| -AutofillDialogController::SuggestionsComboboxModel:: |
| - ~SuggestionsComboboxModel() {} |
| - |
| -void AutofillDialogController::SuggestionsComboboxModel::AddItem( |
| - const string16& item, const std::string& key) { |
| - items_.push_back(std::make_pair(key, item)); |
| -} |
| - |
| -std::string AutofillDialogController::SuggestionsComboboxModel::GetItemKeyAt( |
| - int index) { |
| - return items_[index].first; |
| -} |
| - |
| -int AutofillDialogController::SuggestionsComboboxModel::GetItemCount() const { |
| - return items_.size(); |
| -} |
| - |
| -string16 AutofillDialogController::SuggestionsComboboxModel::GetItemAt( |
| - int index) { |
| - return items_[index].second; |
| -} |
| - |
| } // namespace autofill |
| - |