Chromium Code Reviews| Index: chrome/browser/ui/views/autofill/save_card_bubble_views.cc |
| diff --git a/chrome/browser/ui/views/autofill/save_card_bubble_views.cc b/chrome/browser/ui/views/autofill/save_card_bubble_views.cc |
| index 2549a1759d90632881233199c593c8ef9d5f3ae3..598cf1630ae74333b3667a590cf5d546f243549c 100644 |
| --- a/chrome/browser/ui/views/autofill/save_card_bubble_views.cc |
| +++ b/chrome/browser/ui/views/autofill/save_card_bubble_views.cc |
| @@ -8,9 +8,9 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "build/build_config.h" |
| -#include "chrome/browser/ui/autofill/save_card_bubble_controller.h" |
| #include "components/autofill/core/browser/credit_card.h" |
| #include "components/autofill/core/browser/legal_message_line.h" |
| +#include "components/autofill/core/browser/ui/save_card_bubble_controller.h" |
| #include "components/strings/grit/components_strings.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| @@ -21,8 +21,10 @@ |
| #include "ui/views/controls/label.h" |
| #include "ui/views/controls/link.h" |
| #include "ui/views/controls/styled_label.h" |
| +#include "ui/views/controls/textfield/textfield.h" |
| #include "ui/views/layout/box_layout.h" |
| #include "ui/views/layout/layout_constants.h" |
| +#include "ui/views/window/dialog_client_view.h" |
| namespace autofill { |
| @@ -50,6 +52,7 @@ SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, |
| SaveCardBubbleController* controller) |
| : LocationBarBubbleDelegateView(anchor_view, web_contents), |
| controller_(controller), |
| + cvc_input_(nullptr), |
| learn_more_link_(nullptr) { |
| DCHECK(controller); |
| views::BubbleDialogDelegateView::CreateBubble(this); |
| @@ -91,8 +94,13 @@ views::View* SaveCardBubbleViews::CreateFootnoteView() { |
| } |
| bool SaveCardBubbleViews::Accept() { |
| - if (controller_) |
| + if (controller_) { |
| + if (controller_->ShouldRequestCvcFromUser()) { |
| + const base::string16& cvc = cvc_input_->text(); |
| + controller_->SetCvcEnteredByUser(cvc); |
| + } |
| controller_->OnSaveButton(); |
| + } |
| return true; |
| } |
| @@ -200,6 +208,11 @@ std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() { |
| description_view->AddChildView( |
| new views::Label(card.AbbreviatedExpirationDateForDisplay())); |
| + // Optionally add CVC request field if CVC was missing. |
| + if (controller_->ShouldRequestCvcFromUser()) { |
| + view->AddChildView(CreateRequestCvcView().release()); |
| + } |
| + |
| // Optionally add label that will contain an explanation for upload. |
| base::string16 explanation = controller_->GetExplanatoryMessage(); |
| if (!explanation.empty()) { |
| @@ -212,6 +225,41 @@ std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() { |
| return view; |
| } |
| +std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { |
| + std::unique_ptr<View> request_cvc_view(new View()); |
| + request_cvc_view->SetLayoutManager(new views::BoxLayout( |
| + views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); |
| + DCHECK(!cvc_input_); |
| + cvc_input_ = new views::Textfield(); |
| + cvc_input_->set_placeholder_text( |
| + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)); |
| + cvc_input_->set_controller(this); |
| + cvc_input_->set_default_width_in_chars(kDefaultWidthForCvc); |
| + request_cvc_view->AddChildView(cvc_input_); |
| + views::ImageView* cvc_image = new views::ImageView(); |
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| + cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid())); |
| + request_cvc_view->AddChildView(cvc_image); |
| + request_cvc_view->AddChildView(new views::Label( |
| + l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); |
| + 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!
|
| +} |
| + |
| +bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { |
| + if (button == ui::DIALOG_BUTTON_CANCEL) |
| + return true; |
| + |
| + DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); |
| + return !controller_->ShouldRequestCvcFromUser() || |
| + (cvc_input_->enabled() && |
| + controller_->InputCvcIsValid(cvc_input_->text())); |
| +} |
| + |
| +void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, |
| + const base::string16& new_contents) { |
| + GetDialogClientView()->UpdateDialogButtons(); |
| +} |
| + |
| void SaveCardBubbleViews::Init() { |
| SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| AddChildView(CreateMainContentView().release()); |