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

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

Powered by Google App Engine
This is Rietveld 408576698