OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "ios/chrome/browser/payments/payment_request.h" | 5 #include "ios/chrome/browser/payments/payment_request.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/containers/adapters.h" | 9 #include "base/containers/adapters.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "components/autofill/core/browser/autofill_data_util.h" | 12 #include "components/autofill/core/browser/autofill_data_util.h" |
13 #include "components/autofill/core/browser/autofill_profile.h" | 13 #include "components/autofill/core/browser/autofill_profile.h" |
14 #include "components/autofill/core/browser/credit_card.h" | 14 #include "components/autofill/core/browser/credit_card.h" |
15 #include "components/autofill/core/browser/personal_data_manager.h" | 15 #include "components/autofill/core/browser/personal_data_manager.h" |
16 #include "components/autofill/core/browser/region_data_loader_impl.h" | 16 #include "components/autofill/core/browser/region_data_loader_impl.h" |
17 #include "components/autofill/core/browser/validation.h" | 17 #include "components/autofill/core/browser/validation.h" |
18 #include "components/payments/core/address_normalizer_impl.h" | 18 #include "components/payments/core/address_normalizer_impl.h" |
19 #include "components/payments/core/currency_formatter.h" | 19 #include "components/payments/core/currency_formatter.h" |
20 #include "components/payments/core/payment_request_data_util.h" | 20 #include "components/payments/core/payment_request_data_util.h" |
21 #include "ios/chrome/browser/application_context.h" | 21 #include "ios/chrome/browser/application_context.h" |
22 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" | 22 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" |
| 23 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
23 #import "ios/chrome/browser/payments/payment_request_util.h" | 24 #import "ios/chrome/browser/payments/payment_request_util.h" |
24 #include "ios/web/public/payments/payment_request.h" | 25 #include "ios/web/public/payments/payment_request.h" |
25 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" | 26 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" |
26 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h" | 27 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h" |
27 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" | 28 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" |
28 | 29 |
29 #if !defined(__has_feature) || !__has_feature(objc_arc) | 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
30 #error "This file requires ARC support." | 31 #error "This file requires ARC support." |
31 #endif | 32 #endif |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 std::unique_ptr<::i18n::addressinput::Source> GetAddressInputSource( | 36 std::unique_ptr<::i18n::addressinput::Source> GetAddressInputSource( |
36 net::URLRequestContextGetter* url_context_getter) { | 37 net::URLRequestContextGetter* url_context_getter) { |
37 return std::unique_ptr<::i18n::addressinput::Source>( | 38 return std::unique_ptr<::i18n::addressinput::Source>( |
38 new autofill::ChromeMetadataSource(I18N_ADDRESS_VALIDATION_DATA_URL, | 39 new autofill::ChromeMetadataSource(I18N_ADDRESS_VALIDATION_DATA_URL, |
39 url_context_getter)); | 40 url_context_getter)); |
40 } | 41 } |
41 | 42 |
42 std::unique_ptr<::i18n::addressinput::Storage> GetAddressInputStorage() { | 43 std::unique_ptr<::i18n::addressinput::Storage> GetAddressInputStorage() { |
43 return autofill::ValidationRulesStorageFactory::CreateStorage(); | 44 return autofill::ValidationRulesStorageFactory::CreateStorage(); |
44 } | 45 } |
45 | 46 |
46 } // namespace | 47 } // namespace |
47 | 48 |
48 PaymentRequest::PaymentRequest( | 49 PaymentRequest::PaymentRequest( |
49 const web::PaymentRequest& web_payment_request, | 50 const web::PaymentRequest& web_payment_request, |
| 51 ios::ChromeBrowserState* browser_state, |
50 autofill::PersonalDataManager* personal_data_manager, | 52 autofill::PersonalDataManager* personal_data_manager, |
51 id<PaymentRequestUIDelegate> payment_request_ui_delegate) | 53 id<PaymentRequestUIDelegate> payment_request_ui_delegate) |
52 : web_payment_request_(web_payment_request), | 54 : web_payment_request_(web_payment_request), |
| 55 browser_state_(browser_state), |
53 personal_data_manager_(personal_data_manager), | 56 personal_data_manager_(personal_data_manager), |
54 payment_request_ui_delegate_(payment_request_ui_delegate), | 57 payment_request_ui_delegate_(payment_request_ui_delegate), |
55 address_normalizer_(new payments::AddressNormalizerImpl( | 58 address_normalizer_(new payments::AddressNormalizerImpl( |
56 GetAddressInputSource( | 59 GetAddressInputSource( |
57 personal_data_manager_->GetURLRequestContextGetter()), | 60 personal_data_manager_->GetURLRequestContextGetter()), |
58 GetAddressInputStorage())), | 61 GetAddressInputStorage())), |
59 selected_shipping_profile_(nullptr), | 62 selected_shipping_profile_(nullptr), |
60 selected_contact_profile_(nullptr), | 63 selected_contact_profile_(nullptr), |
61 selected_credit_card_(nullptr), | 64 selected_credit_card_(nullptr), |
62 selected_shipping_option_(nullptr), | 65 selected_shipping_option_(nullptr), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 104 |
102 autofill::PersonalDataManager* PaymentRequest::GetPersonalDataManager() { | 105 autofill::PersonalDataManager* PaymentRequest::GetPersonalDataManager() { |
103 return personal_data_manager_; | 106 return personal_data_manager_; |
104 } | 107 } |
105 | 108 |
106 const std::string& PaymentRequest::GetApplicationLocale() const { | 109 const std::string& PaymentRequest::GetApplicationLocale() const { |
107 return GetApplicationContext()->GetApplicationLocale(); | 110 return GetApplicationContext()->GetApplicationLocale(); |
108 } | 111 } |
109 | 112 |
110 bool PaymentRequest::IsIncognito() const { | 113 bool PaymentRequest::IsIncognito() const { |
111 NOTREACHED() << "Implementation is never used"; | 114 return browser_state_->IsOffTheRecord(); |
112 return false; | |
113 } | 115 } |
114 | 116 |
115 bool PaymentRequest::IsSslCertificateValid() { | 117 bool PaymentRequest::IsSslCertificateValid() { |
116 NOTREACHED() << "Implementation is never used"; | 118 NOTREACHED() << "Implementation is never used"; |
117 return false; | 119 return false; |
118 } | 120 } |
119 | 121 |
120 const GURL& PaymentRequest::GetLastCommittedURL() const { | 122 const GURL& PaymentRequest::GetLastCommittedURL() const { |
121 NOTREACHED() << "Implementation is never used"; | 123 NOTREACHED() << "Implementation is never used"; |
122 return GURL::EmptyGURL(); | 124 return GURL::EmptyGURL(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 // A card only has to have a cardholder name and a number for the purposes | 267 // A card only has to have a cardholder name and a number for the purposes |
266 // of CanMakePayment. An expired card or one without a billing address is | 268 // of CanMakePayment. An expired card or one without a billing address is |
267 // valid for this purpose. | 269 // valid for this purpose. |
268 return !(status & autofill::CREDIT_CARD_NO_CARDHOLDER || | 270 return !(status & autofill::CREDIT_CARD_NO_CARDHOLDER || |
269 status & autofill::CREDIT_CARD_NO_NUMBER); | 271 status & autofill::CREDIT_CARD_NO_NUMBER); |
270 } | 272 } |
271 return false; | 273 return false; |
272 } | 274 } |
273 | 275 |
274 void PaymentRequest::PopulateCreditCardCache() { | 276 void PaymentRequest::PopulateCreditCardCache() { |
| 277 for (const payments::PaymentMethodData& method_data_entry : |
| 278 web_payment_request_.method_data) { |
| 279 for (const std::string& method : method_data_entry.supported_methods) { |
| 280 stringified_method_data_[method].insert(method_data_entry.data); |
| 281 } |
| 282 } |
| 283 |
275 // TODO(crbug.com/709036): Validate method data. | 284 // TODO(crbug.com/709036): Validate method data. |
276 payments::data_util::ParseBasicCardSupportedNetworks( | 285 payments::data_util::ParseBasicCardSupportedNetworks( |
277 web_payment_request_.method_data, &supported_card_networks_, | 286 web_payment_request_.method_data, &supported_card_networks_, |
278 &basic_card_specified_networks_); | 287 &basic_card_specified_networks_); |
279 | 288 |
280 const std::vector<autofill::CreditCard*>& credit_cards_to_suggest = | 289 const std::vector<autofill::CreditCard*>& credit_cards_to_suggest = |
281 personal_data_manager_->GetCreditCardsToSuggest(); | 290 personal_data_manager_->GetCreditCardsToSuggest(); |
282 // Return early if the user has no stored credit cards. | 291 // Return early if the user has no stored credit cards. |
283 if (credit_cards_to_suggest.empty()) | 292 if (credit_cards_to_suggest.empty()) |
284 return; | 293 return; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 void PaymentRequest::SetSelectedShippingOption() { | 337 void PaymentRequest::SetSelectedShippingOption() { |
329 // If more than one option has |selected| set, the last one in the sequence | 338 // If more than one option has |selected| set, the last one in the sequence |
330 // should be treated as the selected item. | 339 // should be treated as the selected item. |
331 for (auto* shipping_option : base::Reversed(shipping_options_)) { | 340 for (auto* shipping_option : base::Reversed(shipping_options_)) { |
332 if (shipping_option->selected) { | 341 if (shipping_option->selected) { |
333 selected_shipping_option_ = shipping_option; | 342 selected_shipping_option_ = shipping_option; |
334 break; | 343 break; |
335 } | 344 } |
336 } | 345 } |
337 } | 346 } |
OLD | NEW |