fix: make BrowserView aware of owning window (#31796)

This commit is contained in:
Shelley Vohr 2021-11-15 16:23:31 +01:00 committed by GitHub
parent bf7b245fa0
commit 65e4f75058
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 27 deletions

View file

@ -99,10 +99,18 @@ BrowserView::BrowserView(gin::Arguments* args,
NativeBrowserView::Create(api_web_contents_->inspectable_web_contents()));
}
void BrowserView::SetOwnerWindow(NativeWindow* window) {
// Ensure WebContents and BrowserView owner windows are in sync.
if (web_contents())
web_contents()->SetOwnerWindow(window);
owner_window_ = window ? window->GetWeakPtr() : nullptr;
}
BrowserView::~BrowserView() {
if (api_web_contents_) { // destroy() called without closing WebContents
api_web_contents_->RemoveObserver(this);
api_web_contents_->Destroy();
if (web_contents()) { // destroy() called without closing WebContents
web_contents()->RemoveObserver(this);
web_contents()->Destroy();
}
}