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

Unified Diff: ios/chrome/browser/payments/payment_request_manager.mm

Issue 2701923003: [Payment Request] Error message screen (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
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..03c20991660ec017d8db8aadfee7a1758f73f084 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 "unkown"
lpromero 2017/02/20 17:14:07 *unknown
Moe 2017/02/21 05:07:06 Done.
+// 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,49 @@ const NSTimeInterval kTimeoutInterval = 60.0;
[_unblockEventQueueTimer invalidate];
[_paymentResponseTimeoutTimer invalidate];
+ [_updateEventTimeoutTimer invalidate];
+
+ void (^callback)() = ^{
+ [self 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];
- [_paymentRequestJsManager resolveResponsePromiseWithCompletionHandler:nil];
+ std::string result;
+ if (!message.GetString("result", &result)) {
+ DLOG(ERROR) << "JS message parameter 'result' is missing";
+ return NO;
+ }
+
+ void (^callback)() = ^{
+ [self dismissUI];
lpromero 2017/02/20 17:14:07 There seems to be a retain cycle. self retains _pa
Moe 2017/02/21 05:07:06 Done.
+ [_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 +436,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 +471,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 +488,7 @@ const NSTimeInterval kTimeoutInterval = 60.0;
[_paymentRequestJsManager updateShippingAddress:shippingAddress
completionHandler:nil];
[self setUnblockEventQueueTimer];
+ [self setUpdateEventTimeoutTimer];
}
- (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator
@@ -443,6 +496,7 @@ const NSTimeInterval kTimeoutInterval = 60.0;
[_paymentRequestJsManager updateShippingOption:shippingOption
completionHandler:nil];
[self setUnblockEventQueueTimer];
+ [self setUpdateEventTimeoutTimer];
}
#pragma mark - CRWWebStateObserver methods

Powered by Google App Engine
This is Rietveld 408576698