| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "components/payments/core/payment_instrument.h" | 21 #include "components/payments/core/payment_instrument.h" |
| 22 #include "components/payments/core/payment_request_data_util.h" | 22 #include "components/payments/core/payment_request_data_util.h" |
| 23 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 24 #include "components/signin/core/browser/signin_manager.h" | 24 #include "components/signin/core/browser/signin_manager.h" |
| 25 #include "ios/chrome/browser/application_context.h" | 25 #include "ios/chrome/browser/application_context.h" |
| 26 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" | 26 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" |
| 27 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 27 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 28 #import "ios/chrome/browser/payments/payment_request_util.h" | 28 #import "ios/chrome/browser/payments/payment_request_util.h" |
| 29 #include "ios/chrome/browser/signin/signin_manager_factory.h" | 29 #include "ios/chrome/browser/signin/signin_manager_factory.h" |
| 30 #include "ios/web/public/payments/payment_request.h" | 30 #include "ios/web/public/payments/payment_request.h" |
| 31 #include "ios/web/public/web_state/web_state.h" |
| 31 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" | 32 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" |
| 32 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h" | 33 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h" |
| 33 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" | 34 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" |
| 34 | 35 |
| 35 #if !defined(__has_feature) || !__has_feature(objc_arc) | 36 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 36 #error "This file requires ARC support." | 37 #error "This file requires ARC support." |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 std::unique_ptr<::i18n::addressinput::Source> GetAddressInputSource( | 42 std::unique_ptr<::i18n::addressinput::Source> GetAddressInputSource( |
| 42 net::URLRequestContextGetter* url_context_getter) { | 43 net::URLRequestContextGetter* url_context_getter) { |
| 43 return std::unique_ptr<::i18n::addressinput::Source>( | 44 return std::unique_ptr<::i18n::addressinput::Source>( |
| 44 new autofill::ChromeMetadataSource(I18N_ADDRESS_VALIDATION_DATA_URL, | 45 new autofill::ChromeMetadataSource(I18N_ADDRESS_VALIDATION_DATA_URL, |
| 45 url_context_getter)); | 46 url_context_getter)); |
| 46 } | 47 } |
| 47 | 48 |
| 48 std::unique_ptr<::i18n::addressinput::Storage> GetAddressInputStorage() { | 49 std::unique_ptr<::i18n::addressinput::Storage> GetAddressInputStorage() { |
| 49 return autofill::ValidationRulesStorageFactory::CreateStorage(); | 50 return autofill::ValidationRulesStorageFactory::CreateStorage(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 } // namespace | 53 } // namespace |
| 53 | 54 |
| 54 namespace payments { | 55 namespace payments { |
| 55 | 56 |
| 56 PaymentRequest::PaymentRequest( | 57 PaymentRequest::PaymentRequest( |
| 57 const web::PaymentRequest& web_payment_request, | 58 const web::PaymentRequest& web_payment_request, |
| 58 ios::ChromeBrowserState* browser_state, | 59 ios::ChromeBrowserState* browser_state, |
| 60 web::WebState* web_state, |
| 59 autofill::PersonalDataManager* personal_data_manager, | 61 autofill::PersonalDataManager* personal_data_manager, |
| 60 id<PaymentRequestUIDelegate> payment_request_ui_delegate) | 62 id<PaymentRequestUIDelegate> payment_request_ui_delegate) |
| 61 : web_payment_request_(web_payment_request), | 63 : web_payment_request_(web_payment_request), |
| 62 browser_state_(browser_state), | 64 browser_state_(browser_state), |
| 65 web_state_(web_state), |
| 63 personal_data_manager_(personal_data_manager), | 66 personal_data_manager_(personal_data_manager), |
| 64 payment_request_ui_delegate_(payment_request_ui_delegate), | 67 payment_request_ui_delegate_(payment_request_ui_delegate), |
| 65 address_normalizer_(new AddressNormalizerImpl( | 68 address_normalizer_(new AddressNormalizerImpl( |
| 66 GetAddressInputSource( | 69 GetAddressInputSource( |
| 67 personal_data_manager_->GetURLRequestContextGetter()), | 70 personal_data_manager_->GetURLRequestContextGetter()), |
| 68 GetAddressInputStorage())), | 71 GetAddressInputStorage())), |
| 69 selected_shipping_profile_(nullptr), | 72 selected_shipping_profile_(nullptr), |
| 70 selected_contact_profile_(nullptr), | 73 selected_contact_profile_(nullptr), |
| 71 selected_payment_method_(nullptr), | 74 selected_payment_method_(nullptr), |
| 72 selected_shipping_option_(nullptr), | 75 selected_shipping_option_(nullptr), |
| 73 profile_comparator_(GetApplicationContext()->GetApplicationLocale(), | 76 profile_comparator_(GetApplicationContext()->GetApplicationLocale(), |
| 74 *this) { | 77 *this), |
| 78 journey_logger_(IsIncognito(), |
| 79 web_state->GetLastCommittedURL(), |
| 80 GetUkmRecorder()) { |
| 75 PopulateAvailableShippingOptions(); | 81 PopulateAvailableShippingOptions(); |
| 76 PopulateProfileCache(); | 82 PopulateProfileCache(); |
| 77 PopulateAvailableProfiles(); | 83 PopulateAvailableProfiles(); |
| 78 PopulatePaymentMethodCache(); | 84 PopulatePaymentMethodCache(); |
| 79 PopulateAvailablePaymentMethods(); | 85 PopulateAvailablePaymentMethods(); |
| 80 | 86 |
| 81 SetSelectedShippingOption(); | 87 SetSelectedShippingOption(); |
| 82 | 88 |
| 83 if (request_shipping()) { | 89 if (request_shipping()) { |
| 84 // If the merchant provided a default shipping option, and the | 90 // If the merchant provided a default shipping option, and the |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 // should be treated as the selected item. | 396 // should be treated as the selected item. |
| 391 for (auto* shipping_option : base::Reversed(shipping_options_)) { | 397 for (auto* shipping_option : base::Reversed(shipping_options_)) { |
| 392 if (shipping_option->selected) { | 398 if (shipping_option->selected) { |
| 393 selected_shipping_option_ = shipping_option; | 399 selected_shipping_option_ = shipping_option; |
| 394 break; | 400 break; |
| 395 } | 401 } |
| 396 } | 402 } |
| 397 } | 403 } |
| 398 | 404 |
| 399 } // namespace payments | 405 } // namespace payments |
| OLD | NEW |