Skip to content

Commit

Permalink
fix: crash when beforeunload prevented
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Feb 13, 2023
1 parent 8b3e498 commit 1a36853
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion shell/browser/api/electron_api_browser_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ BrowserWindow::~BrowserWindow() {
api_web_contents_->RemoveObserver(this);
// Destroy the WebContents.
OnCloseContents();
api_web_contents_->Destroy();
}
}

Expand All @@ -139,7 +138,9 @@ void BrowserWindow::WebContentsDestroyed() {
}

void BrowserWindow::OnCloseContents() {
LOG(INFO) << "BrowserWindow::OnCloseContents";
BaseWindow::ResetBrowserViews();
api_web_contents_->Destroy();
}

void BrowserWindow::OnRendererResponsive(content::RenderProcessHost*) {
Expand Down
4 changes: 3 additions & 1 deletion shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,9 @@ void WebContents::CloseContents(content::WebContents* source) {
for (ExtendedWebContentsObserver& observer : observers_)
observer.OnCloseContents();

Destroy();
// If there are observers, OnCloseContents will call Destroy()
if (observers_.empty())
Destroy();
}

void WebContents::ActivateContents(content::WebContents* source) {
Expand Down

0 comments on commit 1a36853

Please sign in to comment.