From 7f6283352f9f1b9c2579a416c93726355c010356 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 1 Mar 2017 08:48:03 -0800 Subject: [PATCH 1/2] Add failing spec for fetch from isolated world --- spec/fixtures/api/isolated-preload.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/fixtures/api/isolated-preload.js b/spec/fixtures/api/isolated-preload.js index 9ff121929c92..4093c37d8f40 100644 --- a/spec/fixtures/api/isolated-preload.js +++ b/spec/fixtures/api/isolated-preload.js @@ -1,9 +1,15 @@ +// Ensure fetch works from isolated world origin +fetch('http://localhost:1234') +fetch('https://localhost:1234') +fetch(`file://${__filename}`) + const {ipcRenderer, webFrame} = require('electron') window.foo = 3 webFrame.executeJavaScript('window.preloadExecuteJavaScriptProperty = 1234;') + window.addEventListener('message', (event) => { ipcRenderer.send('isolated-world', { preloadContext: { From 7fb77ee1cb9d57f2e59d6adc5dd159746b11a608 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 1 Mar 2017 08:48:35 -0800 Subject: [PATCH 2/2] Set isolated world security origin --- atom/renderer/atom_renderer_client.cc | 11 +++++++++-- spec/fixtures/api/isolated-preload.js | 1 - 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 9979aae9000b..9f91c901965f 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -86,14 +86,21 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver { } void CreateIsolatedWorldContext() { + auto frame = render_frame_->GetWebFrame(); + // This maps to the name shown in the context combo box in the Console tab // of the dev tools. - render_frame_->GetWebFrame()->setIsolatedWorldHumanReadableName( + frame->setIsolatedWorldHumanReadableName( World::ISOLATED_WORLD, blink::WebString::fromUTF8("Electron Isolated Context")); + // Setup document's origin policy in isolated world + frame->setIsolatedWorldSecurityOrigin( + World::ISOLATED_WORLD, frame->document().getSecurityOrigin()); + + // Create initial script context in isolated world blink::WebScriptSource source("void 0"); - render_frame_->GetWebFrame()->executeScriptInIsolatedWorld( + frame->executeScriptInIsolatedWorld( World::ISOLATED_WORLD, &source, 1, ExtensionGroup::MAIN_GROUP); } diff --git a/spec/fixtures/api/isolated-preload.js b/spec/fixtures/api/isolated-preload.js index 4093c37d8f40..0f19cdea8255 100644 --- a/spec/fixtures/api/isolated-preload.js +++ b/spec/fixtures/api/isolated-preload.js @@ -9,7 +9,6 @@ window.foo = 3 webFrame.executeJavaScript('window.preloadExecuteJavaScriptProperty = 1234;') - window.addEventListener('message', (event) => { ipcRenderer.send('isolated-world', { preloadContext: {