summaryrefslogtreecommitdiffstats
path: root/webkit/glue/devtools/devtools_rpc_js.h
blob: 761f59006d4e14f8b09c8f553e5c184ac566c4af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Additional set of macros for the JS RPC.

#ifndef WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_JS_H_
#define WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_JS_H_

// Do not remove this one although it is not used.
#include <wtf/Noncopyable.h>
#include <wtf/OwnPtr.h>

#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "webkit/glue/devtools/bound_object.h"
#include "webkit/glue/devtools/devtools_rpc.h"
#include "webkit/glue/glue_util.h"

///////////////////////////////////////////////////////
// JS RPC binds and stubs

#define TOOLS_RPC_JS_BIND_METHOD0(Method) \
  bound_obj.AddProtoFunction(#Method, OCLASS::Js##Method);

#define TOOLS_RPC_JS_BIND_METHOD1(Method, T1) \
  bound_obj.AddProtoFunction(#Method, OCLASS::Js##Method);

#define TOOLS_RPC_JS_BIND_METHOD2(Method, T1, T2) \
  bound_obj.AddProtoFunction(#Method, OCLASS::Js##Method);

#define TOOLS_RPC_JS_BIND_METHOD3(Method, T1, T2, T3) \
  bound_obj.AddProtoFunction(#Method, OCLASS::Js##Method);

#define TOOLS_RPC_JS_STUB_METHOD0(Method) \
  static v8::Handle<v8::Value> Js##Method(const v8::Arguments& args) { \
    SendRpcMessageFromJs(#Method, args, 0); \
    return v8::Undefined(); \
  }

#define TOOLS_RPC_JS_STUB_METHOD1(Method, T1) \
  static v8::Handle<v8::Value> Js##Method(const v8::Arguments& args) { \
    SendRpcMessageFromJs(#Method, args, 1); \
    return v8::Undefined(); \
  }

#define TOOLS_RPC_JS_STUB_METHOD2(Method, T1, T2) \
  static v8::Handle<v8::Value> Js##Method(const v8::Arguments& args) { \
    SendRpcMessageFromJs(#Method, args, 2); \
    return v8::Undefined(); \
  }

#define TOOLS_RPC_JS_STUB_METHOD3(Method, T1, T2, T3) \
  static v8::Handle<v8::Value> Js##Method(const v8::Arguments& args) { \
    SendRpcMessageFromJs(#Method, args, 3); \
    return v8::Undefined(); \
  }

///////////////////////////////////////////////////////
// JS RPC main obj macro

#define DEFINE_RPC_JS_BOUND_OBJ(Class, STRUCT, DClass, DELEGATE_STRUCT) \
class Js##Class##BoundObj : public Class##Stub { \
 public: \
  Js##Class##BoundObj(Delegate* rpc_delegate, \
                      v8::Handle<v8::Context> context, \
                      const char* classname) \
      : Class##Stub(rpc_delegate) { \
    BoundObject bound_obj(context, this, classname); \
    STRUCT( \
        TOOLS_RPC_JS_BIND_METHOD0, \
        TOOLS_RPC_JS_BIND_METHOD1, \
        TOOLS_RPC_JS_BIND_METHOD2, \
        TOOLS_RPC_JS_BIND_METHOD3) \
    bound_obj.Build(); \
  } \
  virtual ~Js##Class##BoundObj() {} \
  typedef Js##Class##BoundObj OCLASS; \
  STRUCT( \
      TOOLS_RPC_JS_STUB_METHOD0, \
      TOOLS_RPC_JS_STUB_METHOD1, \
      TOOLS_RPC_JS_STUB_METHOD2, \
      TOOLS_RPC_JS_STUB_METHOD3) \
 private: \
  static void SendRpcMessageFromJs(const char* method, \
                                   const v8::Arguments& js_arguments, \
                                   size_t args_count) { \
    Vector<String> args(args_count); \
    for (size_t i = 0; i < args_count; i++) { \
      args[i].swap(WebCore::toWebCoreStringWithNullCheck(js_arguments[i])); \
    } \
    void* self_ptr = v8::External::Cast(*js_arguments.Data())->Value(); \
    Js##Class##BoundObj* self = static_cast<Js##Class##BoundObj*>(self_ptr); \
    self->SendRpcMessage(#Class, method, args); \
  } \
};

#endif  // WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_JS_H_