fix: prevent crash if BrowserView webContents was destroyed (#25112)

This commit is contained in:
Shelley Vohr 2020-08-25 20:04:13 -07:00 committed by GitHub
parent c97f8109c2
commit c8a0b2b71d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 32 deletions

View file

@ -745,7 +745,8 @@ void BaseWindow::AddBrowserView(v8::Local<v8::Value> value) {
auto get_that_view = browser_views_.find(browser_view->ID());
if (get_that_view == browser_views_.end()) {
window_->AddBrowserView(browser_view->view());
browser_view->web_contents()->SetOwnerWindow(window_.get());
if (browser_view->web_contents())
browser_view->web_contents()->SetOwnerWindow(window_.get());
browser_views_[browser_view->ID()].Reset(isolate(), value);
}
}
@ -758,8 +759,8 @@ void BaseWindow::RemoveBrowserView(v8::Local<v8::Value> value) {
auto get_that_view = browser_views_.find(browser_view->ID());
if (get_that_view != browser_views_.end()) {
window_->RemoveBrowserView(browser_view->view());
browser_view->web_contents()->SetOwnerWindow(nullptr);
if (browser_view->web_contents())
browser_view->web_contents()->SetOwnerWindow(nullptr);
(*get_that_view).second.Reset(isolate(), value);
browser_views_.erase(get_that_view);
}
@ -1055,7 +1056,8 @@ void BaseWindow::ResetBrowserViews() {
&browser_view) &&
!browser_view.IsEmpty()) {
window_->RemoveBrowserView(browser_view->view());
browser_view->web_contents()->SetOwnerWindow(nullptr);
if (browser_view->web_contents())
browser_view->web_contents()->SetOwnerWindow(nullptr);
}
item.second.Reset();