From c22d927b6f9ffbea77d3a2c2d6a206751851bb67 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 22 Apr 2013 22:24:02 +0800 Subject: [PATCH] Messages from renderer will be emitted to the process object in browser. --- browser/api/atom_browser_bindings.cc | 24 ++++++++++++++++++++++-- browser/atom_browser_main_parts.cc | 1 - browser/default_app/main.js | 6 ++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/browser/api/atom_browser_bindings.cc b/browser/api/atom_browser_bindings.cc index c23a1f92f1f1..e6be1db6026a 100644 --- a/browser/api/atom_browser_bindings.cc +++ b/browser/api/atom_browser_bindings.cc @@ -4,12 +4,16 @@ #include "browser/api/atom_browser_bindings.h" +#include + #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 context = v8::Context::GetCurrent(); + + scoped_ptr converter(new V8ValueConverterImpl()); + + std::vector> 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 diff --git a/browser/atom_browser_main_parts.cc b/browser/atom_browser_main_parts.cc index fadf32aaa5c4..ac5d0aff72e5 100644 --- a/browser/atom_browser_main_parts.cc +++ b/browser/atom_browser_main_parts.cc @@ -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" diff --git a/browser/default_app/main.js b/browser/default_app/main.js index 149a68e3a16e..ebbd4ca4bab0 100644 --- a/browser/default_app/main.js +++ b/browser/default_app/main.js @@ -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();