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 2667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2678 if (section == SECTION_CC) { | 2678 if (section == SECTION_CC) { |
2679 CreditCard card; | 2679 CreditCard card; |
2680 card.set_origin(kAutofillDialogOrigin); | 2680 card.set_origin(kAutofillDialogOrigin); |
2681 FillFormGroupFromOutputs(output, &card); | 2681 FillFormGroupFromOutputs(output, &card); |
2682 | 2682 |
2683 // The card holder name comes from the billing address section. | 2683 // The card holder name comes from the billing address section. |
2684 card.SetRawInfo(CREDIT_CARD_NAME, | 2684 card.SetRawInfo(CREDIT_CARD_NAME, |
2685 GetValueFromSection(SECTION_BILLING, NAME_FULL)); | 2685 GetValueFromSection(SECTION_BILLING, NAME_FULL)); |
2686 | 2686 |
2687 if (ShouldSaveDetailsLocally()) { | 2687 if (ShouldSaveDetailsLocally()) { |
2688 GetManager()->SaveImportedCreditCard(card); | 2688 newly_saved_card_guid_ = GetManager()->SaveImportedCreditCard(card); |
2689 DCHECK(!profile()->IsOffTheRecord()); | 2689 DCHECK(!profile()->IsOffTheRecord()); |
2690 newly_saved_card_.reset(new CreditCard(card)); | 2690 newly_saved_card_.reset(new CreditCard(card)); |
2691 } | 2691 } |
2692 | 2692 |
2693 AutofillCreditCardWrapper card_wrapper(&card); | 2693 AutofillCreditCardWrapper card_wrapper(&card); |
2694 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2694 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
2695 | 2695 |
2696 // Again, CVC needs special-casing. Fill it in directly from |output|. | 2696 // Again, CVC needs special-casing. Fill it in directly from |output|. |
2697 SetOutputForFieldsOfType( | 2697 SetOutputForFieldsOfType( |
2698 CREDIT_CARD_VERIFICATION_CODE, | 2698 CREDIT_CARD_VERIFICATION_CODE, |
2699 GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); | 2699 GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); |
2700 } else { | 2700 } else { |
2701 AutofillProfile profile; | 2701 AutofillProfile profile; |
2702 profile.set_origin(kAutofillDialogOrigin); | 2702 profile.set_origin(kAutofillDialogOrigin); |
2703 FillFormGroupFromOutputs(output, &profile); | 2703 FillFormGroupFromOutputs(output, &profile); |
2704 | 2704 |
2705 if (ShouldSaveDetailsLocally()) | 2705 if (ShouldSaveDetailsLocally()) { |
2706 SaveProfileGleanedFromSection(profile, section); | 2706 std::string guid = GetManager()->SaveImportedProfile(profile); |
Evan Stade
2013/09/16 16:58:12
nit: I think the code might be a bit more concise
Ilya Sherman
2013/09/16 20:08:52
Good call. Done.
| |
2707 if (section == SECTION_BILLING) { | |
2708 newly_saved_billing_profile_guid_ = guid; | |
2709 } else { | |
2710 DCHECK_EQ(section, SECTION_SHIPPING); | |
2711 newly_saved_shipping_profile_guid_ = guid; | |
2712 } | |
2713 } | |
2707 | 2714 |
2708 AutofillProfileWrapper profile_wrapper(&profile); | 2715 AutofillProfileWrapper profile_wrapper(&profile); |
2709 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2716 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
2710 } | 2717 } |
2711 } | 2718 } |
2712 } | 2719 } |
2713 | 2720 |
2714 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 2721 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
2715 FillOutputForSectionWithComparator( | 2722 FillOutputForSectionWithComparator( |
2716 section, base::Bind(common::DetailInputMatchesField, section)); | 2723 section, base::Bind(common::DetailInputMatchesField, section)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2749 view_->GetUserInput(section, &output); | 2756 view_->GetUserInput(section, &output); |
2750 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); | 2757 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); |
2751 ++iter) { | 2758 ++iter) { |
2752 if (iter->first->type == type) | 2759 if (iter->first->type == type) |
2753 return iter->second; | 2760 return iter->second; |
2754 } | 2761 } |
2755 | 2762 |
2756 return string16(); | 2763 return string16(); |
2757 } | 2764 } |
2758 | 2765 |
2759 void AutofillDialogControllerImpl::SaveProfileGleanedFromSection( | |
2760 const AutofillProfile& profile, | |
2761 DialogSection section) { | |
2762 GetManager()->SaveImportedProfile(profile); | |
2763 } | |
2764 | |
2765 SuggestionsMenuModel* AutofillDialogControllerImpl:: | 2766 SuggestionsMenuModel* AutofillDialogControllerImpl:: |
2766 SuggestionsMenuModelForSection(DialogSection section) { | 2767 SuggestionsMenuModelForSection(DialogSection section) { |
2767 switch (section) { | 2768 switch (section) { |
2768 case SECTION_CC: | 2769 case SECTION_CC: |
2769 return &suggested_cc_; | 2770 return &suggested_cc_; |
2770 case SECTION_BILLING: | 2771 case SECTION_BILLING: |
2771 return &suggested_billing_; | 2772 return &suggested_billing_; |
2772 case SECTION_SHIPPING: | 2773 case SECTION_SHIPPING: |
2773 return &suggested_shipping_; | 2774 return &suggested_shipping_; |
2774 case SECTION_CC_BILLING: | 2775 case SECTION_CC_BILLING: |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3143 } | 3144 } |
3144 | 3145 |
3145 if (!IsPayingWithWallet()) { | 3146 if (!IsPayingWithWallet()) { |
3146 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 3147 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
3147 DialogSection section = static_cast<DialogSection>(i); | 3148 DialogSection section = static_cast<DialogSection>(i); |
3148 if (!SectionIsActive(section)) | 3149 if (!SectionIsActive(section)) |
3149 continue; | 3150 continue; |
3150 | 3151 |
3151 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 3152 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
3152 std::string item_key = model->GetItemKeyForCheckedItem(); | 3153 std::string item_key = model->GetItemKeyForCheckedItem(); |
3153 if (IsASuggestionItemKey(item_key) || item_key == kSameAsBillingKey) | 3154 if (IsASuggestionItemKey(item_key) || item_key == kSameAsBillingKey) { |
3154 PersistAutofillChoice(section, item_key); | 3155 PersistAutofillChoice(section, item_key); |
3156 } else if (item_key == kAddNewItemKey) { | |
3157 if (section == SECTION_CC) | |
3158 PersistAutofillChoice(section, newly_saved_card_guid_); | |
3159 else if (section == SECTION_BILLING) | |
3160 PersistAutofillChoice(section, newly_saved_billing_profile_guid_); | |
3161 else if (section == SECTION_SHIPPING) | |
3162 PersistAutofillChoice(section, newly_saved_shipping_profile_guid_); | |
3163 else | |
3164 NOTREACHED(); | |
3165 } | |
3155 } | 3166 } |
3156 | 3167 |
3157 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogSaveData, | 3168 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogSaveData, |
3158 view_->SaveDetailsLocally()); | 3169 view_->SaveDetailsLocally()); |
3159 } | 3170 } |
3160 | 3171 |
3161 // On a successful submit, if the user manually selected "pay without wallet", | 3172 // On a successful submit, if the user manually selected "pay without wallet", |
3162 // stop trying to pay with Wallet on future runs of the dialog. On the other | 3173 // stop trying to pay with Wallet on future runs of the dialog. On the other |
3163 // hand, if there was an error that prevented the user from having the choice | 3174 // hand, if there was an error that prevented the user from having the choice |
3164 // of using Wallet, leave the pref alone. | 3175 // of using Wallet, leave the pref alone. |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3370 } | 3381 } |
3371 | 3382 |
3372 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { | 3383 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { |
3373 if (!view_) | 3384 if (!view_) |
3374 return; | 3385 return; |
3375 ScopedViewUpdates updates(view_.get()); | 3386 ScopedViewUpdates updates(view_.get()); |
3376 view_->UpdateButtonStrip(); | 3387 view_->UpdateButtonStrip(); |
3377 } | 3388 } |
3378 | 3389 |
3379 } // namespace autofill | 3390 } // namespace autofill |
OLD | NEW |