Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1129)

Side by Side Diff: ios/chrome/browser/payments/payment_request_manager.mm

Issue 2804853002: Cancels payment request when Settings is tapped, and opens the Autofill settings page. (Closed)
Patch Set: Rebase and Addresses comments from mahmadi@. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_manager.h" 5 #import "ios/chrome/browser/payments/payment_request_manager.h"
6 6
7 #include "base/ios/block_types.h" 7 #include "base/ios/block_types.h"
8 #include "base/ios/ios_util.h" 8 #include "base/ios/ios_util.h"
9 #import "base/mac/bind_objc_block.h" 9 #import "base/mac/bind_objc_block.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #import "base/values.h" 13 #import "base/values.h"
14 #include "components/autofill/core/browser/autofill_manager.h" 14 #include "components/autofill/core/browser/autofill_manager.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/ios/browser/autofill_driver_ios.h" 16 #include "components/autofill/ios/browser/autofill_driver_ios.h"
17 #include "components/payments/core/payment_address.h" 17 #include "components/payments/core/payment_address.h"
18 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" 18 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
20 #import "ios/chrome/browser/payments/js_payment_request_manager.h" 20 #import "ios/chrome/browser/payments/js_payment_request_manager.h"
21 #include "ios/chrome/browser/payments/payment_request.h" 21 #include "ios/chrome/browser/payments/payment_request.h"
22 #import "ios/chrome/browser/payments/payment_request_coordinator.h" 22 #import "ios/chrome/browser/payments/payment_request_coordinator.h"
23 #include "ios/chrome/browser/procedural_block_types.h" 23 #include "ios/chrome/browser/procedural_block_types.h"
24 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
25 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
26 #import "ios/chrome/browser/ui/commands/ios_command_ids.h"
24 #include "ios/web/public/favicon_status.h" 27 #include "ios/web/public/favicon_status.h"
25 #include "ios/web/public/navigation_item.h" 28 #include "ios/web/public/navigation_item.h"
26 #include "ios/web/public/navigation_manager.h" 29 #include "ios/web/public/navigation_manager.h"
27 #include "ios/web/public/payments/payment_request.h" 30 #include "ios/web/public/payments/payment_request.h"
28 #include "ios/web/public/ssl_status.h" 31 #include "ios/web/public/ssl_status.h"
29 #import "ios/web/public/url_scheme_util.h" 32 #import "ios/web/public/url_scheme_util.h"
30 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" 33 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
31 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" 34 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h"
32 #include "ios/web/public/web_state/url_verification_constants.h" 35 #include "ios/web/public/web_state/url_verification_constants.h"
33 #include "ios/web/public/web_state/web_state.h" 36 #include "ios/web/public/web_state/web_state.h"
34 #import "ios/web/public/web_state/web_state_observer_bridge.h" 37 #import "ios/web/public/web_state/web_state_observer_bridge.h"
35 38
36 #if !defined(__has_feature) || !__has_feature(objc_arc) 39 #if !defined(__has_feature) || !__has_feature(objc_arc)
37 #error "This file requires ARC support." 40 #error "This file requires ARC support."
38 #endif 41 #endif
39 42
40 namespace { 43 namespace {
41 // Command prefix for injected JavaScript. 44 // Command prefix for injected JavaScript.
42 const std::string kCommandPrefix = "paymentRequest"; 45 const std::string kCommandPrefix = "paymentRequest";
43 46
44 // Time interval between attempts to unblock the webview's JS event queue. 47 // Time interval between attempts to unblock the webview's JS event queue.
45 const NSTimeInterval kNoopInterval = 0.1; 48 const NSTimeInterval kNoopInterval = 0.1;
46 49
47 // Time interval before closing the UI if the page has not yet called 50 // Time interval before closing the UI if the page has not yet called
48 // PaymentResponse.complete(). 51 // PaymentResponse.complete().
49 const NSTimeInterval kTimeoutInterval = 60.0; 52 const NSTimeInterval kTimeoutInterval = 60.0;
50 53
54 NSString* kAbortMessage = @"The payment request was aborted.";
55 NSString* kCancelMessage = @"The payment request was canceled.";
56
51 } // namespace 57 } // namespace
52 58
53 @interface PaymentRequestManager ()<CRWWebStateObserver, 59 @interface PaymentRequestManager ()<CRWWebStateObserver,
54 PaymentRequestCoordinatorDelegate> { 60 PaymentRequestCoordinatorDelegate> {
55 // View controller used to present the PaymentRequest view controller. 61 // View controller used to present the PaymentRequest view controller.
56 __weak UIViewController* _baseViewController; 62 __weak UIViewController* _baseViewController;
57 63
58 // PersonalDataManager used to manage user credit cards and addresses. 64 // PersonalDataManager used to manage user credit cards and addresses.
59 autofill::PersonalDataManager* _personalDataManager; 65 autofill::PersonalDataManager* _personalDataManager;
60 66
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 if (changing) { 224 if (changing) {
219 if (!enabled) { 225 if (!enabled) {
220 [self dismissUI]; 226 [self dismissUI];
221 } 227 }
222 _enabled = enabled; 228 _enabled = enabled;
223 [self enableCurrentWebState]; 229 [self enableCurrentWebState];
224 } 230 }
225 } 231 }
226 232
227 - (void)cancelRequest { 233 - (void)cancelRequest {
228 [self terminateRequestWithErrorMessage:@"The payment request was canceled." 234 [self terminateRequestWithErrorMessage:kCancelMessage callback:nil];
229 callback:nil];
230 } 235 }
231 236
232 - (void)terminateRequestWithErrorMessage:(NSString*)errorMessage 237 - (void)terminateRequestWithErrorMessage:(NSString*)errorMessage
233 callback:(ProceduralBlockWithBool)callback { 238 callback:(ProceduralBlockWithBool)callback {
234 [self dismissUI]; 239 [self dismissUI];
235 [_paymentRequestJsManager rejectRequestPromiseWithErrorMessage:errorMessage 240 [_paymentRequestJsManager rejectRequestPromiseWithErrorMessage:errorMessage
236 completionHandler:callback]; 241 completionHandler:callback];
237 } 242 }
238 243
239 - (void)close { 244 - (void)close {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 return; 385 return;
381 [[strongSelf paymentRequestJsManager] 386 [[strongSelf paymentRequestJsManager]
382 resolveAbortPromiseWithCompletionHandler:nil]; 387 resolveAbortPromiseWithCompletionHandler:nil];
383 }; 388 };
384 389
385 ProceduralBlock callback = ^{ 390 ProceduralBlock callback = ^{
386 PaymentRequestManager* strongSelf = weakSelf; 391 PaymentRequestManager* strongSelf = weakSelf;
387 // Early return if the manager has been deallocated. 392 // Early return if the manager has been deallocated.
388 if (!strongSelf) 393 if (!strongSelf)
389 return; 394 return;
390 [strongSelf 395 [strongSelf terminateRequestWithErrorMessage:kAbortMessage
marq (ping after 24h) 2017/04/06 15:16:45 Delete lines 391-394 and just call the method on w
macourteau 2017/04/06 15:24:00 Done.
391 terminateRequestWithErrorMessage:@"The payment request was aborted." 396 callback:cancellationCallback];
392 callback:cancellationCallback];
393 }; 397 };
394 398
395 [_paymentRequestCoordinator displayErrorWithCallback:callback]; 399 [_paymentRequestCoordinator displayErrorWithCallback:callback];
396 400
397 return YES; 401 return YES;
398 } 402 }
399 403
400 - (BOOL)displayErrorThenCancelRequest { 404 - (BOOL)displayErrorThenCancelRequest {
401 // TODO(crbug.com/602666): Check that there is already a pending request. 405 // TODO(crbug.com/602666): Check that there is already a pending request.
402 406
403 [_unblockEventQueueTimer invalidate]; 407 [_unblockEventQueueTimer invalidate];
404 [_paymentResponseTimeoutTimer invalidate]; 408 [_paymentResponseTimeoutTimer invalidate];
405 [_updateEventTimeoutTimer invalidate]; 409 [_updateEventTimeoutTimer invalidate];
406 410
407 __weak PaymentRequestManager* weakSelf = self; 411 __weak PaymentRequestManager* weakSelf = self;
408 ProceduralBlock callback = ^{ 412 ProceduralBlock callback = ^{
409 PaymentRequestManager* strongSelf = weakSelf; 413 PaymentRequestManager* strongSelf = weakSelf;
410 // Early return if the manager has been deallocated. 414 // Early return if the manager has been deallocated.
411 if (!strongSelf) 415 if (!strongSelf)
412 return; 416 return;
413 [strongSelf 417 [strongSelf terminateRequestWithErrorMessage:kCancelMessage callback:nil];
marq (ping after 24h) 2017/04/06 15:16:45 Delete lines 413-416 and just call the method on w
macourteau 2017/04/06 15:23:59 Done.
414 terminateRequestWithErrorMessage:@"The payment request was canceled."
415 callback:nil];
416 }; 418 };
417 419
418 [_paymentRequestCoordinator displayErrorWithCallback:callback]; 420 [_paymentRequestCoordinator displayErrorWithCallback:callback];
419 421
420 return YES; 422 return YES;
421 } 423 }
422 424
423 - (BOOL)doResponseComplete { 425 - (BOOL)doResponseComplete {
424 base::DictionaryValue command; 426 base::DictionaryValue command;
425 command.SetString("result", "unknown"); 427 command.SetString("result", "unknown");
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 [self webState]->GetNavigationManager()->GetLastCommittedItem(); 530 [self webState]->GetNavigationManager()->GetLastCommittedItem();
529 return navigationItem && 531 return navigationItem &&
530 navigationItem->GetSSL().security_style == 532 navigationItem->GetSSL().security_style ==
531 web::SECURITY_STYLE_AUTHENTICATED; 533 web::SECURITY_STYLE_AUTHENTICATED;
532 } 534 }
533 535
534 #pragma mark - PaymentRequestCoordinatorDelegate methods 536 #pragma mark - PaymentRequestCoordinatorDelegate methods
535 537
536 - (void)paymentRequestCoordinatorDidCancel: 538 - (void)paymentRequestCoordinatorDidCancel:
537 (PaymentRequestCoordinator*)coordinator { 539 (PaymentRequestCoordinator*)coordinator {
538 [self terminateRequestWithErrorMessage:@"The payment request was canceled." 540 [self terminateRequestWithErrorMessage:kCancelMessage callback:nil];
539 callback:nil]; 541 }
542
543 - (void)paymentRequestCoordinatorDidSelectSettings:
544 (PaymentRequestCoordinator*)coordinator {
545 ProceduralBlockWithBool callback = ^(BOOL) {
546 UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
547 DCHECK(mainWindow);
548 GenericChromeCommand* command =
549 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_AUTOFILL_SETTINGS];
550 [mainWindow chromeExecuteCommand:command];
551 };
552
553 [self terminateRequestWithErrorMessage:kCancelMessage callback:callback];
540 } 554 }
541 555
542 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator 556 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator
543 didConfirmWithPaymentResponse:(web::PaymentResponse)paymentResponse { 557 didConfirmWithPaymentResponse:(web::PaymentResponse)paymentResponse {
544 [_paymentRequestJsManager 558 [_paymentRequestJsManager
545 resolveRequestPromiseWithPaymentResponse:paymentResponse 559 resolveRequestPromiseWithPaymentResponse:paymentResponse
546 completionHandler:nil]; 560 completionHandler:nil];
547 [self setUnblockEventQueueTimer]; 561 [self setUnblockEventQueueTimer];
548 [self setPaymentResponseTimeoutTimer]; 562 [self setPaymentResponseTimeoutTimer];
549 } 563 }
(...skipping 19 matching lines...) Expand all
569 - (void)webState:(web::WebState*)webState 583 - (void)webState:(web::WebState*)webState
570 didCommitNavigationWithDetails: 584 didCommitNavigationWithDetails:
571 (const web::LoadCommittedDetails&)load_details { 585 (const web::LoadCommittedDetails&)load_details {
572 [self dismissUI]; 586 [self dismissUI];
573 _isScriptInjected = NO; 587 _isScriptInjected = NO;
574 [self enableCurrentWebState]; 588 [self enableCurrentWebState];
575 [self initializeWebViewForPaymentRequest]; 589 [self initializeWebViewForPaymentRequest];
576 } 590 }
577 591
578 @end 592 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698