Initialize node integration after window object is cleared
This commit is contained in:
parent
706f547287
commit
ef15b670a9
3 changed files with 27 additions and 14 deletions
|
@ -68,7 +68,8 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {
|
|||
AtomRendererClient::AtomRendererClient()
|
||||
: node_bindings_(NodeBindings::Create(false)),
|
||||
atom_bindings_(new AtomRendererBindings),
|
||||
main_frame_(nullptr) {
|
||||
main_frame_(nullptr),
|
||||
is_initialized_(false) {
|
||||
}
|
||||
|
||||
AtomRendererClient::~AtomRendererClient() {
|
||||
|
@ -137,13 +138,6 @@ void AtomRendererClient::DidCreateScriptContext(blink::WebFrame* frame,
|
|||
// The first web frame is the main frame.
|
||||
main_frame_ = frame;
|
||||
|
||||
v8::Context::Scope scope(context);
|
||||
|
||||
// Check the existance of process object to prevent duplicate initialization.
|
||||
if (context->Global()->Has(
|
||||
mate::StringToV8(context->GetIsolate(), "process")))
|
||||
return;
|
||||
|
||||
// Give the node loop a run to make sure everything is ready.
|
||||
node_bindings_->RunMessageLoop();
|
||||
|
||||
|
@ -156,12 +150,22 @@ void AtomRendererClient::DidCreateScriptContext(blink::WebFrame* frame,
|
|||
// Make uv loop being wrapped by window context.
|
||||
if (node_bindings_->uv_env() == nullptr)
|
||||
node_bindings_->set_uv_env(env);
|
||||
|
||||
// Load everything.
|
||||
node_bindings_->LoadEnvironment(env);
|
||||
}
|
||||
|
||||
void AtomRendererClient::DidClearWindowObject() {
|
||||
if (!main_frame_ || is_initialized_)
|
||||
return;
|
||||
|
||||
is_initialized_ = true;
|
||||
|
||||
v8::Local<v8::Context> context = main_frame_->mainWorldScriptContext();
|
||||
v8::Context::Scope scope(context);
|
||||
|
||||
node::Environment* env = node::Environment::GetCurrent(context);
|
||||
DCHECK(env);
|
||||
|
||||
// Load everything.
|
||||
node_bindings_->LoadEnvironment(env);
|
||||
}
|
||||
|
||||
bool AtomRendererClient::ShouldFork(blink::WebFrame* frame,
|
||||
|
|
|
@ -66,6 +66,9 @@ class AtomRendererClient : public content::ContentRendererClient,
|
|||
// The main frame.
|
||||
blink::WebFrame* main_frame_;
|
||||
|
||||
// Whether we have already initialized.
|
||||
bool is_initialized_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomRendererClient);
|
||||
};
|
||||
|
||||
|
|
|
@ -86,6 +86,12 @@ if nodeIntegration in ['true', 'all', 'except-iframe', 'manual-enable-iframe']
|
|||
window.addEventListener 'unload', ->
|
||||
process.emit 'exit'
|
||||
else
|
||||
# The Module.runMain will run process._tickCallck() immediately, so we are
|
||||
# able to delete the symbols in this tick even though we used process.nextTick
|
||||
# to schedule it.
|
||||
# It is important that we put this in process.nextTick, if we delete them now
|
||||
# some code in node.js will complain about "process not defined".
|
||||
process.nextTick ->
|
||||
delete global.process
|
||||
delete global.setImmediate
|
||||
delete global.clearImmediate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue