| Index: ios/chrome/browser/payments/payment_request_manager.mm
|
| diff --git a/ios/chrome/browser/payments/payment_request_manager.mm b/ios/chrome/browser/payments/payment_request_manager.mm
|
| index f4cbdc022fec5cc0d939a4ba67268069b53365c8..01f0a999b1c364551d611a18849799d3ab808ff0 100644
|
| --- a/ios/chrome/browser/payments/payment_request_manager.mm
|
| +++ b/ios/chrome/browser/payments/payment_request_manager.mm
|
| @@ -86,9 +86,13 @@ const NSTimeInterval kTimeoutInterval = 60.0;
|
| // Timer used to periodically unblock the webview's JS event queue.
|
| base::scoped_nsobject<NSTimer> _unblockEventQueueTimer;
|
|
|
| - // Timer used to close the UI if the page does not call
|
| - // PaymentResponse.complete() in a timely fashion.
|
| + // Timer used to complete the Payment Request flow and close the UI if the
|
| + // page does not call PaymentResponse.complete() in a timely fashion.
|
| base::scoped_nsobject<NSTimer> _paymentResponseTimeoutTimer;
|
| +
|
| + // Timer used to cancel the Payment Request flow and close the UI if the
|
| + // page does not call settle the pending update promise in a timely fashion.
|
| + base::scoped_nsobject<NSTimer> _updateEventTimeoutTimer;
|
| }
|
|
|
| // Synchronous method executed by -asynchronouslyEnablePaymentRequest:
|
| @@ -105,9 +109,14 @@ const NSTimeInterval kTimeoutInterval = 60.0;
|
| // invocation was successful.
|
| - (BOOL)handleRequestShow:(const base::DictionaryValue&)message;
|
|
|
| +// Called by |_paymentResponseTimeoutTimer|, invokes handleResponseComplete:
|
| +// as if PaymentResponse.complete() was invoked with the default "unknown"
|
| +// argument.
|
| +- (BOOL)handleResponseComplete;
|
| +
|
| // Handles invocations of PaymentResponse.complete(). Returns YES if the
|
| // invocation was successful.
|
| -- (BOOL)handleResponseComplete;
|
| +- (BOOL)handleResponseComplete:(const base::DictionaryValue&)message;
|
|
|
| // Handles invocations of PaymentRequestUpdateEvent.updateWith(). Returns YES if
|
| // the invocation was successful.
|
| @@ -124,6 +133,13 @@ const NSTimeInterval kTimeoutInterval = 60.0;
|
| // called with no arguments.
|
| - (void)setPaymentResponseTimeoutTimer;
|
|
|
| +// Establishes a timer that dismisses the Payment Request UI when it times out.
|
| +// Per the spec, implementations may choose to consider a timeout for the
|
| +// promise provided with the PaymentRequestUpdateEvent.updateWith() call. If the
|
| +// promise doesn't get settled in a reasonable amount of time, it is as if it
|
| +// was rejected.
|
| +- (void)setUpdateEventTimeoutTimer;
|
| +
|
| @end
|
|
|
| @implementation PaymentRequestManager
|
| @@ -275,7 +291,7 @@ const NSTimeInterval kTimeoutInterval = 60.0;
|
| return [self handleRequestCancel];
|
| }
|
| if (command == "paymentRequest.responseComplete") {
|
| - return [self handleResponseComplete];
|
| + return [self handleResponseComplete:JSONCommand];
|
| }
|
| if (command == "paymentRequest.updatePaymentDetails") {
|
| return [self handleUpdatePaymentDetails:JSONCommand];
|
| @@ -334,22 +350,53 @@ const NSTimeInterval kTimeoutInterval = 60.0;
|
|
|
| [_unblockEventQueueTimer invalidate];
|
| [_paymentResponseTimeoutTimer invalidate];
|
| + [_updateEventTimeoutTimer invalidate];
|
| +
|
| + base::WeakNSObject<PaymentRequestManager> weakSelf(self);
|
| + void (^callback)() = ^{
|
| + base::scoped_nsobject<PaymentRequestManager> strongSelf([weakSelf retain]);
|
| + [strongSelf cancelRequestWithErrorMessage:@"Request canceled."];
|
| + };
|
|
|
| - [self cancelRequestWithErrorMessage:@"Request canceled by the page."];
|
| + [_paymentRequestCoordinator displayErrorWithCallback:callback];
|
|
|
| return YES;
|
| }
|
|
|
| - (BOOL)handleResponseComplete {
|
| + base::DictionaryValue command;
|
| + command.SetString("result", "unknown");
|
| + return [self handleResponseComplete:command];
|
| +}
|
| +
|
| +- (BOOL)handleResponseComplete:(const base::DictionaryValue&)message {
|
| // TODO(crbug.com/602666): Check that there *is* a pending response here.
|
| - // TODO(crbug.com/602666): Indicate success or failure in the UI.
|
|
|
| [_unblockEventQueueTimer invalidate];
|
| [_paymentResponseTimeoutTimer invalidate];
|
| + [_updateEventTimeoutTimer invalidate];
|
|
|
| - [self dismissUI];
|
| + [_unblockEventQueueTimer invalidate];
|
| +
|
| + std::string result;
|
| + if (!message.GetString("result", &result)) {
|
| + DLOG(ERROR) << "JS message parameter 'result' is missing";
|
| + return NO;
|
| + }
|
|
|
| - [_paymentRequestJsManager resolveResponsePromiseWithCompletionHandler:nil];
|
| + base::WeakNSObject<PaymentRequestManager> weakSelf(self);
|
| + void (^callback)() = ^{
|
| + base::scoped_nsobject<PaymentRequestManager> strongSelf([weakSelf retain]);
|
| + [strongSelf dismissUI];
|
| + [_paymentRequestJsManager resolveResponsePromiseWithCompletionHandler:nil];
|
| + };
|
| +
|
| + // Display UI indicating failure if the value of |result| is "fail".
|
| + if (result == "fail") {
|
| + [_paymentRequestCoordinator displayErrorWithCallback:callback];
|
| + } else {
|
| + callback();
|
| + }
|
|
|
| return YES;
|
| }
|
| @@ -393,6 +440,15 @@ const NSTimeInterval kTimeoutInterval = 60.0;
|
| repeats:NO] retain]);
|
| }
|
|
|
| +- (void)setUpdateEventTimeoutTimer {
|
| + _updateEventTimeoutTimer.reset(
|
| + [[NSTimer scheduledTimerWithTimeInterval:kTimeoutInterval
|
| + target:self
|
| + selector:@selector(handleRequestCancel)
|
| + userInfo:nil
|
| + repeats:NO] retain]);
|
| +}
|
| +
|
| - (void)dismissUI {
|
| [_paymentRequestCoordinator stop];
|
| _paymentRequestCoordinator.reset();
|
| @@ -419,7 +475,7 @@ const NSTimeInterval kTimeoutInterval = 60.0;
|
|
|
| - (void)paymentRequestCoordinatorDidCancel:
|
| (PaymentRequestCoordinator*)coordinator {
|
| - [self cancelRequestWithErrorMessage:@"Request canceled by user."];
|
| + [self cancelRequestWithErrorMessage:@"Request canceled."];
|
| }
|
|
|
| - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator
|
| @@ -436,6 +492,7 @@ const NSTimeInterval kTimeoutInterval = 60.0;
|
| [_paymentRequestJsManager updateShippingAddress:shippingAddress
|
| completionHandler:nil];
|
| [self setUnblockEventQueueTimer];
|
| + [self setUpdateEventTimeoutTimer];
|
| }
|
|
|
| - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator
|
| @@ -443,6 +500,7 @@ const NSTimeInterval kTimeoutInterval = 60.0;
|
| [_paymentRequestJsManager updateShippingOption:shippingOption
|
| completionHandler:nil];
|
| [self setUnblockEventQueueTimer];
|
| + [self setUpdateEventTimeoutTimer];
|
| }
|
|
|
| #pragma mark - CRWWebStateObserver methods
|
|
|