]> khamidou — GitHub mirrors - electron.git/commitdiff
Make sure javascript environment is initialized after ProxyResolverV8.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 28 Jul 2014 08:00:15 +0000 (16:00 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 28 Jul 2014 12:28:50 +0000 (20:28 +0800)
atom.gyp
atom/browser/atom_browser_main_parts.cc
atom/browser/atom_browser_main_parts.h
atom/browser/javascript_environment.cc [new file with mode: 0644]
atom/browser/javascript_environment.h [new file with mode: 0644]

index 6a79cb8c93a6982bbdc4460101111623ed4636f9..6bd28b25d90d17eb31e2ea89dffd6b8b39535e26 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -93,6 +93,8 @@
       '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',
index 86d8d6b1e7459ee1d958fd1edee17025d38433f4..d883367495bc2c93f22a2f055cf69a78c1812aac 100644 (file)
@@ -7,10 +7,10 @@
 #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"
@@ -28,14 +28,9 @@ namespace atom {
 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;
 }
@@ -53,21 +48,20 @@ brightray::BrowserContext* AtomBrowserMainParts::CreateBrowserContext() {
   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() {
index d9b94e8d8310268d39c02d0dbd075596c3330da8..269e042b3768fd72ba4cc6f50010766b5af48930 100644 (file)
@@ -6,12 +6,12 @@
 #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 {
@@ -26,7 +26,6 @@ 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;
@@ -37,16 +36,10 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
 #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_;
 
diff --git a/atom/browser/javascript_environment.cc b/atom/browser/javascript_environment.cc
new file mode 100644 (file)
index 0000000..ddc29af
--- /dev/null
@@ -0,0 +1,17 @@
+// 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
diff --git a/atom/browser/javascript_environment.h b/atom/browser/javascript_environment.h
new file mode 100644 (file)
index 0000000..67cab80
--- /dev/null
@@ -0,0 +1,34 @@
+// 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_