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

Side by Side Diff: chrome/browser/ui/views/payments/cvc_unmask_view_controller.cc

Issue 2779283002: [Web Payments] Implement the CVC Unmask dialog. (Closed)
Patch Set: BUILD 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
(Empty)
1 // Copyright 2017 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 "chrome/browser/ui/views/payments/cvc_unmask_view_controller.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/autofill/risk_util.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
11 #include "chrome/browser/signin/signin_manager_factory.h"
12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
13 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/autofill/core/browser/credit_card.h"
16 #include "components/autofill/core/browser/payments/full_card_request.h"
17 #include "components/grit/components_scaled_resources.h"
18 #include "components/payments/content/payment_request_state.h"
19 #include "components/payments/core/payment_request_delegate.h"
20 #include "components/signin/core/browser/profile_identity_provider.h"
21 #include "components/signin/core/browser/signin_manager.h"
22 #include "components/strings/grit/components_strings.h"
23 #include "content/public/browser/web_contents.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/views/controls/button/md_text_button.h"
27 #include "ui/views/controls/textfield/textfield.h"
28 #include "ui/views/layout/fill_layout.h"
29 #include "ui/views/layout/grid_layout.h"
30
31 namespace payments {
32
33 enum class Tags {
34 CONFIRM_TAG = static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG),
35 };
36
37 CvcUnmaskViewController::CvcUnmaskViewController(
38 PaymentRequestSpec* spec,
39 PaymentRequestState* state,
40 PaymentRequestDialogView* dialog,
41 const autofill::CreditCard& credit_card,
42 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
43 result_delegate,
44 content::WebContents* web_contents)
45 : PaymentRequestSheetController(spec, state, dialog),
46 credit_card_(credit_card),
47 web_contents_(web_contents),
48 payments_client_(
49 Profile::FromBrowserContext(web_contents_->GetBrowserContext())
50 ->GetRequestContext(),
51 this),
52 full_card_request_(this,
53 &payments_client_,
54 state->GetPersonalDataManager()),
55 weak_ptr_factory_(this) {
56 full_card_request_.GetFullCard(
57 credit_card,
58 autofill::AutofillClient::UnmaskCardReason::UNMASK_FOR_PAYMENT_REQUEST,
59 result_delegate, weak_ptr_factory_.GetWeakPtr());
60 }
61
62 CvcUnmaskViewController::~CvcUnmaskViewController() {}
63
64 IdentityProvider* CvcUnmaskViewController::GetIdentityProvider() {
65 if (!identity_provider_) {
66 Profile* profile =
67 Profile::FromBrowserContext(web_contents_->GetBrowserContext())
68 ->GetOriginalProfile();
69 identity_provider_.reset(new ProfileIdentityProvider(
70 SigninManagerFactory::GetForProfile(profile),
71 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
72 base::Closure()));
73 }
74
75 return identity_provider_.get();
76 }
77
78 void CvcUnmaskViewController::OnDidGetRealPan(
79 autofill::AutofillClient::PaymentsRpcResult result,
80 const std::string& real_pan) {
81 full_card_request_.OnDidGetRealPan(result, real_pan);
82 }
83
84 void CvcUnmaskViewController::OnDidGetUploadDetails(
85 autofill::AutofillClient::PaymentsRpcResult result,
86 const base::string16& context_token,
87 std::unique_ptr<base::DictionaryValue> legal_message) {
88 NOTIMPLEMENTED();
89 }
90
91 void CvcUnmaskViewController::OnDidUploadCard(
92 autofill::AutofillClient::PaymentsRpcResult result) {
93 NOTIMPLEMENTED();
94 }
95
96 void CvcUnmaskViewController::LoadRiskData(
97 const base::Callback<void(const std::string&)>& callback) {
98 autofill::LoadRiskData(0, web_contents_, callback);
99 }
100
101 void CvcUnmaskViewController::ShowUnmaskPrompt(
102 const autofill::CreditCard& card,
103 autofill::AutofillClient::UnmaskCardReason reason,
104 base::WeakPtr<autofill::CardUnmaskDelegate> delegate) {
105 unmask_delegate_ = delegate;
106 }
107
108 void CvcUnmaskViewController::OnUnmaskVerificationResult(
109 autofill::AutofillClient::PaymentsRpcResult result) {
110 // TODO(anthonyvd): Show result.
111 }
112
113 base::string16 CvcUnmaskViewController::GetSheetTitle() {
114 return l10n_util::GetStringFUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE,
115 credit_card_.TypeAndLastFourDigits());
116 }
117
118 void CvcUnmaskViewController::FillContentView(views::View* content_view) {
119 std::unique_ptr<views::GridLayout> layout =
120 base::MakeUnique<views::GridLayout>(content_view);
121 layout->SetInsets(
122 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets,
123 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets);
124
125 views::ColumnSet* instructions_columns = layout->AddColumnSet(0);
126 instructions_columns->AddColumn(views::GridLayout::Alignment::LEADING,
127 views::GridLayout::Alignment::LEADING, 1,
128 views::GridLayout::SizeType::USE_PREF, 0, 0);
129
130 layout->StartRow(0, 0);
131 std::unique_ptr<views::Label> instructions = base::MakeUnique<views::Label>(
132 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS));
133 instructions->SetMultiLine(true);
134 instructions->SetHorizontalAlignment(gfx::ALIGN_LEFT);
135 layout->AddView(instructions.release());
136
137 layout->AddPaddingRow(0, 22);
138
139 views::ColumnSet* cvc_field_columns = layout->AddColumnSet(1);
140 cvc_field_columns->AddColumn(views::GridLayout::Alignment::LEADING,
141 views::GridLayout::Alignment::BASELINE, 0,
142 views::GridLayout::SizeType::FIXED, 32, 32);
143 cvc_field_columns->AddPaddingColumn(0, 16);
144 cvc_field_columns->AddColumn(views::GridLayout::Alignment::FILL,
145 views::GridLayout::Alignment::BASELINE, 0,
146 views::GridLayout::SizeType::FIXED, 80, 80);
147
148 layout->StartRow(0, 1);
149 std::unique_ptr<views::ImageView> cvc_image =
150 base::MakeUnique<views::ImageView>();
151 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
152 // TODO(anthonyvd): Consider using
153 // CardUnmaskPromptControllerImpl::GetCvcImageRid.
154 cvc_image->SetImage(
155 rb.GetImageSkiaNamed(credit_card_.type() == autofill::kAmericanExpressCard
156 ? IDR_CREDIT_CARD_CVC_HINT_AMEX
157 : IDR_CREDIT_CARD_CVC_HINT));
158 layout->AddView(cvc_image.release());
159
160 std::unique_ptr<views::Textfield> cvc_field =
161 base::MakeUnique<views::Textfield>();
162 cvc_field->set_id(static_cast<int>(DialogViewID::CVC_PROMPT_TEXT_FIELD));
163 cvc_field_ = cvc_field.get();
164 layout->AddView(cvc_field.release());
165
166 content_view->SetLayoutManager(layout.release());
167 }
168
169 std::unique_ptr<views::Button> CvcUnmaskViewController::CreatePrimaryButton() {
170 std::unique_ptr<views::Button> button(
171 views::MdTextButton::CreateSecondaryUiBlueButton(
172 this, l10n_util::GetStringUTF16(IDS_CONFIRM)));
173 button->set_id(static_cast<int>(DialogViewID::CVC_PROMPT_CONFIRM_BUTTON));
174 button->set_tag(static_cast<int>(Tags::CONFIRM_TAG));
175 return button;
176 }
177
178 void CvcUnmaskViewController::ButtonPressed(views::Button* sender,
179 const ui::Event& event) {
180 switch (sender->tag()) {
181 case static_cast<int>(Tags::CONFIRM_TAG):
182 CvcConfirmed();
183 break;
184 default:
185 PaymentRequestSheetController::ButtonPressed(sender, event);
186 }
187 }
188
189 void CvcUnmaskViewController::CvcConfirmed() {
190 const base::string16& cvc = cvc_field_->text();
191 if (unmask_delegate_) {
192 autofill::CardUnmaskDelegate::UnmaskResponse response;
193 response.cvc = cvc;
194 unmask_delegate_->OnUnmaskResponse(response);
195 }
196 }
197
198 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698