From cad7b942f7e9eb447cf34f5e9355e0b634e565e6 Mon Sep 17 00:00:00 2001 From: "pfeldman@chromium.org" Date: Fri, 15 May 2009 09:00:53 +0000 Subject: DevTools: simplify client dispatch via moving it into javascript. Review URL: http://codereview.chromium.org/113450 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16150 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/devtools/devtools_rpc_js.h | 99 +--------------------------------- webkit/glue/devtools/js/devtools.js | 23 ++++++++ webkit/glue/webdevtoolsclient_impl.cc | 14 ++--- 3 files changed, 28 insertions(+), 108 deletions(-) (limited to 'webkit') diff --git a/webkit/glue/devtools/devtools_rpc_js.h b/webkit/glue/devtools/devtools_rpc_js.h index e70672dd8c..7f9f856 100644 --- a/webkit/glue/devtools/devtools_rpc_js.h +++ b/webkit/glue/devtools/devtools_rpc_js.h @@ -110,110 +110,15 @@ struct RpcJsTypeTrait { } /////////////////////////////////////////////////////// -// JS RPC dispatch method implementations - -#define TOOLS_RPC_JS_DISPATCH0(Method) \ -if (method_name == #Method) { \ - *expr = StringPrintf("%s.%s()", js_obj.c_str(), #Method); \ - return true; \ -} - -#define TOOLS_RPC_JS_DISPATCH1(Method, T1) \ -if (method_name == #Method) { \ - Value* t1; \ - message.Get(2, &t1); \ - *expr = StringPrintf("%s.%s(%s)", js_obj.c_str(), #Method, \ - DevToolsRpc::Serialize(*t1).c_str()); \ - return true; \ -} - -#define TOOLS_RPC_JS_DISPATCH2(Method, T1, T2) \ -if (method_name == #Method) { \ - Value* t1; \ - Value* t2; \ - message.Get(2, &t1); \ - message.Get(3, &t2); \ - *expr = StringPrintf("%s.%s(%s, %s)", js_obj.c_str(), #Method, \ - DevToolsRpc::Serialize(*t1).c_str(), \ - DevToolsRpc::Serialize(*t2).c_str()); \ - return true; \ -} - -#define TOOLS_RPC_JS_DISPATCH3(Method, T1, T2, T3) \ -if (method_name == #Method) { \ - Value* t1; \ - Value* t2; \ - Value* t3; \ - message.Get(2, &t1); \ - message.Get(3, &t2); \ - message.Get(4, &t3); \ - *expr = StringPrintf("%s.%s(%s, %s, %s)", js_obj.c_str(), #Method, \ - DevToolsRpc::Serialize(*t1).c_str(), \ - DevToolsRpc::Serialize(*t2).c_str(), \ - DevToolsRpc::Serialize(*t3).c_str()); \ - return true; \ -} - -#define TOOLS_RPC_JS_DISPATCH4(Method, T1, T2, T3, T4) \ -if (method_name == #Method) { \ - Value* t1; \ - Value* t2; \ - Value* t3; \ - Value* t4; \ - message.Get(2, &t1); \ - message.Get(3, &t2); \ - message.Get(4, &t3); \ - message.Get(5, &t4); \ - *expr = StringPrintf("%s.%s(%s, %s, %s, %s)", js_obj.c_str(), #Method, \ - DevToolsRpc::Serialize(*t1).c_str(), \ - DevToolsRpc::Serialize(*t2).c_str(), \ - DevToolsRpc::Serialize(*t3).c_str(), \ - DevToolsRpc::Serialize(*t4).c_str()); \ - return true; \ -} - -#define DEFINE_RPC_JS_DISPATCH(Class, STRUCT) \ -class Js##Class##Dispatch { \ - public: \ - explicit Js##Class##Dispatch(const std::wstring& classname) \ - : js_obj(WideToUTF8(classname)) {} \ - virtual ~Js##Class##Dispatch() {} \ - \ - bool Dispatch(const ListValue& message, std::string* expr) { \ - std::string class_name; \ - message.GetString(0, &class_name); \ - if (class_name != #Class) { \ - return false; \ - } \ - std::string method_name; \ - message.GetString(1, &method_name); \ - typedef Class CLASS; \ - STRUCT( \ - TOOLS_RPC_JS_DISPATCH0, \ - TOOLS_RPC_JS_DISPATCH1, \ - TOOLS_RPC_JS_DISPATCH2, \ - TOOLS_RPC_JS_DISPATCH3, \ - TOOLS_RPC_JS_DISPATCH4) \ - return false; \ - } \ - private: \ - std::string js_obj; \ - DISALLOW_COPY_AND_ASSIGN(Js##Class##Dispatch); \ -}; - -/////////////////////////////////////////////////////// // JS RPC main obj macro #define DEFINE_RPC_JS_BOUND_OBJ(Class, STRUCT, DClass, DELEGATE_STRUCT) \ -DEFINE_RPC_JS_DISPATCH(DClass, DELEGATE_STRUCT) \ class Js##Class##BoundObj : public Class##Stub, \ - public CppBoundClass, \ - public Js##DClass##Dispatch { \ + public CppBoundClass { \ public: \ Js##Class##BoundObj(Delegate* rpc_delegate, WebFrame* frame, \ const std::wstring& classname) \ - : Class##Stub(rpc_delegate), \ - Js##DClass##Dispatch(classname) { \ + : Class##Stub(rpc_delegate) { \ BindToJavascript(frame, classname); \ STRUCT( \ TOOLS_RPC_JS_BIND_METHOD0, \ diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js index 70b8bba..5b065f87 100644 --- a/webkit/glue/devtools/js/devtools.js +++ b/webkit/glue/devtools/js/devtools.js @@ -13,6 +13,29 @@ goog.require('devtools.DebuggerAgent'); goog.require('devtools.DomAgent'); goog.require('devtools.NetAgent'); + +/** + * Dispatches raw message from the host. + * @param {Object} msg Message to dispatch. + */ +devtools.dispatch = function(msg) { + var delegate = msg[0]; + var methodName = msg[1]; + var remoteName = 'Remote' + delegate.substring(0, delegate.length - 8); + var agent = window[remoteName]; + if (!agent) { + debugPrint('No remote agent "' + remoteName + '" found.'); + return; + } + var method = agent[methodName]; + if (!method) { + debugPrint('No method "' + remoteName + '.' + methodName + '" found.'); + return; + } + method.apply(this, msg.slice(2)); +}; + + devtools.ToolsAgent = function() { RemoteToolsAgent.DidEvaluateJavaScript = devtools.Callback.processCallback; RemoteToolsAgent.DidExecuteUtilityFunction = diff --git a/webkit/glue/webdevtoolsclient_impl.cc b/webkit/glue/webdevtoolsclient_impl.cc index 7de27db..d4f1f00 100644 --- a/webkit/glue/webdevtoolsclient_impl.cc +++ b/webkit/glue/webdevtoolsclient_impl.cc @@ -158,17 +158,9 @@ void WebDevToolsClientImpl::DispatchMessageFromAgent( pending_incoming_messages_.append(raw_msg); return; } - OwnPtr message( - static_cast(DevToolsRpc::ParseMessage(raw_msg))); - - std::string expr; - if (dom_agent_obj_->Dispatch(*message.get(), &expr) - || net_agent_obj_->Dispatch(*message.get(), &expr) - || tools_agent_obj_->Dispatch(*message.get(), &expr) - || debugger_agent_obj_->Dispatch(*message.get(), &expr)) { - web_view_impl_->GetMainFrame()->ExecuteScript( - WebScriptSource(WebString::fromUTF8(expr))); - } + std::string expr = StringPrintf("devtools.dispatch(%s)", raw_msg.c_str()); + web_view_impl_->GetMainFrame()->ExecuteScript( + WebScriptSource(WebString::fromUTF8(expr))); } void WebDevToolsClientImpl::SendRpcMessage(const std::string& raw_msg) { -- cgit v1.1