small tune of IPC interface.

This commit is contained in:
Cheng Zhao 2013-04-23 20:57:14 +08:00
parent d28f51fb9c
commit 8f0b2b6363
8 changed files with 25 additions and 21 deletions

View file

@ -22,12 +22,12 @@ namespace api {
v8::Handle<v8::Value> BrowserIPC::Send(const v8::Arguments &args) {
v8::HandleScope scope;
if (!args[0]->IsNumber() || !args[1]->IsNumber() || !args[2]->IsString())
if (!args[0]->IsString() || !args[1]->IsNumber() || !args[2]->IsNumber())
return node::ThrowTypeError("Bad argument");
int process_id = args[0]->IntegerValue();
int routing_id = args[1]->IntegerValue();
std::string channel(*v8::String::Utf8Value(args[2]));
std::string channel(*v8::String::Utf8Value(args[0]));
int process_id = args[1]->IntegerValue();
int routing_id = args[2]->IntegerValue();
RenderViewHost* render_view_host(RenderViewHost::FromID(
process_id, routing_id));

View file

@ -50,13 +50,17 @@ void AtomBrowserBindings::OnRendererMessage(int process_id,
scoped_ptr<V8ValueConverter> converter(new V8ValueConverterImpl());
// process.emit('ATOM_INTERNAL_MESSAGE', 'message', process_id, routing_id);
std::vector<v8::Handle<v8::Value>> arguments;
arguments.reserve(3 + args.GetSize());
arguments.push_back(v8::String::New(channel.c_str(), channel.size()));
const base::Value* value;
if (args.Get(0, &value))
arguments.push_back(converter->ToV8Value(value, context));
arguments.push_back(v8::Integer::New(process_id));
arguments.push_back(v8::Integer::New(routing_id));
for (size_t i = 0; i < args.GetSize(); i++) {
for (size_t i = 1; i < args.GetSize(); i++) {
const base::Value* value;
if (args.Get(i, &value))
arguments.push_back(converter->ToV8Value(value, context));

View file

@ -4,12 +4,12 @@ send = process.atom_binding('ipc').send
class Ipc extends EventEmitter
constructor: ->
process.on 'ATOM_INTERNAL_MESSAGE', (args...) =>
@emit('message', args...)
@emit(args...)
send: (process_id, routing_id, args...) ->
@sendChannel(process_id, routing_id, 'ATOM_INTERNAL_MESSAGE', args...)
@sendChannel(process_id, routing_id, 'message', args...)
sendChannel: (args...) ->
send(args...)
send('ATOM_INTERNAL_MESSAGE', args...)
module.exports = new Ipc