| 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/payments/payment_request_coordinator.h" | 5 #import "ios/chrome/browser/payments/payment_request_coordinator.h" |
| 6 | 6 |
| 7 #include <unordered_set> | 7 #include <unordered_set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/autofill/core/browser/autofill_client.h" | 14 #include "components/autofill/core/browser/autofill_client.h" |
| 15 #include "components/autofill/core/browser/autofill_data_util.h" | 15 #include "components/autofill/core/browser/autofill_data_util.h" |
| 16 #include "components/autofill/core/browser/autofill_profile.h" | 16 #include "components/autofill/core/browser/autofill_profile.h" |
| 17 #include "components/autofill/core/browser/credit_card.h" | 17 #include "components/autofill/core/browser/credit_card.h" |
| 18 #include "components/autofill/core/browser/field_types.h" | 18 #include "components/autofill/core/browser/field_types.h" |
| 19 #include "components/autofill/core/browser/payments/full_card_request.h" | 19 #include "components/autofill/core/browser/payments/full_card_request.h" |
| 20 #include "components/autofill/core/browser/personal_data_manager.h" | 20 #include "components/autofill/core/browser/personal_data_manager.h" |
| 21 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl
.h" | 21 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl
.h" |
| 22 #include "components/strings/grit/components_strings.h" |
| 22 #include "ios/chrome/browser/application_context.h" | 23 #include "ios/chrome/browser/application_context.h" |
| 23 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 24 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 24 #include "ios/chrome/browser/payments/payment_request.h" | 25 #include "ios/chrome/browser/payments/payment_request.h" |
| 25 #include "ios/chrome/browser/payments/payment_request_util.h" | 26 #include "ios/chrome/browser/payments/payment_request_util.h" |
| 26 #include "ios/chrome/browser/ui/autofill/card_unmask_prompt_view_bridge.h" | 27 #include "ios/chrome/browser/ui/autofill/card_unmask_prompt_view_bridge.h" |
| 28 #include "ui/base/l10n/l10n_util.h" |
| 27 | 29 |
| 28 #if !defined(__has_feature) || !__has_feature(objc_arc) | 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 29 #error "This file requires ARC support." | 31 #error "This file requires ARC support." |
| 30 #endif | 32 #endif |
| 31 | 33 |
| 32 // The unmask prompt UI for Payment Request. | 34 // The unmask prompt UI for Payment Request. |
| 33 class PRCardUnmaskPromptViewBridge | 35 class PRCardUnmaskPromptViewBridge |
| 34 : public autofill::CardUnmaskPromptViewBridge { | 36 : public autofill::CardUnmaskPromptViewBridge { |
| 35 public: | 37 public: |
| 36 explicit PRCardUnmaskPromptViewBridge( | 38 explicit PRCardUnmaskPromptViewBridge( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 __weak PaymentRequestCoordinator* owner_; | 114 __weak PaymentRequestCoordinator* owner_; |
| 113 __weak UIViewController* base_view_controller_; | 115 __weak UIViewController* base_view_controller_; |
| 114 autofill::CardUnmaskPromptControllerImpl unmask_controller_; | 116 autofill::CardUnmaskPromptControllerImpl unmask_controller_; |
| 115 | 117 |
| 116 DISALLOW_COPY_AND_ASSIGN(FullCardRequester); | 118 DISALLOW_COPY_AND_ASSIGN(FullCardRequester); |
| 117 }; | 119 }; |
| 118 | 120 |
| 119 @implementation PaymentRequestCoordinator { | 121 @implementation PaymentRequestCoordinator { |
| 120 UINavigationController* _navigationController; | 122 UINavigationController* _navigationController; |
| 121 PaymentRequestViewController* _viewController; | 123 PaymentRequestViewController* _viewController; |
| 124 PaymentRequestErrorCoordinator* _errorCoordinator; |
| 122 PaymentItemsDisplayCoordinator* _itemsDisplayCoordinator; | 125 PaymentItemsDisplayCoordinator* _itemsDisplayCoordinator; |
| 123 ShippingAddressSelectionCoordinator* _shippingAddressSelectionCoordinator; | 126 ShippingAddressSelectionCoordinator* _shippingAddressSelectionCoordinator; |
| 124 ShippingOptionSelectionCoordinator* _shippingOptionSelectionCoordinator; | 127 ShippingOptionSelectionCoordinator* _shippingOptionSelectionCoordinator; |
| 125 PaymentMethodSelectionCoordinator* _methodSelectionCoordinator; | 128 PaymentMethodSelectionCoordinator* _methodSelectionCoordinator; |
| 126 | 129 |
| 127 // Receiver of the full credit card details. Also displays the unmask prompt | 130 // Receiver of the full credit card details. Also displays the unmask prompt |
| 128 // UI. | 131 // UI. |
| 129 std::unique_ptr<FullCardRequester> _fullCardRequester; | 132 std::unique_ptr<FullCardRequester> _fullCardRequester; |
| 130 | 133 |
| 131 // The selected shipping address, pending approval from the page. | 134 // The selected shipping address, pending approval from the page. |
| 132 autofill::AutofillProfile* _pendingShippingAddress; | 135 autofill::AutofillProfile* _pendingShippingAddress; |
| 133 } | 136 } |
| 134 | 137 |
| 135 @synthesize paymentRequest = _paymentRequest; | 138 @synthesize paymentRequest = _paymentRequest; |
| 136 @synthesize autofillManager = _autofillManager; | 139 @synthesize autofillManager = _autofillManager; |
| 137 @synthesize browserState = _browserState; | 140 @synthesize browserState = _browserState; |
| 138 @synthesize pageFavicon = _pageFavicon; | 141 @synthesize pageFavicon = _pageFavicon; |
| 139 @synthesize pageTitle = _pageTitle; | 142 @synthesize pageTitle = _pageTitle; |
| 140 @synthesize pageHost = _pageHost; | 143 @synthesize pageHost = _pageHost; |
| 141 @synthesize delegate = _delegate; | 144 @synthesize delegate = _delegate; |
| 142 | 145 |
| 143 - (instancetype)initWithBaseViewController:(UIViewController*)viewController { | |
| 144 return [super initWithBaseViewController:viewController]; | |
| 145 } | |
| 146 | |
| 147 - (void)start { | 146 - (void)start { |
| 148 _viewController = [[PaymentRequestViewController alloc] | 147 _viewController = [[PaymentRequestViewController alloc] |
| 149 initWithPaymentRequest:_paymentRequest]; | 148 initWithPaymentRequest:_paymentRequest]; |
| 150 [_viewController setPageFavicon:_pageFavicon]; | 149 [_viewController setPageFavicon:_pageFavicon]; |
| 151 [_viewController setPageTitle:_pageTitle]; | 150 [_viewController setPageTitle:_pageTitle]; |
| 152 [_viewController setPageHost:_pageHost]; | 151 [_viewController setPageHost:_pageHost]; |
| 153 [_viewController setDelegate:self]; | 152 [_viewController setDelegate:self]; |
| 154 [_viewController loadModel]; | 153 [_viewController loadModel]; |
| 155 | 154 |
| 156 _navigationController = [[UINavigationController alloc] | 155 _navigationController = [[UINavigationController alloc] |
| 157 initWithRootViewController:_viewController]; | 156 initWithRootViewController:_viewController]; |
| 158 [_navigationController setNavigationBarHidden:YES]; | 157 [_navigationController setNavigationBarHidden:YES]; |
| 159 | 158 |
| 160 [[self baseViewController] presentViewController:_navigationController | 159 [[self baseViewController] presentViewController:_navigationController |
| 161 animated:YES | 160 animated:YES |
| 162 completion:nil]; | 161 completion:nil]; |
| 163 } | 162 } |
| 164 | 163 |
| 165 - (void)stop { | 164 - (void)stop { |
| 166 [[_navigationController presentingViewController] | 165 [[_navigationController presentingViewController] |
| 167 dismissViewControllerAnimated:YES | 166 dismissViewControllerAnimated:YES |
| 168 completion:nil]; | 167 completion:nil]; |
| 169 _itemsDisplayCoordinator = nil; | 168 _itemsDisplayCoordinator = nil; |
| 170 _shippingAddressSelectionCoordinator = nil; | 169 _shippingAddressSelectionCoordinator = nil; |
| 171 _shippingOptionSelectionCoordinator = nil; | 170 _shippingOptionSelectionCoordinator = nil; |
| 172 _methodSelectionCoordinator = nil; | 171 _methodSelectionCoordinator = nil; |
| 172 _errorCoordinator = nil; |
| 173 _viewController = nil; |
| 173 _navigationController = nil; | 174 _navigationController = nil; |
| 174 _viewController = nil; | |
| 175 } | 175 } |
| 176 | 176 |
| 177 - (void)sendPaymentResponse { | 177 - (void)sendPaymentResponse { |
| 178 DCHECK(_paymentRequest->selected_credit_card()); | 178 DCHECK(_paymentRequest->selected_credit_card()); |
| 179 autofill::CreditCard* card = _paymentRequest->selected_credit_card(); | 179 autofill::CreditCard* card = _paymentRequest->selected_credit_card(); |
| 180 _fullCardRequester = base::MakeUnique<FullCardRequester>( | 180 _fullCardRequester = base::MakeUnique<FullCardRequester>( |
| 181 self, _navigationController, _browserState); | 181 self, _navigationController, _browserState); |
| 182 _fullCardRequester->GetFullCard(card, _autofillManager); | 182 _fullCardRequester->GetFullCard(card, _autofillManager); |
| 183 } | 183 } |
| 184 | 184 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // view. The updated selection is already reflected in |_paymentRequest|. | 249 // view. The updated selection is already reflected in |_paymentRequest|. |
| 250 [_viewController updateSelectedShippingOptionUI]; | 250 [_viewController updateSelectedShippingOptionUI]; |
| 251 | 251 |
| 252 // Dismiss the shipping option selection view. | 252 // Dismiss the shipping option selection view. |
| 253 [_shippingOptionSelectionCoordinator stop]; | 253 [_shippingOptionSelectionCoordinator stop]; |
| 254 _shippingOptionSelectionCoordinator = nil; | 254 _shippingOptionSelectionCoordinator = nil; |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 - (void)displayErrorWithCallback:(ProceduralBlock)callback { |
| 260 _errorCoordinator = [[PaymentRequestErrorCoordinator alloc] |
| 261 initWithBaseViewController:_navigationController]; |
| 262 [_errorCoordinator setCallback:callback]; |
| 263 [_errorCoordinator setDelegate:self]; |
| 264 |
| 265 [_errorCoordinator start]; |
| 266 } |
| 267 |
| 259 #pragma mark - PaymentRequestViewControllerDelegate | 268 #pragma mark - PaymentRequestViewControllerDelegate |
| 260 | 269 |
| 261 - (void)paymentRequestViewControllerDidCancel: | 270 - (void)paymentRequestViewControllerDidCancel: |
| 262 (PaymentRequestViewController*)controller { | 271 (PaymentRequestViewController*)controller { |
| 263 [_delegate paymentRequestCoordinatorDidCancel:self]; | 272 [_delegate paymentRequestCoordinatorDidCancel:self]; |
| 264 } | 273 } |
| 265 | 274 |
| 266 - (void)paymentRequestViewControllerDidConfirm: | 275 - (void)paymentRequestViewControllerDidConfirm: |
| 267 (PaymentRequestViewController*)controller { | 276 (PaymentRequestViewController*)controller { |
| 268 [self sendPaymentResponse]; | 277 [self sendPaymentResponse]; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 - (void)paymentRequestViewControllerDidSelectPaymentMethodItem: | 312 - (void)paymentRequestViewControllerDidSelectPaymentMethodItem: |
| 304 (PaymentRequestViewController*)controller { | 313 (PaymentRequestViewController*)controller { |
| 305 _methodSelectionCoordinator = [[PaymentMethodSelectionCoordinator alloc] | 314 _methodSelectionCoordinator = [[PaymentMethodSelectionCoordinator alloc] |
| 306 initWithBaseViewController:_viewController]; | 315 initWithBaseViewController:_viewController]; |
| 307 [_methodSelectionCoordinator setPaymentRequest:_paymentRequest]; | 316 [_methodSelectionCoordinator setPaymentRequest:_paymentRequest]; |
| 308 [_methodSelectionCoordinator setDelegate:self]; | 317 [_methodSelectionCoordinator setDelegate:self]; |
| 309 | 318 |
| 310 [_methodSelectionCoordinator start]; | 319 [_methodSelectionCoordinator start]; |
| 311 } | 320 } |
| 312 | 321 |
| 322 #pragma mark - PaymentRequestErrorCoordinatorDelegate |
| 323 |
| 324 - (void)paymentRequestErrorCoordinatorDidDismiss: |
| 325 (PaymentRequestErrorCoordinator*)coordinator { |
| 326 ProceduralBlock callback = coordinator.callback; |
| 327 |
| 328 [_errorCoordinator stop]; |
| 329 _errorCoordinator = nil; |
| 330 |
| 331 if (callback) |
| 332 callback(); |
| 333 } |
| 334 |
| 313 #pragma mark - PaymentItemsDisplayCoordinatorDelegate | 335 #pragma mark - PaymentItemsDisplayCoordinatorDelegate |
| 314 | 336 |
| 315 - (void)paymentItemsDisplayCoordinatorDidReturn: | 337 - (void)paymentItemsDisplayCoordinatorDidReturn: |
| 316 (PaymentItemsDisplayCoordinator*)coordinator { | 338 (PaymentItemsDisplayCoordinator*)coordinator { |
| 317 // Clear the 'Updated' label on the payment summary item, if there is one. | 339 // Clear the 'Updated' label on the payment summary item, if there is one. |
| 318 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; | 340 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; |
| 319 | 341 |
| 320 [_itemsDisplayCoordinator stop]; | 342 [_itemsDisplayCoordinator stop]; |
| 321 _itemsDisplayCoordinator = nil; | 343 _itemsDisplayCoordinator = nil; |
| 322 } | 344 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 - (void)paymentMethodSelectionCoordinatorDidReturn: | 408 - (void)paymentMethodSelectionCoordinatorDidReturn: |
| 387 (PaymentMethodSelectionCoordinator*)coordinator { | 409 (PaymentMethodSelectionCoordinator*)coordinator { |
| 388 // Clear the 'Updated' label on the payment summary item, if there is one. | 410 // Clear the 'Updated' label on the payment summary item, if there is one. |
| 389 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; | 411 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; |
| 390 | 412 |
| 391 [_methodSelectionCoordinator stop]; | 413 [_methodSelectionCoordinator stop]; |
| 392 _methodSelectionCoordinator = nil; | 414 _methodSelectionCoordinator = nil; |
| 393 } | 415 } |
| 394 | 416 |
| 395 @end | 417 @end |
| OLD | NEW |