diff --git a/chrome/browser/ui/views/digital_credentials/digital_identity_multi_step_dialog.cc b/chrome/browser/ui/views/digital_credentials/digital_identity_multi_step_dialog.cc index 97b80bbc39f42..e30bebda1c836 100644 --- a/chrome/browser/ui/views/digital_credentials/digital_identity_multi_step_dialog.cc +++ b/chrome/browser/ui/views/digital_credentials/digital_identity_multi_step_dialog.cc @@ -346,10 +346,22 @@ void DigitalIdentityMultiStepDialog::TryShow( std::move(custom_body_field)); if (new_dialog_delegate) { + // ShowWebModalDialogViews → BlockWebContentsInteraction(true) → + // ExitFullscreen / widget activation can re-enter and synchronously destroy + // the hosting WebContents / RenderFrameHost, which tears down the owning + // DigitalIdentityProviderDesktop and therefore `this`. Guard with a + // WeakPtr. + base::WeakPtr weak_this = + weak_ptr_factory_.GetWeakPtr(); // views::Widget takes ownership of `new_dialog_delegate`. - dialog_ = constrained_window::ShowWebModalDialogViews( - new_dialog_delegate.release(), web_contents_.get()) - ->GetWeakPtr(); + base::WeakPtr widget = + constrained_window::ShowWebModalDialogViews( + new_dialog_delegate.release(), web_contents_.get()) + ->GetWeakPtr(); + if (!weak_this) { + return; + } + dialog_ = std::move(widget); extensions::SecurityDialogTracker::GetInstance()->AddSecurityDialog( dialog_.get()); } diff --git a/chrome/browser/ui/views/digital_credentials/digital_identity_multi_step_dialog.h b/chrome/browser/ui/views/digital_credentials/digital_identity_multi_step_dialog.h index 2b355e6a3e8ae..d94980bcff1eb 100644 --- a/chrome/browser/ui/views/digital_credentials/digital_identity_multi_step_dialog.h +++ b/chrome/browser/ui/views/digital_credentials/digital_identity_multi_step_dialog.h @@ -85,6 +85,8 @@ class DigitalIdentityMultiStepDialog { base::WeakPtr web_contents_; base::WeakPtr dialog_; + + base::WeakPtrFactory weak_ptr_factory_{this}; }; #endif // CHROME_BROWSER_UI_VIEWS_DIGITAL_CREDENTIALS_DIGITAL_IDENTITY_MULTI_STEP_DIALOG_H_