Chromium Code Reviews| Index: chrome/browser/ui/views/payments/payment_request_dialog_view.cc |
| diff --git a/chrome/browser/ui/views/payments/payment_request_dialog_view.cc b/chrome/browser/ui/views/payments/payment_request_dialog_view.cc |
| index a9933f44b882c56edc2533163ba0a8aaa3b49c59..a945e6dbfacd4d9c6ae2a0abba4700ef9799f735 100644 |
| --- a/chrome/browser/ui/views/payments/payment_request_dialog_view.cc |
| +++ b/chrome/browser/ui/views/payments/payment_request_dialog_view.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" |
| +#include "chrome/browser/ui/views/payments/cvc_unmask_view_controller.h" |
| #include "chrome/browser/ui/views/payments/error_message_view_controller.h" |
| #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" |
| #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" |
| @@ -32,6 +33,66 @@ payments::PaymentRequestDialog* CreatePaymentRequestDialog( |
| } // namespace chrome |
| namespace payments { |
| + |
| +class CvcUnmaskUIDelegate |
|
Mathieu
2017/03/30 14:37:32
Can CvcUnmaskViewController be the autofill::payme
anthonyvd
2017/04/04 13:25:22
The UIDelegate is now the CvcUnmaskViewController.
|
| + : public autofill::payments::FullCardRequest::UIDelegate, |
| + public CvcUnmaskViewController::Observer { |
| + public: |
| + explicit CvcUnmaskUIDelegate(PaymentRequestDialogView* dialog, |
|
please use gerrit instead
2017/03/30 13:14:09
Explicit keyword is used only for constructors wit
anthonyvd
2017/03/30 15:43:41
Ah, there was a time when this only took one param
|
| + PaymentRequestSpec* spec, |
| + PaymentRequestState* state) |
| + : dialog_(dialog), spec_(spec), state_(state), weak_ptr_factory_(this) {} |
| + |
| + ~CvcUnmaskUIDelegate() override { OnClosed(); } |
| + |
| + // autofill::payments::FullCardRequest::UIDelegate: |
| + void ShowUnmaskPrompt( |
| + const autofill::CreditCard& card, |
| + autofill::AutofillClient::UnmaskCardReason reason, |
| + base::WeakPtr<autofill::CardUnmaskDelegate> delegate) override { |
| + unmask_delegate_ = delegate; |
| + std::unique_ptr<CvcUnmaskViewController> view_controller = |
| + base::MakeUnique<CvcUnmaskViewController>( |
| + spec_, state_, dialog_, card.TypeAndLastFourDigits(), card.type()); |
| + |
| + view_controller->AddObserver(this); |
| + dialog_->ShowCvcUnmaskSheet(std::move(view_controller)); |
| + } |
| + |
| + void OnUnmaskVerificationResult( |
| + autofill::AutofillClient::PaymentsRpcResult result) override { |
| + // TODO(anthonyvd): Check result and display UI. |
| + } |
| + |
| + // CvcUnmaskViewController::Observer |
| + void OnCvcConfirmed(const base::string16& cvc) override { |
| + if (unmask_delegate_) { |
| + autofill::CardUnmaskDelegate::UnmaskResponse response; |
| + response.cvc = cvc; |
| + unmask_delegate_->OnUnmaskResponse(response); |
| + } |
| + } |
| + |
| + void OnClosed() override { |
| + // TODO(anthonyvd): The dialog was closed, notify the full card request. |
| + } |
| + |
| + base::WeakPtr<CvcUnmaskUIDelegate> AsWeakPtr() { |
| + return weak_ptr_factory_.GetWeakPtr(); |
| + } |
| + |
| + private: |
| + PaymentRequestDialogView* dialog_; |
| + PaymentRequestSpec* spec_; |
| + PaymentRequestState* state_; |
| + |
| + base::WeakPtr<autofill::CardUnmaskDelegate> unmask_delegate_; |
| + |
| + base::WeakPtrFactory<CvcUnmaskUIDelegate> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CvcUnmaskUIDelegate); |
| +}; |
| + |
| namespace { |
| // This function creates an instance of a PaymentRequestSheetController |
| @@ -177,6 +238,13 @@ void PaymentRequestDialogView::ShowShippingOptionSheet() { |
| /* animate = */ true); |
| } |
| +void PaymentRequestDialogView::ShowCvcUnmaskSheet( |
| + std::unique_ptr<CvcUnmaskViewController> view_controller) { |
| + view_stack_.Push(CreateViewAndInstallController(std::move(view_controller), |
| + &controller_map_), |
| + /* animate = */ true); |
| +} |
| + |
| void PaymentRequestDialogView::ShowCreditCardEditor() { |
| view_stack_.Push(CreateViewAndInstallController( |
| base::MakeUnique<CreditCardEditorViewController>( |
| @@ -202,6 +270,13 @@ void PaymentRequestDialogView::EditorViewUpdated() { |
| observer_for_testing_->OnEditorViewUpdated(); |
| } |
| +base::WeakPtr<autofill::payments::FullCardRequest::UIDelegate> |
| +PaymentRequestDialogView::GetFullCardRequestUIDelegate() { |
| + cvc_unmask_ui_delegate_ = base::MakeUnique<CvcUnmaskUIDelegate>( |
| + this, request_->spec(), request_->state()); |
| + return cvc_unmask_ui_delegate_->AsWeakPtr(); |
| +} |
| + |
| void PaymentRequestDialogView::ShowInitialPaymentSheet() { |
| view_stack_.Push(CreateViewAndInstallController( |
| base::MakeUnique<PaymentSheetViewController>( |