diff --git a/components/subresource_filter/android/java/src/org/chromium/components/subresource_filter/AdsBlockedDialog.java b/components/subresource_filter/android/java/src/org/chromium/components/subresource_filter/AdsBlockedDialog.java --- a/components/subresource_filter/android/java/src/org/chromium/components/subresource_filter/AdsBlockedDialog.java +++ b/components/subresource_filter/android/java/src/org/chromium/components/subresource_filter/AdsBlockedDialog.java @@ -135,6 +135,12 @@ public class AdsBlockedDialog implements ModalDialogProperties.Controller { @CalledByNative void dismiss() { + // The native AdsBlockedDialog is being destroyed. Proactively cancel any + // pending show task and clear the native pointer here, because + // ModalDialogManager.dismissDialog() will early-return without invoking + // onDismiss() if the dialog has not yet been shown or queued. + mDialogHandler.removeCallbacksAndMessages(null); + mNativeDialog = 0; mModalDialogManager.dismissDialog(mDialogModel, DialogDismissalCause.DISMISSED_BY_NATIVE); } @@ -153,7 +159,7 @@ public class AdsBlockedDialog implements ModalDialogProperties.Controller { // ModalDialogProperties.Controller implementation. @Override public void onClick(PropertyModel model, @ButtonType int buttonType) { - assert mNativeDialog != 0; + if (mNativeDialog == 0) return; if (buttonType == ButtonType.POSITIVE) { AdsBlockedDialogJni.get().onAllowAdsClicked(mNativeDialog); } @@ -167,6 +173,7 @@ public class AdsBlockedDialog implements ModalDialogProperties.Controller { @Override public void onDismiss(PropertyModel model, @DialogDismissalCause int dismissalCause) { mDialogHandler.removeCallbacksAndMessages(null); + if (mNativeDialog == 0) return; AdsBlockedDialogJni.get().onDismissed(mNativeDialog); mNativeDialog = 0; }