diff --git a/shell/browser/api/electron_api_base_window.cc b/shell/browser/api/electron_api_base_window.cc index cad0598faed..dad65dbb299 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -744,9 +744,10 @@ void BaseWindow::AddBrowserView(v8::Local value) { gin::ConvertFromV8(isolate(), value, &browser_view)) { auto get_that_view = browser_views_.find(browser_view->ID()); if (get_that_view == browser_views_.end()) { - window_->AddBrowserView(browser_view->view()); - if (browser_view->web_contents()) + if (browser_view->web_contents()) { + window_->AddBrowserView(browser_view->view()); browser_view->web_contents()->SetOwnerWindow(window_.get()); + } browser_views_[browser_view->ID()].Reset(isolate(), value); } } @@ -758,9 +759,10 @@ void BaseWindow::RemoveBrowserView(v8::Local value) { gin::ConvertFromV8(isolate(), value, &browser_view)) { auto get_that_view = browser_views_.find(browser_view->ID()); if (get_that_view != browser_views_.end()) { - window_->RemoveBrowserView(browser_view->view()); - if (browser_view->web_contents()) + if (browser_view->web_contents()) { + window_->RemoveBrowserView(browser_view->view()); browser_view->web_contents()->SetOwnerWindow(nullptr); + } (*get_that_view).second.Reset(isolate(), value); browser_views_.erase(get_that_view); } @@ -1055,9 +1057,10 @@ void BaseWindow::ResetBrowserViews() { v8::Local::New(isolate(), item.second), &browser_view) && !browser_view.IsEmpty()) { - window_->RemoveBrowserView(browser_view->view()); - if (browser_view->web_contents()) + if (browser_view->web_contents()) { browser_view->web_contents()->SetOwnerWindow(nullptr); + window_->RemoveBrowserView(browser_view->view()); + } } item.second.Reset();