Commit bf25f3be authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PaymentHandler] Delay hider to avoid destroying WebContents in itself

Context: the Bottom-sheet Payment Handler UI observes the load finish
of the WebContents. Upon observing that, the UI check the validity of
the page of the payment handler app, and if invalid, close the page.

Old behavior: closing the invalid payment handler crashes.

Cause: because the load finish hook is called within WebContents, when
the hook tries to destroy WebContents itself, it causes a crash.

Change: defer destroying WebContents until WebContents is not being
used.

New behavior: Payment Handler UI destroys WebContents outside of the
observer hook. So the crash is fixed.

Bug: 1029995
Change-Id: I7968daaad793a949808fc30e6f08b03bb19c330f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1949057Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721542}
parent af32755a
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.payments.handler;
import android.os.Handler;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChangeReason;
import org.chromium.chrome.browser.payments.ServiceWorkerPaymentAppBridge;
import org.chromium.chrome.browser.payments.SslValidityChecker;
......@@ -31,6 +33,7 @@ import org.chromium.ui.modelutil.PropertyModel;
// null.
private final WebContents mWebContentsRef;
private final PaymentHandlerUiObserver mPaymentHandlerUiObserver;
private final Handler mHandler = new Handler();
/**
* Build a new mediator that handle events from outside the payment handler component.
......@@ -57,7 +60,7 @@ import org.chromium.ui.modelutil.PropertyModel;
switch (newState) {
case BottomSheetController.SheetState.HIDDEN:
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef);
mHider.run();
mHandler.post(mHider);
break;
}
}
......@@ -90,7 +93,7 @@ import org.chromium.ui.modelutil.PropertyModel;
if (!SslValidityChecker.isValidPageInPaymentHandlerWindow(mWebContentsRef)) {
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindowForInsecureNavigation(
mWebContentsRef);
mHider.run();
mHandler.post(mHider);
}
}
......@@ -98,7 +101,7 @@ import org.chromium.ui.modelutil.PropertyModel;
public void didAttachInterstitialPage() {
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindowForInsecureNavigation(
mWebContentsRef);
mHider.run();
mHandler.post(mHider);
}
@Override
......@@ -106,20 +109,20 @@ import org.chromium.ui.modelutil.PropertyModel;
boolean isMainFrame, int errorCode, String description, String failingUrl) {
// TODO(crbug.com/1017926): Respond to service worker with the net error.
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef);
mHider.run();
mHandler.post(mHider);
}
// PaymentHandlerToolbarObserver:
@Override
public void onToolbarCloseButtonClicked() {
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef);
mHider.run();
mHandler.post(mHider);
}
@Override
public void onToolbarError() {
// TODO(maxlg): send an error message to users.
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef);
mHider.run();
mHandler.post(mHider);
}
}
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