browser: make destruction of webContents async
This commit is contained in:
parent
ca7ca3ba1c
commit
f974a6bda9
5 changed files with 21 additions and 9 deletions
|
@ -417,15 +417,22 @@ WebContents::~WebContents() {
|
||||||
guest_delegate_->Destroy();
|
guest_delegate_->Destroy();
|
||||||
|
|
||||||
RenderViewDeleted(web_contents()->GetRenderViewHost());
|
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
|
// This event is only for internal use, which is emitted when WebContents is
|
||||||
// being destroyed.
|
// being destroyed.
|
||||||
Emit("will-destroy");
|
Emit("will-destroy");
|
||||||
ResetManagedWebContents();
|
ResetManagedWebContents(async);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContents::DidAddMessageToConsole(content::WebContents* source,
|
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,
|
if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
|
||||||
initial_rect.x(), initial_rect.y(), initial_rect.width(),
|
initial_rect.x(), initial_rect.y(), initial_rect.width(),
|
||||||
initial_rect.height())) {
|
initial_rect.height())) {
|
||||||
api_web_contents->DestroyWebContents();
|
api_web_contents->DestroyWebContents(false /* async */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
v8::Local<v8::FunctionTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
// Notifies to destroy any guest web contents before destroying self.
|
// Notifies to destroy any guest web contents before destroying self.
|
||||||
void DestroyWebContents();
|
void DestroyWebContents(bool async);
|
||||||
|
|
||||||
int64_t GetID() const;
|
int64_t GetID() const;
|
||||||
int GetProcessID() const;
|
int GetProcessID() const;
|
||||||
|
|
|
@ -173,7 +173,7 @@ void Window::WillDestroyNativeObject() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::OnWindowClosed() {
|
void Window::OnWindowClosed() {
|
||||||
api_web_contents_->DestroyWebContents();
|
api_web_contents_->DestroyWebContents(true /* async */);
|
||||||
|
|
||||||
RemoveFromWeakMap();
|
RemoveFromWeakMap();
|
||||||
window_->RemoveObserver(this);
|
window_->RemoveObserver(this);
|
||||||
|
|
|
@ -188,9 +188,14 @@ void CommonWebContentsDelegate::SetOwnerWindow(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommonWebContentsDelegate::ResetManagedWebContents() {
|
void CommonWebContentsDelegate::ResetManagedWebContents(bool async) {
|
||||||
|
if (async) {
|
||||||
|
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE,
|
||||||
|
web_contents_.release());
|
||||||
|
} else {
|
||||||
web_contents_.reset();
|
web_contents_.reset();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
content::WebContents* CommonWebContentsDelegate::GetWebContents() const {
|
content::WebContents* CommonWebContentsDelegate::GetWebContents() const {
|
||||||
if (!web_contents_)
|
if (!web_contents_)
|
||||||
|
|
|
@ -112,7 +112,7 @@ class CommonWebContentsDelegate
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Destroy the managed InspectableWebContents object.
|
// Destroy the managed InspectableWebContents object.
|
||||||
void ResetManagedWebContents();
|
void ResetManagedWebContents(bool async);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Callback for when DevToolsSaveToFile has completed.
|
// Callback for when DevToolsSaveToFile has completed.
|
||||||
|
|
Loading…
Reference in a new issue