| OLD | NEW |
| 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 #import "ios/chrome/browser/ui/payments/payment_request_manager.h" | 5 #import "ios/chrome/browser/ui/payments/payment_request_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/ios/block_types.h" | 9 #include "base/ios/block_types.h" |
| 10 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "components/autofill/core/browser/credit_card.h" | 22 #include "components/autofill/core/browser/credit_card.h" |
| 23 #include "components/autofill/core/browser/personal_data_manager.h" | 23 #include "components/autofill/core/browser/personal_data_manager.h" |
| 24 #include "components/autofill/ios/browser/autofill_driver_ios.h" | 24 #include "components/autofill/ios/browser/autofill_driver_ios.h" |
| 25 #include "components/payments/core/address_normalization_manager.h" | 25 #include "components/payments/core/address_normalization_manager.h" |
| 26 #include "components/payments/core/can_make_payment_query.h" | 26 #include "components/payments/core/can_make_payment_query.h" |
| 27 #include "components/payments/core/payment_address.h" | 27 #include "components/payments/core/payment_address.h" |
| 28 #include "components/payments/core/payment_prefs.h" | 28 #include "components/payments/core/payment_prefs.h" |
| 29 #include "components/payments/core/payment_request_base_delegate.h" | 29 #include "components/payments/core/payment_request_base_delegate.h" |
| 30 #include "components/payments/core/payment_request_data_util.h" | 30 #include "components/payments/core/payment_request_data_util.h" |
| 31 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
| 32 #include "ios/chrome/browser/application_context.h" | |
| 33 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" | 32 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" |
| 34 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" | 33 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" |
| 35 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 34 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 36 #include "ios/chrome/browser/payments/ios_can_make_payment_query_factory.h" | 35 #include "ios/chrome/browser/payments/ios_can_make_payment_query_factory.h" |
| 37 #include "ios/chrome/browser/payments/payment_request.h" | 36 #include "ios/chrome/browser/payments/payment_request.h" |
| 38 #include "ios/chrome/browser/procedural_block_types.h" | 37 #include "ios/chrome/browser/procedural_block_types.h" |
| 39 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 38 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 40 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 39 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 41 #import "ios/chrome/browser/ui/commands/ios_command_ids.h" | 40 #import "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 42 #import "ios/chrome/browser/ui/payments/js_payment_request_manager.h" | 41 #import "ios/chrome/browser/ui/payments/js_payment_request_manager.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 personalDataManager->GetProfilesToSuggest()) { | 372 personalDataManager->GetProfilesToSuggest()) { |
| 374 std::string countryCode = | 373 std::string countryCode = |
| 375 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | 374 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |
| 376 if (autofill::data_util::IsValidCountryCode(countryCode)) { | 375 if (autofill::data_util::IsValidCountryCode(countryCode)) { |
| 377 addressNormalizer->LoadRulesForRegion(countryCode); | 376 addressNormalizer->LoadRulesForRegion(countryCode); |
| 378 } | 377 } |
| 379 } | 378 } |
| 380 | 379 |
| 381 const std::string default_country_code = | 380 const std::string default_country_code = |
| 382 autofill::AutofillCountry::CountryCodeForLocale( | 381 autofill::AutofillCountry::CountryCodeForLocale( |
| 383 GetApplicationContext()->GetApplicationLocale()); | 382 _paymentRequest->GetApplicationLocale()); |
| 384 | 383 |
| 385 _addressNormalizationManager = | 384 _addressNormalizationManager = |
| 386 base::MakeUnique<payments::AddressNormalizationManager>( | 385 base::MakeUnique<payments::AddressNormalizationManager>( |
| 387 addressNormalizer, default_country_code); | 386 addressNormalizer, default_country_code); |
| 388 } | 387 } |
| 389 | 388 |
| 390 // Ensures that |_paymentRequest| is set to the correct value for |message|. | 389 // Ensures that |_paymentRequest| is set to the correct value for |message|. |
| 391 // Returns YES if |_paymentRequest| was already set to the right value, or if it | 390 // Returns YES if |_paymentRequest| was already set to the right value, or if it |
| 392 // was updated to match |message|. | 391 // was updated to match |message|. |
| 393 - (BOOL)createPaymentRequestFromMessage:(const base::DictionaryValue&)message { | 392 - (BOOL)createPaymentRequestFromMessage:(const base::DictionaryValue&)message { |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 726 |
| 728 paymentResponse.method_name = | 727 paymentResponse.method_name = |
| 729 base::ASCIIToUTF16(_pendingPaymentResponse.methodName); | 728 base::ASCIIToUTF16(_pendingPaymentResponse.methodName); |
| 730 | 729 |
| 731 paymentResponse.details = _pendingPaymentResponse.stringifiedDetails; | 730 paymentResponse.details = _pendingPaymentResponse.stringifiedDetails; |
| 732 | 731 |
| 733 if (_paymentRequest->request_shipping()) { | 732 if (_paymentRequest->request_shipping()) { |
| 734 paymentResponse.shipping_address = | 733 paymentResponse.shipping_address = |
| 735 payments::data_util::GetPaymentAddressFromAutofillProfile( | 734 payments::data_util::GetPaymentAddressFromAutofillProfile( |
| 736 _pendingPaymentResponse.shippingAddress, | 735 _pendingPaymentResponse.shippingAddress, |
| 737 GetApplicationContext()->GetApplicationLocale()); | 736 _paymentRequest->GetApplicationLocale()); |
| 738 | 737 |
| 739 web::PaymentShippingOption* shippingOption = | 738 web::PaymentShippingOption* shippingOption = |
| 740 _paymentRequest->selected_shipping_option(); | 739 _paymentRequest->selected_shipping_option(); |
| 741 DCHECK(shippingOption); | 740 DCHECK(shippingOption); |
| 742 paymentResponse.shipping_option = shippingOption->id; | 741 paymentResponse.shipping_option = shippingOption->id; |
| 743 } | 742 } |
| 744 | 743 |
| 745 if (_paymentRequest->request_payer_name()) { | 744 if (_paymentRequest->request_payer_name()) { |
| 746 paymentResponse.payer_name = _pendingPaymentResponse.contactAddress.GetInfo( | 745 paymentResponse.payer_name = _pendingPaymentResponse.contactAddress.GetInfo( |
| 747 autofill::AutofillType(autofill::NAME_FULL), | 746 autofill::AutofillType(autofill::NAME_FULL), |
| 748 GetApplicationContext()->GetApplicationLocale()); | 747 _paymentRequest->GetApplicationLocale()); |
| 749 } | 748 } |
| 750 | 749 |
| 751 if (_paymentRequest->request_payer_email()) { | 750 if (_paymentRequest->request_payer_email()) { |
| 752 paymentResponse.payer_email = | 751 paymentResponse.payer_email = |
| 753 _pendingPaymentResponse.contactAddress.GetRawInfo( | 752 _pendingPaymentResponse.contactAddress.GetRawInfo( |
| 754 autofill::EMAIL_ADDRESS); | 753 autofill::EMAIL_ADDRESS); |
| 755 } | 754 } |
| 756 | 755 |
| 757 if (_paymentRequest->request_payer_phone()) { | 756 if (_paymentRequest->request_payer_phone()) { |
| 758 paymentResponse.payer_phone = | 757 paymentResponse.payer_phone = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 770 completionHandler:nil]; | 769 completionHandler:nil]; |
| 771 [self setUnblockEventQueueTimer]; | 770 [self setUnblockEventQueueTimer]; |
| 772 [self setPaymentResponseTimeoutTimer]; | 771 [self setPaymentResponseTimeoutTimer]; |
| 773 } | 772 } |
| 774 | 773 |
| 775 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator | 774 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator |
| 776 didSelectShippingAddress: | 775 didSelectShippingAddress: |
| 777 (const autofill::AutofillProfile&)shippingAddress { | 776 (const autofill::AutofillProfile&)shippingAddress { |
| 778 payments::PaymentAddress address = | 777 payments::PaymentAddress address = |
| 779 payments::data_util::GetPaymentAddressFromAutofillProfile( | 778 payments::data_util::GetPaymentAddressFromAutofillProfile( |
| 780 shippingAddress, GetApplicationContext()->GetApplicationLocale()); | 779 shippingAddress, _paymentRequest->GetApplicationLocale()); |
| 781 [_paymentRequestJsManager updateShippingAddress:address | 780 [_paymentRequestJsManager updateShippingAddress:address |
| 782 completionHandler:nil]; | 781 completionHandler:nil]; |
| 783 [self setUnblockEventQueueTimer]; | 782 [self setUnblockEventQueueTimer]; |
| 784 [self setUpdateEventTimeoutTimer]; | 783 [self setUpdateEventTimeoutTimer]; |
| 785 } | 784 } |
| 786 | 785 |
| 787 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator | 786 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator |
| 788 didSelectShippingOption: | 787 didSelectShippingOption: |
| 789 (const web::PaymentShippingOption&)shippingOption { | 788 (const web::PaymentShippingOption&)shippingOption { |
| 790 [_paymentRequestJsManager updateShippingOption:shippingOption | 789 [_paymentRequestJsManager updateShippingOption:shippingOption |
| 791 completionHandler:nil]; | 790 completionHandler:nil]; |
| 792 [self setUnblockEventQueueTimer]; | 791 [self setUnblockEventQueueTimer]; |
| 793 [self setUpdateEventTimeoutTimer]; | 792 [self setUpdateEventTimeoutTimer]; |
| 794 } | 793 } |
| 795 | 794 |
| 796 #pragma mark - CRWWebStateObserver methods | 795 #pragma mark - CRWWebStateObserver methods |
| 797 | 796 |
| 798 - (void)webState:(web::WebState*)webState | 797 - (void)webState:(web::WebState*)webState |
| 799 didCommitNavigationWithDetails: | 798 didCommitNavigationWithDetails: |
| 800 (const web::LoadCommittedDetails&)load_details { | 799 (const web::LoadCommittedDetails&)load_details { |
| 801 [self dismissUI]; | 800 [self dismissUI]; |
| 802 [self enableCurrentWebState]; | 801 [self enableCurrentWebState]; |
| 803 } | 802 } |
| 804 | 803 |
| 805 @end | 804 @end |
| OLD | NEW |