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

@ -371,13 +371,8 @@ InspectableWebContents::InspectableWebContents(
InspectableWebContents::~InspectableWebContents() {
g_web_contents_instances_.remove(this);
// Unsubscribe from devtools and Clean up resources.
if (GetDevToolsWebContents()) {
if (managed_devtools_web_contents_)
managed_devtools_web_contents_->SetDelegate(nullptr);
// Calling this also unsubscribes the observer, so WebContentsDestroyed
// won't be called again.
if (GetDevToolsWebContents())
WebContentsDestroyed();
}
// Let destructor destroy managed_devtools_web_contents_.
}
@ -416,6 +411,8 @@ bool InspectableWebContents::IsGuest() const {
void InspectableWebContents::ReleaseWebContents() {
web_contents_.release();
WebContentsDestroyed();
view_.reset();
}
void InspectableWebContents::SetDockState(const std::string& state) {
@ -936,6 +933,9 @@ void InspectableWebContents::RenderFrameHostChanged(
}
void InspectableWebContents::WebContentsDestroyed() {
if (managed_devtools_web_contents_)
managed_devtools_web_contents_->SetDelegate(nullptr);
frontend_loaded_ = false;
external_devtools_web_contents_ = nullptr;
Observe(nullptr);