]> khamidou — GitHub mirrors - electron.git/commitdiff
Simplify browser_ipc api.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 17 Apr 2014 05:51:59 +0000 (13:51 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 17 Apr 2014 05:51:59 +0000 (13:51 +0800)
atom.gyp
atom/browser/api/atom_api_browser_ipc.cc
atom/browser/api/atom_api_browser_ipc.h [deleted file]

index 09bb7cdb52d1a7395675e5d2d507345fd0e3adf2..a86e09eea379de667395ebdf72dce6c94bc876bd 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -49,7 +49,6 @@
       'atom/browser/api/atom_api_auto_updater.cc',
       'atom/browser/api/atom_api_auto_updater.h',
       'atom/browser/api/atom_api_browser_ipc.cc',
-      'atom/browser/api/atom_api_browser_ipc.h',
       'atom/browser/api/atom_api_dialog.cc',
       'atom/browser/api/atom_api_event.cc',
       'atom/browser/api/atom_api_event.h',
index 71da2c7cccfd9a686d096ded23800aa4542121e0..b2fb31cead1adf0acede1028106580ea8fb77890 100644 (file)
@@ -2,47 +2,35 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "atom/browser/api/atom_api_browser_ipc.h"
-
 #include "atom/common/api/api_messages.h"
-#include "atom/common/node_includes.h"
-#include "atom/common/v8/native_type_conversions.h"
+#include "atom/common/native_mate_converters/string16_converter.h"
+#include "atom/common/native_mate_converters/value_converter.h"
 #include "content/public/browser/render_view_host.h"
 
-using content::RenderViewHost;
-
-namespace atom {
-
-namespace api {
+#include "atom/common/node_includes.h"
 
-// static
-void BrowserIPC::Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  string16 channel;
-  int process_id, routing_id;
-  scoped_ptr<base::Value> arguments;
-  if (!FromV8Arguments(args, &channel, &process_id, &routing_id, &arguments))
-    return node::ThrowTypeError("Bad argument");
+using content::RenderViewHost;
 
-  DCHECK(arguments && arguments->IsType(base::Value::TYPE_LIST));
+namespace {
 
+bool Send(const string16& channel, int process_id, int routing_id,
+          const base:ListValue& arguments) {
   RenderViewHost* render_view_host(RenderViewHost::FromID(
       process_id, routing_id));
-  if (!render_view_host)
-    return node::ThrowError("Invalid render view host");
+  if (!render_view_host) {
+    node::ThrowError("Invalid render view host");
+    return false;
+  }
 
-  args.GetReturnValue().Set(render_view_host->Send(new AtomViewMsg_Message(
-      routing_id,
-      channel,
-      *static_cast<base::ListValue*>(arguments.get()))));
+  return render_view_host->Send(new AtomViewMsg_Message(routing_id, channel,
+                                                        arguments));
 }
 
-// static
-void BrowserIPC::Initialize(v8::Handle<v8::Object> target) {
-  NODE_SET_METHOD(target, "send", Send);
+void Initialize(v8::Handle<v8::Object> exports) {
+  mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
+  dict.SetMethod("send", &Send);
 }
 
-}  // namespace api
-
-}  // namespace atom
+}  // namespace
 
-NODE_MODULE(atom_browser_ipc, atom::api::BrowserIPC::Initialize)
+NODE_MODULE(atom_browser_ipc, Initialize)
diff --git a/atom/browser/api/atom_api_browser_ipc.h b/atom/browser/api/atom_api_browser_ipc.h
deleted file mode 100644 (file)
index 93f0ba7..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (c) 2013 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_BROWSER_API_ATOM_API_BROWSER_IPC_H_
-#define ATOM_BROWSER_API_ATOM_API_BROWSER_IPC_H_
-
-#include "base/basictypes.h"
-#include "v8/include/v8.h"
-
-namespace atom {
-
-namespace api {
-
-class BrowserIPC {
- public:
-  static void Initialize(v8::Handle<v8::Object> target);
-
- private:
-  static void Send(const v8::FunctionCallbackInfo<v8::Value>& args);
-
-  DISALLOW_IMPLICIT_CONSTRUCTORS(BrowserIPC);
-};
-
-}  // namespace api
-
-}  // namespace atom
-
-#endif  // ATOM_BROWSER_API_ATOM_API_BROWSER_IPC_H_