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

Unified Diff: chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc

Issue 773653002: [Views] Instrument unmasking prompt initial implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: butterfingers Created 6 years 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
« no previous file with comments | « chrome/browser/ui/autofill/card_unmask_prompt_view.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc
diff --git a/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc b/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e478eee62fdec3780fc383f99ec8adcfe1062cb0
--- /dev/null
+++ b/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc
@@ -0,0 +1,159 @@
+// Copyright 2014 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 "base/basictypes.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/ui/autofill/card_unmask_prompt_view.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/constrained_window/constrained_window_views.h"
+#include "grit/theme_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/controls/textfield/textfield.h"
+#include "ui/views/controls/textfield/textfield_controller.h"
+#include "ui/views/layout/box_layout.h"
+#include "ui/views/window/dialog_client_view.h"
+#include "ui/views/window/dialog_delegate.h"
+
+namespace autofill {
+
+namespace {
+
+class CardUnmaskPromptViews : public CardUnmaskPromptView,
+ views::DialogDelegateView,
+ views::TextfieldController {
+ public:
+ CardUnmaskPromptViews(content::WebContents* web_contents,
+ const UnmaskCallback& finished)
+ : web_contents_(web_contents),
+ finished_(finished),
+ accepted_(false),
+ cvc_(nullptr) {}
+
+ ~CardUnmaskPromptViews() override {
+ finished_.Run(accepted_ ? cvc_->text() : base::string16());
+ }
+
+ void Show() {
+ constrained_window::ShowWebModalDialogViews(this, web_contents_);
+ }
+
+ // views::DialogDelegateView
+ View* GetContentsView() override {
+ InitIfNecessary();
+ return this;
+ }
+
+ ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; }
+
+ base::string16 GetWindowTitle() const override {
+ // TODO(estade): fix this.
+ return base::ASCIIToUTF16("Unlocking Visa - 1111");
+ }
+
+ void DeleteDelegate() override { delete this; }
+
+ int GetDialogButtons() const override {
+ return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
+ }
+
+ base::string16 GetDialogButtonLabel(ui::DialogButton button) const override {
+ // TODO(estade): fix this.
+ if (button == ui::DIALOG_BUTTON_OK)
+ return base::ASCIIToUTF16("Verify");
+
+ return DialogDelegateView::GetDialogButtonLabel(button);
+ }
+
+ bool ShouldDefaultButtonBeBlue() const override { return true; }
+
+ bool IsDialogButtonEnabled(ui::DialogButton button) const override {
+ if (button == ui::DIALOG_BUTTON_CANCEL)
+ return true;
+
+ DCHECK_EQ(ui::DIALOG_BUTTON_OK, button);
+
+ base::string16 input_text;
+ base::TrimWhitespace(cvc_->text(), base::TRIM_ALL, &input_text);
+ return input_text.size() == 3 &&
+ base::ContainsOnlyChars(input_text,
+ base::ASCIIToUTF16("0123456789"));
+ }
+
+ views::View* GetInitiallyFocusedView() override { return cvc_; }
+
+ bool Cancel() override {
+ DCHECK_EQ(false, accepted_);
+ return true;
+ }
+
+ bool Accept() override {
+ accepted_ = true;
+ return true;
+ }
+
+ // views::TextfieldController
+ void ContentsChanged(views::Textfield* sender,
+ const base::string16& new_contents) override {
+ GetDialogClientView()->UpdateDialogButtons();
+ }
+
+ private:
+ void InitIfNecessary() {
+ if (has_children())
+ return;
+
+ // TODO(estade): for amex, text and CVC image should be different.
+ SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kVertical, 19, 0, 5));
+ AddChildView(new views::Label(base::ASCIIToUTF16(
+ "Enter the three digit verification code from the back of your credit "
+ "card")));
+
+ views::View* cvc_container = new views::View();
+ cvc_container->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5));
+ AddChildView(cvc_container);
+
+ cvc_ = new views::Textfield();
+ cvc_->set_controller(this);
+ cvc_->set_placeholder_text(
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC));
+ cvc_->set_default_width_in_chars(10);
+ cvc_container->AddChildView(cvc_);
+
+ views::ImageView* cvc_image = new views::ImageView();
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ cvc_image->SetImage(rb.GetImageSkiaNamed(IDR_CREDIT_CARD_CVC_HINT));
+ cvc_container->AddChildView(cvc_image);
+ }
+
+ content::WebContents* web_contents_;
+
+ UnmaskCallback finished_;
+
+ // Set to true when the user accepts.
+ bool accepted_;
+
+ views::Textfield* cvc_;
+
+ DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViews);
+};
+
+} // namespace
+
+// static
+CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow(
+ content::WebContents* web_contents,
+ const UnmaskCallback& finished) {
+ CardUnmaskPromptViews* view =
+ new CardUnmaskPromptViews(web_contents, finished);
+ view->Show();
+ return view;
+}
+
+} // namespace autofill
« no previous file with comments | « chrome/browser/ui/autofill/card_unmask_prompt_view.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698