v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);
- v8::Local<v8::Context> context = renderer_client_->GetContext();
+ v8::Local<v8::Context> context = renderer_client_->GetAPIContext(isolate);
v8::Context::Scope context_scope(context);
// Only emit IPC event for context with node integration.
if (!render_frame->IsMainFrame() && !IsDevToolsExtension(render_frame))
return;
+ api_context_.Reset(context->GetIsolate(), context);
+ api_context_.SetWeak();
+
// Whether the node binding has been initialized.
bool first_time = node_bindings_->uv_env() == nullptr;
}
}
-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
AddChromeKeySystems(key_systems);
}
+v8::Local<v8::Context> AtomRendererClient::GetAPIContext(v8::Isolate* isolate) {
+ return api_context_.Get(isolate);
+}
+
} // namespace atom
void WillReleaseScriptContext(
v8::Handle<v8::Context> context, content::RenderFrame* render_frame);
- v8::Local<v8::Context> GetContext();
+ // Get the context that the Electron API is running in.
+ v8::Local<v8::Context> GetAPIContext(v8::Isolate* isolate);
private:
enum NodeIntegration {
std::unique_ptr<NodeBindings> node_bindings_;
std::unique_ptr<AtomBindings> atom_bindings_;
std::unique_ptr<PreferencesManager> preferences_manager_;
+ v8::Persistent<v8::Context> api_context_;
DISALLOW_COPY_AND_ASSIGN(AtomRendererClient);
};