fix: potentially closed webContents in BrowserView (#42633)

This commit is contained in:
Shelley Vohr 2024-07-08 12:13:53 +02:00 committed by GitHub
parent 2f4a46f47a
commit cb2e7f130b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 107 additions and 21 deletions

View file

@ -249,14 +249,16 @@ void View::AddChildViewAt(gin::Handle<View> child,
void View::RemoveChildView(gin::Handle<View> child) {
if (!view_)
return;
if (!child->view())
return;
const auto it = base::ranges::find(child_views_, child.ToV8());
if (it != child_views_.end()) {
#if BUILDFLAG(IS_MAC)
ScopedCAActionDisabler disable_animations;
#endif
view_->RemoveChildView(child->view());
// It's possible for the child's view to be invalid here
// if the child's webContents was closed or destroyed.
if (child->view())
view_->RemoveChildView(child->view());
child_views_.erase(it);
}
}