fix: destroy WebContents synchronously on shutdown (#15541)

This commit is contained in:
Cheng Zhao 2018-11-09 00:57:28 +09:00 committed by Shelley Vohr
parent 6162d9090d
commit 746beb0d8b
12 changed files with 122 additions and 13 deletions

View file

@ -66,6 +66,7 @@ void BrowserView::Init(v8::Isolate* isolate,
web_contents_.Reset(isolate, web_contents.ToV8());
api_web_contents_ = web_contents.get();
Observe(web_contents->web_contents());
view_.reset(
NativeBrowserView::Create(api_web_contents_->managed_web_contents()));
@ -74,7 +75,16 @@ void BrowserView::Init(v8::Isolate* isolate,
}
BrowserView::~BrowserView() {
api_web_contents_->DestroyWebContents(true /* async */);
if (api_web_contents_) { // destroy() is called
// Destroy WebContents asynchronously unless app is shutting down,
// because destroy() might be called inside WebContents's event handler.
api_web_contents_->DestroyWebContents(!Browser::Get()->is_shutting_down());
}
}
void BrowserView::WebContentsDestroyed() {
api_web_contents_ = nullptr;
web_contents_.Reset();
}
// static