Store all created environments in renderer.
This commit is contained in:
parent
e7b7efeb0a
commit
fff743053a
2 changed files with 26 additions and 4 deletions
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include "renderer/atom_renderer_client.h"
|
#include "renderer/atom_renderer_client.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "common/node_bindings.h"
|
#include "common/node_bindings.h"
|
||||||
#include "renderer/api/atom_renderer_bindings.h"
|
#include "renderer/api/atom_renderer_bindings.h"
|
||||||
#include "renderer/atom_render_view_observer.h"
|
#include "renderer/atom_render_view_observer.h"
|
||||||
|
@ -56,8 +58,12 @@ void AtomRendererClient::DidCreateScriptContext(WebKit::WebFrame* frame,
|
||||||
// Add atom-shell extended APIs.
|
// Add atom-shell extended APIs.
|
||||||
atom_bindings_->BindToFrame(frame);
|
atom_bindings_->BindToFrame(frame);
|
||||||
|
|
||||||
|
// Store the created environment.
|
||||||
|
web_page_envs_.push_back(env);
|
||||||
|
|
||||||
// Make uv loop being wrapped by window context.
|
// Make uv loop being wrapped by window context.
|
||||||
node_bindings_->set_uv_env(env);
|
if (node_bindings_->get_uv_env() == NULL)
|
||||||
|
node_bindings_->set_uv_env(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomRendererClient::WillReleaseScriptContext(
|
void AtomRendererClient::WillReleaseScriptContext(
|
||||||
|
@ -70,10 +76,18 @@ void AtomRendererClient::WillReleaseScriptContext(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env == node_bindings_->get_uv_env())
|
// Clear the environment.
|
||||||
node_bindings_->set_uv_env(NULL);
|
|
||||||
|
|
||||||
env->Dispose();
|
env->Dispose();
|
||||||
|
web_page_envs_.erase(
|
||||||
|
std::remove(web_page_envs_.begin(), web_page_envs_.end(), env),
|
||||||
|
web_page_envs_.end());
|
||||||
|
|
||||||
|
// Wrap the uv loop with another environment.
|
||||||
|
if (env == node_bindings_->get_uv_env()) {
|
||||||
|
node::Environment* env = web_page_envs_.size() > 0 ? web_page_envs_[0] :
|
||||||
|
NULL;
|
||||||
|
node_bindings_->set_uv_env(env);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -5,8 +5,14 @@
|
||||||
#ifndef ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
|
#ifndef ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
|
||||||
#define ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
|
#define ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "content/public/renderer/content_renderer_client.h"
|
#include "content/public/renderer/content_renderer_client.h"
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
class Environment;
|
||||||
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class AtomRendererBindings;
|
class AtomRendererBindings;
|
||||||
|
@ -30,6 +36,8 @@ class AtomRendererClient : public content::ContentRendererClient {
|
||||||
v8::Handle<v8::Context>,
|
v8::Handle<v8::Context>,
|
||||||
int world_id) OVERRIDE;
|
int world_id) OVERRIDE;
|
||||||
|
|
||||||
|
std::vector<node::Environment*> web_page_envs_;
|
||||||
|
|
||||||
scoped_ptr<NodeBindings> node_bindings_;
|
scoped_ptr<NodeBindings> node_bindings_;
|
||||||
scoped_ptr<AtomRendererBindings> atom_bindings_;
|
scoped_ptr<AtomRendererBindings> atom_bindings_;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue