Fix crash when closing page with webview

This commit is contained in:
Cheng Zhao 2016-01-13 14:47:39 +08:00
parent af02739c4e
commit 44b8343585
2 changed files with 13 additions and 9 deletions

View file

@ -280,15 +280,11 @@ WebContents::WebContents(v8::Isolate* isolate,
} }
WebContents::~WebContents() { WebContents::~WebContents() {
if (type_ == WEB_VIEW && managed_web_contents()) { // The webview's lifetime is completely controlled by GuestViewManager, so
// When force destroying the "destroyed" event is not emitted. // it is always destroyed by calling webview.destroy(), we need to make
// sure the "destroyed" event is emitted manually.
if (type_ == WEB_VIEW && managed_web_contents())
WebContentsDestroyed(); WebContentsDestroyed();
guest_delegate_->Destroy();
Observe(nullptr);
DestroyWebContents();
}
} }
bool WebContents::AddMessageToConsole(content::WebContents* source, bool WebContents::AddMessageToConsole(content::WebContents* source,
@ -624,7 +620,15 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
void WebContents::WebContentsDestroyed() { void WebContents::WebContentsDestroyed() {
// The RenderViewDeleted was not called when the WebContents is destroyed. // The RenderViewDeleted was not called when the WebContents is destroyed.
RenderViewDeleted(web_contents()->GetRenderViewHost()); RenderViewDeleted(web_contents()->GetRenderViewHost());
// This event is only for internal use, which is emitted when WebContents is
// being destroyed.
Emit("will-destroy");
// Cleanup relationships with other parts.
RemoveFromWeakMap(); RemoveFromWeakMap();
if (type_ == WEB_VIEW)
guest_delegate_->Destroy();
// We can not call Destroy here because we need to call Emit first, but we // We can not call Destroy here because we need to call Emit first, but we
// also do not want any method to be used, so just mark as destroyed here. // also do not want any method to be used, so just mark as destroyed here.

View file

@ -52,7 +52,7 @@ createGuest = function(embedder, params) {
}; };
/* Destroy guest when the embedder is gone or navigated. */ /* Destroy guest when the embedder is gone or navigated. */
destroyEvents = ['destroyed', 'crashed', 'did-navigate']; destroyEvents = ['will-destroy', 'crashed', 'did-navigate'];
destroy = function() { destroy = function() {
if (guestInstances[id] != null) { if (guestInstances[id] != null) {
return destroyGuest(embedder, id); return destroyGuest(embedder, id);