--- /dev/null
+// Copyright (c) 2016 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/renderer/atom_isolated_world.h"
+
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
+#include "third_party/WebKit/public/web/WebScriptSource.h"
+
+namespace atom {
+
+NodeBindings* AtomIsolatedWorld::node_bindings_ = nullptr;
+node::Environment* AtomIsolatedWorld::env_ = nullptr;
+
+AtomIsolatedWorld::AtomIsolatedWorld(NodeBindings* node_bindings) :
+ v8::Extension("ElectronIsolatedWorldExtension",
+ "native function SetupNode();") {
+ node_bindings_ = node_bindings;
+ env_ = nullptr;
+}
+
+AtomIsolatedWorld::~AtomIsolatedWorld() {
+ node_bindings_ = nullptr;
+ env_ = nullptr;
+}
+
+node::Environment* AtomIsolatedWorld::CreateEnvironment(
+ content::RenderFrame* frame) {
+ blink::WebScriptSource source("SetupNode()");
+ frame->GetWebFrame()->executeScriptInIsolatedWorld(
+ 1,
+ &source,
+ 1,
+ 1,
+ nullptr);
+ return env_;
+}
+
+v8::Local<v8::FunctionTemplate> AtomIsolatedWorld::GetNativeFunctionTemplate(
+ v8::Isolate* isolate,
+ v8::Local<v8::String> name) {
+ if (name->Equals(v8::String::NewFromUtf8(isolate, "SetupNode")))
+ return v8::FunctionTemplate::New(isolate, SetupNode);
+ return v8::Local<v8::FunctionTemplate>();
+}
+
+// static
+void AtomIsolatedWorld::SetupNode(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ env_ = node_bindings_->CreateEnvironment(
+ args.GetIsolate()->GetCurrentContext());
+}
+
+// static
+AtomIsolatedWorld* AtomIsolatedWorld::Create(NodeBindings* node_bindings) {
+ AtomIsolatedWorld* world = new AtomIsolatedWorld(node_bindings);
+ content::RenderThread::Get()->RegisterExtension(world);
+ return world;
+}
+
+} // namespace atom
--- /dev/null
+// Copyright (c) 2016 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_RENDERER_ATOM_ISOLATED_WORLD_H_
+#define ATOM_RENDERER_ATOM_ISOLATED_WORLD_H_
+
+#include "atom/common/node_bindings.h"
+#include "content/public/renderer/render_frame.h"
+#include "content/public/renderer/render_thread.h"
+
+namespace atom {
+
+class AtomIsolatedWorld : public v8::Extension {
+ public:
+ explicit AtomIsolatedWorld(NodeBindings* node_bindings);
+ ~AtomIsolatedWorld() override;
+ node::Environment* CreateEnvironment(content::RenderFrame* frame);
+ v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
+ v8::Isolate* isolate,
+ v8::Local<v8::String> name) override;
+
+ static AtomIsolatedWorld* Create(NodeBindings* node_bindings);
+
+ private:
+ static void SetupNode(const v8::FunctionCallbackInfo<v8::Value>& args);
+
+ private:
+ static NodeBindings* node_bindings_;
+ static node::Environment* env_;
+};
+
+} // namespace atom
+
+#endif // ATOM_RENDERER_ATOM_ISOLATED_WORLD_H_
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_bindings.h"
#include "atom/common/options_switches.h"
+#include "atom/renderer/atom_isolated_world.h"
#include "atom/renderer/atom_render_view_observer.h"
#include "atom/renderer/content_settings_observer.h"
#include "atom/renderer/guest_view_container.h"
blink::WebCustomElement::addEmbedderCustomElementName("webview");
blink::WebCustomElement::addEmbedderCustomElementName("browserplugin");
+ isolated_world_.reset(AtomIsolatedWorld::Create(node_bindings_.get()));
+
OverrideNodeArrayBuffer();
preferences_manager_.reset(new PreferencesManager);
}
// Setup node environment for each window.
- node::Environment* env = node_bindings_->CreateEnvironment(context);
+ node::Environment* env = isolated_world_->CreateEnvironment(render_frame);
// Add Electron extended APIs.
atom_bindings_->BindTo(env->isolate(), env->process_object());
namespace atom {
class AtomBindings;
+class AtomIsolatedWorld;
class PreferencesManager;
class NodeBindings;
std::unique_ptr<NodeBindings> node_bindings_;
std::unique_ptr<AtomBindings> atom_bindings_;
std::unique_ptr<PreferencesManager> preferences_manager_;
+ std::unique_ptr<AtomIsolatedWorld> isolated_world_;
DISALLOW_COPY_AND_ASSIGN(AtomRendererClient);
};
'atom/renderer/api/atom_api_spell_check_client.h',
'atom/renderer/api/atom_api_web_frame.cc',
'atom/renderer/api/atom_api_web_frame.h',
+ 'atom/renderer/atom_isolated_world.cc',
+ 'atom/renderer/atom_isolated_world.h',
'atom/renderer/atom_render_view_observer.cc',
'atom/renderer/atom_render_view_observer.h',
'atom/renderer/atom_renderer_client.cc',