Fix releasing script contexts.

This commit is contained in:
Cheng Zhao 2014-07-18 09:04:41 +08:00
parent a1c2adda3d
commit 66aea0c3e8
2 changed files with 30 additions and 4 deletions

View file

@ -11,6 +11,8 @@
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "atom/renderer/api/atom_renderer_bindings.h" #include "atom/renderer/api/atom_renderer_bindings.h"
#include "atom/renderer/atom_render_view_observer.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 "base/command_line.h"
#include "native_mate/converter.h" #include "native_mate/converter.h"
#include "third_party/WebKit/public/web/WebDocument.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* kSecurityDisable = "disable";
const char* kSecurityEnableNodeIntegration = "enable-node-integration"; 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<v8::Context> context,
int world_id) OVERRIDE {
renderer_client_->WillReleaseScriptContext(
render_frame()->GetWebFrame(), context, world_id);
}
private:
AtomRendererClient* renderer_client_;
DISALLOW_COPY_AND_ASSIGN(AtomRenderFrameObserver);
};
} // namespace } // namespace
AtomRendererClient::AtomRendererClient() AtomRendererClient::AtomRendererClient()
@ -74,6 +97,7 @@ void AtomRendererClient::RenderThreadStarted() {
void AtomRendererClient::RenderFrameCreated( void AtomRendererClient::RenderFrameCreated(
content::RenderFrame* render_frame) { content::RenderFrame* render_frame) {
new AtomRenderFrameObserver(render_frame, this);
} }
void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) { void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {

View file

@ -26,6 +26,11 @@ class AtomRendererClient : public content::ContentRendererClient {
bool IsNodeBindingEnabled(blink::WebFrame* frame = NULL); bool IsNodeBindingEnabled(blink::WebFrame* frame = NULL);
// Forwarded by RenderFrameObserver.
void WillReleaseScriptContext(blink::WebFrame* frame,
v8::Handle<v8::Context> context,
int world_id);
AtomRendererBindings* atom_bindings() const { return atom_bindings_.get(); } AtomRendererBindings* atom_bindings() const { return atom_bindings_.get(); }
private: private:
@ -44,15 +49,12 @@ class AtomRendererClient : public content::ContentRendererClient {
v8::Handle<v8::Context> context, v8::Handle<v8::Context> context,
int extension_group, int extension_group,
int world_id) OVERRIDE; int world_id) OVERRIDE;
virtual void WillReleaseScriptContext(blink::WebFrame* frame,
v8::Handle<v8::Context>,
int world_id);
virtual bool ShouldFork(blink::WebFrame* frame, virtual bool ShouldFork(blink::WebFrame* frame,
const GURL& url, const GURL& url,
const std::string& http_method, const std::string& http_method,
bool is_initial_navigation, bool is_initial_navigation,
bool is_server_redirect, bool is_server_redirect,
bool* send_referrer); bool* send_referrer) OVERRIDE;
std::vector<node::Environment*> web_page_envs_; std::vector<node::Environment*> web_page_envs_;