diff --git a/components/autofill/core/browser/ui/payments/autofill_progress_dialog_controller_impl.cc b/components/autofill/core/browser/ui/payments/autofill_progress_dialog_controller_impl.cc index 5f1aed3b9fa56..942867aca0212 100644 --- a/components/autofill/core/browser/ui/payments/autofill_progress_dialog_controller_impl.cc +++ b/components/autofill/core/browser/ui/payments/autofill_progress_dialog_controller_impl.cc @@ -69,6 +69,12 @@ void AutofillProgressDialogControllerImpl::OnDismissed( bool is_canceled_by_user) { // Dialog is being dismissed so set the pointer to nullptr. autofill_progress_dialog_view_.reset(); + // The callbacks below can synchronously enter a nested run loop on some + // platforms (e.g. macOS AuthorizationCopyRights() via mandatory-reauth, see + // device_authenticator_mac.mm and crbug.com/508289938). The owning + // WebContents — and therefore `this` — may be destroyed inside that nested + // run loop, so guard all subsequent member access with a WeakPtr. + auto weak_this = weak_ptr_factory_.GetWeakPtr(); if (is_canceled_by_user) { std::move(cancel_callback_).Run(); } else { @@ -76,6 +82,9 @@ void AutofillProgressDialogControllerImpl::OnDismissed( std::move(no_interactive_authentication_callback_).Run(); } } + if (!weak_this) { + return; + } AutofillMetrics::LogProgressDialogResultMetric( is_canceled_by_user, autofill_progress_dialog_type_);