From 6755aa44f67b6dcad4937d09e14d87b38a8686e7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 30 May 2016 14:56:31 +0900 Subject: [PATCH] Initialize script context in DidClearWindowObject Doing it in RunScriptsAtDocumentStart would somehow result in weird results when webSecurity is off. --- atom/renderer/atom_renderer_client.cc | 12 +++++++++--- atom/renderer/atom_renderer_client.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 283930b829a2..ee2dd7d54e04 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -68,6 +68,10 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver { renderer_client_(renderer_client) {} // content::RenderFrameObserver: + void DidClearWindowObject() override { + renderer_client_->DidClearWindowObject(render_frame_); + } + void DidCreateScriptContext(v8::Handle context, int extension_group, int world_id) override { @@ -185,12 +189,14 @@ void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) { } } -void AtomRendererClient::RunScriptsAtDocumentStart( +void AtomRendererClient::DidClearWindowObject( content::RenderFrame* render_frame) { // Make sure every page will get a script context created. - render_frame->GetWebFrame()->executeScript( - blink::WebScriptSource("void 0")); + render_frame->GetWebFrame()->executeScript(blink::WebScriptSource("void 0")); +} +void AtomRendererClient::RunScriptsAtDocumentStart( + content::RenderFrame* render_frame) { // Inform the document start pharse. node::Environment* env = node_bindings_->uv_env(); if (env) { diff --git a/atom/renderer/atom_renderer_client.h b/atom/renderer/atom_renderer_client.h index 51872e5bcba9..f4a548908e06 100644 --- a/atom/renderer/atom_renderer_client.h +++ b/atom/renderer/atom_renderer_client.h @@ -21,6 +21,7 @@ class AtomRendererClient : public content::ContentRendererClient { AtomRendererClient(); virtual ~AtomRendererClient(); + void DidClearWindowObject(content::RenderFrame* render_frame); void DidCreateScriptContext( v8::Handle context, content::RenderFrame* render_frame); void WillReleaseScriptContext(