diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-31 14:18:12 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-31 14:18:12 +0000 |
commit | a4886765ba2e32b77bc9c8f5f75f33779fb2ae17 (patch) | |
tree | ba6e0ee1bde1a5ce6c22c42ad33f3c5658a3d071 | |
parent | 97c4e8980c65df6fa56f87c09a820ec7626d2e02 (diff) | |
download | chromium_src-a4886765ba2e32b77bc9c8f5f75f33779fb2ae17.zip chromium_src-a4886765ba2e32b77bc9c8f5f75f33779fb2ae17.tar.gz chromium_src-a4886765ba2e32b77bc9c8f5f75f33779fb2ae17.tar.bz2 |
DevTools: Migrate from CppBound class to devtools bound object.
Review URL: http://codereview.chromium.org/183014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24878 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/devtools/devtools_rpc_js.h | 108 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsclient_impl.cc | 59 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsclient_impl.h | 6 |
3 files changed, 74 insertions, 99 deletions
diff --git a/webkit/glue/devtools/devtools_rpc_js.h b/webkit/glue/devtools/devtools_rpc_js.h index bb54150..8830d19 100644 --- a/webkit/glue/devtools/devtools_rpc_js.h +++ b/webkit/glue/devtools/devtools_rpc_js.h @@ -14,103 +14,77 @@ #include "base/basictypes.h" #include "webkit/api/public/WebFrame.h" -#include "webkit/glue/cpp_bound_class.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 -template<typename T> -struct RpcJsTypeTrait { -}; - -template<> -struct RpcJsTypeTrait<bool> { - static std::string ToString(const CppVariant& var) { - return IntToString(var.ToBoolean() ? 1 : 0); - } -}; - -template<> -struct RpcJsTypeTrait<int> { - static std::string ToString(const CppVariant& var) { - return IntToString(var.ToInt32()); - } -}; - -template<> -struct RpcJsTypeTrait<String> { - static std::string ToString(const CppVariant& var) { - return var.ToString(); - } -}; - -template<> -struct RpcJsTypeTrait<std::string> { - static std::string ToString(const CppVariant& var) { - return var.ToString(); - } -}; - #define TOOLS_RPC_JS_BIND_METHOD0(Method) \ - BindMethod(#Method, &OCLASS::Js##Method); + bound_obj_->AddProtoFunction(#Method, OCLASS::Js##Method); #define TOOLS_RPC_JS_BIND_METHOD1(Method, T1) \ - BindMethod(#Method, &OCLASS::Js##Method); + bound_obj_->AddProtoFunction(#Method, OCLASS::Js##Method); #define TOOLS_RPC_JS_BIND_METHOD2(Method, T1, T2) \ - BindMethod(#Method, &OCLASS::Js##Method); + bound_obj_->AddProtoFunction(#Method, OCLASS::Js##Method); #define TOOLS_RPC_JS_BIND_METHOD3(Method, T1, T2, T3) \ - BindMethod(#Method, &OCLASS::Js##Method); + bound_obj_->AddProtoFunction(#Method, OCLASS::Js##Method); #define TOOLS_RPC_JS_STUB_METHOD0(Method) \ - void Js##Method(const CppArgumentList& args, CppVariant* result) { \ - this->delegate_->SendRpcMessage(class_name, #Method); \ - result->SetNull(); \ + static v8::Handle<v8::Value> Js##Method(const v8::Arguments& args) { \ + SendRpcMessage(v8::External::Cast(*args.Data())->Value(), \ + #Method, "", "", ""); \ + return v8::Undefined(); \ } #define TOOLS_RPC_JS_STUB_METHOD1(Method, T1) \ - void Js##Method(const CppArgumentList& args, CppVariant* result) { \ - this->delegate_->SendRpcMessage(class_name, #Method, \ - RpcJsTypeTrait<T1>::ToString(args[0])); \ - result->SetNull(); \ + static v8::Handle<v8::Value> Js##Method(const v8::Arguments& args) { \ + SendRpcMessage(v8::External::Cast(*args.Data())->Value(), \ + #Method, \ + WebCore::toWebCoreStringWithNullCheck(args[0]), "", ""); \ + return v8::Undefined(); \ } #define TOOLS_RPC_JS_STUB_METHOD2(Method, T1, T2) \ - void Js##Method(const CppArgumentList& args, CppVariant* result) { \ - this->delegate_->SendRpcMessage(class_name, #Method, \ - RpcJsTypeTrait<T1>::ToString(args[0]), \ - RpcJsTypeTrait<T2>::ToString(args[1])); \ - result->SetNull(); \ + static v8::Handle<v8::Value> Js##Method(const v8::Arguments& args) { \ + SendRpcMessage(v8::External::Cast(*args.Data())->Value(), \ + #Method, \ + WebCore::toWebCoreStringWithNullCheck(args[0]), \ + WebCore::toWebCoreStringWithNullCheck(args[1]), \ + ""); \ + return v8::Undefined(); \ } #define TOOLS_RPC_JS_STUB_METHOD3(Method, T1, T2, T3) \ - void Js##Method(const CppArgumentList& args, CppVariant* result) { \ - this->delegate_->SendRpcMessage(class_name, #Method, \ - RpcJsTypeTrait<T1>::ToString(args[0]), \ - RpcJsTypeTrait<T2>::ToString(args[1]), \ - RpcJsTypeTrait<T3>::ToString(args[2])); \ - result->SetNull(); \ + static v8::Handle<v8::Value> Js##Method(const v8::Arguments& args) { \ + SendRpcMessage(v8::External::Cast(*args.Data())->Value(), \ + #Method, \ + WebCore::toWebCoreStringWithNullCheck(args[0]), \ + WebCore::toWebCoreStringWithNullCheck(args[1]), \ + WebCore::toWebCoreStringWithNullCheck(args[2])); \ + 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 CppBoundClass { \ +class Js##Class##BoundObj : public Class##Stub { \ public: \ - Js##Class##BoundObj(Delegate* rpc_delegate, WebFrame* frame, \ - const std::wstring& classname) \ + Js##Class##BoundObj(Delegate* rpc_delegate, \ + v8::Handle<v8::Context> context, \ + const char* classname) \ : Class##Stub(rpc_delegate) { \ - BindToJavascript(frame, classname); \ + bound_obj_.set(new BoundObject(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; \ @@ -120,6 +94,20 @@ class Js##Class##BoundObj : public Class##Stub, \ TOOLS_RPC_JS_STUB_METHOD2, \ TOOLS_RPC_JS_STUB_METHOD3) \ private: \ + static void SendRpcMessage(void* self_ptr, \ + const char* method, \ + const String& param1, \ + const String& param2, \ + const String& param3) { \ + Js##Class##BoundObj* self = static_cast<Js##Class##BoundObj*>(self_ptr); \ + self->delegate_->SendRpcMessage( \ + #Class, \ + method, \ + webkit_glue::StringToStdString(param1), \ + webkit_glue::StringToStdString(param2), \ + webkit_glue::StringToStdString(param3)); \ + } \ + OwnPtr<BoundObject> bound_obj_; \ DISALLOW_COPY_AND_ASSIGN(Js##Class##BoundObj); \ }; diff --git a/webkit/glue/webdevtoolsclient_impl.cc b/webkit/glue/webdevtoolsclient_impl.cc index a0cfe1b..d580d65 100644 --- a/webkit/glue/webdevtoolsclient_impl.cc +++ b/webkit/glue/webdevtoolsclient_impl.cc @@ -95,35 +95,6 @@ class ToolsAgentNativeDelegateImpl : public ToolsAgentNativeDelegate { DISALLOW_COPY_AND_ASSIGN(ToolsAgentNativeDelegateImpl); }; -namespace { - -class RemoteDebuggerCommandExecutor : public CppBoundClass { - public: - RemoteDebuggerCommandExecutor( - WebDevToolsClientDelegate* delegate, - WebFrame* frame, - const std::wstring& classname) - : delegate_(delegate) { - BindToJavascript(frame, classname); - BindMethod("DebuggerCommand", - &RemoteDebuggerCommandExecutor::DebuggerCommand); - } - virtual ~RemoteDebuggerCommandExecutor() {} - - // The DebuggerCommand() function provided to Javascript. - void DebuggerCommand(const CppArgumentList& args, CppVariant* result) { - std::string command = args[0].ToString(); - result->SetNull(); - delegate_->SendDebuggerCommandToAgent(command); - } - - private: - WebDevToolsClientDelegate* delegate_; - DISALLOW_COPY_AND_ASSIGN(RemoteDebuggerCommandExecutor); -}; - -} // namespace - // static WebDevToolsClient* WebDevToolsClient::Create( WebView* view, @@ -143,17 +114,22 @@ WebDevToolsClientImpl::WebDevToolsClientImpl( application_locale_(application_locale.c_str()), loaded_(false) { WebFrameImpl* frame = web_view_impl_->main_frame(); + v8::HandleScope scope; + v8::Handle<v8::Context> frame_context = V8Proxy::context(frame->frame()); - // Debugger commands should be sent using special method. - debugger_command_executor_obj_.set(new RemoteDebuggerCommandExecutor( - delegate, frame, L"RemoteDebuggerCommandExecutor")); debugger_agent_obj_.set(new JsDebuggerAgentBoundObj( - this, frame, L"RemoteDebuggerAgent")); + this, frame_context, "RemoteDebuggerAgent")); tools_agent_obj_.set( - new JsToolsAgentBoundObj(this, frame, L"RemoteToolsAgent")); + new JsToolsAgentBoundObj(this, frame_context, "RemoteToolsAgent")); + + // Debugger commands should be sent using special method. + debugger_command_executor_obj_.set( + new BoundObject(frame_context, this, "RemoteDebuggerCommandExecutor")); + debugger_command_executor_obj_->AddProtoFunction( + "DebuggerCommand", + WebDevToolsClientImpl::JsDebuggerCommand); + debugger_command_executor_obj_->Build(); - v8::HandleScope scope; - v8::Handle<v8::Context> frame_context = V8Proxy::context(frame->frame()); dev_tools_host_.set(new BoundObject(frame_context, this, "DevToolsHost")); dev_tools_host_->AddProtoFunction( "reset", @@ -408,3 +384,14 @@ v8::Handle<v8::Value> WebDevToolsClientImpl::JsGetApplicationLocale( v8::External::Cast(*args.Data())->Value()); return v8String(client->application_locale_); } + +// static +v8::Handle<v8::Value> WebDevToolsClientImpl::JsDebuggerCommand( + const v8::Arguments& args) { + WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( + v8::External::Cast(*args.Data())->Value()); + String command = WebCore::toWebCoreStringWithNullCheck(args[0]); + std::string std_command = webkit_glue::StringToStdString(command); + client->delegate_->SendDebuggerCommandToAgent(std_command); + return v8::Undefined(); +} diff --git a/webkit/glue/webdevtoolsclient_impl.h b/webkit/glue/webdevtoolsclient_impl.h index e58414a..b817a23 100644 --- a/webkit/glue/webdevtoolsclient_impl.h +++ b/webkit/glue/webdevtoolsclient_impl.h @@ -12,7 +12,6 @@ #include <wtf/RefPtr.h> #include "v8.h" -#include "webkit/glue/cpp_bound_class.h" #include "webkit/glue/devtools/devtools_rpc.h" #include "webkit/glue/webdevtoolsclient.h" @@ -31,7 +30,6 @@ class WebDevToolsClientDelegate; class WebViewImpl; class WebDevToolsClientImpl : public WebDevToolsClient, - public CppBoundClass, public DevToolsRpc::Delegate { public: WebDevToolsClientImpl( @@ -75,11 +73,13 @@ class WebDevToolsClientImpl : public WebDevToolsClient, const v8::Arguments& args); static v8::Handle<v8::Value> JsGetApplicationLocale( const v8::Arguments& args); + static v8::Handle<v8::Value> JsDebuggerCommand( + const v8::Arguments& args); WebViewImpl* web_view_impl_; WebDevToolsClientDelegate* delegate_; String application_locale_; - OwnPtr<CppBoundClass> debugger_command_executor_obj_; + OwnPtr<BoundObject> debugger_command_executor_obj_; OwnPtr<JsDebuggerAgentBoundObj> debugger_agent_obj_; OwnPtr<JsToolsAgentBoundObj> tools_agent_obj_; bool loaded_; |