Messages from renderer will be emitted to the process object in browser.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 22 Apr 2013 14:24:02 +0000 (22:24 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 22 Apr 2013 14:24:02 +0000 (22:24 +0800)
browser/api/atom_browser_bindings.cc
browser/atom_browser_main_parts.cc
browser/default_app/main.js

index c23a1f9..e6be1db 100644 (file)
@@ -4,12 +4,16 @@
 
 #include "browser/api/atom_browser_bindings.h"
 
+#include <vector>
+
 #include "base/logging.h"
 #include "base/values.h"
+#include "common/v8_value_converter_impl.h"
 #include "content/public/browser/browser_thread.h"
 #include "vendor/node/src/node.h"
 #include "vendor/node/src/node_internals.h"
 
+using content::V8ValueConverter;
 using node::node_isolate;
 
 namespace atom {
@@ -38,8 +42,24 @@ void AtomBrowserBindings::AfterLoad() {
 
 void AtomBrowserBindings::OnRendererMessage(
     int routing_id, const base::ListValue& args) {
-  LOG(ERROR) << "OnRendererMessage routing_id:" << routing_id
-             << " args:" << args;
+  v8::HandleScope scope;
+
+  v8::Handle<v8::Context> context = v8::Context::GetCurrent();
+
+  scoped_ptr<V8ValueConverter> converter(new V8ValueConverterImpl());
+
+  std::vector<v8::Handle<v8::Value>> arguments;
+  arguments.reserve(2 + args.GetSize());
+  arguments.push_back(v8::String::New("message"));
+  arguments.push_back(v8::Integer::New(routing_id));
+
+  for (size_t i = 0; i < args.GetSize(); i++) {
+    const base::Value* value;
+    if (args.Get(i, &value))
+      arguments.push_back(converter->ToV8Value(value, context));
+  }
+
+  node::MakeCallback(node::process, "emit", arguments.size(), &arguments[0]);
 }
 
 }  // namespace atom
index fadf32a..ac5d0af 100644 (file)
@@ -7,7 +7,6 @@
 #include "browser/api/atom_browser_bindings.h"
 #include "browser/atom_browser_client.h"
 #include "browser/atom_browser_context.h"
-#include "browser/native_window.h"
 #include "common/node_bindings.h"
 #include "vendor/node/src/node.h"
 #include "vendor/node/src/node_internals.h"
index 149a68e..ebbd4ca 100644 (file)
@@ -3,12 +3,14 @@ var Window = require('window');
 
 var mainWindow = null;
 
+process.on('message', function() {
+  console.log.apply(this, arguments);
+});
+
 atom.browserMainParts.preMainMessageLoopRun = function() {
   mainWindow = new Window({ width: 800, height: 600 });
   mainWindow.url = 'file://' + __dirname + '/index.html';
 
-  console.log(mainWindow.id);
-
   mainWindow.on('page-title-updated', function(event, title) {
     event.preventDefault();