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

Unified Diff: chrome/browser/ui/views/payments/cvc_unmask_view_controller.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/cvc_unmask_view_controller.cc
diff --git a/chrome/browser/ui/views/payments/cvc_unmask_view_controller.cc b/chrome/browser/ui/views/payments/cvc_unmask_view_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1332fc5d1e5b65f79e80bb5222368c19f665fc06
--- /dev/null
+++ b/chrome/browser/ui/views/payments/cvc_unmask_view_controller.cc
@@ -0,0 +1,127 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/payments/cvc_unmask_view_controller.h"
+
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/ui/views/payments/payment_request_views_util.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/autofill/core/browser/credit_card.h"
+#include "components/grit/components_scaled_resources.h"
+#include "components/strings/grit/components_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/views/controls/button/md_text_button.h"
+#include "ui/views/controls/textfield/textfield.h"
+#include "ui/views/layout/fill_layout.h"
+#include "ui/views/layout/grid_layout.h"
+
+namespace payments {
+
+enum class Tags {
+ CONFIRM_TAG = static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG),
+};
+
+CvcUnmaskViewController::CvcUnmaskViewController(
+ PaymentRequestSpec* spec,
+ PaymentRequestState* state,
+ PaymentRequestDialogView* dialog,
+ const base::string16& masked_card_number,
+ const std::string& card_type)
+ : PaymentRequestSheetController(spec, state, dialog),
+ masked_card_number_(masked_card_number),
+ card_type_(card_type) {}
+
+CvcUnmaskViewController::~CvcUnmaskViewController() {
+ for (Observer& observer : observer_list_) {
+ observer.OnClosed();
+ }
+}
+
+void CvcUnmaskViewController::AddObserver(Observer* observer) {
+ observer_list_.AddObserver(observer);
+}
+
+base::string16 CvcUnmaskViewController::GetSheetTitle() {
+ return l10n_util::GetStringFUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE,
+ masked_card_number_);
+}
+
+void CvcUnmaskViewController::FillContentView(views::View* content_view) {
+ std::unique_ptr<views::GridLayout> layout =
+ base::MakeUnique<views::GridLayout>(content_view);
+ layout->SetInsets(
+ kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets,
+ kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets);
+
+ views::ColumnSet* instructions_columns = layout->AddColumnSet(0);
+ instructions_columns->AddColumn(views::GridLayout::Alignment::LEADING,
+ views::GridLayout::Alignment::LEADING, 1,
+ views::GridLayout::SizeType::USE_PREF, 0, 0);
+
+ layout->StartRow(0, 0);
+ std::unique_ptr<views::Label> instructions = base::MakeUnique<views::Label>(
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS));
+ instructions->SetMultiLine(true);
+ instructions->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ layout->AddView(instructions.release());
+
+ layout->AddPaddingRow(0, 22);
+
+ views::ColumnSet* cvc_field_columns = layout->AddColumnSet(1);
+ cvc_field_columns->AddColumn(views::GridLayout::Alignment::LEADING,
+ views::GridLayout::Alignment::BASELINE, 0,
+ views::GridLayout::SizeType::FIXED, 32, 32);
+ cvc_field_columns->AddPaddingColumn(0, 16);
+ cvc_field_columns->AddColumn(views::GridLayout::Alignment::FILL,
+ views::GridLayout::Alignment::BASELINE, 0,
+ views::GridLayout::SizeType::FIXED, 80, 80);
+
+ layout->StartRow(0, 1);
+ std::unique_ptr<views::ImageView> cvc_image =
+ base::MakeUnique<views::ImageView>();
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ // TODO(anthonyvd): Consider using
+ // CardUnmaskPromptControllerImpl::GetCvcImageRid.
+ cvc_image->SetImage(
+ rb.GetImageSkiaNamed(card_type_ == autofill::kAmericanExpressCard
+ ? IDR_CREDIT_CARD_CVC_HINT_AMEX
+ : IDR_CREDIT_CARD_CVC_HINT));
+ layout->AddView(cvc_image.release());
+
+ std::unique_ptr<views::Textfield> cvc_field =
+ base::MakeUnique<views::Textfield>();
+ cvc_field_ = cvc_field.get();
+ layout->AddView(cvc_field.release());
+
+ content_view->SetLayoutManager(layout.release());
+}
+
+std::unique_ptr<views::Button> CvcUnmaskViewController::CreatePrimaryButton() {
+ std::unique_ptr<views::Button> button(
+ views::MdTextButton::CreateSecondaryUiBlueButton(
+ this, l10n_util::GetStringUTF16(IDS_CONFIRM)));
+ button->set_tag(static_cast<int>(Tags::CONFIRM_TAG));
+ return button;
+}
+
+void CvcUnmaskViewController::ButtonPressed(views::Button* sender,
+ const ui::Event& event) {
+ switch (sender->tag()) {
+ case static_cast<int>(Tags::CONFIRM_TAG):
+ RaiseOnCvcConfirmed();
Mathieu 2017/03/30 14:37:32 Raise is not immediately clear, change name? Noti
+ break;
+ default:
+ PaymentRequestSheetController::ButtonPressed(sender, event);
+ }
+}
+
+void CvcUnmaskViewController::RaiseOnCvcConfirmed() {
+ const base::string16& cvc = cvc_field_->text();
+ for (Observer& observer : observer_list_) {
+ observer.OnCvcConfirmed(cvc);
+ }
+}
+
+} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698