Add getRoutingID and getProcessID for window API.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 23 Apr 2013 09:21:34 +0000 (17:21 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 23 Apr 2013 09:21:34 +0000 (17:21 +0800)
browser/api/atom_api_window.cc
browser/api/atom_api_window.h
browser/api/lib/ipc.coffee
browser/default_app/main.js
renderer/api/lib/ipc.coffee

index bb94f61..848c2cd 100644 (file)
@@ -9,6 +9,7 @@
 #include "common/v8_value_converter_impl.h"
 #include "content/public/browser/navigation_entry.h"
 #include "content/public/browser/web_contents.h"
+#include "content/public/browser/render_process_host.h"
 #include "ui/gfx/point.h"
 #include "ui/gfx/rect.h"
 #include "ui/gfx/size.h"
@@ -397,6 +398,21 @@ v8::Handle<v8::Value> Window::Stop(const v8::Arguments &args) {
 }
 
 // static
+v8::Handle<v8::Value> Window::GetRoutingID(const v8::Arguments &args) {
+  Window* self = ObjectWrap::Unwrap<Window>(args.This());
+
+  return v8::Integer::New(self->window_->GetWebContents()->GetRoutingID());
+}
+
+// static
+v8::Handle<v8::Value> Window::GetProcessID(const v8::Arguments &args) {
+  Window* self = ObjectWrap::Unwrap<Window>(args.This());
+
+  return v8::Integer::New(
+      self->window_->GetWebContents()->GetRenderProcessHost()->GetID());
+}
+
+// static
 v8::Handle<v8::Value> Window::LoadURL(const v8::Arguments &args) {
   Window* self = ObjectWrap::Unwrap<Window>(args.This());
 
@@ -576,6 +592,8 @@ void Window::Initialize(v8::Handle<v8::Object> target) {
   NODE_SET_PROTOTYPE_METHOD(t, "isLoading", IsLoading);
   NODE_SET_PROTOTYPE_METHOD(t, "isWaitingForResponse", IsWaitingForResponse);
   NODE_SET_PROTOTYPE_METHOD(t, "stop", Stop);
+  NODE_SET_PROTOTYPE_METHOD(t, "getRoutingID", GetRoutingID);
+  NODE_SET_PROTOTYPE_METHOD(t, "getProcessID", GetProcessID);
 
   NODE_SET_PROTOTYPE_METHOD(t, "loadURL", LoadURL);
   NODE_SET_PROTOTYPE_METHOD(t, "getURL", GetURL);
index 4fc32a9..25f16b3 100644 (file)
@@ -76,6 +76,8 @@ class Window : public EventEmitter,
   static v8::Handle<v8::Value> IsLoading(const v8::Arguments &args);
   static v8::Handle<v8::Value> IsWaitingForResponse(const v8::Arguments &args);
   static v8::Handle<v8::Value> Stop(const v8::Arguments &args);
+  static v8::Handle<v8::Value> GetRoutingID(const v8::Arguments &args);
+  static v8::Handle<v8::Value> GetProcessID(const v8::Arguments &args);
 
   // APIs for NavigationController.
   static v8::Handle<v8::Value> LoadURL(const v8::Arguments &args);
index 5f3b3a4..108bc30 100644 (file)
@@ -7,6 +7,9 @@ class Ipc extends EventEmitter
       @emit('message', args...)
 
   send: (process_id, routing_id, args...) ->
-    send(process_id, routing_id, 'ATOM_INTERNAL_MESSAGE', args...)
+    @sendChannel(process_id, routing_id, 'ATOM_INTERNAL_MESSAGE', args...)
+
+  sendChannel: (args...) ->
+    send(args...)
 
 module.exports = new Ipc
index 12873bf..f5e43ab 100644 (file)
@@ -4,8 +4,8 @@ var Window = require('window');
 
 var mainWindow = null;
 
+// Echo every message back.
 ipc.on('message', function(process_id, routing_id) {
-  console.log('message from', process_id, routing_id);
   ipc.send.apply(ipc, arguments);
 });
 
index c36dd03..884cab7 100644 (file)
@@ -7,6 +7,9 @@ class Ipc extends EventEmitter
       @emit('message', args...)
 
   send: (args...) ->
-    send('ATOM_INTERNAL_MESSAGE', args...)
+    @sendChannel('ATOM_INTERNAL_MESSAGE', args...)
+
+  sendChannel: (args...) ->
+    send(args...)
 
 module.exports = new Ipc