diff --git a/shell/renderer/atom_render_frame_observer.cc b/shell/renderer/atom_render_frame_observer.cc index 926ad477252..a22667f16ea 100644 --- a/shell/renderer/atom_render_frame_observer.cc +++ b/shell/renderer/atom_render_frame_observer.cc @@ -81,7 +81,8 @@ void AtomRenderFrameObserver::DidCreateScriptContext( if (should_create_isolated_context) { CreateIsolatedWorldContext(); - renderer_client_->SetupMainWorldOverrides(context, render_frame_); + if (!renderer_client_->IsWebViewFrame(context, render_frame_)) + renderer_client_->SetupMainWorldOverrides(context, render_frame_); } if (world_id >= World::ISOLATED_WORLD_EXTENSIONS && diff --git a/shell/renderer/atom_renderer_client.cc b/shell/renderer/atom_renderer_client.cc index a25ce6c68e6..e74d70a3a42 100644 --- a/shell/renderer/atom_renderer_client.cc +++ b/shell/renderer/atom_renderer_client.cc @@ -83,7 +83,8 @@ void AtomRendererClient::DidCreateScriptContext( base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kNodeIntegrationInSubFrames); bool should_load_node = - is_main_frame || is_devtools || allow_node_in_subframes; + (is_main_frame || is_devtools || allow_node_in_subframes) && + !IsWebViewFrame(renderer_context, render_frame); if (!should_load_node) { return; } diff --git a/shell/renderer/atom_sandboxed_renderer_client.cc b/shell/renderer/atom_sandboxed_renderer_client.cc index 07111257896..689373b26b3 100644 --- a/shell/renderer/atom_sandboxed_renderer_client.cc +++ b/shell/renderer/atom_sandboxed_renderer_client.cc @@ -208,7 +208,8 @@ void AtomSandboxedRendererClient::DidCreateScriptContext( base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kNodeIntegrationInSubFrames); bool should_load_preload = - is_main_frame || is_devtools || allow_node_in_sub_frames; + (is_main_frame || is_devtools || allow_node_in_sub_frames) && + !IsWebViewFrame(context, render_frame); if (!should_load_preload) return; diff --git a/shell/renderer/renderer_client_base.cc b/shell/renderer/renderer_client_base.cc index b88fccf74a1..b8b600a6605 100644 --- a/shell/renderer/renderer_client_base.cc +++ b/shell/renderer/renderer_client_base.cc @@ -310,4 +310,28 @@ v8::Local RendererClientBase::RunScript( return script->Run(context).ToLocalChecked(); } +bool RendererClientBase::IsWebViewFrame( + v8::Handle context, + content::RenderFrame* render_frame) const { + auto* isolate = context->GetIsolate(); + + if (render_frame->IsMainFrame()) + return false; + + mate::Dictionary window_dict( + isolate, GetContext(render_frame->GetWebFrame(), isolate)->Global()); + + v8::Local frame_element; + if (!window_dict.Get("frameElement", &frame_element)) + return false; + + mate::Dictionary frame_element_dict(isolate, frame_element); + + v8::Local internal; + if (!frame_element_dict.GetHidden("internal", &internal)) + return false; + + return !internal.IsEmpty(); +} + } // namespace electron diff --git a/shell/renderer/renderer_client_base.h b/shell/renderer/renderer_client_base.h index 970d3db01cc..15397933fa5 100644 --- a/shell/renderer/renderer_client_base.h +++ b/shell/renderer/renderer_client_base.h @@ -45,6 +45,10 @@ class RendererClientBase : public content::ContentRendererClient { static v8::Local RunScript(v8::Local context, v8::Local source); + // v8Util.getHiddenValue(window.frameElement, 'internal') + bool IsWebViewFrame(v8::Handle context, + content::RenderFrame* render_frame) const; + protected: void AddRenderBindings(v8::Isolate* isolate, v8::Local binding_object); diff --git a/spec/api-subframe-spec.js b/spec/api-subframe-spec.js index 142a4e5c167..bf1b11418c7 100644 --- a/spec/api-subframe-spec.js +++ b/spec/api-subframe-spec.js @@ -149,6 +149,39 @@ describe('renderer nodeIntegrationInSubFrames', () => { ).forEach(config => { generateTests(config.title, config.webPreferences) }) + + describe('internal