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

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

Powered by Google App Engine
This is Rietveld 408576698