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

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

Powered by Google App Engine
This is Rietveld 408576698