diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index 427423cc394..fae7d814323 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -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; } diff --git a/atom/app/atom_main_delegate.h b/atom/app/atom_main_delegate.h index 89d6ec7a3bc..650e9f3c765 100644 --- a/atom/app/atom_main_delegate.h +++ b/atom/app/atom_main_delegate.h @@ -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 content_client_; + brightray::ContentClient content_client_; scoped_ptr browser_client_; scoped_ptr renderer_client_; diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 60c1d314be9..cbe5f5b8a53 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -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; } diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index 2ca497b6496..f599c3daebc 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -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::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 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::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() { diff --git a/atom/browser/atom_browser_main_parts.h b/atom/browser/atom_browser_main_parts.h index de95a0f2e9e..5437ef33f9e 100644 --- a/atom/browser/atom_browser_main_parts.h +++ b/atom/browser/atom_browser_main_parts.h @@ -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_; scoped_ptr node_bindings_; + // The V8 environment of browser process. + v8::Isolate* isolate_; + v8::Locker locker_; + v8::HandleScope handle_scope_; + v8::UniquePersistent context_; + v8::Context::Scope context_scope_; + static AtomBrowserMainParts* self_; DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts); diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index eb4adb6f45d..57038106eac 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -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.