]> khamidou — GitHub mirrors - electron.git/commitdiff
Initialize node in browser process.
authorCheng Zhao <zcbenz@gmail.com>
Sat, 13 Apr 2013 10:39:09 +0000 (18:39 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sat, 13 Apr 2013 10:39:09 +0000 (18:39 +0800)
atom.gyp
browser/atom_browser_main_parts.cc
browser/atom_browser_main_parts.h
common/node_bindings.cc [new file with mode: 0644]
common/node_bindings.h [new file with mode: 0644]
vendor/brightray
vendor/node

index 505c0c59c05c363638b1a9ef627295e6a27bdc9a..48adf5f69215268ff352ee1a03c0437fe9fc97dd 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -18,6 +18,8 @@
       'browser/native_window.h',
       'browser/native_window_mac.h',
       'browser/native_window_mac.mm',
+      'common/node_bindings.cc',
+      'common/node_bindings.h',
       'common/options_switches.cc',
       'common/options_switches.h',
       'renderer/atom_render_view_observer.cc',
index 770a89a6586156d40c5f454c66e9dddd49785ec9..fc70e3df94d920cbc4a58dea6288711b2b16a84e 100644 (file)
 #include "brightray/browser/default_web_contents_delegate.h"
 #include "brightray/browser/inspectable_web_contents.h"
 #include "brightray/browser/inspectable_web_contents_view.h"
+#include "common/node_bindings.h"
 
 namespace atom {
 
-AtomBrowserMainParts::AtomBrowserMainParts() {
+AtomBrowserMainParts::AtomBrowserMainParts()
+    : node_bindings_(new NodeBindings) {
 }
 
 AtomBrowserMainParts::~AtomBrowserMainParts() {
 }
 
+void AtomBrowserMainParts::PostEarlyInitialization() {
+  node_bindings_->Initialize();
+}
+
 void AtomBrowserMainParts::PreMainMessageLoopRun() {
   brightray::BrowserMainParts::PreMainMessageLoopRun();
 
index 1fc5fa4c0749421e250522bd68e174547dc9e3a0..c0d43e2f58e1e0fafdc5f8286906960b051e3321 100644 (file)
@@ -6,17 +6,24 @@
 #define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_
 
 #include "brightray/browser/browser_main_parts.h"
+#include "common/node_bindings.h"
 
 namespace atom {
 
+class NodeBindings;
+
 class AtomBrowserMainParts : public brightray::BrowserMainParts {
  public:
   AtomBrowserMainParts();
   virtual ~AtomBrowserMainParts();
 
  protected:
+  virtual void PostEarlyInitialization() OVERRIDE;
   virtual void PreMainMessageLoopRun() OVERRIDE;
 
+ private:
+  scoped_ptr<NodeBindings> node_bindings_;
+
   DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
 };
 
diff --git a/common/node_bindings.cc b/common/node_bindings.cc
new file mode 100644 (file)
index 0000000..f0a997c
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "common/node_bindings.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "v8/include/v8.h"
+#include "vendor/node/src/node.h"
+#include "vendor/node/src/node_internals.h"
+
+namespace atom {
+
+NodeBindings::NodeBindings() {
+}
+
+NodeBindings::~NodeBindings() {
+}
+
+void NodeBindings::Initialize() {
+  CommandLine::StringVector str_argv = CommandLine::ForCurrentProcess()->argv();
+
+  // Convert string vector to char* array.
+  std::vector<char*> argv(str_argv.size(), NULL);
+  for (size_t i = 0; i < str_argv.size(); ++i) {
+    LOG(ERROR) << str_argv[i];
+    argv[i] = const_cast<char*>(str_argv[i].c_str());
+  }
+
+  // Init node.
+  node::Init(argv.size(), &argv[0]);
+  v8::V8::Initialize();
+
+  // Load node.js.
+  v8::HandleScope scope;
+  node::g_context = v8::Context::New();
+  {
+    v8::Context::Scope context_scope(node::g_context);
+    v8::Handle<v8::Object> process = node::SetupProcessObject(
+        argv.size(), &argv[0]);
+    node::Load(process);
+  }
+}
+  
+}  // namespace at
diff --git a/common/node_bindings.h b/common/node_bindings.h
new file mode 100644 (file)
index 0000000..77d6f91
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef RAVE_COMMON_NODE_BINDINGS_
+#define RAVE_COMMON_NODE_BINDINGS_
+
+#include "base/basictypes.h"
+
+namespace atom {
+
+class NodeBindings {
+ public:
+  NodeBindings();
+  virtual ~NodeBindings();
+
+  // Setup everything including V8, libuv and node.js main script.
+  void Initialize();
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(NodeBindings);
+};
+
+}  // namespace at
+
+#endif  // RAVE_COMMON_NODE_BINDINGS_
index 5a1c81d204ef308cb747ad3b2e4535f6dd456704..b163e8a2d0941043d171da48233c8ea9aaca2fdb 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 5a1c81d204ef308cb747ad3b2e4535f6dd456704
+Subproject commit b163e8a2d0941043d171da48233c8ea9aaca2fdb
index c3ecd4ac369d87492786645327ba7349dc47a4af..4ca67139123acff24c884377ebfd6f31eb4efa01 160000 (submodule)
@@ -1 +1 @@
-Subproject commit c3ecd4ac369d87492786645327ba7349dc47a4af
+Subproject commit 4ca67139123acff24c884377ebfd6f31eb4efa01