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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 if (is_submitting_ || ShouldShowSpinner()) | 743 if (is_submitting_ || ShouldShowSpinner()) |
744 return false; | 744 return false; |
745 return true; | 745 return true; |
746 } | 746 } |
747 | 747 |
748 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); | 748 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); |
749 return !is_submitting_ || autocheckout_state_ != AUTOCHECKOUT_NOT_STARTED || | 749 return !is_submitting_ || autocheckout_state_ != AUTOCHECKOUT_NOT_STARTED || |
750 IsSubmitPausedOn(wallet::VERIFY_CVV); | 750 IsSubmitPausedOn(wallet::VERIFY_CVV); |
751 } | 751 } |
752 | 752 |
753 DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { | |
754 bool show_wallet_interstitial = IsPayingWithWallet() && is_submitting_ && | |
755 !IsSubmitPausedOn(wallet::VERIFY_CVV); | |
756 if (!show_wallet_interstitial) | |
757 return DialogOverlayState(); | |
758 | |
759 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
760 DialogOverlayState state; | |
761 // TODO(estade): use the correct image and strings below. | |
762 state.image = rb.GetImageNamed(IDR_PRODUCT_LOGO_NAME_48); | |
763 | |
764 state.strings.push_back(DialogOverlayString()); | |
765 DialogOverlayString& string = state.strings.back(); | |
766 #if !defined(OS_ANDROID) | |
Evan Stade
2013/07/08 19:47:28
here's the fix.
| |
767 // gfx::Font isn't implemented on Android; DeriveFont() causes a null deref. | |
768 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); | |
769 #endif | |
770 | |
771 // First-run, post-submit, Wallet expository page. | |
772 if (full_wallet_ && full_wallet_->required_actions().empty()) { | |
773 string.text = ASCIIToUTF16("...consectetur adipisicing elit"); | |
774 | |
775 state.strings.push_back(DialogOverlayString()); | |
776 DialogOverlayString& subtext = state.strings.back(); | |
777 subtext.font = rb.GetFont(ui::ResourceBundle::BaseFont); | |
778 subtext.text = ASCIIToUTF16("sed do eiusmod tempor incididunt ut labore " | |
779 "et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " | |
780 "exercitation ullamco laboris nisi ut aliquip ex ea commodo " | |
781 "consequat."); | |
782 | |
783 state.button_text = ASCIIToUTF16("OK, gotcha"); | |
784 } else { | |
785 // "Submitting" waiting page. | |
786 string.text = ASCIIToUTF16("Lorem ipsum dolor sit amet..."); | |
787 string.alignment = gfx::ALIGN_CENTER; | |
788 } | |
789 | |
790 return state; | |
791 } | |
792 | |
753 const std::vector<ui::Range>& AutofillDialogControllerImpl:: | 793 const std::vector<ui::Range>& AutofillDialogControllerImpl:: |
754 LegalDocumentLinks() { | 794 LegalDocumentLinks() { |
755 EnsureLegalDocumentsText(); | 795 EnsureLegalDocumentsText(); |
756 return legal_document_link_ranges_; | 796 return legal_document_link_ranges_; |
757 } | 797 } |
758 | 798 |
759 bool AutofillDialogControllerImpl::SectionIsActive(DialogSection section) | 799 bool AutofillDialogControllerImpl::SectionIsActive(DialogSection section) |
760 const { | 800 const { |
761 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) | 801 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) |
762 return section == SECTION_CC_BILLING; | 802 return section == SECTION_CC_BILLING; |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1790 for (size_t i = 0; i < legal_document_link_ranges_.size(); ++i) { | 1830 for (size_t i = 0; i < legal_document_link_ranges_.size(); ++i) { |
1791 if (legal_document_link_ranges_[i] == range) { | 1831 if (legal_document_link_ranges_[i] == range) { |
1792 OpenTabWithUrl(wallet_items_->legal_documents()[i]->url()); | 1832 OpenTabWithUrl(wallet_items_->legal_documents()[i]->url()); |
1793 return; | 1833 return; |
1794 } | 1834 } |
1795 } | 1835 } |
1796 | 1836 |
1797 NOTREACHED(); | 1837 NOTREACHED(); |
1798 } | 1838 } |
1799 | 1839 |
1840 void AutofillDialogControllerImpl::OverlayButtonPressed() { | |
1841 DCHECK(is_submitting_); | |
1842 DCHECK(full_wallet_); | |
1843 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, | |
1844 true); | |
1845 FinishSubmit(); | |
1846 } | |
1847 | |
1800 void AutofillDialogControllerImpl::OnCancel() { | 1848 void AutofillDialogControllerImpl::OnCancel() { |
1801 HidePopup(); | 1849 HidePopup(); |
1802 if (autocheckout_state_ == AUTOCHECKOUT_NOT_STARTED && !is_submitting_) | 1850 if (autocheckout_state_ == AUTOCHECKOUT_NOT_STARTED && !is_submitting_) |
1803 LogOnCancelMetrics(); | 1851 LogOnCancelMetrics(); |
1804 if (autocheckout_state_ == AUTOCHECKOUT_IN_PROGRESS) { | 1852 if (autocheckout_state_ == AUTOCHECKOUT_IN_PROGRESS) { |
1805 GetMetricLogger().LogAutocheckoutDuration( | 1853 GetMetricLogger().LogAutocheckoutDuration( |
1806 base::Time::Now() - autocheckout_started_timestamp_, | 1854 base::Time::Now() - autocheckout_started_timestamp_, |
1807 AutofillMetrics::AUTOCHECKOUT_CANCELLED); | 1855 AutofillMetrics::AUTOCHECKOUT_CANCELLED); |
1808 } | 1856 } |
1809 callback_.Run(NULL, std::string()); | 1857 callback_.Run(NULL, std::string()); |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3053 if (*iter != wallet::INVALID_FORM_FIELD) { | 3101 if (*iter != wallet::INVALID_FORM_FIELD) { |
3054 // TODO(dbeam): handle this more gracefully. | 3102 // TODO(dbeam): handle this more gracefully. |
3055 DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); | 3103 DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); |
3056 } | 3104 } |
3057 } | 3105 } |
3058 SetAutocheckoutState(AUTOCHECKOUT_NOT_STARTED); | 3106 SetAutocheckoutState(AUTOCHECKOUT_NOT_STARTED); |
3059 SetIsSubmitting(false); | 3107 SetIsSubmitting(false); |
3060 } | 3108 } |
3061 | 3109 |
3062 void AutofillDialogControllerImpl::FinishSubmit() { | 3110 void AutofillDialogControllerImpl::FinishSubmit() { |
3111 if (IsPayingWithWallet() && | |
3112 !profile_->GetPrefs()->GetBoolean( | |
3113 ::prefs::kAutofillDialogHasPaidWithWallet)) { | |
3114 // To get past this point, the view must call back OverlayButtonPressed. | |
3115 #if defined(TOOLKIT_VIEWS) | |
3116 view_->UpdateButtonStrip(); | |
3117 #else | |
3118 // TODO(estade): implement overlays on other platforms. | |
3119 OverlayButtonPressed(); | |
3120 #endif | |
3121 return; | |
3122 } | |
3123 | |
3063 FillOutputForSection(SECTION_EMAIL); | 3124 FillOutputForSection(SECTION_EMAIL); |
3064 FillOutputForSection(SECTION_CC); | 3125 FillOutputForSection(SECTION_CC); |
3065 FillOutputForSection(SECTION_BILLING); | 3126 FillOutputForSection(SECTION_BILLING); |
3066 FillOutputForSection(SECTION_CC_BILLING); | 3127 FillOutputForSection(SECTION_CC_BILLING); |
3067 | 3128 |
3068 if (ShouldUseBillingForShipping()) { | 3129 if (ShouldUseBillingForShipping()) { |
3069 FillOutputForSectionWithComparator( | 3130 FillOutputForSectionWithComparator( |
3070 SECTION_BILLING, | 3131 SECTION_BILLING, |
3071 base::Bind(DetailInputMatchesShippingField)); | 3132 base::Bind(DetailInputMatchesShippingField)); |
3072 FillOutputForSectionWithComparator( | 3133 FillOutputForSectionWithComparator( |
3073 SECTION_CC, | 3134 SECTION_CC, |
3074 base::Bind(DetailInputMatchesShippingField)); | 3135 base::Bind(DetailInputMatchesShippingField)); |
3075 FillOutputForSectionWithComparator( | 3136 FillOutputForSectionWithComparator( |
3076 SECTION_CC_BILLING, | 3137 SECTION_CC_BILLING, |
3077 base::Bind(DetailInputMatchesShippingField)); | 3138 base::Bind(DetailInputMatchesShippingField)); |
3078 } else { | 3139 } else { |
3079 FillOutputForSection(SECTION_SHIPPING); | 3140 FillOutputForSection(SECTION_SHIPPING); |
3080 } | 3141 } |
3081 | 3142 |
3082 if (IsPayingWithWallet()) { | 3143 if (!IsPayingWithWallet()) { |
3083 profile_->GetPrefs()->SetBoolean( | |
3084 ::prefs::kAutofillDialogHasPaidWithWallet, true); | |
3085 } else { | |
3086 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 3144 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
3087 DialogSection section = static_cast<DialogSection>(i); | 3145 DialogSection section = static_cast<DialogSection>(i); |
3088 if (!SectionIsActive(section)) | 3146 if (!SectionIsActive(section)) |
3089 continue; | 3147 continue; |
3090 | 3148 |
3091 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 3149 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
3092 std::string item_key = model->GetItemKeyForCheckedItem(); | 3150 std::string item_key = model->GetItemKeyForCheckedItem(); |
3093 if (IsASuggestionItemKey(item_key) || item_key == kSameAsBillingKey) { | 3151 if (IsASuggestionItemKey(item_key) || item_key == kSameAsBillingKey) { |
3094 int variant = GetSelectedVariantForModel(*model); | 3152 int variant = GetSelectedVariantForModel(*model); |
3095 PersistAutofillChoice(section, item_key, variant); | 3153 PersistAutofillChoice(section, item_key, variant); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3301 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 3359 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
3302 } | 3360 } |
3303 | 3361 |
3304 // Has Wallet items. | 3362 // Has Wallet items. |
3305 return has_autofill_profiles ? | 3363 return has_autofill_profiles ? |
3306 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 3364 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
3307 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 3365 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
3308 } | 3366 } |
3309 | 3367 |
3310 } // namespace autofill | 3368 } // namespace autofill |
OLD | NEW |