Commit 27309f38 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Payment Request][Android] Block payment UI from background tab

Before this patch, a background tab could show the payment sheet.

This patch aborts payment if the web contents of the currently active
tab are not the same as the web contents that invoked the PaymentRequest
API.

After this patch, Chrome rejects the PaymentRequest.show() with
"AbortError: Request cancelled" if it was called from a tab that is not
currently shown to the user.

Bug: 939162
Change-Id: Ia4e3eba7b882b5361185536e5b2b96edc80f5a11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1507125Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638409}
parent 5c8bd34b
......@@ -48,6 +48,7 @@ import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import org.chromium.chrome.browser.tabmodel.TabSelectionType;
import org.chromium.chrome.browser.widget.prefeditor.Completable;
import org.chromium.chrome.browser.widget.prefeditor.EditableOption;
......@@ -628,6 +629,15 @@ public class PaymentRequestImpl
mObservedTabModelSelector.addObserver(mSelectorObserver);
mObservedTabModel.addObserver(mTabModelObserver);
// Only the currently selected tab is allowed to show the payment UI.
if (TabModelUtils.getCurrentWebContents(mObservedTabModel) != mWebContents) {
mJourneyLogger.setNotShown(NotShownReason.OTHER);
disconnectFromClientWithDebugMessage(
"Background tab is not allowed to show PaymentRequest UI");
if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
return;
}
// Catch any time the user enters the overview mode and dismiss the payment UI.
if (chromeActivity instanceof ChromeTabbedActivity) {
mOverviewModeBehavior =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment