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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "components/constrained_window/constrained_window_views.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/views/controls/image_view.h"
15 #include "ui/views/controls/label.h"
16 #include "ui/views/controls/textfield/textfield.h"
17 #include "ui/views/controls/textfield/textfield_controller.h"
18 #include "ui/views/layout/box_layout.h"
19 #include "ui/views/window/dialog_client_view.h"
20 #include "ui/views/window/dialog_delegate.h"
21
22 namespace autofill {
23
24 namespace {
25
26 class CardUnmaskPromptViews : public CardUnmaskPromptView,
27 views::DialogDelegateView,
28 views::TextfieldController {
29 public:
30 CardUnmaskPromptViews(content::WebContents* web_contents,
31 const UnmaskCallback& finished)
32 : web_contents_(web_contents),
33 finished_(finished),
34 accepted_(false),
35 cvc_(nullptr) {}
36
37 ~CardUnmaskPromptViews() override {
38 finished_.Run(accepted_ ? cvc_->text() : base::string16());
39 }
40
41 void Show() {
42 constrained_window::ShowWebModalDialogViews(this, web_contents_);
43 }
44
45 // views::DialogDelegateView
46 View* GetContentsView() override {
47 InitIfNecessary();
48 return this;
49 }
50
51 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; }
52
53 base::string16 GetWindowTitle() const override {
54 // TODO(estade): fix this.
55 return base::ASCIIToUTF16("Unlocking Visa - 1111");
56 }
57
58 void DeleteDelegate() override { delete this; }
59
60 int GetDialogButtons() const override {
61 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
62 }
63
64 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override {
65 // TODO(estade): fix this.
66 if (button == ui::DIALOG_BUTTON_OK)
67 return base::ASCIIToUTF16("Verify");
68
69 return DialogDelegateView::GetDialogButtonLabel(button);
70 }
71
72 bool ShouldDefaultButtonBeBlue() const override { return true; }
73
74 bool IsDialogButtonEnabled(ui::DialogButton button) const override {
75 if (button == ui::DIALOG_BUTTON_CANCEL)
76 return true;
77
78 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button);
79
80 base::string16 input_text;
81 base::TrimWhitespace(cvc_->text(), base::TRIM_ALL, &input_text);
82 return input_text.size() == 3 &&
83 base::ContainsOnlyChars(input_text,
84 base::ASCIIToUTF16("0123456789"));
85 }
86
87 views::View* GetInitiallyFocusedView() override { return cvc_; }
88
89 bool Cancel() override {
90 DCHECK_EQ(false, accepted_);
91 return true;
92 }
93
94 bool Accept() override {
95 accepted_ = true;
96 return true;
97 }
98
99 // views::TextfieldController
100 void ContentsChanged(views::Textfield* sender,
101 const base::string16& new_contents) override {
102 GetDialogClientView()->UpdateDialogButtons();
103 }
104
105 private:
106 void InitIfNecessary() {
107 if (has_children())
108 return;
109
110 // TODO(estade): for amex, text and CVC image should be different.
111 SetLayoutManager(
112 new views::BoxLayout(views::BoxLayout::kVertical, 19, 0, 5));
113 AddChildView(new views::Label(base::ASCIIToUTF16(
114 "Enter the three digit verification code from the back of your credit "
115 "card")));
116
117 views::View* cvc_container = new views::View();
118 cvc_container->SetLayoutManager(
119 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5));
120 AddChildView(cvc_container);
121
122 cvc_ = new views::Textfield();
123 cvc_->set_controller(this);
124 cvc_->set_placeholder_text(
125 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC));
126 cvc_->set_default_width_in_chars(10);
127 cvc_container->AddChildView(cvc_);
128
129 views::ImageView* cvc_image = new views::ImageView();
130 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
131 cvc_image->SetImage(rb.GetImageSkiaNamed(IDR_CREDIT_CARD_CVC_HINT));
132 cvc_container->AddChildView(cvc_image);
133 }
134
135 content::WebContents* web_contents_;
136
137 UnmaskCallback finished_;
138
139 // Set to true when the user accepts.
140 bool accepted_;
141
142 views::Textfield* cvc_;
143
144 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViews);
145 };
146
147 } // namespace
148
149 // static
150 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow(
151 content::WebContents* web_contents,
152 const UnmaskCallback& finished) {
153 CardUnmaskPromptViews* view =
154 new CardUnmaskPromptViews(web_contents, finished);
155 view->Show();
156 return view;
157 }
158
159 } // namespace autofill
OLDNEW
« 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