| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 2657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2668 if (section == SECTION_CC) { | 2668 if (section == SECTION_CC) { |
| 2669 CreditCard card; | 2669 CreditCard card; |
| 2670 card.set_origin(kAutofillDialogOrigin); | 2670 card.set_origin(kAutofillDialogOrigin); |
| 2671 FillFormGroupFromOutputs(output, &card); | 2671 FillFormGroupFromOutputs(output, &card); |
| 2672 | 2672 |
| 2673 // The card holder name comes from the billing address section. | 2673 // The card holder name comes from the billing address section. |
| 2674 card.SetRawInfo(CREDIT_CARD_NAME, | 2674 card.SetRawInfo(CREDIT_CARD_NAME, |
| 2675 GetValueFromSection(SECTION_BILLING, NAME_FULL)); | 2675 GetValueFromSection(SECTION_BILLING, NAME_FULL)); |
| 2676 | 2676 |
| 2677 if (ShouldSaveDetailsLocally()) { | 2677 if (ShouldSaveDetailsLocally()) { |
| 2678 GetManager()->SaveImportedCreditCard(card); | 2678 std::string guid = GetManager()->SaveImportedCreditCard(card); |
| 2679 newly_saved_data_model_guids_[section] = guid; |
| 2679 DCHECK(!profile()->IsOffTheRecord()); | 2680 DCHECK(!profile()->IsOffTheRecord()); |
| 2680 newly_saved_card_.reset(new CreditCard(card)); | 2681 newly_saved_card_.reset(new CreditCard(card)); |
| 2681 } | 2682 } |
| 2682 | 2683 |
| 2683 AutofillCreditCardWrapper card_wrapper(&card); | 2684 AutofillCreditCardWrapper card_wrapper(&card); |
| 2684 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2685 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
| 2685 | 2686 |
| 2686 // Again, CVC needs special-casing. Fill it in directly from |output|. | 2687 // Again, CVC needs special-casing. Fill it in directly from |output|. |
| 2687 SetOutputForFieldsOfType( | 2688 SetOutputForFieldsOfType( |
| 2688 CREDIT_CARD_VERIFICATION_CODE, | 2689 CREDIT_CARD_VERIFICATION_CODE, |
| 2689 GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); | 2690 GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); |
| 2690 } else { | 2691 } else { |
| 2691 AutofillProfile profile; | 2692 AutofillProfile profile; |
| 2692 profile.set_origin(kAutofillDialogOrigin); | 2693 profile.set_origin(kAutofillDialogOrigin); |
| 2693 FillFormGroupFromOutputs(output, &profile); | 2694 FillFormGroupFromOutputs(output, &profile); |
| 2694 | 2695 |
| 2695 if (ShouldSaveDetailsLocally()) | 2696 if (ShouldSaveDetailsLocally()) { |
| 2696 SaveProfileGleanedFromSection(profile, section); | 2697 std::string guid = GetManager()->SaveImportedProfile(profile); |
| 2698 newly_saved_data_model_guids_[section] = guid; |
| 2699 } |
| 2697 | 2700 |
| 2698 AutofillProfileWrapper profile_wrapper(&profile); | 2701 AutofillProfileWrapper profile_wrapper(&profile); |
| 2699 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2702 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
| 2700 } | 2703 } |
| 2701 } | 2704 } |
| 2702 } | 2705 } |
| 2703 | 2706 |
| 2704 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 2707 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
| 2705 FillOutputForSectionWithComparator( | 2708 FillOutputForSectionWithComparator( |
| 2706 section, base::Bind(common::DetailInputMatchesField, section)); | 2709 section, base::Bind(common::DetailInputMatchesField, section)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2739 view_->GetUserInput(section, &output); | 2742 view_->GetUserInput(section, &output); |
| 2740 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); | 2743 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); |
| 2741 ++iter) { | 2744 ++iter) { |
| 2742 if (iter->first->type == type) | 2745 if (iter->first->type == type) |
| 2743 return iter->second; | 2746 return iter->second; |
| 2744 } | 2747 } |
| 2745 | 2748 |
| 2746 return string16(); | 2749 return string16(); |
| 2747 } | 2750 } |
| 2748 | 2751 |
| 2749 void AutofillDialogControllerImpl::SaveProfileGleanedFromSection( | |
| 2750 const AutofillProfile& profile, | |
| 2751 DialogSection section) { | |
| 2752 GetManager()->SaveImportedProfile(profile); | |
| 2753 } | |
| 2754 | |
| 2755 SuggestionsMenuModel* AutofillDialogControllerImpl:: | 2752 SuggestionsMenuModel* AutofillDialogControllerImpl:: |
| 2756 SuggestionsMenuModelForSection(DialogSection section) { | 2753 SuggestionsMenuModelForSection(DialogSection section) { |
| 2757 switch (section) { | 2754 switch (section) { |
| 2758 case SECTION_CC: | 2755 case SECTION_CC: |
| 2759 return &suggested_cc_; | 2756 return &suggested_cc_; |
| 2760 case SECTION_BILLING: | 2757 case SECTION_BILLING: |
| 2761 return &suggested_billing_; | 2758 return &suggested_billing_; |
| 2762 case SECTION_SHIPPING: | 2759 case SECTION_SHIPPING: |
| 2763 return &suggested_shipping_; | 2760 return &suggested_shipping_; |
| 2764 case SECTION_CC_BILLING: | 2761 case SECTION_CC_BILLING: |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3133 } | 3130 } |
| 3134 | 3131 |
| 3135 if (!IsPayingWithWallet()) { | 3132 if (!IsPayingWithWallet()) { |
| 3136 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 3133 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 3137 DialogSection section = static_cast<DialogSection>(i); | 3134 DialogSection section = static_cast<DialogSection>(i); |
| 3138 if (!SectionIsActive(section)) | 3135 if (!SectionIsActive(section)) |
| 3139 continue; | 3136 continue; |
| 3140 | 3137 |
| 3141 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 3138 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 3142 std::string item_key = model->GetItemKeyForCheckedItem(); | 3139 std::string item_key = model->GetItemKeyForCheckedItem(); |
| 3143 if (IsASuggestionItemKey(item_key) || item_key == kSameAsBillingKey) | 3140 if (IsASuggestionItemKey(item_key) || item_key == kSameAsBillingKey) { |
| 3144 PersistAutofillChoice(section, item_key); | 3141 PersistAutofillChoice(section, item_key); |
| 3142 } else if (item_key == kAddNewItemKey && ShouldSaveDetailsLocally()) { |
| 3143 DCHECK(newly_saved_data_model_guids_.count(section)); |
| 3144 PersistAutofillChoice(section, newly_saved_data_model_guids_[section]); |
| 3145 } |
| 3145 } | 3146 } |
| 3146 | 3147 |
| 3147 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogSaveData, | 3148 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogSaveData, |
| 3148 view_->SaveDetailsLocally()); | 3149 view_->SaveDetailsLocally()); |
| 3149 } | 3150 } |
| 3150 | 3151 |
| 3151 // On a successful submit, if the user manually selected "pay without wallet", | 3152 // On a successful submit, if the user manually selected "pay without wallet", |
| 3152 // stop trying to pay with Wallet on future runs of the dialog. On the other | 3153 // stop trying to pay with Wallet on future runs of the dialog. On the other |
| 3153 // hand, if there was an error that prevented the user from having the choice | 3154 // hand, if there was an error that prevented the user from having the choice |
| 3154 // of using Wallet, leave the pref alone. | 3155 // of using Wallet, leave the pref alone. |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3360 } | 3361 } |
| 3361 | 3362 |
| 3362 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { | 3363 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { |
| 3363 if (!view_) | 3364 if (!view_) |
| 3364 return; | 3365 return; |
| 3365 ScopedViewUpdates updates(view_.get()); | 3366 ScopedViewUpdates updates(view_.get()); |
| 3366 view_->UpdateButtonStrip(); | 3367 view_->UpdateButtonStrip(); |
| 3367 } | 3368 } |
| 3368 | 3369 |
| 3369 } // namespace autofill | 3370 } // namespace autofill |
| OLD | NEW |