'atom/browser/browser_mac.mm',
'atom/browser/browser_win.cc',
'atom/browser/browser_observer.h',
+ 'atom/browser/javascript_environment.cc',
+ 'atom/browser/javascript_environment.h',
'atom/browser/mac/atom_application.h',
'atom/browser/mac/atom_application.mm',
'atom/browser/mac/atom_application_delegate.h',
#include "atom/browser/atom_browser_client.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/browser.h"
+#include "atom/browser/javascript_environment.h"
#include "atom/common/api/atom_bindings.h"
#include "atom/common/node_bindings.h"
#include "base/command_line.h"
-#include "net/proxy/proxy_resolver_v8.h"
#if defined(OS_WIN)
#include "ui/gfx/win/dpi.h"
AtomBrowserMainParts* AtomBrowserMainParts::self_ = NULL;
AtomBrowserMainParts::AtomBrowserMainParts()
- : atom_bindings_(new AtomBindings),
- browser_(new Browser),
+ : browser_(new Browser),
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_)) {
+ atom_bindings_(new AtomBindings) {
DCHECK(!self_) << "Cannot have two AtomBrowserMainParts";
self_ = this;
}
return new AtomBrowserContext();
}
-void AtomBrowserMainParts::InitProxyResolverV8() {
- brightray::BrowserMainParts::InitProxyResolverV8();
-}
-
void AtomBrowserMainParts::PostEarlyInitialization() {
brightray::BrowserMainParts::PostEarlyInitialization();
+ // The ProxyResolverV8 has setup a complete V8 environment, in order to avoid
+ // conflicts we only initialize our V8 environment after that.
+ js_env_.reset(new JavascriptEnvironment);
+
node_bindings_->Initialize();
// Create the global environment.
- global_env = node_bindings_->CreateEnvironment(
- v8::Local<v8::Context>::New(isolate_, context_));
+ global_env = node_bindings_->CreateEnvironment(js_env_->context());
// Add atom-shell extended APIs.
- atom_bindings_->BindTo(isolate_, global_env->process_object());
+ atom_bindings_->BindTo(js_env_->isolate(), global_env->process_object());
}
void AtomBrowserMainParts::PreMainMessageLoopRun() {
#define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
#include "brightray/browser/browser_main_parts.h"
-#include "v8/include/v8.h"
namespace atom {
class AtomBindings;
class Browser;
+class JavascriptEnvironment;
class NodeBindings;
class AtomBrowserMainParts : public brightray::BrowserMainParts {
protected:
// Implementations of brightray::BrowserMainParts.
virtual brightray::BrowserContext* CreateBrowserContext() OVERRIDE;
- virtual void InitProxyResolverV8() OVERRIDE;
// Implementations of content::BrowserMainParts.
virtual void PostEarlyInitialization() OVERRIDE;
#endif
private:
- scoped_ptr<AtomBindings> atom_bindings_;
scoped_ptr<Browser> browser_;
+ scoped_ptr<JavascriptEnvironment> js_env_;
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_;
+ scoped_ptr<AtomBindings> atom_bindings_;
static AtomBrowserMainParts* self_;
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/browser/javascript_environment.h"
+
+namespace atom {
+
+JavascriptEnvironment::JavascriptEnvironment()
+ : isolate_(v8::Isolate::GetCurrent()),
+ locker_(isolate_),
+ handle_scope_(isolate_),
+ context_(isolate_, v8::Context::New(isolate_)),
+ context_scope_(v8::Local<v8::Context>::New(isolate_, context_)) {
+}
+
+} // namespace atom
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
+#define ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
+
+#include "base/basictypes.h"
+#include "v8/include/v8.h"
+
+namespace atom {
+
+class JavascriptEnvironment {
+ public:
+ JavascriptEnvironment();
+
+ v8::Isolate* isolate() const { return isolate_; }
+ v8::Local<v8::Context> context() const {
+ return v8::Local<v8::Context>::New(isolate_, context_);
+ }
+
+ private:
+ v8::Isolate* isolate_;
+ v8::Locker locker_;
+ v8::HandleScope handle_scope_;
+ v8::UniquePersistent<v8::Context> context_;
+ v8::Context::Scope context_scope_;
+
+ DISALLOW_COPY_AND_ASSIGN(JavascriptEnvironment);
+};
+
+} // namespace atom
+
+#endif // ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_