browser: make destruction of webContents async

This commit is contained in:
deepak1556 2017-04-04 01:33:51 +05:30 committed by Cheng Zhao
parent ca7ca3ba1c
commit f974a6bda9
5 changed files with 21 additions and 9 deletions

View file

@ -417,15 +417,22 @@ WebContents::~WebContents() {
guest_delegate_->Destroy();
RenderViewDeleted(web_contents()->GetRenderViewHost());
DestroyWebContents();
if (type_ == BROWSER_WINDOW && owner_window()) {
owner_window()->CloseContents(nullptr);
} else if (type_ == WEB_VIEW) {
DestroyWebContents(false /* async */);
} else {
DestroyWebContents(true /* async */);
}
}
}
void WebContents::DestroyWebContents() {
void WebContents::DestroyWebContents(bool async) {
// This event is only for internal use, which is emitted when WebContents is
// being destroyed.
Emit("will-destroy");
ResetManagedWebContents();
ResetManagedWebContents(async);
}
bool WebContents::DidAddMessageToConsole(content::WebContents* source,
@ -477,7 +484,7 @@ void WebContents::AddNewContents(content::WebContents* source,
if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
initial_rect.x(), initial_rect.y(), initial_rect.width(),
initial_rect.height())) {
api_web_contents->DestroyWebContents();
api_web_contents->DestroyWebContents(false /* async */);
}
}

View file

@ -78,7 +78,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
v8::Local<v8::FunctionTemplate> prototype);
// Notifies to destroy any guest web contents before destroying self.
void DestroyWebContents();
void DestroyWebContents(bool async);
int64_t GetID() const;
int GetProcessID() const;

View file

@ -173,7 +173,7 @@ void Window::WillDestroyNativeObject() {
}
void Window::OnWindowClosed() {
api_web_contents_->DestroyWebContents();
api_web_contents_->DestroyWebContents(true /* async */);
RemoveFromWeakMap();
window_->RemoveObserver(this);