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

View file

@ -51,8 +51,8 @@ void AtomRendererBindings::BindToFrame(WebFrame* frame) {
AtomBindings::BindTo(GetProcessObject(context));
}
void AtomRendererBindings::OnRendererMessage(const std::string& channel,
const base::ListValue& args) {
void AtomRendererBindings::OnBrowserMessage(const std::string& channel,
const base::ListValue& args) {
if (!render_view_->GetWebView())
return;

View file

@ -32,8 +32,8 @@ class AtomRendererBindings : public AtomBindings {
void BindToFrame(WebKit::WebFrame* frame);
// Dispatch messages from browser.
void OnRendererMessage(const std::string& channel,
const base::ListValue& args);
void OnBrowserMessage(const std::string& channel,
const base::ListValue& args);
private:
content::RenderView* render_view_;

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: (args...) ->
@sendChannel('ATOM_INTERNAL_MESSAGE', args...)
@sendChannel('message', args...)
sendChannel: (args...) ->
send(args...)
send('ATOM_INTERNAL_MESSAGE', args...)
module.exports = new Ipc

View file

@ -82,16 +82,16 @@ void AtomRenderViewObserver::FrameWillClose(WebFrame* frame) {
bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(AtomRenderViewObserver, message)
IPC_MESSAGE_HANDLER(AtomViewMsg_Message, OnRendererMessage)
IPC_MESSAGE_HANDLER(AtomViewMsg_Message, OnBrowserMessage)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void AtomRenderViewObserver::OnRendererMessage(const std::string& channel,
const base::ListValue& args) {
atom_bindings()->OnRendererMessage(channel, args);
void AtomRenderViewObserver::OnBrowserMessage(const std::string& channel,
const base::ListValue& args) {
atom_bindings()->OnBrowserMessage(channel, args);
}
} // namespace atom

View file

@ -34,8 +34,8 @@ class AtomRenderViewObserver : content::RenderViewObserver {
// content::RenderViewObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
void OnRendererMessage(const std::string& channel,
const base::ListValue& args);
void OnBrowserMessage(const std::string& channel,
const base::ListValue& args);
scoped_ptr<AtomRendererBindings> atom_bindings_;