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> |
| 8 |
7 #include "base/ios/block_types.h" | 9 #include "base/ios/block_types.h" |
8 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
9 #import "base/mac/bind_objc_block.h" | 11 #import "base/mac/bind_objc_block.h" |
10 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
11 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
12 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
13 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
15 #import "base/values.h" | 17 #import "base/values.h" |
16 #include "components/autofill/core/browser/autofill_country.h" | 18 #include "components/autofill/core/browser/autofill_country.h" |
17 #include "components/autofill/core/browser/autofill_data_util.h" | 19 #include "components/autofill/core/browser/autofill_data_util.h" |
18 #include "components/autofill/core/browser/autofill_manager.h" | 20 #include "components/autofill/core/browser/autofill_manager.h" |
19 #include "components/autofill/core/browser/credit_card.h" | 21 #include "components/autofill/core/browser/credit_card.h" |
20 #include "components/autofill/core/browser/personal_data_manager.h" | 22 #include "components/autofill/core/browser/personal_data_manager.h" |
21 #include "components/autofill/ios/browser/autofill_driver_ios.h" | 23 #include "components/autofill/ios/browser/autofill_driver_ios.h" |
22 #include "components/payments/core/address_normalization_manager.h" | 24 #include "components/payments/core/address_normalization_manager.h" |
| 25 #include "components/payments/core/can_make_payment_query.h" |
23 #include "components/payments/core/payment_address.h" | 26 #include "components/payments/core/payment_address.h" |
24 #include "components/payments/core/payment_request_base_delegate.h" | 27 #include "components/payments/core/payment_request_base_delegate.h" |
25 #include "components/payments/core/payment_request_data_util.h" | 28 #include "components/payments/core/payment_request_data_util.h" |
26 #include "ios/chrome/browser/application_context.h" | 29 #include "ios/chrome/browser/application_context.h" |
27 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" | 30 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" |
28 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" | 31 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" |
29 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 32 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 33 #include "ios/chrome/browser/payments/ios_can_make_payment_query_factory.h" |
30 #include "ios/chrome/browser/payments/payment_request.h" | 34 #include "ios/chrome/browser/payments/payment_request.h" |
31 #include "ios/chrome/browser/procedural_block_types.h" | 35 #include "ios/chrome/browser/procedural_block_types.h" |
32 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 36 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
33 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 37 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
34 #import "ios/chrome/browser/ui/commands/ios_command_ids.h" | 38 #import "ios/chrome/browser/ui/commands/ios_command_ids.h" |
35 #import "ios/chrome/browser/ui/payments/js_payment_request_manager.h" | 39 #import "ios/chrome/browser/ui/payments/js_payment_request_manager.h" |
36 #import "ios/chrome/browser/ui/payments/payment_request_coordinator.h" | 40 #import "ios/chrome/browser/ui/payments/payment_request_coordinator.h" |
37 #include "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" | 41 #include "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" |
38 #include "ios/web/public/favicon_status.h" | 42 #include "ios/web/public/favicon_status.h" |
39 #include "ios/web/public/navigation_item.h" | 43 #include "ios/web/public/navigation_item.h" |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 } | 401 } |
398 | 402 |
399 // TODO(crbug.com/711419): make sure multiple PaymentRequests can be active | 403 // TODO(crbug.com/711419): make sure multiple PaymentRequests can be active |
400 // simultaneously. | 404 // simultaneously. |
401 if (_paymentRequest && | 405 if (_paymentRequest && |
402 (_paymentRequest->web_payment_request() == webPaymentRequest)) { | 406 (_paymentRequest->web_payment_request() == webPaymentRequest)) { |
403 return YES; | 407 return YES; |
404 } | 408 } |
405 | 409 |
406 _paymentRequest = base::MakeUnique<PaymentRequest>( | 410 _paymentRequest = base::MakeUnique<PaymentRequest>( |
407 webPaymentRequest, _personalDataManager, self); | 411 webPaymentRequest, _browserState, _personalDataManager, self); |
408 | 412 |
409 return YES; | 413 return YES; |
410 } | 414 } |
411 | 415 |
412 - (BOOL)handleRequestShow:(const base::DictionaryValue&)message { | 416 - (BOOL)handleRequestShow:(const base::DictionaryValue&)message { |
413 // TODO(crbug.com/602666): check that there's not already a pending request. | 417 // TODO(crbug.com/602666): check that there's not already a pending request. |
414 // TODO(crbug.com/602666): compare our supported payment types (i.e. autofill | 418 // TODO(crbug.com/602666): compare our supported payment types (i.e. autofill |
415 // credit card types) against the merchant supported types and return NO | 419 // credit card types) against the merchant supported types and return NO |
416 // if the intersection is empty. | 420 // if the intersection is empty. |
417 | 421 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 callback:cancellationCallback]; | 472 callback:cancellationCallback]; |
469 }; | 473 }; |
470 | 474 |
471 [_paymentRequestCoordinator displayErrorWithCallback:callback]; | 475 [_paymentRequestCoordinator displayErrorWithCallback:callback]; |
472 | 476 |
473 return YES; | 477 return YES; |
474 } | 478 } |
475 | 479 |
476 - (BOOL)handleCanMakePayment:(const base::DictionaryValue&)message { | 480 - (BOOL)handleCanMakePayment:(const base::DictionaryValue&)message { |
477 if (![self createPaymentRequestFromMessage:message]) { | 481 if (![self createPaymentRequestFromMessage:message]) { |
478 return NO; | 482 // TODO(crbug.com/602666): Reject the promise with an error of |
| 483 // "InvalidStateError" type. |
| 484 [_paymentRequestJsManager |
| 485 rejectCanMakePaymentPromiseWithErrorMessage:@"Invalid state error" |
| 486 completionHandler:nil]; |
| 487 return YES; |
479 } | 488 } |
480 | 489 |
481 // TODO(crbug.com/602666): reject the promise if quota (TBD) was exceeded. | 490 if (_paymentRequest->IsIncognito()) { |
| 491 [_paymentRequestJsManager resolveCanMakePaymentPromiseWithValue:YES |
| 492 completionHandler:nil]; |
| 493 return YES; |
| 494 } |
482 | 495 |
483 [_paymentRequestJsManager | 496 BOOL canMakePayment = _paymentRequest->CanMakePayment(); |
484 resolveCanMakePaymentPromiseWithValue:_paymentRequest->CanMakePayment() | |
485 completionHandler:nil]; | |
486 | 497 |
| 498 payments::CanMakePaymentQuery* canMakePaymentQuery = |
| 499 IOSCanMakePaymentQueryFactory::GetInstance()->GetForBrowserState( |
| 500 _browserState); |
| 501 DCHECK(canMakePaymentQuery); |
| 502 if (canMakePaymentQuery->CanQuery( |
| 503 [self webState]->GetLastCommittedURL().GetOrigin(), |
| 504 _paymentRequest->stringified_method_data())) { |
| 505 [_paymentRequestJsManager |
| 506 resolveCanMakePaymentPromiseWithValue:canMakePayment |
| 507 completionHandler:nil]; |
| 508 // TODO(crbug.com/602666): Warn on console if origin is localhost or file. |
| 509 } else { |
| 510 [_paymentRequestJsManager |
| 511 rejectCanMakePaymentPromiseWithErrorMessage: |
| 512 @"Not allowed to check whether can make payment" |
| 513 completionHandler:nil]; |
| 514 } |
487 return YES; | 515 return YES; |
488 } | 516 } |
489 | 517 |
490 - (BOOL)displayErrorThenCancelRequest { | 518 - (BOOL)displayErrorThenCancelRequest { |
491 // TODO(crbug.com/602666): Check that there is already a pending request. | 519 // TODO(crbug.com/602666): Check that there is already a pending request. |
492 | 520 |
493 [_unblockEventQueueTimer invalidate]; | 521 [_unblockEventQueueTimer invalidate]; |
494 [_paymentResponseTimeoutTimer invalidate]; | 522 [_paymentResponseTimeoutTimer invalidate]; |
495 [_updateEventTimeoutTimer invalidate]; | 523 [_updateEventTimeoutTimer invalidate]; |
496 | 524 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 #pragma mark - CRWWebStateObserver methods | 807 #pragma mark - CRWWebStateObserver methods |
780 | 808 |
781 - (void)webState:(web::WebState*)webState | 809 - (void)webState:(web::WebState*)webState |
782 didCommitNavigationWithDetails: | 810 didCommitNavigationWithDetails: |
783 (const web::LoadCommittedDetails&)load_details { | 811 (const web::LoadCommittedDetails&)load_details { |
784 [self dismissUI]; | 812 [self dismissUI]; |
785 [self enableCurrentWebState]; | 813 [self enableCurrentWebState]; |
786 } | 814 } |
787 | 815 |
788 @end | 816 @end |
OLD | NEW |