diff --git a/browser/api/atom_browser_bindings.cc b/browser/api/atom_browser_bindings.cc index 35488612c2be..6fa06e89695e 100644 --- a/browser/api/atom_browser_bindings.cc +++ b/browser/api/atom_browser_bindings.cc @@ -23,20 +23,6 @@ AtomBrowserBindings::AtomBrowserBindings() { AtomBrowserBindings::~AtomBrowserBindings() { } -void AtomBrowserBindings::AfterLoad() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - - v8::HandleScope handle_scope(node_isolate); - - v8::Handle global = global_env->context()->Global(); - v8::Handle atom = global->Get(ToV8Value("__atom"))->ToObject(); - DCHECK(!atom.IsEmpty()); - - browser_main_parts_.reset( - atom->Get(ToV8Value("browserMainParts"))->ToObject()); - DCHECK(!browser_main_parts_.IsEmpty()); -} - void AtomBrowserBindings::OnRendererMessage(int process_id, int routing_id, const string16& channel, diff --git a/browser/api/atom_browser_bindings.h b/browser/api/atom_browser_bindings.h index 25e17f24890a..d110fadd6f72 100644 --- a/browser/api/atom_browser_bindings.h +++ b/browser/api/atom_browser_bindings.h @@ -26,9 +26,6 @@ class AtomBrowserBindings : public AtomBindings { AtomBrowserBindings(); virtual ~AtomBrowserBindings(); - // Called when the node.js main script has been loaded. - virtual void AfterLoad(); - // Called when received a message from renderer. void OnRendererMessage(int process_id, int routing_id, diff --git a/browser/atom_browser_main_parts.cc b/browser/atom_browser_main_parts.cc index 3c3b2e70196e..823eac946814 100644 --- a/browser/atom_browser_main_parts.cc +++ b/browser/atom_browser_main_parts.cc @@ -9,6 +9,7 @@ #include "browser/atom_browser_context.h" #include "browser/browser.h" #include "common/node_bindings.h" +#include "net/proxy/proxy_resolver_v8.h" #include "common/v8/node_common.h" @@ -49,32 +50,20 @@ void AtomBrowserMainParts::PostEarlyInitialization() { v8::HandleScope handle_scope(node_isolate); v8::Local context = v8::Context::New(node_isolate); - // Wrap whole process in one global context. - context->Enter(); - // Create the global environment. global_env = node_bindings_->CreateEnvironment(context); + // Wrap whole process in one global context. + context->Enter(); + // Add atom-shell extended APIs. atom_bindings_->BindTo(global_env->process_object()); - atom_bindings_->AfterLoad(); } void AtomBrowserMainParts::PreMainMessageLoopRun() { - node_bindings_->PrepareMessageLoop(); - brightray::BrowserMainParts::PreMainMessageLoopRun(); - { - v8::HandleScope handle_scope(node_isolate); - v8::Context::Scope context_scope(global_env->context()); - - v8::Handle args; - node::MakeCallback(atom_bindings_->browser_main_parts(), - "preMainMessageLoopRun", - 0, &args); - } - + node_bindings_->PrepareMessageLoop(); node_bindings_->RunMessageLoop(); // Make sure the url request job factory is created before the @@ -89,4 +78,14 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { #endif } +int AtomBrowserMainParts::PreCreateThreads() { + // Note that we are overriding the PreCreateThreads of brightray, since we + // are integrating node in browser, we can just be sure that an V8 instance + // would be prepared, while the ProxyResolverV8::CreateIsolate() would + // try to create a V8 isolate, which messed everything on Windows, so we + // have to override and call RememberDefaultIsolate on Windows instead. + net::ProxyResolverV8::RememberDefaultIsolate(); + return 0; +} + } // namespace atom diff --git a/browser/atom_browser_main_parts.h b/browser/atom_browser_main_parts.h index 3b7ac1071aa2..a7fd1809328c 100644 --- a/browser/atom_browser_main_parts.h +++ b/browser/atom_browser_main_parts.h @@ -30,6 +30,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { // Implementations of content::BrowserMainParts. virtual void PostEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopRun() OVERRIDE; + virtual int PreCreateThreads() OVERRIDE; #if defined(OS_MACOSX) virtual void PreMainMessageLoopStart() OVERRIDE; virtual void PostDestroyThreads() OVERRIDE; diff --git a/common/node_bindings.cc b/common/node_bindings.cc index 14e6b03b9ded..a349aef011f9 100644 --- a/common/node_bindings.cc +++ b/common/node_bindings.cc @@ -142,6 +142,7 @@ node::Environment* NodeBindings::CreateEnvironment( // Following code are stripped from node::CreateEnvironment in node.cc: HandleScope handle_scope(isolate); + Context::Scope context_scope(context); Environment* env = Environment::New(context);