From: Cheng Zhao Date: Mon, 6 Jul 2015 10:21:04 +0000 (+0800) Subject: Check whether WebContents lives before using its methods X-Git-Tag: v0.29.2~8^2~4 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=54dac0f37a5ed62813112b4087a9dd66a50f695f;p=electron.git Check whether WebContents lives before using its methods Close #2064. --- diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index d07b0376..480cb51c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -792,6 +792,10 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( isolate, v8::Local::New(isolate, template_)); } +bool WebContents::IsDestroyed() const { + return !IsAlive(); +} + void WebContents::OnRendererMessage(const base::string16& channel, const base::ListValue& args) { // webContents.emit(channel, new Event(), args...); diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index e6056d05..085f82e3 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -111,6 +111,7 @@ class WebContents : public mate::TrackableObject, // mate::Wrappable: mate::ObjectTemplateBuilder GetObjectTemplateBuilder( v8::Isolate* isolate) override; + bool IsDestroyed() const override; // content::WebContentsDelegate: bool AddMessageToConsole(content::WebContents* source,