mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
Store all created environments in renderer.
This commit is contained in:
@@ -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_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user