Support IPC messages in isolated context
authorKevin Sawicki <kevinsawicki@gmail.com>
Fri, 9 Dec 2016 00:58:27 +0000 (16:58 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Mon, 16 Jan 2017 20:38:16 +0000 (12:38 -0800)
atom/renderer/atom_render_view_observer.cc
atom/renderer/atom_render_view_observer.h
atom/renderer/atom_renderer_client.cc
atom/renderer/atom_renderer_client.h

index edc7306..65cc9b5 100644 (file)
@@ -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<v8::Context> context = frame->mainWorldScriptContext();
+  v8::Local<v8::Context> context = renderer_client_->GetContext();
   v8::Context::Scope context_scope(context);
 
   // Only emit IPC event for context with node integration.
index ce42606..e642bbe 100644 (file)
@@ -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_;
 
index ac66403..4339a19 100644 (file)
@@ -334,6 +334,10 @@ void AtomRendererClient::DidCreateScriptContext(
   }
 }
 
+v8::Local<v8::Context> AtomRendererClient::GetContext() {
+  return node_bindings_->uv_env()->context();
+}
+
 void AtomRendererClient::WillReleaseScriptContext(
     v8::Handle<v8::Context> context, content::RenderFrame* render_frame) {
   // Only allow node integration for the main frame, unless it is a devtools
index 5419692..7fab5dd 100644 (file)
@@ -27,6 +27,8 @@ class AtomRendererClient : public content::ContentRendererClient {
   void WillReleaseScriptContext(
       v8::Handle<v8::Context> context, content::RenderFrame* render_frame);
 
+  v8::Local<v8::Context> GetContext();
+
  private:
   enum NodeIntegration {
     ALL,