From: Cheng Zhao Date: Mon, 3 Nov 2014 11:45:09 +0000 (+0800) Subject: Fix double freeing WebContents X-Git-Tag: v0.19.1~4^2~3 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=1731d609b7f27f1cbfe01f7407ce2743e35772e2;p=electron.git Fix double freeing WebContents --- diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 9c878adf..e47eccad 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -58,12 +58,9 @@ WebContents::WebContents(const mate::Dictionary& options) if (options.Get("isGuest", &is_guest) && is_guest) params.guest_delegate = this; - storage_.reset(content::WebContents::Create(params)); - storage_->SetDelegate(this); - Observe(storage_.get()); - - inspectable_web_contents_.reset( - brightray::InspectableWebContents::Create(storage_.get())); + storage_.reset(brightray::InspectableWebContents::Create(params)); + Observe(storage_->GetWebContents()); + web_contents()->SetDelegate(this); } WebContents::~WebContents() { @@ -375,10 +372,10 @@ void WebContents::ExecuteJavaScript(const base::string16& code) { } void WebContents::OpenDevTools() { - inspectable_web_contents()->ShowDevTools(); + storage_->ShowDevTools(); - // force the inspectable web contents to be undocked when it is opened. - inspectable_web_contents()->GetView()->SetIsDocked(false); + // Force the inspectable web contents to be undocked when it is opened. + storage_->GetView()->SetIsDocked(false); } bool WebContents::SendIPCMessage(const base::string16& channel, diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 45fccba6..f8f6de9e 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -12,8 +12,6 @@ #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" #include "brightray/browser/default_web_contents_delegate.h" -#include "brightray/browser/inspectable_web_contents_delegate.h" -#include "brightray/browser/inspectable_web_contents_impl.h" #include "native_mate/handle.h" namespace mate { @@ -21,8 +19,7 @@ class Dictionary; } namespace brightray { - class InspectableWebContents; - class InspectableWebContentsImpl; +class InspectableWebContents; } namespace atom { @@ -92,11 +89,6 @@ class WebContents : public mate::EventEmitter, explicit WebContents(const mate::Dictionary& options); ~WebContents(); - brightray::InspectableWebContentsImpl* inspectable_web_contents() const { - return static_cast( - inspectable_web_contents_.get()); - } - // mate::Wrappable: virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder( v8::Isolate* isolate) override; @@ -189,16 +181,11 @@ class WebContents : public mate::EventEmitter, scoped_ptr extra_params_; // Stores the WebContents that managed by this class. - scoped_ptr storage_; + scoped_ptr storage_; // The WebContents that attaches this guest view. content::WebContents* embedder_web_contents_; - // Notice that inspectable_web_contents_ must be placed after dialog_manager_, - // so we can make sure inspectable_web_contents_ is destroyed before - // dialog_manager_, otherwise a crash would happen. - scoped_ptr inspectable_web_contents_; - // The size of the container element. gfx::Size element_size_;