Verify behavior of PaymentRequest.show() method, part 1.
Before this patch, Chrome on Android would allow only one instance of
PaymentRequest per browser process to be displayed, but desktop had no
such restriction.
This patch adds a check for currently displaying PaymentRequest UI on
desktop. The currently displayed instance of PaymentRequest is kept
track of in PaymentRequestWebContentsManager.
After this patch, Chrome on desktop allows only one instance of
PaymentRequest per tab to be displayed.
From https://w3c.github.io/browser-payment-api/#show-method
"If the user agent's "payment request is showing" boolean is true, then
return a promise rejected with an "AbortError" DOMException."
From https://w3c.github.io/browser-payment-api/#dfn-payment-request-is-showing
"The user agent as a whole has a single "payment request is showing"
boolean, initially false. This is used to prevent multiple
PaymentRequests from being shown, via their show() method, at the same
time."
BUG=705252
Review-Url: https://codereview.chromium.org/2864013002
Cr-Commit-Position: refs/heads/master@{#469988}
diff --git a/components/payments/content/payment_request.cc b/components/payments/content/payment_request.cc
index 68da7ff..9dbe1c5 100644
--- a/components/payments/content/payment_request.cc
+++ b/components/payments/content/payment_request.cc
@@ -99,6 +99,14 @@
return;
}
+ // A tab can display only one PaymentRequest UI at a time.
+ if (!manager_->CanShow(this)) {
+ LOG(ERROR) << "A PaymentRequest UI is already showing";
+ client_->OnError(mojom::PaymentErrorReason::USER_CANCEL);
+ OnConnectionTerminated();
+ return;
+ }
+
if (!state_->AreRequestedMethodsSupported()) {
client_->OnError(mojom::PaymentErrorReason::NOT_SUPPORTED);
if (observer_for_testing_)