From 66aea0c3e84a597cdc0a3fc32ce6d9032eb3f3ff Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 18 Jul 2014 09:04:41 +0800 Subject: [PATCH] Fix releasing script contexts. --- atom/renderer/atom_renderer_client.cc | 24 ++++++++++++++++++++++++ atom/renderer/atom_renderer_client.h | 10 ++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index eb7131d9a8e8..8b3aaee517f6 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -11,6 +11,8 @@ #include "atom/common/options_switches.h" #include "atom/renderer/api/atom_renderer_bindings.h" #include "atom/renderer/atom_render_view_observer.h" +#include "content/public/renderer/render_frame.h" +#include "content/public/renderer/render_frame_observer.h" #include "base/command_line.h" #include "native_mate/converter.h" #include "third_party/WebKit/public/web/WebDocument.h" @@ -29,6 +31,27 @@ const char* kSecurityManualEnableIframe = "manual-enable-iframe"; const char* kSecurityDisable = "disable"; const char* kSecurityEnableNodeIntegration = "enable-node-integration"; +// Helper class to forward the WillReleaseScriptContext message to the client. +class AtomRenderFrameObserver : public content::RenderFrameObserver { + public: + AtomRenderFrameObserver(content::RenderFrame* frame, + AtomRendererClient* renderer_client) + : content::RenderFrameObserver(frame), + renderer_client_(renderer_client) {} + + // content::RenderFrameObserver: + virtual void WillReleaseScriptContext(v8::Handle context, + int world_id) OVERRIDE { + renderer_client_->WillReleaseScriptContext( + render_frame()->GetWebFrame(), context, world_id); + } + + private: + AtomRendererClient* renderer_client_; + + DISALLOW_COPY_AND_ASSIGN(AtomRenderFrameObserver); +}; + } // namespace AtomRendererClient::AtomRendererClient() @@ -74,6 +97,7 @@ void AtomRendererClient::RenderThreadStarted() { void AtomRendererClient::RenderFrameCreated( content::RenderFrame* render_frame) { + new AtomRenderFrameObserver(render_frame, this); } void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) { diff --git a/atom/renderer/atom_renderer_client.h b/atom/renderer/atom_renderer_client.h index 78eab3012ae3..dd143d1a4a9f 100644 --- a/atom/renderer/atom_renderer_client.h +++ b/atom/renderer/atom_renderer_client.h @@ -26,6 +26,11 @@ class AtomRendererClient : public content::ContentRendererClient { bool IsNodeBindingEnabled(blink::WebFrame* frame = NULL); + // Forwarded by RenderFrameObserver. + void WillReleaseScriptContext(blink::WebFrame* frame, + v8::Handle context, + int world_id); + AtomRendererBindings* atom_bindings() const { return atom_bindings_.get(); } private: @@ -44,15 +49,12 @@ class AtomRendererClient : public content::ContentRendererClient { v8::Handle context, int extension_group, int world_id) OVERRIDE; - virtual void WillReleaseScriptContext(blink::WebFrame* frame, - v8::Handle, - int world_id); virtual bool ShouldFork(blink::WebFrame* frame, const GURL& url, const std::string& http_method, bool is_initial_navigation, bool is_server_redirect, - bool* send_referrer); + bool* send_referrer) OVERRIDE; std::vector web_page_envs_;