Browse Source

clear pointer when WebContents is closed

Cheng Zhao 7 years ago
parent
commit
3b81312cf7
1 changed files with 6 additions and 3 deletions
  1. 6 3
      atom/browser/api/atom_api_web_contents_view.cc

+ 6 - 3
atom/browser/api/atom_api_web_contents_view.cc

@@ -63,12 +63,15 @@ WebContentsView::WebContentsView(v8::Isolate* isolate,
 }
 
 WebContentsView::~WebContentsView() {
-  api_web_contents_->RemoveObserver(this);
-  api_web_contents_->DestroyWebContents(false /* async */);
+  if (api_web_contents_) {
+    api_web_contents_->RemoveObserver(this);
+    api_web_contents_->DestroyWebContents(false /* async */);
+  }
 }
 
 void WebContentsView::OnCloseContents() {
-  // TODO(zcbenz): WebContents is closed, report the event.
+  api_web_contents_ = nullptr;
+  web_contents_.Reset();
 }
 
 // static