From 84004cb3c2bf5cc7111c8ddb29b329458c480dc7 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 23 Jun 2023 15:18:26 +0200 Subject: [PATCH] fix: account for main frame replacement --- shell/common/node_bindings.cc | 4 ++-- shell/common/node_bindings.h | 2 +- shell/renderer/electron_renderer_client.cc | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 348d66723573e..830e355b807c8 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -518,8 +518,8 @@ node::Environment* NodeBindings::CreateEnvironment( args.insert(args.begin() + 1, init_script); - if (!isolate_data()) - set_isolate_data(node::CreateIsolateData(isolate, uv_loop_, platform)); + if (!isolate_data_) + isolate_data_ = node::CreateIsolateData(isolate, uv_loop_, platform); node::Environment* env; uint64_t flags = node::EnvironmentFlags::kDefaultFlags | diff --git a/shell/common/node_bindings.h b/shell/common/node_bindings.h index a980ce4e08734..f5b721cbb34cf 100644 --- a/shell/common/node_bindings.h +++ b/shell/common/node_bindings.h @@ -108,10 +108,10 @@ class NodeBindings { // Notify embed thread to start polling after environment is loaded. void StartPolling(); + // Gets/sets the per isolate data. void set_isolate_data(node::IsolateData* isolate_data) { isolate_data_ = isolate_data; } - node::IsolateData* isolate_data() const { return isolate_data_; } // Gets/sets the environment to wrap uv loop. diff --git a/shell/renderer/electron_renderer_client.cc b/shell/renderer/electron_renderer_client.cc index 412d89a6ce887..77d5f38cade01 100644 --- a/shell/renderer/electron_renderer_client.cc +++ b/shell/renderer/electron_renderer_client.cc @@ -18,7 +18,6 @@ #include "shell/renderer/electron_render_frame_observer.h" #include "shell/renderer/web_worker_observer.h" #include "third_party/blink/public/common/web_preferences/web_preferences.h" -#include "third_party/blink/public/web/blink.h" #include "third_party/blink/public/web/web_document.h" #include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" // nogncheck @@ -90,9 +89,10 @@ void ElectronRendererClient::DidCreateScriptContext( CHECK(!initialized.IsNothing() && initialized.FromJust()); // If DidCreateScriptContext is called and we've already created a Node.js - // Environment, then we're in the same process with a new V8::Context. We + // Environment, then we're in the same process with a new V8::Context. If + // render_frame is the main frame, then we should replace it. Otherwise, we // should assign the existing Environment to the new V8::Context. - if (env_) { + if (env_ && !render_frame->IsMainFrame()) { env_->AssignToContext(context, nullptr, node::ContextInfo("")); return; } @@ -201,7 +201,6 @@ node::Environment* ElectronRendererClient::GetEnvironment( content::RenderFrame* render_frame) const { if (!base::Contains(injected_frames_, render_frame)) return nullptr; - return env_; }