refactor: cleanup how WebContents is destroyed (#27920)

This commit is contained in:
Cheng Zhao 2021-03-07 21:14:12 +09:00 committed by GitHub
parent b3a0743121
commit f4e1a343b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 131 additions and 235 deletions

View file

@ -44,18 +44,8 @@ WebContentsView::WebContentsView(v8::Isolate* isolate,
}
WebContentsView::~WebContentsView() {
if (api_web_contents_) { // destroy() is called
// Destroy WebContents asynchronously, as we might be in GC currently and
// WebContents emits an event in its destructor.
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(
[](base::WeakPtr<WebContents> contents) {
if (contents)
contents->DestroyWebContents(
!Browser::Get()->is_shutting_down());
},
api_web_contents_->GetWeakPtr()));
}
if (api_web_contents_) // destroy() called without closing WebContents
api_web_contents_->Destroy();
}
gin::Handle<WebContents> WebContentsView::GetWebContents(v8::Isolate* isolate) {