]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix crash when closing page with webview
authorCheng Zhao <zcbenz@gmail.com>
Wed, 13 Jan 2016 06:47:39 +0000 (14:47 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 13 Jan 2016 06:47:39 +0000 (14:47 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/lib/guest-view-manager.js

index c4de932d37ccc80e3ca09571e55244499a0252b6..77e445efae35e93788d8f091ef8530587bb6fecd 100644 (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.
index a1d82483a954c4e9f487d1aaa385d8e9824a5a44..83f1f6ac2e18c14bfbbedd3696925ea337cdc913 100644 (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);