chore: wrap add/remove view in extra check (#25166)

This commit is contained in:
Shelley Vohr 2020-08-27 13:04:06 -07:00 committed by GitHub
parent 075502477e
commit e8ef1ef252
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -744,9 +744,10 @@ void BaseWindow::AddBrowserView(v8::Local<v8::Value> 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<v8::Value> 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<v8::Value>::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();