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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 // If the user switched away from this tab and then switched back, reload the | 603 // If the user switched away from this tab and then switched back, reload the |
604 // Wallet items, in case they've changed. | 604 // Wallet items, in case they've changed. |
605 int seconds_elapsed_since_last_refresh = | 605 int seconds_elapsed_since_last_refresh = |
606 (base::TimeTicks::Now() - last_wallet_items_fetch_timestamp_).InSeconds(); | 606 (base::TimeTicks::Now() - last_wallet_items_fetch_timestamp_).InSeconds(); |
607 if (IsPayingWithWallet() && wallet_items_ && | 607 if (IsPayingWithWallet() && wallet_items_ && |
608 seconds_elapsed_since_last_refresh >= kWalletItemsRefreshRateSeconds) { | 608 seconds_elapsed_since_last_refresh >= kWalletItemsRefreshRateSeconds) { |
609 GetWalletItems(); | 609 GetWalletItems(); |
610 } | 610 } |
611 } | 611 } |
612 | 612 |
613 void AutofillDialogControllerImpl::OnAutocheckoutError() { | |
614 DCHECK_EQ(AUTOCHECKOUT_IN_PROGRESS, autocheckout_state_); | |
615 GetMetricLogger().LogAutocheckoutDuration( | |
616 base::Time::Now() - autocheckout_started_timestamp_, | |
617 AutofillMetrics::AUTOCHECKOUT_FAILED); | |
618 SetAutocheckoutState(AUTOCHECKOUT_ERROR); | |
619 autocheckout_started_timestamp_ = base::Time(); | |
620 } | |
621 | |
622 void AutofillDialogControllerImpl::OnAutocheckoutSuccess() { | |
623 DCHECK_EQ(AUTOCHECKOUT_IN_PROGRESS, autocheckout_state_); | |
624 GetMetricLogger().LogAutocheckoutDuration( | |
625 base::Time::Now() - autocheckout_started_timestamp_, | |
626 AutofillMetrics::AUTOCHECKOUT_SUCCEEDED); | |
627 SetAutocheckoutState(AUTOCHECKOUT_SUCCESS); | |
628 autocheckout_started_timestamp_ = base::Time(); | |
629 } | |
630 | |
631 | |
632 TestableAutofillDialogView* AutofillDialogControllerImpl::GetTestableView() { | 613 TestableAutofillDialogView* AutofillDialogControllerImpl::GetTestableView() { |
633 return view_ ? view_->GetTestableView() : NULL; | 614 return view_ ? view_->GetTestableView() : NULL; |
634 } | 615 } |
635 | 616 |
636 void AutofillDialogControllerImpl::AddAutocheckoutStep( | |
637 AutocheckoutStepType step_type) { | |
638 for (size_t i = 0; i < steps_.size(); ++i) { | |
639 if (steps_[i].type() == step_type) | |
640 return; | |
641 } | |
642 steps_.push_back( | |
643 DialogAutocheckoutStep(step_type, AUTOCHECKOUT_STEP_UNSTARTED)); | |
644 } | |
645 | |
646 void AutofillDialogControllerImpl::UpdateAutocheckoutStep( | |
647 AutocheckoutStepType step_type, | |
648 AutocheckoutStepStatus step_status) { | |
649 ScopedViewUpdates updates(view_.get()); | |
650 | |
651 int total_steps = 0; | |
652 int completed_steps = 0; | |
653 for (size_t i = 0; i < steps_.size(); ++i) { | |
654 ++total_steps; | |
655 if (steps_[i].status() == AUTOCHECKOUT_STEP_COMPLETED) | |
656 ++completed_steps; | |
657 if (steps_[i].type() == step_type && steps_[i].status() != step_status) | |
658 steps_[i] = DialogAutocheckoutStep(step_type, step_status); | |
659 } | |
660 if (view_) { | |
661 view_->UpdateAutocheckoutStepsArea(); | |
662 view_->UpdateProgressBar(1.0 * completed_steps / total_steps); | |
663 } | |
664 } | |
665 | |
666 std::vector<DialogAutocheckoutStep> | |
667 AutofillDialogControllerImpl::CurrentAutocheckoutSteps() const { | |
668 if (autocheckout_state_ != AUTOCHECKOUT_NOT_STARTED) | |
669 return steps_; | |
670 | |
671 std::vector<DialogAutocheckoutStep> empty_steps; | |
672 return empty_steps; | |
673 } | |
674 | |
675 //////////////////////////////////////////////////////////////////////////////// | 617 //////////////////////////////////////////////////////////////////////////////// |
676 // AutofillDialogViewDelegate implementation. | 618 // AutofillDialogViewDelegate implementation. |
677 | 619 |
678 string16 AutofillDialogControllerImpl::DialogTitle() const { | 620 string16 AutofillDialogControllerImpl::DialogTitle() const { |
679 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE); | 621 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE); |
680 } | 622 } |
681 | 623 |
682 string16 AutofillDialogControllerImpl::EditSuggestionText() const { | 624 string16 AutofillDialogControllerImpl::EditSuggestionText() const { |
683 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT); | 625 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT); |
684 } | 626 } |
685 | 627 |
686 string16 AutofillDialogControllerImpl::CancelButtonText() const { | 628 string16 AutofillDialogControllerImpl::CancelButtonText() const { |
687 return l10n_util::GetStringUTF16(IDS_CANCEL); | 629 return l10n_util::GetStringUTF16(IDS_CANCEL); |
688 } | 630 } |
689 | 631 |
690 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { | 632 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { |
691 if (autocheckout_state_ == AUTOCHECKOUT_ERROR) | |
692 return l10n_util::GetStringUTF16(IDS_OK); | |
693 if (autocheckout_state_ == AUTOCHECKOUT_SUCCESS) | |
694 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CONTINUE_BUTTON); | |
695 | |
696 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ? | 633 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ? |
697 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); | 634 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); |
698 } | 635 } |
699 | 636 |
700 string16 AutofillDialogControllerImpl::SaveLocallyText() const { | 637 string16 AutofillDialogControllerImpl::SaveLocallyText() const { |
701 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); | 638 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); |
702 } | 639 } |
703 | 640 |
704 string16 AutofillDialogControllerImpl::SaveLocallyTooltip() const { | 641 string16 AutofillDialogControllerImpl::SaveLocallyTooltip() const { |
705 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_TOOLTIP); | 642 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_TOOLTIP); |
706 } | 643 } |
707 | 644 |
708 string16 AutofillDialogControllerImpl::LegalDocumentsText() { | 645 string16 AutofillDialogControllerImpl::LegalDocumentsText() { |
709 if (!IsPayingWithWallet() || autocheckout_state_ != AUTOCHECKOUT_NOT_STARTED) | 646 if (!IsPayingWithWallet()) |
710 return string16(); | 647 return string16(); |
711 | 648 |
712 EnsureLegalDocumentsText(); | 649 EnsureLegalDocumentsText(); |
713 return legal_documents_text_; | 650 return legal_documents_text_; |
714 } | 651 } |
715 | 652 |
716 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { | 653 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { |
717 if (account_chooser_model_.HadWalletError()) | 654 if (account_chooser_model_.HadWalletError()) |
718 return SIGN_IN_DISABLED; | 655 return SIGN_IN_DISABLED; |
719 | 656 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 | 690 |
754 bool AutofillDialogControllerImpl::ShouldOfferToSaveInChrome() const { | 691 bool AutofillDialogControllerImpl::ShouldOfferToSaveInChrome() const { |
755 return !IsPayingWithWallet() && | 692 return !IsPayingWithWallet() && |
756 !profile_->IsOffTheRecord() && | 693 !profile_->IsOffTheRecord() && |
757 IsManuallyEditingAnySection() && | 694 IsManuallyEditingAnySection() && |
758 ShouldShowDetailArea() && | 695 ShouldShowDetailArea() && |
759 !ShouldShowSpinner(); | 696 !ShouldShowSpinner(); |
760 } | 697 } |
761 | 698 |
762 int AutofillDialogControllerImpl::GetDialogButtons() const { | 699 int AutofillDialogControllerImpl::GetDialogButtons() const { |
763 if (autocheckout_state_ == AUTOCHECKOUT_IN_PROGRESS) | 700 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
764 return ui::DIALOG_BUTTON_CANCEL; | |
765 if (autocheckout_state_ == AUTOCHECKOUT_NOT_STARTED) | |
766 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | |
767 return ui::DIALOG_BUTTON_OK; | |
768 } | 701 } |
769 | 702 |
770 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( | 703 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( |
771 ui::DialogButton button) const { | 704 ui::DialogButton button) const { |
772 if (button == ui::DIALOG_BUTTON_OK) { | 705 if (button == ui::DIALOG_BUTTON_OK) { |
773 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) | 706 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) |
774 return true; | 707 return true; |
775 | 708 |
776 if (ShouldShowSpinner()) | 709 if (ShouldShowSpinner() || is_submitting_) |
777 return false; | 710 return false; |
778 | 711 |
779 if (is_submitting_) { | |
780 return autocheckout_state_ == AUTOCHECKOUT_SUCCESS || | |
781 autocheckout_state_ == AUTOCHECKOUT_ERROR; | |
782 } | |
783 | |
784 return true; | 712 return true; |
785 } | 713 } |
786 | 714 |
787 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); | 715 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); |
788 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV); | 716 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV); |
789 } | 717 } |
790 | 718 |
791 DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { | 719 DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { |
792 bool show_wallet_interstitial = IsPayingWithWallet() && is_submitting_ && | 720 bool show_wallet_interstitial = IsPayingWithWallet() && is_submitting_ && |
793 !IsSubmitPausedOn(wallet::VERIFY_CVV) && | 721 !IsSubmitPausedOn(wallet::VERIFY_CVV) && |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1215 | 1143 |
1216 gfx::Image icon; | 1144 gfx::Image icon; |
1217 account_chooser_model_.GetIconAt( | 1145 account_chooser_model_.GetIconAt( |
1218 account_chooser_model_.GetIndexOfCommandId( | 1146 account_chooser_model_.GetIndexOfCommandId( |
1219 account_chooser_model_.checked_item()), | 1147 account_chooser_model_.checked_item()), |
1220 &icon); | 1148 &icon); |
1221 return icon; | 1149 return icon; |
1222 } | 1150 } |
1223 | 1151 |
1224 bool AutofillDialogControllerImpl::ShouldShowDetailArea() const { | 1152 bool AutofillDialogControllerImpl::ShouldShowDetailArea() const { |
1225 // Hide the detail area when Autocheckout is running or there was an error (as | 1153 return true; |
1226 // there's nothing they can do after an error but cancel). | |
1227 return autocheckout_state_ == AUTOCHECKOUT_NOT_STARTED; | |
1228 } | |
1229 | |
1230 bool AutofillDialogControllerImpl::ShouldShowProgressBar() const { | |
1231 // Show the progress bar while Autocheckout is running but hide it on errors, | |
1232 // as there's no use leaving it up if the flow has failed. | |
1233 return autocheckout_state_ == AUTOCHECKOUT_IN_PROGRESS; | |
1234 } | 1154 } |
Ilya Sherman
2013/08/27 18:57:57
Could you remove this method, or mark it as slated
Raman Kakilate
2013/08/27 21:52:59
Done.
| |
1235 | 1155 |
1236 gfx::Image AutofillDialogControllerImpl::ButtonStripImage() const { | 1156 gfx::Image AutofillDialogControllerImpl::ButtonStripImage() const { |
1237 if (ShouldShowDetailArea() && IsPayingWithWallet()) { | 1157 if (ShouldShowDetailArea() && IsPayingWithWallet()) { |
1238 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 1158 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
1239 IDR_WALLET_LOGO); | 1159 IDR_WALLET_LOGO); |
1240 } | 1160 } |
1241 | 1161 |
1242 return gfx::Image(); | 1162 return gfx::Image(); |
1243 } | 1163 } |
1244 | 1164 |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1788 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 1708 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
1789 IDR_PRODUCT_LOGO_NAME_48); | 1709 IDR_PRODUCT_LOGO_NAME_48); |
1790 } | 1710 } |
1791 | 1711 |
1792 return gfx::Image(); | 1712 return gfx::Image(); |
1793 } | 1713 } |
1794 | 1714 |
1795 void AutofillDialogControllerImpl::ViewClosed() { | 1715 void AutofillDialogControllerImpl::ViewClosed() { |
1796 GetManager()->RemoveObserver(this); | 1716 GetManager()->RemoveObserver(this); |
1797 | 1717 |
1798 // TODO(ahutter): Once a user can cancel Autocheckout mid-flow, log that | |
1799 // metric here. | |
1800 | |
1801 // Called from here rather than in ~AutofillDialogControllerImpl as this | 1718 // Called from here rather than in ~AutofillDialogControllerImpl as this |
1802 // relies on virtual methods that change to their base class in the dtor. | 1719 // relies on virtual methods that change to their base class in the dtor. |
1803 MaybeShowCreditCardBubble(); | 1720 MaybeShowCreditCardBubble(); |
1804 | 1721 |
1805 delete this; | 1722 delete this; |
1806 } | 1723 } |
1807 | 1724 |
1808 std::vector<DialogNotification> AutofillDialogControllerImpl:: | 1725 std::vector<DialogNotification> AutofillDialogControllerImpl:: |
1809 CurrentNotifications() { | 1726 CurrentNotifications() { |
1810 std::vector<DialogNotification> notifications; | 1727 std::vector<DialogNotification> notifications; |
(...skipping 25 matching lines...) Expand all Loading... | |
1836 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, | 1753 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, |
1837 account_chooser_model_.wallet_error_message()))); | 1754 account_chooser_model_.wallet_error_message()))); |
1838 } | 1755 } |
1839 | 1756 |
1840 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1757 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1841 notifications.push_back(DialogNotification( | 1758 notifications.push_back(DialogNotification( |
1842 DialogNotification::REQUIRED_ACTION, | 1759 DialogNotification::REQUIRED_ACTION, |
1843 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV))); | 1760 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV))); |
1844 } | 1761 } |
1845 | 1762 |
1846 if (autocheckout_state_ == AUTOCHECKOUT_ERROR) { | |
1847 notifications.push_back(DialogNotification( | |
1848 DialogNotification::AUTOCHECKOUT_ERROR, | |
1849 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR))); | |
1850 } | |
1851 | |
1852 if (autocheckout_state_ == AUTOCHECKOUT_SUCCESS) { | |
1853 notifications.push_back(DialogNotification( | |
1854 DialogNotification::AUTOCHECKOUT_SUCCESS, | |
1855 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_SUCCESS))); | |
1856 } | |
1857 | |
1858 if (!wallet_server_validation_recoverable_) { | 1763 if (!wallet_server_validation_recoverable_) { |
1859 notifications.push_back(DialogNotification( | 1764 notifications.push_back(DialogNotification( |
1860 DialogNotification::REQUIRED_ACTION, | 1765 DialogNotification::REQUIRED_ACTION, |
1861 l10n_util::GetStringUTF16( | 1766 l10n_util::GetStringUTF16( |
1862 IDS_AUTOFILL_DIALOG_FAILED_TO_SAVE_WALLET_DATA))); | 1767 IDS_AUTOFILL_DIALOG_FAILED_TO_SAVE_WALLET_DATA))); |
1863 } | 1768 } |
1864 | 1769 |
1865 if (choose_another_instrument_or_address_) { | 1770 if (choose_another_instrument_or_address_) { |
1866 notifications.push_back(DialogNotification( | 1771 notifications.push_back(DialogNotification( |
1867 DialogNotification::REQUIRED_ACTION, | 1772 DialogNotification::REQUIRED_ACTION, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1939 void AutofillDialogControllerImpl::OverlayButtonPressed() { | 1844 void AutofillDialogControllerImpl::OverlayButtonPressed() { |
1940 DCHECK(is_submitting_); | 1845 DCHECK(is_submitting_); |
1941 DCHECK(full_wallet_); | 1846 DCHECK(full_wallet_); |
1942 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, | 1847 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, |
1943 true); | 1848 true); |
1944 FinishSubmit(); | 1849 FinishSubmit(); |
1945 } | 1850 } |
1946 | 1851 |
1947 bool AutofillDialogControllerImpl::OnCancel() { | 1852 bool AutofillDialogControllerImpl::OnCancel() { |
1948 HidePopup(); | 1853 HidePopup(); |
1949 if (autocheckout_state_ == AUTOCHECKOUT_NOT_STARTED && !is_submitting_) | 1854 if (!is_submitting_) |
1950 LogOnCancelMetrics(); | 1855 LogOnCancelMetrics(); |
1951 if (autocheckout_state_ == AUTOCHECKOUT_IN_PROGRESS) { | |
1952 GetMetricLogger().LogAutocheckoutDuration( | |
1953 base::Time::Now() - autocheckout_started_timestamp_, | |
1954 AutofillMetrics::AUTOCHECKOUT_CANCELLED); | |
1955 } | |
1956 callback_.Run(NULL, std::string()); | 1856 callback_.Run(NULL, std::string()); |
1957 return true; | 1857 return true; |
1958 } | 1858 } |
1959 | 1859 |
1960 bool AutofillDialogControllerImpl::OnAccept() { | 1860 bool AutofillDialogControllerImpl::OnAccept() { |
1961 // If autocheckout has already started, the only thing left to do is to | |
1962 // close the dialog. | |
1963 if (autocheckout_state_ != AUTOCHECKOUT_NOT_STARTED) | |
1964 return true; | |
1965 | |
1966 choose_another_instrument_or_address_ = false; | 1861 choose_another_instrument_or_address_ = false; |
1967 wallet_server_validation_recoverable_ = true; | 1862 wallet_server_validation_recoverable_ = true; |
1968 HidePopup(); | 1863 HidePopup(); |
1969 if (IsPayingWithWallet()) { | |
1970 bool has_proxy_card_step = false; | |
1971 for (size_t i = 0; i < steps_.size(); ++i) { | |
1972 if (steps_[i].type() == AUTOCHECKOUT_STEP_PROXY_CARD) { | |
1973 has_proxy_card_step = true; | |
1974 break; | |
1975 } | |
1976 } | |
1977 if (!has_proxy_card_step) { | |
1978 steps_.insert(steps_.begin(), | |
1979 DialogAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD, | |
1980 AUTOCHECKOUT_STEP_UNSTARTED)); | |
1981 } | |
1982 } | |
1983 | |
1984 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) | |
1985 DeemphasizeRenderView(); | |
1986 | 1864 |
1987 SetIsSubmitting(true); | 1865 SetIsSubmitting(true); |
1988 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1866 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1989 DCHECK(!active_instrument_id_.empty()); | 1867 DCHECK(!active_instrument_id_.empty()); |
1990 GetWalletClient()->AuthenticateInstrument( | 1868 GetWalletClient()->AuthenticateInstrument( |
1991 active_instrument_id_, | 1869 active_instrument_id_, |
1992 UTF16ToUTF8(view_->GetCvc())); | 1870 UTF16ToUTF8(view_->GetCvc())); |
1993 } else if (IsPayingWithWallet()) { | 1871 } else if (IsPayingWithWallet()) { |
1994 // TODO(dbeam): disallow interacting with the dialog while submitting. | 1872 // TODO(dbeam): disallow interacting with the dialog while submitting. |
1995 // http://crbug.com/230932 | 1873 // http://crbug.com/230932 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2160 } | 2038 } |
2161 | 2039 |
2162 void AutofillDialogControllerImpl::OnDidGetFullWallet( | 2040 void AutofillDialogControllerImpl::OnDidGetFullWallet( |
2163 scoped_ptr<wallet::FullWallet> full_wallet) { | 2041 scoped_ptr<wallet::FullWallet> full_wallet) { |
2164 DCHECK(is_submitting_ && IsPayingWithWallet()); | 2042 DCHECK(is_submitting_ && IsPayingWithWallet()); |
2165 ScopedViewUpdates updates(view_.get()); | 2043 ScopedViewUpdates updates(view_.get()); |
2166 | 2044 |
2167 full_wallet_ = full_wallet.Pass(); | 2045 full_wallet_ = full_wallet.Pass(); |
2168 | 2046 |
2169 if (full_wallet_->required_actions().empty()) { | 2047 if (full_wallet_->required_actions().empty()) { |
2170 UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD, | |
2171 AUTOCHECKOUT_STEP_COMPLETED); | |
2172 FinishSubmit(); | 2048 FinishSubmit(); |
2173 return; | 2049 return; |
2174 } | 2050 } |
2175 | 2051 |
2176 SetAutocheckoutState(AUTOCHECKOUT_NOT_STARTED); | |
2177 | |
2178 switch (full_wallet_->required_actions()[0]) { | 2052 switch (full_wallet_->required_actions()[0]) { |
2179 case wallet::CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS: | 2053 case wallet::CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS: |
2180 choose_another_instrument_or_address_ = true; | 2054 choose_another_instrument_or_address_ = true; |
2181 SetIsSubmitting(false); | 2055 SetIsSubmitting(false); |
2182 GetWalletItems(); | 2056 GetWalletItems(); |
2183 view_->UpdateNotificationArea(); | 2057 view_->UpdateNotificationArea(); |
2184 view_->UpdateButtonStrip(); | 2058 view_->UpdateButtonStrip(); |
2185 break; | 2059 break; |
2186 | 2060 |
2187 case wallet::VERIFY_CVV: | 2061 case wallet::VERIFY_CVV: |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2338 content::WebContents* contents, | 2212 content::WebContents* contents, |
2339 const FormData& form_structure, | 2213 const FormData& form_structure, |
2340 const GURL& source_url, | 2214 const GURL& source_url, |
2341 const DialogType dialog_type, | 2215 const DialogType dialog_type, |
2342 const base::Callback<void(const FormStructure*, | 2216 const base::Callback<void(const FormStructure*, |
2343 const std::string&)>& callback) | 2217 const std::string&)>& callback) |
2344 : WebContentsObserver(contents), | 2218 : WebContentsObserver(contents), |
2345 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2219 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
2346 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2220 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
2347 dialog_type_(dialog_type), | 2221 dialog_type_(dialog_type), |
2348 form_structure_(form_structure, std::string()), | 2222 form_structure_(form_structure), |
2349 invoked_from_same_origin_(true), | 2223 invoked_from_same_origin_(true), |
2350 source_url_(source_url), | 2224 source_url_(source_url), |
2351 callback_(callback), | 2225 callback_(callback), |
2352 account_chooser_model_(this, profile_->GetPrefs(), metric_logger_, | 2226 account_chooser_model_(this, profile_->GetPrefs(), metric_logger_, |
2353 dialog_type), | 2227 dialog_type), |
2354 wallet_client_(profile_->GetRequestContext(), this), | 2228 wallet_client_(profile_->GetRequestContext(), this), |
2355 suggested_email_(this), | 2229 suggested_email_(this), |
2356 suggested_cc_(this), | 2230 suggested_cc_(this), |
2357 suggested_billing_(this), | 2231 suggested_billing_(this), |
2358 suggested_cc_billing_(this), | 2232 suggested_cc_billing_(this), |
2359 suggested_shipping_(this), | 2233 suggested_shipping_(this), |
2360 cares_about_shipping_(true), | 2234 cares_about_shipping_(true), |
2361 input_showing_popup_(NULL), | 2235 input_showing_popup_(NULL), |
2362 weak_ptr_factory_(this), | 2236 weak_ptr_factory_(this), |
2363 should_show_wallet_promo_(!profile_->GetPrefs()->GetBoolean( | 2237 should_show_wallet_promo_(!profile_->GetPrefs()->GetBoolean( |
2364 ::prefs::kAutofillDialogHasPaidWithWallet)), | 2238 ::prefs::kAutofillDialogHasPaidWithWallet)), |
2365 has_shown_wallet_usage_confirmation_(false), | 2239 has_shown_wallet_usage_confirmation_(false), |
2366 has_accepted_legal_documents_(false), | 2240 has_accepted_legal_documents_(false), |
2367 is_submitting_(false), | 2241 is_submitting_(false), |
2368 choose_another_instrument_or_address_(false), | 2242 choose_another_instrument_or_address_(false), |
2369 wallet_server_validation_recoverable_(true), | 2243 wallet_server_validation_recoverable_(true), |
2370 data_was_passed_back_(false), | 2244 data_was_passed_back_(false), |
2371 autocheckout_state_(AUTOCHECKOUT_NOT_STARTED), | |
2372 was_ui_latency_logged_(false), | 2245 was_ui_latency_logged_(false), |
2373 deemphasized_render_view_(false) { | 2246 deemphasized_render_view_(false) { |
2374 // TODO(estade): remove duplicates from |form_structure|? | 2247 // TODO(estade): remove duplicates from |form_structure|? |
2375 DCHECK(!callback_.is_null()); | 2248 DCHECK(!callback_.is_null()); |
2376 } | 2249 } |
2377 | 2250 |
2378 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { | 2251 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { |
2379 return AutofillDialogView::Create(this); | 2252 return AutofillDialogView::Create(this); |
2380 } | 2253 } |
2381 | 2254 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2457 GetWalletClient()->CancelRequests(); | 2330 GetWalletClient()->CancelRequests(); |
2458 LogDialogLatencyToShow(); | 2331 LogDialogLatencyToShow(); |
2459 } | 2332 } |
2460 | 2333 |
2461 void AutofillDialogControllerImpl::DisableWallet( | 2334 void AutofillDialogControllerImpl::DisableWallet( |
2462 wallet::WalletClient::ErrorType error_type) { | 2335 wallet::WalletClient::ErrorType error_type) { |
2463 signin_helper_.reset(); | 2336 signin_helper_.reset(); |
2464 wallet_items_.reset(); | 2337 wallet_items_.reset(); |
2465 wallet_errors_.clear(); | 2338 wallet_errors_.clear(); |
2466 GetWalletClient()->CancelRequests(); | 2339 GetWalletClient()->CancelRequests(); |
2467 SetAutocheckoutState(AUTOCHECKOUT_NOT_STARTED); | |
2468 for (std::vector<DialogAutocheckoutStep>::iterator it = steps_.begin(); | |
2469 it != steps_.end(); ++it) { | |
2470 if (it->type() == AUTOCHECKOUT_STEP_PROXY_CARD) { | |
2471 steps_.erase(it); | |
2472 break; | |
2473 } | |
2474 } | |
2475 SetIsSubmitting(false); | 2340 SetIsSubmitting(false); |
2476 account_chooser_model_.SetHadWalletError(WalletErrorMessage(error_type)); | 2341 account_chooser_model_.SetHadWalletError(WalletErrorMessage(error_type)); |
2477 } | 2342 } |
2478 | 2343 |
2479 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 2344 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
2480 ScopedViewUpdates updates(view_.get()); | 2345 ScopedViewUpdates updates(view_.get()); |
2481 | 2346 |
2482 const DetailOutputMap snapshot = TakeUserInputSnapshot(); | 2347 const DetailOutputMap snapshot = TakeUserInputSnapshot(); |
2483 | 2348 |
2484 suggested_email_.Reset(); | 2349 suggested_email_.Reset(); |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3044 } | 2909 } |
3045 | 2910 |
3046 const wallet::Address* active_address = ActiveShippingAddress(); | 2911 const wallet::Address* active_address = ActiveShippingAddress(); |
3047 if (!IsManuallyEditingSection(SECTION_SHIPPING) && | 2912 if (!IsManuallyEditingSection(SECTION_SHIPPING) && |
3048 !ShouldUseBillingForShipping() && | 2913 !ShouldUseBillingForShipping() && |
3049 IsShippingAddressRequired()) { | 2914 IsShippingAddressRequired()) { |
3050 active_address_id_ = active_address->object_id(); | 2915 active_address_id_ = active_address->object_id(); |
3051 DCHECK(!active_address_id_.empty()); | 2916 DCHECK(!active_address_id_.empty()); |
3052 } | 2917 } |
3053 | 2918 |
3054 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) { | |
3055 DCHECK_EQ(AUTOCHECKOUT_NOT_STARTED, autocheckout_state_); | |
3056 SetAutocheckoutState(AUTOCHECKOUT_IN_PROGRESS); | |
3057 } | |
3058 | |
3059 scoped_ptr<wallet::Instrument> inputted_instrument = | 2919 scoped_ptr<wallet::Instrument> inputted_instrument = |
3060 CreateTransientInstrument(); | 2920 CreateTransientInstrument(); |
3061 if (inputted_instrument && IsEditingExistingData(SECTION_CC_BILLING)) { | 2921 if (inputted_instrument && IsEditingExistingData(SECTION_CC_BILLING)) { |
3062 inputted_instrument->set_object_id(active_instrument->object_id()); | 2922 inputted_instrument->set_object_id(active_instrument->object_id()); |
3063 DCHECK(!inputted_instrument->object_id().empty()); | 2923 DCHECK(!inputted_instrument->object_id().empty()); |
3064 } | 2924 } |
3065 | 2925 |
3066 scoped_ptr<wallet::Address> inputted_address; | 2926 scoped_ptr<wallet::Address> inputted_address; |
3067 if (active_address_id_.empty() && IsShippingAddressRequired()) { | 2927 if (active_address_id_.empty() && IsShippingAddressRequired()) { |
3068 if (ShouldUseBillingForShipping()) { | 2928 if (ShouldUseBillingForShipping()) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3133 void AutofillDialogControllerImpl::GetFullWallet() { | 2993 void AutofillDialogControllerImpl::GetFullWallet() { |
3134 DCHECK(is_submitting_); | 2994 DCHECK(is_submitting_); |
3135 DCHECK(IsPayingWithWallet()); | 2995 DCHECK(IsPayingWithWallet()); |
3136 DCHECK(wallet_items_); | 2996 DCHECK(wallet_items_); |
3137 DCHECK(!active_instrument_id_.empty()); | 2997 DCHECK(!active_instrument_id_.empty()); |
3138 DCHECK(!active_address_id_.empty() || !IsShippingAddressRequired()); | 2998 DCHECK(!active_address_id_.empty() || !IsShippingAddressRequired()); |
3139 | 2999 |
3140 std::vector<wallet::WalletClient::RiskCapability> capabilities; | 3000 std::vector<wallet::WalletClient::RiskCapability> capabilities; |
3141 capabilities.push_back(wallet::WalletClient::VERIFY_CVC); | 3001 capabilities.push_back(wallet::WalletClient::VERIFY_CVC); |
3142 | 3002 |
3143 UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD, | |
3144 AUTOCHECKOUT_STEP_STARTED); | |
3145 | |
3146 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( | 3003 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( |
3147 active_instrument_id_, | 3004 active_instrument_id_, |
3148 active_address_id_, | 3005 active_address_id_, |
3149 source_url_, | 3006 source_url_, |
3150 wallet_items_->google_transaction_id(), | 3007 wallet_items_->google_transaction_id(), |
3151 capabilities)); | 3008 capabilities)); |
3152 } | 3009 } |
3153 | 3010 |
3154 void AutofillDialogControllerImpl::HandleSaveOrUpdateRequiredActions( | 3011 void AutofillDialogControllerImpl::HandleSaveOrUpdateRequiredActions( |
3155 const std::vector<wallet::RequiredAction>& required_actions) { | 3012 const std::vector<wallet::RequiredAction>& required_actions) { |
3156 DCHECK(!required_actions.empty()); | 3013 DCHECK(!required_actions.empty()); |
3157 | 3014 |
3158 // TODO(ahutter): Invesitigate if we need to support more generic actions on | 3015 // TODO(ahutter): Invesitigate if we need to support more generic actions on |
3159 // this call such as GAIA_AUTH. See crbug.com/243457. | 3016 // this call such as GAIA_AUTH. See crbug.com/243457. |
3160 for (std::vector<wallet::RequiredAction>::const_iterator iter = | 3017 for (std::vector<wallet::RequiredAction>::const_iterator iter = |
3161 required_actions.begin(); | 3018 required_actions.begin(); |
3162 iter != required_actions.end(); ++iter) { | 3019 iter != required_actions.end(); ++iter) { |
3163 if (*iter != wallet::INVALID_FORM_FIELD) { | 3020 if (*iter != wallet::INVALID_FORM_FIELD) { |
3164 // TODO(dbeam): handle this more gracefully. | 3021 // TODO(dbeam): handle this more gracefully. |
3165 DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); | 3022 DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); |
3166 } | 3023 } |
3167 } | 3024 } |
3168 SetAutocheckoutState(AUTOCHECKOUT_NOT_STARTED); | |
3169 SetIsSubmitting(false); | 3025 SetIsSubmitting(false); |
3170 } | 3026 } |
3171 | 3027 |
3172 void AutofillDialogControllerImpl::FinishSubmit() { | 3028 void AutofillDialogControllerImpl::FinishSubmit() { |
3173 if (IsPayingWithWallet() && | 3029 if (IsPayingWithWallet() && |
3174 !profile_->GetPrefs()->GetBoolean( | 3030 !profile_->GetPrefs()->GetBoolean( |
3175 ::prefs::kAutofillDialogHasPaidWithWallet)) { | 3031 ::prefs::kAutofillDialogHasPaidWithWallet)) { |
3176 if (GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { | 3032 if (GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { |
3177 // To get past this point, the view must call back OverlayButtonPressed. | 3033 // To get past this point, the view must call back OverlayButtonPressed. |
3178 #if defined(TOOLKIT_VIEWS) | 3034 #if defined(TOOLKIT_VIEWS) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3227 // stop trying to pay with Wallet on future runs of the dialog. On the other | 3083 // stop trying to pay with Wallet on future runs of the dialog. On the other |
3228 // hand, if there was an error that prevented the user from having the choice | 3084 // hand, if there was an error that prevented the user from having the choice |
3229 // of using Wallet, leave the pref alone. | 3085 // of using Wallet, leave the pref alone. |
3230 if (!account_chooser_model_.HadWalletError() && | 3086 if (!account_chooser_model_.HadWalletError() && |
3231 account_chooser_model_.HasAccountsToChoose()) { | 3087 account_chooser_model_.HasAccountsToChoose()) { |
3232 profile_->GetPrefs()->SetBoolean( | 3088 profile_->GetPrefs()->SetBoolean( |
3233 ::prefs::kAutofillDialogPayWithoutWallet, | 3089 ::prefs::kAutofillDialogPayWithoutWallet, |
3234 !account_chooser_model_.WalletIsSelected()); | 3090 !account_chooser_model_.WalletIsSelected()); |
3235 } | 3091 } |
3236 | 3092 |
3237 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) { | |
3238 // Stop observing PersonalDataManager to avoid the dialog redrawing while | |
3239 // in an Autocheckout flow. | |
3240 GetManager()->RemoveObserver(this); | |
3241 autocheckout_started_timestamp_ = base::Time::Now(); | |
3242 SetAutocheckoutState(AUTOCHECKOUT_IN_PROGRESS); | |
3243 } | |
3244 | |
3245 LogOnFinishSubmitMetrics(); | 3093 LogOnFinishSubmitMetrics(); |
3246 | 3094 |
3247 // Callback should be called as late as possible. | 3095 // Callback should be called as late as possible. |
3248 callback_.Run(&form_structure_, !wallet_items_ ? std::string() : | 3096 callback_.Run(&form_structure_, !wallet_items_ ? std::string() : |
3249 wallet_items_->google_transaction_id()); | 3097 wallet_items_->google_transaction_id()); |
3250 data_was_passed_back_ = true; | 3098 data_was_passed_back_ = true; |
3251 | 3099 |
3252 // This might delete us. | 3100 // This might delete us. |
3253 if (GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) | 3101 if (GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) |
3254 Hide(); | 3102 Hide(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3385 void AutofillDialogControllerImpl::LogDialogLatencyToShow() { | 3233 void AutofillDialogControllerImpl::LogDialogLatencyToShow() { |
3386 if (was_ui_latency_logged_) | 3234 if (was_ui_latency_logged_) |
3387 return; | 3235 return; |
3388 | 3236 |
3389 GetMetricLogger().LogDialogLatencyToShow( | 3237 GetMetricLogger().LogDialogLatencyToShow( |
3390 GetDialogType(), | 3238 GetDialogType(), |
3391 base::Time::Now() - dialog_shown_timestamp_); | 3239 base::Time::Now() - dialog_shown_timestamp_); |
3392 was_ui_latency_logged_ = true; | 3240 was_ui_latency_logged_ = true; |
3393 } | 3241 } |
3394 | 3242 |
3395 void AutofillDialogControllerImpl::SetAutocheckoutState( | |
3396 AutocheckoutState autocheckout_state) { | |
3397 if (autocheckout_state_ == autocheckout_state) | |
3398 return; | |
3399 | |
3400 autocheckout_state_ = autocheckout_state; | |
3401 if (view_) { | |
3402 ScopedViewUpdates updates(view_.get()); | |
3403 view_->UpdateDetailArea(); | |
3404 view_->UpdateButtonStrip(); | |
3405 view_->UpdateAutocheckoutStepsArea(); | |
3406 view_->UpdateNotificationArea(); | |
3407 } | |
3408 } | |
3409 | |
3410 void AutofillDialogControllerImpl::DeemphasizeRenderView() { | 3243 void AutofillDialogControllerImpl::DeemphasizeRenderView() { |
3411 web_contents()->GetRenderViewHost()->Send( | 3244 web_contents()->GetRenderViewHost()->Send( |
3412 new ChromeViewMsg_SetVisuallyDeemphasized( | 3245 new ChromeViewMsg_SetVisuallyDeemphasized( |
3413 web_contents()->GetRenderViewHost()->GetRoutingID(), true)); | 3246 web_contents()->GetRenderViewHost()->GetRoutingID(), true)); |
3414 deemphasized_render_view_ = true; | 3247 deemphasized_render_view_ = true; |
3415 } | 3248 } |
Ilya Sherman
2013/08/27 18:57:57
Can this method now be removed?
Raman Kakilate
2013/08/27 21:52:59
Done.
| |
3416 | 3249 |
3417 AutofillMetrics::DialogInitialUserStateMetric | 3250 AutofillMetrics::DialogInitialUserStateMetric |
3418 AutofillDialogControllerImpl::GetInitialUserState() const { | 3251 AutofillDialogControllerImpl::GetInitialUserState() const { |
3419 // Consider a user to be an Autofill user if the user has any credit cards | 3252 // Consider a user to be an Autofill user if the user has any credit cards |
3420 // or addresses saved. Check that the item count is greater than 2 because | 3253 // or addresses saved. Check that the item count is greater than 2 because |
3421 // an "empty" menu still has the "add new" menu item and "manage" menu item. | 3254 // an "empty" menu still has the "add new" menu item and "manage" menu item. |
3422 const bool has_autofill_profiles = | 3255 const bool has_autofill_profiles = |
3423 suggested_cc_.GetItemCount() > 2 || | 3256 suggested_cc_.GetItemCount() > 2 || |
3424 suggested_billing_.GetItemCount() > 2; | 3257 suggested_billing_.GetItemCount() > 2; |
3425 | 3258 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3470 GetValueFromSection(SECTION_EMAIL, EMAIL_ADDRESS)); | 3303 GetValueFromSection(SECTION_EMAIL, EMAIL_ADDRESS)); |
3471 | 3304 |
3472 ShowNewCreditCardBubble(newly_saved_card_.Pass(), | 3305 ShowNewCreditCardBubble(newly_saved_card_.Pass(), |
3473 billing_profile.Pass()); | 3306 billing_profile.Pass()); |
3474 return; | 3307 return; |
3475 } | 3308 } |
3476 | 3309 |
3477 if (!full_wallet_ || !full_wallet_->billing_address()) | 3310 if (!full_wallet_ || !full_wallet_->billing_address()) |
3478 return; | 3311 return; |
3479 | 3312 |
3480 // Don't show GeneratedCardBubble if Autocheckout failed. | |
3481 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT && | |
3482 autocheckout_state_ != AUTOCHECKOUT_SUCCESS) { | |
3483 return; | |
3484 } | |
3485 | |
3486 base::string16 backing_last_four; | 3313 base::string16 backing_last_four; |
3487 if (ActiveInstrument()) { | 3314 if (ActiveInstrument()) { |
3488 backing_last_four = ActiveInstrument()->TypeAndLastFourDigits(); | 3315 backing_last_four = ActiveInstrument()->TypeAndLastFourDigits(); |
3489 } else { | 3316 } else { |
3490 DetailOutputMap output; | 3317 DetailOutputMap output; |
3491 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3318 view_->GetUserInput(SECTION_CC_BILLING, &output); |
3492 CreditCard card; | 3319 CreditCard card; |
3493 GetBillingInfoFromOutputs(output, &card, NULL, NULL); | 3320 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
3494 backing_last_four = card.TypeAndLastFourDigits(); | 3321 backing_last_four = card.TypeAndLastFourDigits(); |
3495 } | 3322 } |
3496 #if !defined(OS_ANDROID) | 3323 #if !defined(OS_ANDROID) |
3497 GeneratedCreditCardBubbleController::Show( | 3324 GeneratedCreditCardBubbleController::Show( |
3498 web_contents(), | 3325 web_contents(), |
3499 backing_last_four, | 3326 backing_last_four, |
3500 full_wallet_->TypeAndLastFourDigits()); | 3327 full_wallet_->TypeAndLastFourDigits()); |
3501 #endif | 3328 #endif |
3502 } | 3329 } |
3503 | 3330 |
3504 } // namespace autofill | 3331 } // namespace autofill |
OLD | NEW |