mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: check web_contents() for destroyed WebContents (#27966)
Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
This commit is contained in:
@@ -1073,7 +1073,7 @@ content::WebContents* WebContents::OpenURLFromTab(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!weak_this)
|
||||
if (!weak_this || !web_contents())
|
||||
return nullptr;
|
||||
|
||||
content::NavigationController::LoadURLParams load_url_params(params.url);
|
||||
@@ -1406,7 +1406,7 @@ void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
||||
Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
|
||||
|
||||
// User might destroy WebContents in the crashed event.
|
||||
if (!weak_this)
|
||||
if (!weak_this || !web_contents())
|
||||
return;
|
||||
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
@@ -1477,7 +1477,7 @@ void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||
// ⚠️WARNING!⚠️
|
||||
// Emit() triggers JS which can call destroy() on |this|. It's not safe to
|
||||
// assume that |this| points to valid memory at this point.
|
||||
if (is_main_frame && weak_this)
|
||||
if (is_main_frame && weak_this && web_contents())
|
||||
Emit("did-finish-load");
|
||||
}
|
||||
|
||||
@@ -1866,6 +1866,7 @@ void WebContents::WebContentsDestroyed() {
|
||||
// also do not want any method to be used, so just mark as destroyed here.
|
||||
MarkDestroyed();
|
||||
|
||||
Observe(nullptr); // this->web_contents() will return nullptr
|
||||
Emit("destroyed");
|
||||
|
||||
// For guest view based on OOPIF, the WebContents is released by the embedder
|
||||
@@ -1997,7 +1998,7 @@ void WebContents::LoadURL(const GURL& url,
|
||||
// ⚠️WARNING!⚠️
|
||||
// LoadURLWithParams() triggers JS events which can call destroy() on |this|.
|
||||
// It's not safe to assume that |this| points to valid memory at this point.
|
||||
if (!weak_this)
|
||||
if (!weak_this || !web_contents())
|
||||
return;
|
||||
|
||||
// Required to make beforeunload handler work.
|
||||
|
||||
Reference in New Issue
Block a user