|
@@ -213,7 +213,8 @@ std::vector<std::string> ParseSchemesCLISwitch(const char* switch_name) {
|
|
|
} // namespace
|
|
|
|
|
|
AtomRendererClient::AtomRendererClient()
|
|
|
- : node_bindings_(NodeBindings::Create(false)),
|
|
|
+ : node_integration_initialized_(false),
|
|
|
+ node_bindings_(NodeBindings::Create(false)),
|
|
|
atom_bindings_(new AtomBindings) {
|
|
|
isolated_world_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
|
|
|
switches::kContextIsolation);
|
|
@@ -349,11 +350,9 @@ void AtomRendererClient::DidCreateScriptContext(
|
|
|
if (!render_frame->IsMainFrame() && !IsDevToolsExtension(render_frame))
|
|
|
return;
|
|
|
|
|
|
- // Whether the node binding has been initialized.
|
|
|
- bool first_time = node_bindings_->uv_env() == nullptr;
|
|
|
-
|
|
|
// Prepare the node bindings.
|
|
|
- if (first_time) {
|
|
|
+ if (!node_integration_initialized_) {
|
|
|
+ node_integration_initialized_ = true;
|
|
|
node_bindings_->Initialize();
|
|
|
node_bindings_->PrepareMessageLoop();
|
|
|
}
|
|
@@ -369,7 +368,7 @@ void AtomRendererClient::DidCreateScriptContext(
|
|
|
// Load everything.
|
|
|
node_bindings_->LoadEnvironment(env);
|
|
|
|
|
|
- if (first_time) {
|
|
|
+ if (node_bindings_->uv_env() == nullptr) {
|
|
|
// Make uv loop being wrapped by window context.
|
|
|
node_bindings_->set_uv_env(env);
|
|
|
|
|
@@ -388,6 +387,14 @@ void AtomRendererClient::WillReleaseScriptContext(
|
|
|
node::Environment* env = node::Environment::GetCurrent(context);
|
|
|
if (env)
|
|
|
mate::EmitEvent(env->isolate(), env->process_object(), "exit");
|
|
|
+
|
|
|
+ // The main frame may be replaced.
|
|
|
+ if (env == node_bindings_->uv_env())
|
|
|
+ node_bindings_->set_uv_env(nullptr);
|
|
|
+
|
|
|
+ // Destroy the node environment.
|
|
|
+ node::FreeEnvironment(env);
|
|
|
+ atom_bindings_->EnvironmentDestroyed(env);
|
|
|
}
|
|
|
|
|
|
bool AtomRendererClient::ShouldFork(blink::WebLocalFrame* frame,
|