diff --git a/content/browser/digital_credentials/digital_identity_request_impl.cc b/content/browser/digital_credentials/digital_identity_request_impl.cc index f10b4304c79cf..66f6230fe2a9c 100644 --- a/content/browser/digital_credentials/digital_identity_request_impl.cc +++ b/content/browser/digital_credentials/digital_identity_request_impl.cc @@ -648,13 +648,23 @@ void DigitalIdentityRequestImpl::Get( return; } - update_interstitial_on_abort_callback_ = - provider_->ShowDigitalIdentityInterstitial( - *WebContents::FromRenderFrameHost(&render_frame_host()), origin(), - *interstitial_type, - base::BindOnce(&DigitalIdentityRequestImpl::OnInterstitialDone, - weak_ptr_factory_.GetWeakPtr(), - std::move(request_to_send))); + // ShowDigitalIdentityInterstitial() synchronously shows a tab-modal dialog + // (ShowWebModal -> BlockWebContentsInteraction -> ExitFullscreen). On some + // platforms ExitFullscreenModeForTab() can spin the message loop and destroy + // the hosting WebContents (and therefore `this`, a DocumentService). Guard + // with a WeakPtr and bail out if that happens, mirroring the close-UI guard + // in CompleteRequestWithStatus(). + base::WeakPtr weak_this = + weak_ptr_factory_.GetWeakPtr(); + auto abort_callback = provider_->ShowDigitalIdentityInterstitial( + *web_contents, origin(), *interstitial_type, + base::BindOnce(&DigitalIdentityRequestImpl::OnInterstitialDone, + weak_ptr_factory_.GetWeakPtr(), + std::move(request_to_send))); + if (!weak_this) { + return; + } + update_interstitial_on_abort_callback_ = std::move(abort_callback); } void DigitalIdentityRequestImpl::Create(