diff --git a/atom/renderer/atom_render_view_observer.cc b/atom/renderer/atom_render_view_observer.cc index edc7306b5df1..65cc9b5c51e6 100644 --- a/atom/renderer/atom_render_view_observer.cc +++ b/atom/renderer/atom_render_view_observer.cc @@ -76,6 +76,7 @@ AtomRenderViewObserver::AtomRenderViewObserver( content::RenderView* render_view, AtomRendererClient* renderer_client) : content::RenderViewObserver(render_view), + renderer_client_(renderer_client), document_created_(false) { // Initialise resource for directory listing. net::NetModule::SetResourceProvider(NetResourceProvider); @@ -93,7 +94,7 @@ void AtomRenderViewObserver::EmitIPCEvent(blink::WebFrame* frame, v8::Isolate* isolate = blink::mainThreadIsolate(); v8::HandleScope handle_scope(isolate); - v8::Local context = frame->mainWorldScriptContext(); + v8::Local context = renderer_client_->GetContext(); v8::Context::Scope context_scope(context); // Only emit IPC event for context with node integration. diff --git a/atom/renderer/atom_render_view_observer.h b/atom/renderer/atom_render_view_observer.h index ce426060b660..e642bbe94224 100644 --- a/atom/renderer/atom_render_view_observer.h +++ b/atom/renderer/atom_render_view_observer.h @@ -40,6 +40,8 @@ class AtomRenderViewObserver : public content::RenderViewObserver { const base::string16& channel, const base::ListValue& args); + AtomRendererClient* renderer_client_; + // Whether the document object has been created. bool document_created_; diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index ac66403d4f54..4339a19d4734 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -334,6 +334,10 @@ void AtomRendererClient::DidCreateScriptContext( } } +v8::Local AtomRendererClient::GetContext() { + return node_bindings_->uv_env()->context(); +} + void AtomRendererClient::WillReleaseScriptContext( v8::Handle context, content::RenderFrame* render_frame) { // Only allow node integration for the main frame, unless it is a devtools diff --git a/atom/renderer/atom_renderer_client.h b/atom/renderer/atom_renderer_client.h index 5419692d2aeb..7fab5dde86a2 100644 --- a/atom/renderer/atom_renderer_client.h +++ b/atom/renderer/atom_renderer_client.h @@ -27,6 +27,8 @@ class AtomRendererClient : public content::ContentRendererClient { void WillReleaseScriptContext( v8::Handle context, content::RenderFrame* render_frame); + v8::Local GetContext(); + private: enum NodeIntegration { ALL,