WebKit/chromium/src/DevToolsRPCJS.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2010 Google Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions are
       
     6  * met:
       
     7  *
       
     8  *     * Redistributions of source code must retain the above copyright
       
     9  * notice, this list of conditions and the following disclaimer.
       
    10  *     * Redistributions in binary form must reproduce the above
       
    11  * copyright notice, this list of conditions and the following disclaimer
       
    12  * in the documentation and/or other materials provided with the
       
    13  * distribution.
       
    14  *     * Neither the name of Google Inc. nor the names of its
       
    15  * contributors may be used to endorse or promote products derived from
       
    16  * this software without specific prior written permission.
       
    17  *
       
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29  */
       
    30 
       
    31 // Additional set of macros for the JS RPC.
       
    32 
       
    33 #ifndef DevToolsRPCJS_h
       
    34 #define DevToolsRPCJS_h
       
    35 
       
    36 // Do not remove this one although it is not used.
       
    37 #include "BoundObject.h"
       
    38 #include "DevToolsRPC.h"
       
    39 #include "WebFrame.h"
       
    40 #include <wtf/Noncopyable.h>
       
    41 #include <wtf/OwnPtr.h>
       
    42 
       
    43 namespace WebKit {
       
    44 
       
    45 ///////////////////////////////////////////////////////
       
    46 // JS RPC binds and stubs
       
    47 
       
    48 #define TOOLS_RPC_JS_BIND_METHOD0(Method) \
       
    49     boundObj.addProtoFunction(#Method, OCLASS::js##Method);
       
    50 
       
    51 #define TOOLS_RPC_JS_BIND_METHOD1(Method, T1) \
       
    52     boundObj.addProtoFunction(#Method, OCLASS::js##Method);
       
    53 
       
    54 #define TOOLS_RPC_JS_BIND_METHOD2(Method, T1, T2) \
       
    55     boundObj.addProtoFunction(#Method, OCLASS::js##Method);
       
    56 
       
    57 #define TOOLS_RPC_JS_BIND_METHOD3(Method, T1, T2, T3) \
       
    58     boundObj.addProtoFunction(#Method, OCLASS::js##Method);
       
    59 
       
    60 #define TOOLS_RPC_JS_BIND_METHOD4(Method, T1, T2, T3, T4) \
       
    61     boundObj.addProtoFunction(#Method, OCLASS::js##Method);
       
    62 
       
    63 #define TOOLS_RPC_JS_BIND_METHOD5(Method, T1, T2, T3, T4, T5) \
       
    64     boundObj.addProtoFunction(#Method, OCLASS::js##Method);
       
    65 
       
    66 #define TOOLS_RPC_JS_STUB_METHOD0(Method) \
       
    67     static v8::Handle<v8::Value> js##Method(const v8::Arguments& args) { \
       
    68         sendRpcMessageFromJS(#Method, args, 0); \
       
    69         return v8::Undefined(); \
       
    70     }
       
    71 
       
    72 #define TOOLS_RPC_JS_STUB_METHOD1(Method, T1) \
       
    73     static v8::Handle<v8::Value> js##Method(const v8::Arguments& args) { \
       
    74         sendRpcMessageFromJS(#Method, args, 1); \
       
    75         return v8::Undefined(); \
       
    76     }
       
    77 
       
    78 #define TOOLS_RPC_JS_STUB_METHOD2(Method, T1, T2) \
       
    79     static v8::Handle<v8::Value> js##Method(const v8::Arguments& args) { \
       
    80         sendRpcMessageFromJS(#Method, args, 2); \
       
    81         return v8::Undefined(); \
       
    82     }
       
    83 
       
    84 #define TOOLS_RPC_JS_STUB_METHOD3(Method, T1, T2, T3) \
       
    85     static v8::Handle<v8::Value> js##Method(const v8::Arguments& args) { \
       
    86         sendRpcMessageFromJS(#Method, args, 3); \
       
    87         return v8::Undefined(); \
       
    88     }
       
    89 
       
    90 #define TOOLS_RPC_JS_STUB_METHOD4(Method, T1, T2, T3, T4) \
       
    91     static v8::Handle<v8::Value> js##Method(const v8::Arguments& args) { \
       
    92         sendRpcMessageFromJS(#Method, args, 4); \
       
    93         return v8::Undefined(); \
       
    94     }
       
    95 
       
    96 #define TOOLS_RPC_JS_STUB_METHOD5(Method, T1, T2, T3, T4, T5) \
       
    97     static v8::Handle<v8::Value> js##Method(const v8::Arguments& args) { \
       
    98         sendRpcMessageFromJS(#Method, args, 5); \
       
    99         return v8::Undefined(); \
       
   100     }
       
   101 
       
   102 ///////////////////////////////////////////////////////
       
   103 // JS RPC main obj macro
       
   104 
       
   105 #define DEFINE_RPC_JS_BOUND_OBJ(Class, STRUCT, DClass, DELEGATE_STRUCT) \
       
   106 class JS##Class##BoundObj : public Class##Stub { \
       
   107 public: \
       
   108     JS##Class##BoundObj(Delegate* rpcDelegate, \
       
   109                         v8::Handle<v8::Context> context, \
       
   110                         const char* classname) \
       
   111         : Class##Stub(rpcDelegate) { \
       
   112       BoundObject boundObj(context, this, classname); \
       
   113       STRUCT( \
       
   114           TOOLS_RPC_JS_BIND_METHOD0, \
       
   115           TOOLS_RPC_JS_BIND_METHOD1, \
       
   116           TOOLS_RPC_JS_BIND_METHOD2, \
       
   117           TOOLS_RPC_JS_BIND_METHOD3, \
       
   118           TOOLS_RPC_JS_BIND_METHOD4, \
       
   119           TOOLS_RPC_JS_BIND_METHOD5) \
       
   120       boundObj.build(); \
       
   121     } \
       
   122     virtual ~JS##Class##BoundObj() { } \
       
   123     typedef JS##Class##BoundObj OCLASS; \
       
   124     STRUCT( \
       
   125         TOOLS_RPC_JS_STUB_METHOD0, \
       
   126         TOOLS_RPC_JS_STUB_METHOD1, \
       
   127         TOOLS_RPC_JS_STUB_METHOD2, \
       
   128         TOOLS_RPC_JS_STUB_METHOD3, \
       
   129         TOOLS_RPC_JS_STUB_METHOD4, \
       
   130         TOOLS_RPC_JS_STUB_METHOD5) \
       
   131 private: \
       
   132     static void sendRpcMessageFromJS(const char* method, \
       
   133                                      const v8::Arguments& jsArguments, \
       
   134                                      size_t argsCount) \
       
   135     { \
       
   136         Vector<String> args(argsCount); \
       
   137         for (size_t i = 0; i < argsCount; i++) \
       
   138             args[i] = WebCore::toWebCoreStringWithNullCheck(jsArguments[i]); \
       
   139         void* selfPtr = v8::External::Cast(*jsArguments.Data())->Value(); \
       
   140         JS##Class##BoundObj* self = static_cast<JS##Class##BoundObj*>(selfPtr); \
       
   141         self->sendRpcMessage(#Class, method, args); \
       
   142     } \
       
   143 };
       
   144 
       
   145 } // namespace WebKit
       
   146 
       
   147 #endif