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

Side by Side Diff: components/payments/content/payment_request_state.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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/payments/content/payment_request_state.h" 5 #include "components/payments/content/payment_request_state.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_data_util.h" 10 #include "components/autofill/core/browser/autofill_data_util.h"
11 #include "components/autofill/core/browser/autofill_profile.h" 11 #include "components/autofill/core/browser/autofill_profile.h"
12 #include "components/autofill/core/browser/credit_card.h" 12 #include "components/autofill/core/browser/credit_card.h"
13 #include "components/autofill/core/browser/personal_data_manager.h" 13 #include "components/autofill/core/browser/personal_data_manager.h"
14 #include "components/payments/content/payment_request_spec.h" 14 #include "components/payments/content/payment_request_spec.h"
15 #include "components/payments/content/payment_response_helper.h" 15 #include "components/payments/content/payment_response_helper.h"
16 #include "components/payments/core/autofill_payment_instrument.h" 16 #include "components/payments/core/autofill_payment_instrument.h"
17 #include "components/payments/core/payment_request_delegate.h"
17 18
18 namespace payments { 19 namespace payments {
19 20
20 PaymentRequestState::PaymentRequestState( 21 PaymentRequestState::PaymentRequestState(
21 PaymentRequestSpec* spec, 22 PaymentRequestSpec* spec,
22 Delegate* delegate, 23 Delegate* delegate,
23 const std::string& app_locale, 24 const std::string& app_locale,
24 autofill::PersonalDataManager* personal_data_manager) 25 autofill::PersonalDataManager* personal_data_manager,
26 PaymentRequestDelegate* payment_request_delegate)
25 : is_ready_to_pay_(false), 27 : is_ready_to_pay_(false),
26 app_locale_(app_locale), 28 app_locale_(app_locale),
27 spec_(spec), 29 spec_(spec),
28 delegate_(delegate), 30 delegate_(delegate),
29 personal_data_manager_(personal_data_manager), 31 personal_data_manager_(personal_data_manager),
30 selected_shipping_profile_(nullptr), 32 selected_shipping_profile_(nullptr),
31 selected_contact_profile_(nullptr), 33 selected_contact_profile_(nullptr),
32 selected_instrument_(nullptr) { 34 selected_instrument_(nullptr),
35 payment_request_delegate_(payment_request_delegate) {
33 PopulateProfileCache(); 36 PopulateProfileCache();
34 SetDefaultProfileSelections(); 37 SetDefaultProfileSelections();
35 } 38 }
36 PaymentRequestState::~PaymentRequestState() {} 39 PaymentRequestState::~PaymentRequestState() {}
37 40
38 bool PaymentRequestState::CanMakePayment() const { 41 bool PaymentRequestState::CanMakePayment() const {
39 for (const std::unique_ptr<PaymentInstrument>& instrument : 42 for (const std::unique_ptr<PaymentInstrument>& instrument :
40 available_instruments_) { 43 available_instruments_) {
41 if (instrument.get()->IsValid() && 44 if (instrument.get()->IsValid() &&
42 spec_->supported_card_networks_set().count( 45 spec_->supported_card_networks_set().count(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 if (!supported_card_networks.count(basic_card_network)) 179 if (!supported_card_networks.count(basic_card_network))
177 continue; 180 continue;
178 181
179 // TODO(crbug.com/701952): Should use the method name preferred by the 182 // TODO(crbug.com/701952): Should use the method name preferred by the
180 // merchant (either "basic-card" or the basic card network e.g. "visa"). 183 // merchant (either "basic-card" or the basic card network e.g. "visa").
181 184
182 // Copy the credit cards as part of AutofillPaymentInstrument so they are 185 // Copy the credit cards as part of AutofillPaymentInstrument so they are
183 // indirectly owned by this object. 186 // indirectly owned by this object.
184 std::unique_ptr<PaymentInstrument> instrument = 187 std::unique_ptr<PaymentInstrument> instrument =
185 base::MakeUnique<AutofillPaymentInstrument>( 188 base::MakeUnique<AutofillPaymentInstrument>(
186 basic_card_network, *card, shipping_profiles_, app_locale_); 189 basic_card_network, *card, shipping_profiles_, app_locale_,
190 payment_request_delegate_);
187 available_instruments_.push_back(std::move(instrument)); 191 available_instruments_.push_back(std::move(instrument));
188 } 192 }
189 } 193 }
190 194
191 void PaymentRequestState::SetDefaultProfileSelections() { 195 void PaymentRequestState::SetDefaultProfileSelections() {
192 // Only pre-select an address if the merchant provided at least one selected 196 // Only pre-select an address if the merchant provided at least one selected
193 // shipping option. 197 // shipping option.
194 if (!shipping_profiles().empty() && spec_->selected_shipping_option()) 198 if (!shipping_profiles().empty() && spec_->selected_shipping_option())
195 selected_shipping_profile_ = shipping_profiles()[0]; 199 selected_shipping_profile_ = shipping_profiles()[0];
196 200
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 ->GetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), 264 ->GetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
261 app_locale_) 265 app_locale_)
262 .empty())) { 266 .empty())) {
263 return false; 267 return false;
264 } 268 }
265 269
266 return true; 270 return true;
267 } 271 }
268 272
269 } // namespace payments 273 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request_state.h ('k') | components/payments/content/payment_request_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698