Skip to content

Commit 706f547

Browse files
committed
Don't insert node symbols in frames
This greatly simplified our code, and it is not useful to enable node integrations in frames.
1 parent f142f57 commit 706f547

File tree

2 files changed

+6
-53
lines changed

2 files changed

+6
-53
lines changed

atom/renderer/atom_renderer_client.cc

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool IsSwitchEnabled(base::CommandLine* command_line,
4444
return true;
4545
}
4646

47-
// Helper class to forward the WillReleaseScriptContext message to the client.
47+
// Helper class to forward the messages to the client.
4848
class AtomRenderFrameObserver : public content::RenderFrameObserver {
4949
public:
5050
AtomRenderFrameObserver(content::RenderFrame* frame,
@@ -53,11 +53,6 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {
5353
renderer_client_(renderer_client) {}
5454

5555
// content::RenderFrameObserver:
56-
void WillReleaseScriptContext(v8::Handle<v8::Context> context,
57-
int world_id) override {
58-
renderer_client_->WillReleaseScriptContext(
59-
render_frame()->GetWebFrame(), context, world_id);
60-
}
6156
void DidClearWindowObject() override {
6257
renderer_client_->DidClearWindowObject();
6358
}
@@ -135,9 +130,12 @@ void AtomRendererClient::DidCreateScriptContext(blink::WebFrame* frame,
135130
v8::Handle<v8::Context> context,
136131
int extension_group,
137132
int world_id) {
133+
// Only attach node bindings in main frame.
134+
if (main_frame_)
135+
return;
136+
138137
// The first web frame is the main frame.
139-
if (main_frame_ == nullptr)
140-
main_frame_ = frame;
138+
main_frame_ = frame;
141139

142140
v8::Context::Scope scope(context);
143141

@@ -155,9 +153,6 @@ void AtomRendererClient::DidCreateScriptContext(blink::WebFrame* frame,
155153
// Add atom-shell extended APIs.
156154
atom_bindings_->BindTo(env->isolate(), env->process_object());
157155

158-
// Store the created environment.
159-
web_page_envs_.push_back(env);
160-
161156
// Make uv loop being wrapped by window context.
162157
if (node_bindings_->uv_env() == nullptr)
163158
node_bindings_->set_uv_env(env);
@@ -169,38 +164,6 @@ void AtomRendererClient::DidCreateScriptContext(blink::WebFrame* frame,
169164
void AtomRendererClient::DidClearWindowObject() {
170165
}
171166

172-
void AtomRendererClient::WillReleaseScriptContext(
173-
blink::WebLocalFrame* frame,
174-
v8::Handle<v8::Context> context,
175-
int world_id) {
176-
node::Environment* env = node::Environment::GetCurrent(context);
177-
if (env == nullptr) {
178-
LOG(ERROR) << "Encounter a non-node context when releasing script context";
179-
return;
180-
}
181-
182-
// Clear the environment.
183-
web_page_envs_.erase(
184-
std::remove(web_page_envs_.begin(), web_page_envs_.end(), env),
185-
web_page_envs_.end());
186-
187-
// Notice that we are not disposing the environment object here, because there
188-
// may still be pending uv operations in the uv loop, and when they got done
189-
// they would be needing the original environment.
190-
// So we are leaking the environment object here, just like Chrome leaking the
191-
// memory :) . Since it's only leaked when refreshing or unloading, so as long
192-
// as we make sure renderer process is restared then the memory would not be
193-
// leaked.
194-
// env->Dispose();
195-
196-
// Wrap the uv loop with another environment.
197-
if (env == node_bindings_->uv_env()) {
198-
node::Environment* env = web_page_envs_.size() > 0 ? web_page_envs_[0] :
199-
nullptr;
200-
node_bindings_->set_uv_env(env);
201-
}
202-
}
203-
204167
bool AtomRendererClient::ShouldFork(blink::WebFrame* frame,
205168
const GURL& url,
206169
const std::string& http_method,

atom/renderer/atom_renderer_client.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@
66
#define ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
77

88
#include <string>
9-
#include <vector>
109

1110
#include "content/public/renderer/content_renderer_client.h"
1211
#include "content/public/renderer/render_process_observer.h"
1312

14-
namespace node {
15-
class Environment;
16-
}
17-
1813
namespace atom {
1914

2015
class AtomRendererBindings;
@@ -27,9 +22,6 @@ class AtomRendererClient : public content::ContentRendererClient,
2722
virtual ~AtomRendererClient();
2823

2924
// Forwarded by RenderFrameObserver.
30-
void WillReleaseScriptContext(blink::WebLocalFrame* frame,
31-
v8::Handle<v8::Context> context,
32-
int world_id);
3325
void DidClearWindowObject();
3426

3527
AtomRendererBindings* atom_bindings() const { return atom_bindings_.get(); }
@@ -68,8 +60,6 @@ class AtomRendererClient : public content::ContentRendererClient,
6860

6961
void EnableWebRuntimeFeatures();
7062

71-
std::vector<node::Environment*> web_page_envs_;
72-
7363
scoped_ptr<NodeBindings> node_bindings_;
7464
scoped_ptr<AtomRendererBindings> atom_bindings_;
7565

0 commit comments

Comments
 (0)