From 94eb4ce38eb4ecda7b76d1e6584a364bd3f15d69 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 1 May 2020 02:37:01 -0500 Subject: [PATCH] fix: hold browser_context instead of render_frame_host to fix lifetime issues (#23271) --- shell/browser/network_hints_handler_impl.cc | 9 +++++---- shell/browser/network_hints_handler_impl.h | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/shell/browser/network_hints_handler_impl.cc b/shell/browser/network_hints_handler_impl.cc index a7d8a63c823e..3cce9c4b6735 100644 --- a/shell/browser/network_hints_handler_impl.cc +++ b/shell/browser/network_hints_handler_impl.cc @@ -21,7 +21,7 @@ NetworkHintsHandlerImpl::NetworkHintsHandlerImpl( : network_hints::SimpleNetworkHintsHandlerImpl( frame_host->GetProcess()->GetID(), frame_host->GetRoutingID()), - render_frame_host_(frame_host) {} + browser_context_(frame_host->GetProcess()->GetBrowserContext()) {} NetworkHintsHandlerImpl::~NetworkHintsHandlerImpl() = default; @@ -29,11 +29,12 @@ void NetworkHintsHandlerImpl::Preconnect(const GURL& url, bool allow_credentials) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - content::BrowserContext* browser_context = - render_frame_host_->GetProcess()->GetBrowserContext(); + if (!browser_context_) { + return; + } auto* session = electron::api::Session::FromWrappedClass( v8::Isolate::GetCurrent(), - static_cast(browser_context)); + static_cast(browser_context_)); if (session) { session->Emit("preconnect", url, allow_credentials); } diff --git a/shell/browser/network_hints_handler_impl.h b/shell/browser/network_hints_handler_impl.h index 69deda121712..ba49ab6f1986 100644 --- a/shell/browser/network_hints_handler_impl.h +++ b/shell/browser/network_hints_handler_impl.h @@ -9,7 +9,8 @@ namespace content { class RenderFrameHost; -} +class BrowserContext; +} // namespace content class NetworkHintsHandlerImpl : public network_hints::SimpleNetworkHintsHandlerImpl { @@ -27,7 +28,7 @@ class NetworkHintsHandlerImpl private: explicit NetworkHintsHandlerImpl(content::RenderFrameHost*); - content::RenderFrameHost* render_frame_host_ = nullptr; + content::BrowserContext* browser_context_ = nullptr; }; #endif // SHELL_BROWSER_NETWORK_HINTS_HANDLER_IMPL_H_