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

Side by Side Diff: chrome/browser/ui/views/autofill/save_card_bubble_views.cc

Issue 2789843004: [Payments] Upload card UI now has a CVC prompt (Closed)
Patch Set: Addressing code review comments Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h" 5 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h"
12 #include "components/autofill/core/browser/credit_card.h" 11 #include "components/autofill/core/browser/credit_card.h"
13 #include "components/autofill/core/browser/legal_message_line.h" 12 #include "components/autofill/core/browser/legal_message_line.h"
13 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h"
14 #include "components/strings/grit/components_strings.h" 14 #include "components/strings/grit/components_strings.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/views/border.h" 17 #include "ui/views/border.h"
18 #include "ui/views/bubble/bubble_frame_view.h" 18 #include "ui/views/bubble/bubble_frame_view.h"
19 #include "ui/views/controls/button/blue_button.h" 19 #include "ui/views/controls/button/blue_button.h"
20 #include "ui/views/controls/button/label_button.h" 20 #include "ui/views/controls/button/label_button.h"
21 #include "ui/views/controls/label.h" 21 #include "ui/views/controls/label.h"
22 #include "ui/views/controls/link.h" 22 #include "ui/views/controls/link.h"
23 #include "ui/views/controls/styled_label.h" 23 #include "ui/views/controls/styled_label.h"
24 #include "ui/views/controls/textfield/textfield.h"
24 #include "ui/views/layout/box_layout.h" 25 #include "ui/views/layout/box_layout.h"
25 #include "ui/views/layout/layout_constants.h" 26 #include "ui/views/layout/layout_constants.h"
27 #include "ui/views/window/dialog_client_view.h"
26 28
27 namespace autofill { 29 namespace autofill {
28 30
29 namespace { 31 namespace {
30 32
31 // Fixed width of the bubble. 33 // Fixed width of the bubble.
32 const int kBubbleWidth = 395; 34 const int kBubbleWidth = 395;
csashi 2017/04/02 22:36:15 You can put the cvc 8 char width constant here.
Jared Saul 2017/04/03 18:52:59 Done.
33 35
34 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel( 36 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel(
35 const LegalMessageLine& line, 37 const LegalMessageLine& line,
36 views::StyledLabelListener* listener) { 38 views::StyledLabelListener* listener) {
37 std::unique_ptr<views::StyledLabel> label( 39 std::unique_ptr<views::StyledLabel> label(
38 new views::StyledLabel(line.text(), listener)); 40 new views::StyledLabel(line.text(), listener));
39 for (const LegalMessageLine::Link& link : line.links()) { 41 for (const LegalMessageLine::Link& link : line.links()) {
40 label->AddStyleRange(link.range, 42 label->AddStyleRange(link.range,
41 views::StyledLabel::RangeStyleInfo::CreateForLink()); 43 views::StyledLabel::RangeStyleInfo::CreateForLink());
42 } 44 }
43 return label; 45 return label;
44 } 46 }
45 47
46 } // namespace 48 } // namespace
47 49
48 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, 50 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
49 content::WebContents* web_contents, 51 content::WebContents* web_contents,
50 SaveCardBubbleController* controller) 52 SaveCardBubbleController* controller)
51 : LocationBarBubbleDelegateView(anchor_view, web_contents), 53 : LocationBarBubbleDelegateView(anchor_view, web_contents),
52 controller_(controller), 54 controller_(controller),
55 cvc_input_(nullptr),
53 learn_more_link_(nullptr) { 56 learn_more_link_(nullptr) {
54 DCHECK(controller); 57 DCHECK(controller);
55 views::BubbleDialogDelegateView::CreateBubble(this); 58 views::BubbleDialogDelegateView::CreateBubble(this);
56 } 59 }
57 60
58 SaveCardBubbleViews::~SaveCardBubbleViews() {} 61 SaveCardBubbleViews::~SaveCardBubbleViews() {}
59 62
60 void SaveCardBubbleViews::Show(DisplayReason reason) { 63 void SaveCardBubbleViews::Show(DisplayReason reason) {
61 ShowForReason(reason); 64 ShowForReason(reason);
62 } 65 }
(...skipping 21 matching lines...) Expand all
84 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 87 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
85 88
86 // Add a StyledLabel for each line of the legal message. 89 // Add a StyledLabel for each line of the legal message.
87 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) 90 for (const LegalMessageLine& line : controller_->GetLegalMessageLines())
88 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); 91 view->AddChildView(CreateLegalMessageLineLabel(line, this).release());
89 92
90 return view; 93 return view;
91 } 94 }
92 95
93 bool SaveCardBubbleViews::Accept() { 96 bool SaveCardBubbleViews::Accept() {
94 if (controller_) 97 if (controller_) {
98 if (controller_->ShouldRequestCvcFromUser()) {
99 const base::string16& cvc = cvc_input_->text();
100 controller_->SetCvcEnteredByUser(cvc);
101 }
95 controller_->OnSaveButton(); 102 controller_->OnSaveButton();
103 }
96 return true; 104 return true;
97 } 105 }
98 106
99 bool SaveCardBubbleViews::Cancel() { 107 bool SaveCardBubbleViews::Cancel() {
100 if (controller_) 108 if (controller_)
101 controller_->OnCancelButton(); 109 controller_->OnCancelButton();
102 return true; 110 return true;
103 } 111 }
104 112
105 bool SaveCardBubbleViews::Close() { 113 bool SaveCardBubbleViews::Close() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 card_type_icon->SetTooltipText(card.TypeForDisplay()); 201 card_type_icon->SetTooltipText(card.TypeForDisplay());
194 card_type_icon->SetBorder( 202 card_type_icon->SetBorder(
195 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); 203 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10)));
196 description_view->AddChildView(card_type_icon); 204 description_view->AddChildView(card_type_icon);
197 205
198 description_view->AddChildView(new views::Label( 206 description_view->AddChildView(new views::Label(
199 base::string16(kMidlineEllipsis) + card.LastFourDigits())); 207 base::string16(kMidlineEllipsis) + card.LastFourDigits()));
200 description_view->AddChildView( 208 description_view->AddChildView(
201 new views::Label(card.AbbreviatedExpirationDateForDisplay())); 209 new views::Label(card.AbbreviatedExpirationDateForDisplay()));
202 210
211 // Optionally add CVC request field if CVC was missing.
212 if (controller_->ShouldRequestCvcFromUser()) {
213 view->AddChildView(CreateRequestCvcView().release());
214 }
215
203 // Optionally add label that will contain an explanation for upload. 216 // Optionally add label that will contain an explanation for upload.
204 base::string16 explanation = controller_->GetExplanatoryMessage(); 217 base::string16 explanation = controller_->GetExplanatoryMessage();
205 if (!explanation.empty()) { 218 if (!explanation.empty()) {
206 views::Label* explanation_label = new views::Label(explanation); 219 views::Label* explanation_label = new views::Label(explanation);
207 explanation_label->SetMultiLine(true); 220 explanation_label->SetMultiLine(true);
208 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 221 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
209 view->AddChildView(explanation_label); 222 view->AddChildView(explanation_label);
210 } 223 }
211 224
212 return view; 225 return view;
213 } 226 }
214 227
228 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() {
229 std::unique_ptr<View> request_cvc_view(new View());
230 request_cvc_view->SetLayoutManager(new views::BoxLayout(
231 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing));
232 DCHECK(!cvc_input_);
233 cvc_input_ = new views::Textfield();
234 cvc_input_->set_placeholder_text(
235 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC));
236 cvc_input_->set_controller(this);
237 cvc_input_->set_default_width_in_chars(kDefaultWidthForCvc);
238 request_cvc_view->AddChildView(cvc_input_);
239 views::ImageView* cvc_image = new views::ImageView();
240 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
241 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid()));
242 request_cvc_view->AddChildView(cvc_image);
243 request_cvc_view->AddChildView(new views::Label(
244 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC)));
245 return request_cvc_view;
csashi 2017/04/02 22:36:15 Not sure what the whitespace convention in Chrome
Jared Saul 2017/04/03 18:52:59 SGTM, thanks!
246 }
247
248 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const {
249 if (button == ui::DIALOG_BUTTON_CANCEL)
250 return true;
251
252 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button);
253 return !controller_->ShouldRequestCvcFromUser() ||
254 (cvc_input_->enabled() &&
255 controller_->InputCvcIsValid(cvc_input_->text()));
256 }
257
258 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender,
259 const base::string16& new_contents) {
260 GetDialogClientView()->UpdateDialogButtons();
261 }
262
215 void SaveCardBubbleViews::Init() { 263 void SaveCardBubbleViews::Init() {
216 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 264 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
217 AddChildView(CreateMainContentView().release()); 265 AddChildView(CreateMainContentView().release());
218 } 266 }
219 267
220 } // namespace autofill 268 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698