]> khamidou — GitHub mirrors - electron.git/commitdiff
Make the node environment constrained in browser_main_parts.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 30 Jun 2014 06:16:16 +0000 (14:16 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 30 Jun 2014 06:16:16 +0000 (14:16 +0800)
atom/app/atom_main_delegate.cc
atom/app/atom_main_delegate.h
atom/browser/atom_browser_client.cc
atom/browser/atom_browser_main_parts.cc
atom/browser/atom_browser_main_parts.h
atom/common/node_bindings.cc

index 427423cc3945365158d8a48caa196e932d32e6fd..fae7d8143238a8fcd10d6234038860f7c2e2f555 100644 (file)
@@ -14,7 +14,6 @@
 #include "base/path_service.h"
 #include "content/public/common/content_switches.h"
 #include "ui/base/resource/resource_bundle.h"
-#include "vendor/brightray/common/content_client.h"
 
 namespace atom {
 
@@ -49,13 +48,12 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
   base::debug::EnableInProcessStackDumping();
 #endif
 
-  content_client_.reset(new brightray::ContentClient);
-  SetContentClient(content_client_.get());
-
 #if defined(OS_MACOSX)
   OverrideChildProcessPath();
   OverrideFrameworkBundlePath();
 #endif
+
+  SetContentClient(&content_client_);
   return false;
 }
 
index 89d6ec7a3bc8c3dab9d4e6731173ef742b6d0f7c..650e9f3c765ba33528b4eb99884733dfe62a6492 100644 (file)
@@ -6,6 +6,7 @@
 #define ATOM_APP_ATOM_MAIN_DELEGATE_H_
 
 #include "brightray/common/main_delegate.h"
+#include "brightray/common/content_client.h"
 
 namespace atom {
 
@@ -30,7 +31,7 @@ class AtomMainDelegate : public brightray::MainDelegate {
   virtual content::ContentRendererClient*
       CreateContentRendererClient() OVERRIDE;
 
-  scoped_ptr<brightray::ContentClient> content_client_;
+  brightray::ContentClient content_client_;
   scoped_ptr<content::ContentBrowserClient> browser_client_;
   scoped_ptr<content::ContentRendererClient> renderer_client_;
 
index 60c1d314be9807ae5c41e72a08a824fe60bde62a..cbe5f5b8a536b37a5f9b3665cc9f75807f29692c 100644 (file)
@@ -125,6 +125,7 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
 
 brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
     const content::MainFunctionParams&) {
+  v8::V8::Initialize();  // Init V8 before creating main parts.
   return new AtomBrowserMainParts;
 }
 
index 2ca497b64963defa566f1fd631902b556046a2a6..f599c3daebc96124230d7ab82575188460e98081 100644 (file)
@@ -25,7 +25,12 @@ AtomBrowserMainParts* AtomBrowserMainParts::self_ = NULL;
 AtomBrowserMainParts::AtomBrowserMainParts()
     : atom_bindings_(new AtomBindings),
       browser_(new Browser),
-      node_bindings_(NodeBindings::Create(true)) {
+      node_bindings_(NodeBindings::Create(true)),
+      isolate_(v8::Isolate::GetCurrent()),
+      locker_(isolate_),
+      handle_scope_(isolate_),
+      context_(isolate_, v8::Context::New(isolate_)),
+      context_scope_(v8::Local<v8::Context>::New(isolate_, context_)) {
   DCHECK(!self_) << "Cannot have two AtomBrowserMainParts";
   self_ = this;
 }
@@ -48,22 +53,12 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
 
   node_bindings_->Initialize();
 
-  v8::V8::Initialize();
-
-  // Create context.
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::Locker locker(isolate);
-  v8::HandleScope handle_scope(isolate);
-  v8::Local<v8::Context> context = v8::Context::New(isolate);
-
   // Create the global environment.
-  global_env = node_bindings_->CreateEnvironment(context);
-
-  // Wrap whole process in one global context.
-  context->Enter();
+  global_env = node_bindings_->CreateEnvironment(
+      v8::Local<v8::Context>::New(isolate_, context_));
 
   // Add atom-shell extended APIs.
-  atom_bindings_->BindTo(isolate, global_env->process_object());
+  atom_bindings_->BindTo(isolate_, global_env->process_object());
 }
 
 void AtomBrowserMainParts::PreMainMessageLoopRun() {
index de95a0f2e9ea0665dd7be5fda05ece02d93ed803..5437ef33f9ed5688854cb0ab95c2d0abbef5aa74 100644 (file)
@@ -6,6 +6,7 @@
 #define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
 
 #include "brightray/browser/browser_main_parts.h"
+#include "v8/include/v8.h"
 
 namespace atom {
 
@@ -40,6 +41,13 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
   scoped_ptr<Browser> browser_;
   scoped_ptr<NodeBindings> node_bindings_;
 
+  // The V8 environment of browser process.
+  v8::Isolate* isolate_;
+  v8::Locker locker_;
+  v8::HandleScope handle_scope_;
+  v8::UniquePersistent<v8::Context> context_;
+  v8::Context::Scope context_scope_;
+
   static AtomBrowserMainParts* self_;
 
   DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
index eb4adb6f45d45d5daff51f53292af0a3ea0d72ed..57038106eacd0f77f69b57d2274abf610be45aab 100644 (file)
@@ -35,10 +35,10 @@ void SetupProcessObject(Environment*, int, const char* const*, int,
 // DSO constructors, see http://git.io/DRIqCg.
 #if defined(OS_WIN)
 #define REFERENCE_MODULE(name) \
-  __pragma(comment (linker, "/export:_register_" #name))
+  __pragma(comment(linker, "/export:_register_" #name))
 #else
 #define REFERENCE_MODULE(name) \
-  extern "C" void _register_ ## name (void); \
+  extern "C" void _register_ ## name(void); \
   void (*fp_register_ ## name)(void) = _register_ ## name
 #endif
 // Node's builtin modules.