Skip to content

Commit

Permalink
fix: handle BrowserView reparenting
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Dec 14, 2020
1 parent c8eb4ec commit 1d4dd84
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions shell/browser/api/electron_api_base_window.cc
Expand Up @@ -759,6 +759,14 @@ 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()) {
if (browser_view->web_contents()) {
// If we're reparenting a BrowserView, ensure that it's detached from
// its previous owner window.
auto* owner_window = browser_view->web_contents()->owner_window();
if (owner_window && owner_window != window_.get()) {
owner_window->RemoveBrowserView(browser_view->view());
browser_view->web_contents()->SetOwnerWindow(nullptr);
}

window_->AddBrowserView(browser_view->view());
browser_view->web_contents()->SetOwnerWindow(window_.get());
}
Expand Down Expand Up @@ -1071,9 +1079,12 @@ void BaseWindow::ResetBrowserViews() {
v8::Local<v8::Value>::New(isolate(), item.second),
&browser_view) &&
!browser_view.IsEmpty()) {
if (browser_view->web_contents()) {
window_->RemoveBrowserView(browser_view->view());
// There's a chance that the BrowserView may have been reparented - only
// reset if the owner window is *this* window.
auto* owner_window = browser_view->web_contents()->owner_window();
if (browser_view->web_contents() && owner_window == window_.get()) {
browser_view->web_contents()->SetOwnerWindow(nullptr);
owner_window->RemoveBrowserView(browser_view->view());
}
}

Expand Down

0 comments on commit 1d4dd84

Please sign in to comment.