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() {
if (type_ == WEB_VIEW && managed_web_contents()) {
// When force destroying the "destroyed" event is not emitted.
// The webview's lifetime is completely controlled by GuestViewManager, so
// 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();
guest_delegate_->Destroy();
Observe(nullptr);
DestroyWebContents();
}
}
bool WebContents::AddMessageToConsole(content::WebContents* source,
@ -624,7 +620,15 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
void WebContents::WebContentsDestroyed() {
// The RenderViewDeleted was not called when the WebContents is destroyed.
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();
if (type_ == WEB_VIEW)
guest_delegate_->Destroy();
// 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.

View file

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