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

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: Attempt to fix memory leak 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" 11 #include "chrome/browser/ui/views/autofill/view_util.h"
12 #include "components/autofill/core/browser/credit_card.h" 12 #include "components/autofill/core/browser/credit_card.h"
13 #include "components/autofill/core/browser/legal_message_line.h" 13 #include "components/autofill/core/browser/legal_message_line.h"
14 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h"
14 #include "components/strings/grit/components_strings.h" 15 #include "components/strings/grit/components_strings.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/views/border.h" 18 #include "ui/views/border.h"
18 #include "ui/views/bubble/bubble_frame_view.h" 19 #include "ui/views/bubble/bubble_frame_view.h"
19 #include "ui/views/controls/button/blue_button.h" 20 #include "ui/views/controls/button/blue_button.h"
20 #include "ui/views/controls/button/label_button.h" 21 #include "ui/views/controls/button/label_button.h"
21 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
22 #include "ui/views/controls/link.h" 23 #include "ui/views/controls/link.h"
23 #include "ui/views/controls/styled_label.h" 24 #include "ui/views/controls/styled_label.h"
25 #include "ui/views/controls/textfield/textfield.h"
24 #include "ui/views/layout/box_layout.h" 26 #include "ui/views/layout/box_layout.h"
25 #include "ui/views/layout/layout_constants.h" 27 #include "ui/views/layout/layout_constants.h"
28 #include "ui/views/window/dialog_client_view.h"
26 29
27 namespace autofill { 30 namespace autofill {
28 31
29 namespace { 32 namespace {
30 33
31 // Fixed width of the bubble. 34 // Fixed width of the bubble, in dip.
32 const int kBubbleWidth = 395; 35 const int kBubbleWidth = 395;
33 36
34 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel( 37 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel(
35 const LegalMessageLine& line, 38 const LegalMessageLine& line,
36 views::StyledLabelListener* listener) { 39 views::StyledLabelListener* listener) {
37 std::unique_ptr<views::StyledLabel> label( 40 std::unique_ptr<views::StyledLabel> label(
38 new views::StyledLabel(line.text(), listener)); 41 new views::StyledLabel(line.text(), listener));
39 for (const LegalMessageLine::Link& link : line.links()) { 42 for (const LegalMessageLine::Link& link : line.links()) {
40 label->AddStyleRange(link.range, 43 label->AddStyleRange(link.range,
41 views::StyledLabel::RangeStyleInfo::CreateForLink()); 44 views::StyledLabel::RangeStyleInfo::CreateForLink());
42 } 45 }
43 return label; 46 return label;
44 } 47 }
45 48
46 } // namespace 49 } // namespace
47 50
48 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, 51 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
49 content::WebContents* web_contents, 52 content::WebContents* web_contents,
50 SaveCardBubbleController* controller) 53 SaveCardBubbleController* controller)
51 : LocationBarBubbleDelegateView(anchor_view, web_contents), 54 : LocationBarBubbleDelegateView(anchor_view, web_contents),
52 controller_(controller), 55 controller_(controller),
56 cvc_textfield_(nullptr),
53 learn_more_link_(nullptr) { 57 learn_more_link_(nullptr) {
54 DCHECK(controller); 58 DCHECK(controller);
55 views::BubbleDialogDelegateView::CreateBubble(this); 59 views::BubbleDialogDelegateView::CreateBubble(this);
56 } 60 }
57 61
58 SaveCardBubbleViews::~SaveCardBubbleViews() {} 62 SaveCardBubbleViews::~SaveCardBubbleViews() {}
59 63
60 void SaveCardBubbleViews::Show(DisplayReason reason) { 64 void SaveCardBubbleViews::Show(DisplayReason reason) {
61 ShowForReason(reason); 65 ShowForReason(reason);
62 } 66 }
(...skipping 21 matching lines...) Expand all
84 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 88 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
85 89
86 // Add a StyledLabel for each line of the legal message. 90 // Add a StyledLabel for each line of the legal message.
87 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) 91 for (const LegalMessageLine& line : controller_->GetLegalMessageLines())
88 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); 92 view->AddChildView(CreateLegalMessageLineLabel(line, this).release());
89 93
90 return view; 94 return view;
91 } 95 }
92 96
93 bool SaveCardBubbleViews::Accept() { 97 bool SaveCardBubbleViews::Accept() {
94 if (controller_) 98 if (controller_) {
99 if (cvc_textfield_)
100 controller_->SetCvcEnteredByUser(cvc_textfield_->text());
95 controller_->OnSaveButton(); 101 controller_->OnSaveButton();
Evan Stade 2017/04/12 15:21:31 it looks like you only call SetCvcEnteredByUser ri
Jared Saul 2017/04/12 22:49:21 Done.
102 }
96 return true; 103 return true;
97 } 104 }
98 105
99 bool SaveCardBubbleViews::Cancel() { 106 bool SaveCardBubbleViews::Cancel() {
100 if (controller_) 107 if (controller_)
101 controller_->OnCancelButton(); 108 controller_->OnCancelButton();
102 return true; 109 return true;
103 } 110 }
104 111
105 bool SaveCardBubbleViews::Close() { 112 bool SaveCardBubbleViews::Close() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 card_type_icon->SetTooltipText(card.TypeForDisplay()); 200 card_type_icon->SetTooltipText(card.TypeForDisplay());
194 card_type_icon->SetBorder( 201 card_type_icon->SetBorder(
195 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); 202 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10)));
196 description_view->AddChildView(card_type_icon); 203 description_view->AddChildView(card_type_icon);
197 204
198 description_view->AddChildView(new views::Label( 205 description_view->AddChildView(new views::Label(
199 base::string16(kMidlineEllipsis) + card.LastFourDigits())); 206 base::string16(kMidlineEllipsis) + card.LastFourDigits()));
200 description_view->AddChildView( 207 description_view->AddChildView(
201 new views::Label(card.AbbreviatedExpirationDateForDisplay())); 208 new views::Label(card.AbbreviatedExpirationDateForDisplay()));
202 209
210 // Optionally add CVC request field if CVC was missing.
211 if (controller_->ShouldRequestCvcFromUser())
212 view->AddChildView(CreateRequestCvcView().release());
213
203 // Optionally add label that will contain an explanation for upload. 214 // Optionally add label that will contain an explanation for upload.
204 base::string16 explanation = controller_->GetExplanatoryMessage(); 215 base::string16 explanation = controller_->GetExplanatoryMessage();
205 if (!explanation.empty()) { 216 if (!explanation.empty()) {
206 views::Label* explanation_label = new views::Label(explanation); 217 views::Label* explanation_label = new views::Label(explanation);
207 explanation_label->SetMultiLine(true); 218 explanation_label->SetMultiLine(true);
208 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 219 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
209 view->AddChildView(explanation_label); 220 view->AddChildView(explanation_label);
210 } 221 }
211 222
212 return view; 223 return view;
213 } 224 }
214 225
226 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() {
227 std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>();
228 request_cvc_view->SetLayoutManager(
229 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kHorizontal, 0, 0,
Evan Stade 2017/04/12 15:21:31 nit: making a unique pointer and then immediately
Jared Saul 2017/04/12 22:49:21 Fixed.
230 views::kRelatedButtonHSpacing)
231 .release());
232
233 DCHECK(!cvc_textfield_);
234 cvc_textfield_ = autofill::CreateCvcTextfield();
235 cvc_textfield_->set_controller(this);
236 request_cvc_view->AddChildView(cvc_textfield_);
237
238 views::ImageView* cvc_image = new views::ImageView();
239 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
240 cvc_image->SetImage(
241 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId()));
242 request_cvc_view->AddChildView(cvc_image);
243
244 request_cvc_view->AddChildView(new views::Label(
245 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC)));
246 return request_cvc_view;
247 }
248
249 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const {
250 if (button == ui::DIALOG_BUTTON_CANCEL)
251 return true;
252
253 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button);
254 return !cvc_textfield_ ||
255 controller_->InputCvcIsValid(cvc_textfield_->text());
256 }
257
258 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender,
259 const base::string16& new_contents) {
Evan Stade 2017/04/12 15:21:31 nit: DCHECK_EQ(cvc_textfield_, sender);
Jared Saul 2017/04/12 22:49:21 Done.
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