diff options
author | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-11 09:08:17 +0000 |
---|---|---|
committer | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-11 09:08:17 +0000 |
commit | 221f4130ad35eb3074ee079dae571157da727a9d (patch) | |
tree | d647bcdd73ef1e35568d4beb3a7a0e3ed4d4b993 | |
parent | 797f01294b84d46813da707e0ed406dfd27a0f35 (diff) | |
download | chromium_src-221f4130ad35eb3074ee079dae571157da727a9d.zip chromium_src-221f4130ad35eb3074ee079dae571157da727a9d.tar.gz chromium_src-221f4130ad35eb3074ee079dae571157da727a9d.tar.bz2 |
DevTools: use WebDevToolsMessageData for devtools rpc messages
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=34333
Review URL: http://codereview.chromium.org/463065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34337 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 269 insertions, 301 deletions
diff --git a/chrome/browser/debugger/inspectable_tab_proxy.cc b/chrome/browser/debugger/inspectable_tab_proxy.cc index 29e5d32..159be0b 100644 --- a/chrome/browser/debugger/inspectable_tab_proxy.cc +++ b/chrome/browser/debugger/inspectable_tab_proxy.cc @@ -34,21 +34,18 @@ void DevToolsClientHostImpl::SendMessageToClient( IPC_END_MESSAGE_MAP() } -void DevToolsClientHostImpl::OnRpcMessage(const std::string& class_name, - const std::string& message_name, - const std::string& param1, - const std::string& param2, - const std::string& param3) { +void DevToolsClientHostImpl::OnRpcMessage(const DevToolsMessageData& data) { static const std::string kDebuggerAgentDelegate = "DebuggerAgentDelegate"; static const std::string kToolsAgentDelegate = "ToolsAgentDelegate"; static const std::string kDebuggerOutput = "DebuggerOutput"; static const std::string kFrameNavigate = "FrameNavigate"; - if (class_name == kDebuggerAgentDelegate && message_name == kDebuggerOutput) { - DebuggerOutput(param1); - } else if (class_name == kToolsAgentDelegate && - message_name == kFrameNavigate) { - FrameNavigate(param1); + if (data.class_name == kDebuggerAgentDelegate && + data.method_name == kDebuggerOutput) { + DebuggerOutput(data.arguments[0]); + } else if (data.class_name == kToolsAgentDelegate && + data.method_name == kFrameNavigate) { + FrameNavigate(data.arguments[0]); } } diff --git a/chrome/browser/debugger/inspectable_tab_proxy.h b/chrome/browser/debugger/inspectable_tab_proxy.h index 13da2ec..67b5952 100644 --- a/chrome/browser/debugger/inspectable_tab_proxy.h +++ b/chrome/browser/debugger/inspectable_tab_proxy.h @@ -15,6 +15,7 @@ class DebuggerRemoteService; class DevToolsClientHost; class DevToolsClientHostImpl; class NavigationController; +struct DevToolsMessageData; // Proxies debugged tabs' NavigationControllers using their UIDs. // Keeps track of tabs being debugged so that we can detach from @@ -81,11 +82,7 @@ class DevToolsClientHostImpl : public DevToolsClientHost { private: // Message handling routines - void OnRpcMessage(const std::string& class_name, - const std::string& message_name, - const std::string& param1, - const std::string& param2, - const std::string& param3); + void OnRpcMessage(const DevToolsMessageData& data); void DebuggerOutput(const std::string& msg); void FrameNavigate(const std::string& url); void TabClosed(); diff --git a/chrome/browser/extensions/extension_devtools_bridge.cc b/chrome/browser/extensions/extension_devtools_bridge.cc index 99f515b..dcf6375 100644 --- a/chrome/browser/extensions/extension_devtools_bridge.cc +++ b/chrome/browser/extensions/extension_devtools_bridge.cc @@ -80,16 +80,12 @@ void ExtensionDevToolsBridge::SendMessageToClient(const IPC::Message& msg) { static const char kApuAgentClassName[] = "ApuAgentDelegate"; static const char kApuPageEventMessageName[] = "DispatchToApu"; -void ExtensionDevToolsBridge::OnRpcMessage(const std::string& class_name, - const std::string& message_name, - const std::string& param1, - const std::string& param2, - const std::string& param3) { +void ExtensionDevToolsBridge::OnRpcMessage(const DevToolsMessageData& data) { DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - if (class_name == kApuAgentClassName - && message_name == kApuPageEventMessageName) { - std::string json = StringPrintf("[%s]", param1.c_str()); + if (data.class_name == kApuAgentClassName + && data.method_name == kApuPageEventMessageName) { + std::string json = StringPrintf("[%s]", data.arguments[0].c_str()); profile_->GetExtensionMessageService()->DispatchEventToRenderers( on_page_event_name_, json); } diff --git a/chrome/browser/extensions/extension_devtools_bridge.h b/chrome/browser/extensions/extension_devtools_bridge.h index 1745ef7..5543b97 100644 --- a/chrome/browser/extensions/extension_devtools_bridge.h +++ b/chrome/browser/extensions/extension_devtools_bridge.h @@ -13,6 +13,7 @@ #include "chrome/browser/extensions/extension_message_service.h" class Profile; +struct DevToolsMessageData; // This class is a DevToolsClientHost that fires extension events. class ExtensionDevToolsBridge : public DevToolsClientHost { @@ -31,11 +32,7 @@ class ExtensionDevToolsBridge : public DevToolsClientHost { virtual void SendMessageToClient(const IPC::Message& msg); private: - void OnRpcMessage(const std::string& class_name, - const std::string& message_name, - const std::string& param1, - const std::string& param2, - const std::string& param3); + void OnRpcMessage(const DevToolsMessageData& data); // ID of the tab we are monitoring. int tab_id_; diff --git a/chrome/browser/extensions/extension_devtools_browsertests.cc b/chrome/browser/extensions/extension_devtools_browsertests.cc index a2eff3c..cf6ffd5 100644 --- a/chrome/browser/extensions/extension_devtools_browsertests.cc +++ b/chrome/browser/extensions/extension_devtools_browsertests.cc @@ -81,8 +81,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, TimelineApi) { // Test onPageEvent event. result = false; - DevToolsClientMsg_RpcMessage pageEventMessage( - "ApuAgentDelegate", "DispatchToApu", "", "", ""); + + DevToolsMessageData message_data; + message_data.class_name = "ApuAgentDelegate"; + message_data.method_name = "DispatchToApu"; + DevToolsClientMsg_RpcMessage pageEventMessage(message_data); devtools_client_host->SendMessageToClient(pageEventMessage); ui_test_utils::ExecuteJavaScriptAndExtractBool( host->render_view_host(), L"", L"testReceivePageEvent()", &result); diff --git a/chrome/common/devtools_messages.h b/chrome/common/devtools_messages.h index abb740d..6c095f4 100644 --- a/chrome/common/devtools_messages.h +++ b/chrome/common/devtools_messages.h @@ -5,6 +5,33 @@ #ifndef CHROME_COMMON_DEVTOOLS_MESSAGES_H_ #define CHROME_COMMON_DEVTOOLS_MESSAGES_H_ +#include "ipc/ipc_message_utils.h" +#include "webkit/glue/devtools/devtools_message_data.h" + +namespace IPC { + +// Traits for DevToolsMessageData structure to pack/unpack. +template <> +struct ParamTraits<DevToolsMessageData> { + typedef DevToolsMessageData param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, p.class_name); + WriteParam(m, p.method_name); + WriteParam(m, p.arguments); + } + static bool Read(const Message* m, void** iter, param_type* p) { + return + ReadParam(m, iter, &p->class_name) && + ReadParam(m, iter, &p->method_name) && + ReadParam(m, iter, &p->arguments); + } + static void Log(const param_type& p, std::wstring* l) { + l->append(L"<DevToolsMessageData>"); + } +}; + +} // namespace IPC + #define MESSAGES_INTERNAL_FILE "chrome/common/devtools_messages_internal.h" #include "ipc/ipc_message_macros.h" diff --git a/chrome/common/devtools_messages_internal.h b/chrome/common/devtools_messages_internal.h index d80c0ed..d48ec09 100644 --- a/chrome/common/devtools_messages_internal.h +++ b/chrome/common/devtools_messages_internal.h @@ -43,18 +43,15 @@ // This file describes developer tools message types. #include "ipc/ipc_message_macros.h" +#include "webkit/glue/devtools/devtools_message_data.h" // These are messages sent from DevToolsAgent to DevToolsClient through the // browser. IPC_BEGIN_MESSAGES(DevToolsClient) // Sends glue-level Rpc message to the client. - IPC_MESSAGE_CONTROL5(DevToolsClientMsg_RpcMessage, - std::string /* class_name */, - std::string /* method_name */, - std::string /* p1 */, - std::string /* p2 */, - std::string /* p3 */) + IPC_MESSAGE_CONTROL1(DevToolsClientMsg_RpcMessage, + DevToolsMessageData /* message data */) IPC_END_MESSAGES(DevToolsClient) @@ -72,12 +69,8 @@ IPC_BEGIN_MESSAGES(DevToolsAgent) IPC_MESSAGE_CONTROL0(DevToolsAgentMsg_Detach) // Sends glue-level Rpc message to the agent. - IPC_MESSAGE_CONTROL5(DevToolsAgentMsg_RpcMessage, - std::string /* class_name */, - std::string /* method_name */, - std::string /* p1 */, - std::string /* p2 */, - std::string /* p3 */) + IPC_MESSAGE_CONTROL1(DevToolsAgentMsg_RpcMessage, + DevToolsMessageData /* message data */) // Send debugger command to the debugger agent. Debugger commands should // be handled on IO thread(while all other devtools messages are handled in diff --git a/chrome/renderer/devtools_agent.cc b/chrome/renderer/devtools_agent.cc index d1e81e2..11211fd 100644 --- a/chrome/renderer/devtools_agent.cc +++ b/chrome/renderer/devtools_agent.cc @@ -9,13 +9,16 @@ #include "chrome/renderer/devtools_agent_filter.h" #include "chrome/renderer/render_view.h" #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsMessageData.h" #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "webkit/glue/devtools/devtools_message_data.h" #include "webkit/glue/glue_util.h" using WebKit::WebDevToolsAgent; using WebKit::WebPoint; using WebKit::WebString; +using WebKit::WebVector; using WebKit::WebView; // static @@ -53,19 +56,11 @@ bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { return handled; } -void DevToolsAgent::sendMessageToFrontend(const WebString& class_name, - const WebString& method_name, - const WebString& param1, - const WebString& param2, - const WebString& param3) { +void DevToolsAgent::sendMessageToFrontend( + const WebKit::WebDevToolsMessageData& data) { IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( routing_id_, - DevToolsClientMsg_RpcMessage( - class_name.utf8(), - method_name.utf8(), - param1.utf8(), - param2.utf8(), - param3.utf8())); + DevToolsClientMsg_RpcMessage(DevToolsMessageData(data))); render_view_->Send(m); } @@ -113,19 +108,10 @@ void DevToolsAgent::OnDetach() { } } -void DevToolsAgent::OnRpcMessage(const std::string& class_name, - const std::string& method_name, - const std::string& param1, - const std::string& param2, - const std::string& param3) { +void DevToolsAgent::OnRpcMessage(const DevToolsMessageData& data) { WebDevToolsAgent* web_agent = GetWebAgent(); if (web_agent) { - web_agent->dispatchMessageFromFrontend( - WebString::fromUTF8(class_name), - WebString::fromUTF8(method_name), - WebString::fromUTF8(param1), - WebString::fromUTF8(param2), - WebString::fromUTF8(param3)); + web_agent->dispatchMessageFromFrontend(data.ToWebDevToolsMessageData()); } } @@ -155,15 +141,6 @@ WebDevToolsAgent* DevToolsAgent::GetWebAgent() { // static void WebKit::WebDevToolsAgentClient::sendMessageToFrontendOnIOThread( - const WebString& class_name, - const WebString& method_name, - const WebString& param1, - const WebString& param2, - const WebString& param3) { - DevToolsAgentFilter::SendRpcMessage( - class_name.utf8(), - method_name.utf8(), - param1.utf8(), - param2.utf8(), - param3.utf8()); + const WebDevToolsMessageData& data) { + DevToolsAgentFilter::SendRpcMessage(DevToolsMessageData(data)); } diff --git a/chrome/renderer/devtools_agent.h b/chrome/renderer/devtools_agent.h index 26a6297..4d05fe0 100644 --- a/chrome/renderer/devtools_agent.h +++ b/chrome/renderer/devtools_agent.h @@ -21,6 +21,7 @@ class WebDevToolsAgent; } class RenderView; +struct DevToolsMessageData; // DevToolsAgent belongs to the inspectable RenderView and provides Glue's // agents with the communication capabilities. All messages from/to Glue's @@ -37,11 +38,9 @@ class DevToolsAgent : public WebKit::WebDevToolsAgentClient { virtual bool OnMessageReceived(const IPC::Message& message); // WebDevToolsAgentClient implementation - virtual void sendMessageToFrontend(const WebKit::WebString& class_name, - const WebKit::WebString& method_name, - const WebKit::WebString& param1, - const WebKit::WebString& param2, - const WebKit::WebString& param3); + virtual void sendMessageToFrontend( + const WebKit::WebDevToolsMessageData& data); + virtual int hostIdentifier(); virtual void forceRepaint(); virtual void runtimeFeatureStateChanged(const WebKit::WebString& feature, @@ -59,11 +58,7 @@ class DevToolsAgent : public WebKit::WebDevToolsAgentClient { void OnAttach(const std::vector<std::string>& runtime_features); void OnDetach(); - void OnRpcMessage(const std::string& class_name, - const std::string& method_name, - const std::string& param1, - const std::string& param2, - const std::string& param3); + void OnRpcMessage(const DevToolsMessageData& data); void OnInspectElement(int x, int y); void OnSetApuAgentEnabled(bool enabled); diff --git a/chrome/renderer/devtools_agent_filter.cc b/chrome/renderer/devtools_agent_filter.cc index 375c743..d3a8289 100644 --- a/chrome/renderer/devtools_agent_filter.cc +++ b/chrome/renderer/devtools_agent_filter.cc @@ -11,7 +11,9 @@ #include "chrome/renderer/plugin_channel_host.h" #include "chrome/renderer/render_view.h" #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsMessageData.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "webkit/glue/devtools/devtools_message_data.h" using WebKit::WebDevToolsAgent; using WebKit::WebString; @@ -62,32 +64,15 @@ void DevToolsAgentFilter::OnDebuggerPauseScript() { WebDevToolsAgent::debuggerPauseScript(); } -void DevToolsAgentFilter::OnRpcMessage(const std::string& class_name, - const std::string& method_name, - const std::string& param1, - const std::string& param2, - const std::string& param3) { +void DevToolsAgentFilter::OnRpcMessage(const DevToolsMessageData& data) { message_handled_ = WebDevToolsAgent::dispatchMessageFromFrontendOnIOThread( - WebString::fromUTF8(class_name), - WebString::fromUTF8(method_name), - WebString::fromUTF8(param1), - WebString::fromUTF8(param2), - WebString::fromUTF8(param3)); + data.ToWebDevToolsMessageData()); } // static -void DevToolsAgentFilter::SendRpcMessage(const std::string& class_name, - const std::string& method_name, - const std::string& param1, - const std::string& param2, - const std::string& param3) { +void DevToolsAgentFilter::SendRpcMessage(const DevToolsMessageData& data) { IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( current_routing_id_, - DevToolsClientMsg_RpcMessage( - class_name, - method_name, - param1, - param2, - param3)); + DevToolsClientMsg_RpcMessage(data)); channel_->Send(m); } diff --git a/chrome/renderer/devtools_agent_filter.h b/chrome/renderer/devtools_agent_filter.h index ac5fd0c..8d23918 100644 --- a/chrome/renderer/devtools_agent_filter.h +++ b/chrome/renderer/devtools_agent_filter.h @@ -10,6 +10,8 @@ #include "ipc/ipc_channel_proxy.h" +struct DevToolsMessageData; + // DevToolsAgentFilter is registered as an IPC filter in order to be able to // dispatch messages while on the IO thread. The reason for that is that while // debugging, Render thread is being held by the v8 and hence no messages @@ -22,11 +24,7 @@ class DevToolsAgentFilter : public IPC::ChannelProxy::MessageFilter { DevToolsAgentFilter(); virtual ~DevToolsAgentFilter(); - static void SendRpcMessage(const std::string& class_name, - const std::string& method_name, - const std::string& param1, - const std::string& param2, - const std::string& param3); + static void SendRpcMessage(const DevToolsMessageData& data); private: // IPC::ChannelProxy::MessageFilter override. Called on IO thread. @@ -40,11 +38,7 @@ class DevToolsAgentFilter : public IPC::ChannelProxy::MessageFilter { // handle debug messages even when v8 is stopped. void OnDebuggerCommand(const std::string& command); void OnDebuggerPauseScript(); - void OnRpcMessage(const std::string& class_name, - const std::string& method_name, - const std::string& param1, - const std::string& param2, - const std::string& param3); + void OnRpcMessage(const DevToolsMessageData& data); bool message_handled_; diff --git a/chrome/renderer/devtools_client.cc b/chrome/renderer/devtools_client.cc index 8083288..2ab162e 100644 --- a/chrome/renderer/devtools_client.cc +++ b/chrome/renderer/devtools_client.cc @@ -11,6 +11,7 @@ #include "chrome/renderer/render_thread.h" #include "chrome/renderer/render_view.h" #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsFrontend.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsMessageData.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" using WebKit::WebDevToolsFrontend; @@ -47,17 +48,9 @@ bool DevToolsClient::OnMessageReceived(const IPC::Message& message) { return handled; } -void DevToolsClient::sendMessageToAgent(const WebString& class_name, - const WebString& method_name, - const WebString& param1, - const WebString& param2, - const WebString& param3) { - Send(DevToolsAgentMsg_RpcMessage( - class_name.utf8(), - method_name.utf8(), - param1.utf8(), - param2.utf8(), - param3.utf8())); +void DevToolsClient::sendMessageToAgent( + const WebKit::WebDevToolsMessageData& data) { + Send(DevToolsAgentMsg_RpcMessage(DevToolsMessageData(data))); } void DevToolsClient::sendDebuggerCommandToAgent(const WebString& command) { @@ -88,15 +81,7 @@ void DevToolsClient::undockWindow() { render_view_->routing_id())); } -void DevToolsClient::OnRpcMessage(const std::string& class_name, - const std::string& method_name, - const std::string& param1, - const std::string& param2, - const std::string& param3) { +void DevToolsClient::OnRpcMessage(const DevToolsMessageData& data) { web_tools_frontend_->dispatchMessageFromAgent( - WebString::fromUTF8(class_name), - WebString::fromUTF8(method_name), - WebString::fromUTF8(param1), - WebString::fromUTF8(param2), - WebString::fromUTF8(param3)); + data.ToWebDevToolsMessageData()); } diff --git a/chrome/renderer/devtools_client.h b/chrome/renderer/devtools_client.h index aad5c09..c8eba9f 100644 --- a/chrome/renderer/devtools_client.h +++ b/chrome/renderer/devtools_client.h @@ -21,6 +21,8 @@ namespace WebKit { class WebDevToolsFrontend; } +struct DevToolsMessageData; + // Developer tools UI end of communication channel between the render process of // the page being inspected and tools UI renderer process. All messages will // go through browser process. On the side of the inspected page there's @@ -37,11 +39,8 @@ class DevToolsClient : public WebKit::WebDevToolsFrontendClient { bool OnMessageReceived(const IPC::Message& message); // WebDevToolsFrontendClient implementation - virtual void sendMessageToAgent(const WebKit::WebString& class_name, - const WebKit::WebString& method_name, - const WebKit::WebString& param1, - const WebKit::WebString& param2, - const WebKit::WebString& param3); + virtual void sendMessageToAgent( + const WebKit::WebDevToolsMessageData& data); virtual void sendDebuggerCommandToAgent(const WebKit::WebString& command); virtual void sendDebuggerPauseScript(); @@ -51,11 +50,7 @@ class DevToolsClient : public WebKit::WebDevToolsFrontendClient { virtual void undockWindow(); private: - void OnRpcMessage(const std::string& class_name, - const std::string& method_name, - const std::string& param1, - const std::string& param2, - const std::string& param3); + void OnRpcMessage(const DevToolsMessageData& data); // Sends message to DevToolsAgent. void Send(const IPC::Message& tools_agent_message); diff --git a/webkit/glue/devtools/devtools_message_data.cc b/webkit/glue/devtools/devtools_message_data.cc new file mode 100644 index 0000000..68280fb --- /dev/null +++ b/webkit/glue/devtools/devtools_message_data.cc @@ -0,0 +1,31 @@ +// 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. + +#include "config.h" + +#undef LOG + +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsMessageData.h" +#include "webkit/glue/devtools/devtools_message_data.h" +#include "webkit/glue/glue_util.h" + +DevToolsMessageData::DevToolsMessageData( + const WebKit::WebDevToolsMessageData& data) + : class_name(webkit_glue::WebStringToStdString(data.className)), + method_name(webkit_glue::WebStringToStdString(data.methodName)) { + for (size_t i = 0; i < data.arguments.size(); i++) + arguments.push_back(webkit_glue::WebStringToStdString(data.arguments[i])); +} + +WebKit::WebDevToolsMessageData + DevToolsMessageData::ToWebDevToolsMessageData() const { + WebKit::WebDevToolsMessageData result; + result.className = webkit_glue::StdStringToWebString(class_name); + result.methodName = webkit_glue::StdStringToWebString(method_name); + WebKit::WebVector<WebKit::WebString> web_args(arguments.size()); + for (size_t i = 0; i < arguments.size(); i++) + web_args[i] = webkit_glue::StdStringToWebString(arguments[i]); + result.arguments.swap(web_args); + return result; +}
\ No newline at end of file diff --git a/webkit/glue/devtools/devtools_message_data.h b/webkit/glue/devtools/devtools_message_data.h new file mode 100644 index 0000000..4d28b84 --- /dev/null +++ b/webkit/glue/devtools/devtools_message_data.h @@ -0,0 +1,25 @@ +// 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. + +#ifndef WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_MESSAGE_DATA_H_ +#define WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_MESSAGE_DATA_H_ + +#include <string> +#include <vector> + +namespace WebKit { +struct WebDevToolsMessageData; +} + +struct DevToolsMessageData { + DevToolsMessageData() {} + explicit DevToolsMessageData(const WebKit::WebDevToolsMessageData&); + WebKit::WebDevToolsMessageData ToWebDevToolsMessageData() const; + + std::string class_name; + std::string method_name; + std::vector<std::string> arguments; +}; + +#endif // WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_MESSAGE_DATA_H_ diff --git a/webkit/glue/devtools/devtools_rpc.h b/webkit/glue/devtools/devtools_rpc.h index 819bd79..b0c60fe 100644 --- a/webkit/glue/devtools/devtools_rpc.h +++ b/webkit/glue/devtools/devtools_rpc.h @@ -51,14 +51,19 @@ #define WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ #include "PlatformString.h" +#include "Vector.h" #include <wtf/Noncopyable.h> +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsMessageData.h" +#include "webkit/glue/glue_util.h" + namespace WebCore { class String; } using WebCore::String; +using WTF::Vector; /////////////////////////////////////////////////////// // RPC dispatch macro @@ -130,37 +135,35 @@ struct RpcTypeTrait<String> { #define TOOLS_RPC_STUB_METHOD0(Method) \ virtual void Method() { \ - this->delegate_->SendRpcMessage(class_name, #Method); \ + Vector<String> args; \ + this->SendRpcMessage(class_name, #Method, args); \ } #define TOOLS_RPC_STUB_METHOD1(Method, T1) \ virtual void Method(RpcTypeTrait<T1>::ApiType t1) { \ - this->delegate_->SendRpcMessage( \ - class_name, \ - #Method, \ - RpcTypeTrait<T1>::ToString(t1)); \ + Vector<String> args(1); \ + args[0] = RpcTypeTrait<T1>::ToString(t1); \ + this->SendRpcMessage(class_name, #Method, args); \ } #define TOOLS_RPC_STUB_METHOD2(Method, T1, T2) \ virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ RpcTypeTrait<T2>::ApiType t2) { \ - this->delegate_->SendRpcMessage( \ - class_name, \ - #Method, \ - RpcTypeTrait<T1>::ToString(t1), \ - RpcTypeTrait<T2>::ToString(t2)); \ + Vector<String> args(2); \ + args[0] = RpcTypeTrait<T1>::ToString(t1); \ + args[1] = RpcTypeTrait<T2>::ToString(t2); \ + this->SendRpcMessage(class_name, #Method, args); \ } #define TOOLS_RPC_STUB_METHOD3(Method, T1, T2, T3) \ virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ RpcTypeTrait<T2>::ApiType t2, \ RpcTypeTrait<T3>::ApiType t3) { \ - this->delegate_->SendRpcMessage( \ - class_name, \ - #Method, \ - RpcTypeTrait<T1>::ToString(t1), \ - RpcTypeTrait<T2>::ToString(t2), \ - RpcTypeTrait<T3>::ToString(t3)); \ + Vector<String> args(3); \ + args[0] = RpcTypeTrait<T1>::ToString(t1); \ + args[1] = RpcTypeTrait<T2>::ToString(t2); \ + args[2] = RpcTypeTrait<T3>::ToString(t3); \ + this->SendRpcMessage(class_name, #Method, args); \ } /////////////////////////////////////////////////////// @@ -174,15 +177,15 @@ if (method_name == #Method) { \ #define TOOLS_RPC_DISPATCH1(Method, T1) \ if (method_name == #Method) { \ - delegate->Method(RpcTypeTrait<T1>::Parse(p1)); \ + delegate->Method(RpcTypeTrait<T1>::Parse(args[0])); \ return true; \ } #define TOOLS_RPC_DISPATCH2(Method, T1, T2) \ if (method_name == #Method) { \ delegate->Method( \ - RpcTypeTrait<T1>::Parse(p1), \ - RpcTypeTrait<T2>::Parse(p2) \ + RpcTypeTrait<T1>::Parse(args[0]), \ + RpcTypeTrait<T2>::Parse(args[1]) \ ); \ return true; \ } @@ -190,9 +193,9 @@ if (method_name == #Method) { \ #define TOOLS_RPC_DISPATCH3(Method, T1, T2, T3) \ if (method_name == #Method) { \ delegate->Method( \ - RpcTypeTrait<T1>::Parse(p1), \ - RpcTypeTrait<T2>::Parse(p2), \ - RpcTypeTrait<T3>::Parse(p3) \ + RpcTypeTrait<T1>::Parse(args[0]), \ + RpcTypeTrait<T2>::Parse(args[1]), \ + RpcTypeTrait<T3>::Parse(args[2]) \ ); \ return true; \ } @@ -239,14 +242,16 @@ class Class##Dispatch : public Noncopyable { \ virtual ~Class##Dispatch() {} \ \ static bool Dispatch(Class* delegate, \ - const WebCore::String& class_name, \ - const WebCore::String& method_name, \ - const WebCore::String& p1, \ - const WebCore::String& p2, \ - const WebCore::String& p3) { \ + const WebKit::WebDevToolsMessageData& data) { \ + String class_name = webkit_glue::WebStringToString(data.className); \ if (class_name != #Class) { \ return false; \ } \ + String method_name = webkit_glue::WebStringToString(data.methodName); \ + Vector<String> args; \ + for (size_t i = 0; i < data.arguments.size(); i++) { \ + args.append(webkit_glue::WebStringToString(data.arguments[i])); \ + } \ typedef Class CLASS; \ STRUCT( \ TOOLS_RPC_DISPATCH0, \ @@ -265,11 +270,8 @@ class DevToolsRpc { public: Delegate() {} virtual ~Delegate() {} - virtual void SendRpcMessage(const WebCore::String& class_name, - const WebCore::String& method_name, - const WebCore::String& p1 = "", - const WebCore::String& p2 = "", - const WebCore::String& p3 = "") = 0; + virtual void SendRpcMessage( + const WebKit::WebDevToolsMessageData& data) = 0; }; explicit DevToolsRpc(Delegate* delegate) @@ -277,6 +279,20 @@ class DevToolsRpc { virtual ~DevToolsRpc() {}; protected: + void SendRpcMessage(const String& class_name, + const String& method_name, + const Vector<String>& args) { + WebKit::WebVector<WebKit::WebString> web_args(args.size()); + for (size_t i = 0; i < args.size(); i++) { + web_args[i] = webkit_glue::StringToWebString(args[i]); + } + WebKit::WebDevToolsMessageData data; + data.className = webkit_glue::StringToWebString(class_name); + data.methodName = webkit_glue::StringToWebString(method_name); + data.arguments.swap(web_args); + this->delegate_->SendRpcMessage(data); + } + Delegate* delegate_; }; diff --git a/webkit/glue/devtools/devtools_rpc_js.h b/webkit/glue/devtools/devtools_rpc_js.h index c4cfc47..f51d5f6 100644 --- a/webkit/glue/devtools/devtools_rpc_js.h +++ b/webkit/glue/devtools/devtools_rpc_js.h @@ -33,36 +33,25 @@ #define TOOLS_RPC_JS_STUB_METHOD0(Method) \ static v8::Handle<v8::Value> Js##Method(const v8::Arguments& args) { \ - SendRpcMessage(v8::External::Cast(*args.Data())->Value(), \ - #Method, "", "", ""); \ + 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) { \ - SendRpcMessage(v8::External::Cast(*args.Data())->Value(), \ - #Method, \ - WebCore::toWebCoreStringWithNullCheck(args[0]), "", ""); \ + 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) { \ - SendRpcMessage(v8::External::Cast(*args.Data())->Value(), \ - #Method, \ - WebCore::toWebCoreStringWithNullCheck(args[0]), \ - WebCore::toWebCoreStringWithNullCheck(args[1]), \ - ""); \ + 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) { \ - SendRpcMessage(v8::External::Cast(*args.Data())->Value(), \ - #Method, \ - WebCore::toWebCoreStringWithNullCheck(args[0]), \ - WebCore::toWebCoreStringWithNullCheck(args[1]), \ - WebCore::toWebCoreStringWithNullCheck(args[2])); \ + SendRpcMessageFromJs(#Method, args, 3); \ return v8::Undefined(); \ } @@ -92,18 +81,16 @@ 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) { \ + 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] = 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->delegate_->SendRpcMessage( \ - #Class, \ - method, \ - param1, \ - param2, \ - param3); \ + self->SendRpcMessage(#Class, method, args); \ } \ }; diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc index 24b85bb..42fcbb8 100644 --- a/webkit/glue/webdevtoolsagent_impl.cc +++ b/webkit/glue/webdevtoolsagent_impl.cc @@ -30,6 +30,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgentClient.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsMessageData.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" @@ -68,6 +69,7 @@ using WebCore::V8DOMWrapper; using WebCore::V8Proxy; using WebKit::WebDataSource; using WebKit::WebDevToolsAgentClient; +using WebKit::WebDevToolsMessageData; using WebKit::WebFrame; using WebKit::WebFrameImpl; using WebKit::WebPoint; @@ -117,17 +119,9 @@ class IoRpcDelegate : public DevToolsRpc::Delegate { public: IoRpcDelegate() {} virtual ~IoRpcDelegate() {} - virtual void SendRpcMessage(const String& class_name, - const String& method_name, - const String& p1, - const String& p2, - const String& p3) { - WebDevToolsAgentClient::sendMessageToFrontendOnIOThread( - webkit_glue::StringToWebString(class_name), - webkit_glue::StringToWebString(method_name), - webkit_glue::StringToWebString(p1), - webkit_glue::StringToWebString(p2), - webkit_glue::StringToWebString(p3)); + virtual void SendRpcMessage( + const WebKit::WebDevToolsMessageData& data) { + WebDevToolsAgentClient::sendMessageToFrontendOnIOThread(data); } private: @@ -286,19 +280,20 @@ void WebDevToolsAgentImpl::GetResourceContent( tools_agent_native_delegate_stub_->DidGetResourceContent(call_id, content); } +// TODO(yurys): this method is deprecated and will go away soon, use +// overloaded method with WebDevToolsMessageData argument instead. void WebDevToolsAgentImpl::dispatchMessageFromFrontend( const WebString& class_name, const WebString& method_name, const WebString& param1, const WebString& param2, const WebString& param3) { - if (ToolsAgentDispatch::Dispatch( - this, - webkit_glue::WebStringToString(class_name), - webkit_glue::WebStringToString(method_name), - webkit_glue::WebStringToString(param1), - webkit_glue::WebStringToString(param2), - webkit_glue::WebStringToString(param3))) { + ASSERT_NOT_REACHED(); +} + +void WebDevToolsAgentImpl::dispatchMessageFromFrontend( + const WebDevToolsMessageData& data) { + if (ToolsAgentDispatch::Dispatch(this, data)) { return; } @@ -307,22 +302,11 @@ void WebDevToolsAgentImpl::dispatchMessageFromFrontend( } if (debugger_agent_impl_.get() && - DebuggerAgentDispatch::Dispatch( - debugger_agent_impl_.get(), - webkit_glue::WebStringToString(class_name), - webkit_glue::WebStringToString(method_name), - webkit_glue::WebStringToString(param1), - webkit_glue::WebStringToString(param2), - webkit_glue::WebStringToString(param3))) { + DebuggerAgentDispatch::Dispatch(debugger_agent_impl_.get(), data)) { return; } } -void WebDevToolsAgentImpl::dispatchMessageFromFrontend( - const WebKit::WebDevToolsMessageData& data) { - // Stub. -} - void WebDevToolsAgentImpl::inspectElementAt(const WebPoint& point) { web_view_impl_->inspectElementAt(point); } @@ -344,17 +328,8 @@ void WebDevToolsAgentImpl::setRuntimeFeatureEnabled(const WebString& wfeature, } void WebDevToolsAgentImpl::SendRpcMessage( - const String& class_name, - const String& method_name, - const String& param1, - const String& param2, - const String& param3) { - client_->sendMessageToFrontend( - webkit_glue::StringToWebString(class_name), - webkit_glue::StringToWebString(method_name), - webkit_glue::StringToWebString(param1), - webkit_glue::StringToWebString(param2), - webkit_glue::StringToWebString(param3)); + const WebKit::WebDevToolsMessageData& data) { + client_->sendMessageToFrontend(data); } void WebDevToolsAgentImpl::InitDevToolsAgentHost() { @@ -640,6 +615,8 @@ void WebDevToolsAgent::setMessageLoopDispatchHandler( DebuggerAgentManager::SetMessageLoopDispatchHandler(handler); } +// TODO(yurys): this method is deprecated and will go away soon, use +// overloaded method with WebDevToolsMessageData argument instead. // static bool WebDevToolsAgent::dispatchMessageFromFrontendOnIOThread( const WebString& className, @@ -647,16 +624,27 @@ bool WebDevToolsAgent::dispatchMessageFromFrontendOnIOThread( const WebString& param1, const WebString& param2, const WebString& param3) { + WebKit::WebVector<WebString> arguments(static_cast<size_t>(3)); + arguments[0] = param1; + arguments[1] = param2; + arguments[2] = param3; + + WebDevToolsMessageData data; + data.className = className; + data.methodName = methodName; + data.arguments.swap(arguments); + // Delegate to overloaded method. This method will go away soon. + return WebDevToolsAgent::dispatchMessageFromFrontendOnIOThread(data); +} + +// static +bool WebDevToolsAgent::dispatchMessageFromFrontendOnIOThread( + const WebDevToolsMessageData& data) { IoRpcDelegate transport; ProfilerAgentDelegateStub stub(&transport); ProfilerAgentImpl agent(&stub); - return ProfilerAgentDispatch::Dispatch( - &agent, - webkit_glue::WebStringToString(className), - webkit_glue::WebStringToString(methodName), - webkit_glue::WebStringToString(param1), - webkit_glue::WebStringToString(param2), - webkit_glue::WebStringToString(param3)); + return ProfilerAgentDispatch::Dispatch(&agent, data); } + } // namespace WebKit diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h index 65c7eb3..84c7483 100644 --- a/webkit/glue/webdevtoolsagent_impl.h +++ b/webkit/glue/webdevtoolsagent_impl.h @@ -101,11 +101,7 @@ class WebDevToolsAgentImpl : public WebKit::WebDevToolsAgentPrivate, const WebKit::WebURLError& error); // DevToolsRpc::Delegate implementation. - void SendRpcMessage(const WebCore::String& class_name, - const WebCore::String& method_name, - const WebCore::String& param1, - const WebCore::String& param2, - const WebCore::String& param3); + virtual void SendRpcMessage(const WebKit::WebDevToolsMessageData& data); void ForceRepaint(); diff --git a/webkit/glue/webdevtoolsfrontend_impl.cc b/webkit/glue/webdevtoolsfrontend_impl.cc index 15a50a9..1048a41 100644 --- a/webkit/glue/webdevtoolsfrontend_impl.cc +++ b/webkit/glue/webdevtoolsfrontend_impl.cc @@ -36,6 +36,7 @@ #include "third_party/WebKit/WebKit/chromium/src/WebViewImpl.h" #include "webkit/glue/devtools/bound_object.h" #include "webkit/glue/devtools/debugger_agent.h" +#include "webkit/glue/devtools/devtools_message_data.h" #include "webkit/glue/devtools/devtools_rpc_js.h" #include "webkit/glue/devtools/profiler_agent.h" #include "webkit/glue/devtools/tools_agent.h" @@ -218,28 +219,29 @@ WebDevToolsFrontendImpl::~WebDevToolsFrontendImpl() { menu_selection_handler_->disconnect(); } +// TODO(yurys): this method is deprecated and will go away soon, use +// overloaded method with WebDevToolsMessageData argument instead. void WebDevToolsFrontendImpl::dispatchMessageFromAgent( const WebString& class_name, const WebString& method_name, const WebString& param1, const WebString& param2, const WebString& param3) { + ASSERT_NOT_REACHED(); +} + +void WebDevToolsFrontendImpl::dispatchMessageFromAgent( + const WebKit::WebDevToolsMessageData& data) { if (ToolsAgentNativeDelegateDispatch::Dispatch( tools_agent_native_delegate_impl_.get(), - webkit_glue::WebStringToString(class_name), - webkit_glue::WebStringToString(method_name), - webkit_glue::WebStringToString(param1), - webkit_glue::WebStringToString(param2), - webkit_glue::WebStringToString(param3))) { + data)) { return; } - Vector<String> v; - v.append(webkit_glue::WebStringToString(class_name)); - v.append(webkit_glue::WebStringToString(method_name)); - v.append(webkit_glue::WebStringToString(param1)); - v.append(webkit_glue::WebStringToString(param2)); - v.append(webkit_glue::WebStringToString(param3)); + v.append(webkit_glue::WebStringToString(data.className)); + v.append(webkit_glue::WebStringToString(data.methodName)); + for (size_t i = 0; i < data.arguments.size(); i++) + v.append(webkit_glue::WebStringToString(data.arguments[i])); if (!loaded_) { pending_incoming_messages_.append(v); return; @@ -247,11 +249,6 @@ void WebDevToolsFrontendImpl::dispatchMessageFromAgent( ExecuteScript(v); } -void WebDevToolsFrontendImpl::dispatchMessageFromAgent( - const WebKit::WebDevToolsMessageData& data) { - // Stub. -} - void WebDevToolsFrontendImpl::AddResourceSourceToFrame(int resource_id, String mime_type, Node* frame) { @@ -271,15 +268,12 @@ void WebDevToolsFrontendImpl::ExecuteScript(const Vector<String>& v) { v8::Handle<v8::Value> dispatch_function = frame_context->Global()->Get(v8::String::New("devtools$$dispatch")); ASSERT(dispatch_function->IsFunction()); - v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(dispatch_function); - v8::Handle<v8::Value> args[] = { - ToV8String(v.at(0)), - ToV8String(v.at(1)), - ToV8String(v.at(2)), - ToV8String(v.at(3)), - ToV8String(v.at(4)), - }; - function->Call(frame_context->Global(), 5, args); + v8::Handle<v8::Function> function = + v8::Handle<v8::Function>::Cast(dispatch_function); + Vector< v8::Handle<v8::Value> > args; + for (size_t i = 0; i < v.size(); i++) + args.append(ToV8String(v.at(i))); + function->Call(frame_context->Global(), args.size(), args.data()); } void WebDevToolsFrontendImpl::DispatchOnWebInspector( @@ -306,17 +300,9 @@ void WebDevToolsFrontendImpl::DispatchOnWebInspector( } -void WebDevToolsFrontendImpl::SendRpcMessage(const String& class_name, - const String& method_name, - const String& param1, - const String& param2, - const String& param3) { - client_->sendMessageToAgent( - webkit_glue::StringToWebString(class_name), - webkit_glue::StringToWebString(method_name), - webkit_glue::StringToWebString(param1), - webkit_glue::StringToWebString(param2), - webkit_glue::StringToWebString(param3)); +void WebDevToolsFrontendImpl::SendRpcMessage( + const WebKit::WebDevToolsMessageData& data) { + client_->sendMessageToAgent(data); } void WebDevToolsFrontendImpl::ContextMenuItemSelected( diff --git a/webkit/glue/webdevtoolsfrontend_impl.h b/webkit/glue/webdevtoolsfrontend_impl.h index 7557ea1..e60e7d5 100644 --- a/webkit/glue/webdevtoolsfrontend_impl.h +++ b/webkit/glue/webdevtoolsfrontend_impl.h @@ -48,11 +48,7 @@ class WebDevToolsFrontendImpl : public WebKit::WebDevToolsFrontend, virtual ~WebDevToolsFrontendImpl(); // DevToolsRpc::Delegate implementation. - virtual void SendRpcMessage(const String& class_name, - const String& method_name, - const String& param1, - const String& param2, - const String& param3); + virtual void SendRpcMessage(const WebKit::WebDevToolsMessageData& data); // WebDevToolsFrontend implementation. virtual void dispatchMessageFromAgent(const WebKit::WebString& class_name, diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index c2bb0b6..adc6687 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -237,8 +237,6 @@ # those in the test subdirectory and those with unittest in in their # names. 'glue/devtools/apu_agent_delegate.h', - 'glue/devtools/devtools_rpc.h', - 'glue/devtools/devtools_rpc_js.h', 'glue/devtools/bound_object.cc', 'glue/devtools/bound_object.h', 'glue/devtools/debugger_agent.h', @@ -246,6 +244,10 @@ 'glue/devtools/debugger_agent_impl.h', 'glue/devtools/debugger_agent_manager.cc', 'glue/devtools/debugger_agent_manager.h', + 'glue/devtools/devtools_message_data.cc', + 'glue/devtools/devtools_message_data.h', + 'glue/devtools/devtools_rpc.h', + 'glue/devtools/devtools_rpc_js.h', 'glue/devtools/profiler_agent.h', 'glue/devtools/profiler_agent_impl.cc', 'glue/devtools/profiler_agent_impl.h', |