Store context that API is running in to deliver IPC events
This commit is contained in:
parent
2928fe5c43
commit
5b6397aaa6
3 changed files with 11 additions and 6 deletions
|
@ -94,7 +94,7 @@ void AtomRenderViewObserver::EmitIPCEvent(blink::WebFrame* frame,
|
|||
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.
|
||||
|
|
|
@ -292,6 +292,9 @@ void AtomRendererClient::DidCreateScriptContext(
|
|||
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;
|
||||
|
||||
|
@ -321,10 +324,6 @@ 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
|
||||
|
@ -367,4 +366,8 @@ void AtomRendererClient::AddSupportedKeySystems(
|
|||
AddChromeKeySystems(key_systems);
|
||||
}
|
||||
|
||||
v8::Local<v8::Context> AtomRendererClient::GetAPIContext(v8::Isolate* isolate) {
|
||||
return api_context_.Get(isolate);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -27,7 +27,8 @@ class AtomRendererClient : public content::ContentRendererClient {
|
|||
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 {
|
||||
|
@ -66,6 +67,7 @@ class AtomRendererClient : public content::ContentRendererClient {
|
|||
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);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue