fix: hold browser_context instead of render_frame_host to fix lifetime issues (#23271)
This commit is contained in:
parent
c438b93f18
commit
94eb4ce38e
2 changed files with 8 additions and 6 deletions
|
@ -21,7 +21,7 @@ NetworkHintsHandlerImpl::NetworkHintsHandlerImpl(
|
||||||
: network_hints::SimpleNetworkHintsHandlerImpl(
|
: network_hints::SimpleNetworkHintsHandlerImpl(
|
||||||
frame_host->GetProcess()->GetID(),
|
frame_host->GetProcess()->GetID(),
|
||||||
frame_host->GetRoutingID()),
|
frame_host->GetRoutingID()),
|
||||||
render_frame_host_(frame_host) {}
|
browser_context_(frame_host->GetProcess()->GetBrowserContext()) {}
|
||||||
|
|
||||||
NetworkHintsHandlerImpl::~NetworkHintsHandlerImpl() = default;
|
NetworkHintsHandlerImpl::~NetworkHintsHandlerImpl() = default;
|
||||||
|
|
||||||
|
@ -29,11 +29,12 @@ void NetworkHintsHandlerImpl::Preconnect(const GURL& url,
|
||||||
bool allow_credentials) {
|
bool allow_credentials) {
|
||||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||||
|
|
||||||
content::BrowserContext* browser_context =
|
if (!browser_context_) {
|
||||||
render_frame_host_->GetProcess()->GetBrowserContext();
|
return;
|
||||||
|
}
|
||||||
auto* session = electron::api::Session::FromWrappedClass(
|
auto* session = electron::api::Session::FromWrappedClass(
|
||||||
v8::Isolate::GetCurrent(),
|
v8::Isolate::GetCurrent(),
|
||||||
static_cast<electron::ElectronBrowserContext*>(browser_context));
|
static_cast<electron::ElectronBrowserContext*>(browser_context_));
|
||||||
if (session) {
|
if (session) {
|
||||||
session->Emit("preconnect", url, allow_credentials);
|
session->Emit("preconnect", url, allow_credentials);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class RenderFrameHost;
|
class RenderFrameHost;
|
||||||
}
|
class BrowserContext;
|
||||||
|
} // namespace content
|
||||||
|
|
||||||
class NetworkHintsHandlerImpl
|
class NetworkHintsHandlerImpl
|
||||||
: public network_hints::SimpleNetworkHintsHandlerImpl {
|
: public network_hints::SimpleNetworkHintsHandlerImpl {
|
||||||
|
@ -27,7 +28,7 @@ class NetworkHintsHandlerImpl
|
||||||
private:
|
private:
|
||||||
explicit NetworkHintsHandlerImpl(content::RenderFrameHost*);
|
explicit NetworkHintsHandlerImpl(content::RenderFrameHost*);
|
||||||
|
|
||||||
content::RenderFrameHost* render_frame_host_ = nullptr;
|
content::BrowserContext* browser_context_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHELL_BROWSER_NETWORK_HINTS_HANDLER_IMPL_H_
|
#endif // SHELL_BROWSER_NETWORK_HINTS_HANDLER_IMPL_H_
|
||||||
|
|
Loading…
Reference in a new issue