Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3965)

Unified Diff: chrome/browser/ui/views/payments/payment_request_dialog_view.cc

Issue 2779283002: [Web Payments] Implement the CVC Unmask dialog. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 f5660203f2403f7c8798ba4605d285f6bd3a7318..d25ecce282032ef3478804e4e81bd710655fd8a4 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/order_summary_view_controller.h"
#include "chrome/browser/ui/views/payments/payment_method_view_controller.h"
#include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
@@ -31,6 +32,66 @@ payments::PaymentRequestDialog* CreatePaymentRequestDialog(
} // namespace chrome
namespace payments {
+
+class CvcUnmaskUIDelegate
+ : public autofill::payments::FullCardRequest::UIDelegate,
+ public CvcUnmaskViewController::Observer {
+ public:
+ explicit CvcUnmaskUIDelegate(PaymentRequestDialogView* dialog,
+ 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
@@ -156,6 +217,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>(
@@ -191,6 +259,13 @@ void PaymentRequestDialogView::CloseDialog() {
GetWidget()->Close();
}
+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>(

Powered by Google App Engine
This is Rietveld 408576698