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 <algorithm>
|
||||
|
||||
#include "common/node_bindings.h"
|
||||
#include "renderer/api/atom_renderer_bindings.h"
|
||||
#include "renderer/atom_render_view_observer.h"
|
||||
|
@ -56,8 +58,12 @@ void AtomRendererClient::DidCreateScriptContext(WebKit::WebFrame* frame,
|
|||
// Add atom-shell extended APIs.
|
||||
atom_bindings_->BindToFrame(frame);
|
||||
|
||||
// Store the created environment.
|
||||
web_page_envs_.push_back(env);
|
||||
|
||||
// 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(
|
||||
|
@ -70,10 +76,18 @@ void AtomRendererClient::WillReleaseScriptContext(
|
|||
return;
|
||||
}
|
||||
|
||||
if (env == node_bindings_->get_uv_env())
|
||||
node_bindings_->set_uv_env(NULL);
|
||||
|
||||
// Clear the environment.
|
||||
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
|
||||
|
|
|
@ -5,8 +5,14 @@
|
|||
#ifndef ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
|
||||
#define ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "content/public/renderer/content_renderer_client.h"
|
||||
|
||||
namespace node {
|
||||
class Environment;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomRendererBindings;
|
||||
|
@ -30,6 +36,8 @@ class AtomRendererClient : public content::ContentRendererClient {
|
|||
v8::Handle<v8::Context>,
|
||||
int world_id) OVERRIDE;
|
||||
|
||||
std::vector<node::Environment*> web_page_envs_;
|
||||
|
||||
scoped_ptr<NodeBindings> node_bindings_;
|
||||
scoped_ptr<AtomRendererBindings> atom_bindings_;
|
||||
|
||||
|
|
Loading…
Reference in a new issue