OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/devtools_agent_filter.h" | 5 #include "chrome/renderer/devtools_agent_filter.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "chrome/common/devtools_messages.h" | 8 #include "chrome/common/devtools_messages.h" |
| 9 #include "chrome/common/render_messages.h" |
9 #include "chrome/renderer/devtools_agent.h" | 10 #include "chrome/renderer/devtools_agent.h" |
10 #include "chrome/renderer/plugin_channel_host.h" | 11 #include "chrome/renderer/plugin_channel_host.h" |
11 #include "chrome/renderer/render_view.h" | 12 #include "chrome/renderer/render_view.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" |
13 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
14 | 15 |
15 using WebKit::WebDevToolsAgent; | 16 using WebKit::WebDevToolsAgent; |
16 using WebKit::WebString; | 17 using WebKit::WebString; |
17 | 18 |
18 // static | 19 // static |
19 void DevToolsAgentFilter::DispatchMessageLoop() { | 20 void DevToolsAgentFilter::DispatchMessageLoop() { |
20 MessageLoop* current = MessageLoop::current(); | 21 MessageLoop* current = MessageLoop::current(); |
21 bool old_state = current->NestableTasksAllowed(); | 22 bool old_state = current->NestableTasksAllowed(); |
22 current->SetNestableTasksAllowed(true); | 23 current->SetNestableTasksAllowed(true); |
23 current->RunAllPending(); | 24 current->RunAllPending(); |
24 current->SetNestableTasksAllowed(old_state); | 25 current->SetNestableTasksAllowed(old_state); |
25 } | 26 } |
26 | 27 |
| 28 // static |
| 29 IPC::Channel* DevToolsAgentFilter::channel_ = NULL; |
| 30 // static |
| 31 int DevToolsAgentFilter::current_routing_id_ = 0; |
| 32 |
27 DevToolsAgentFilter::DevToolsAgentFilter() | 33 DevToolsAgentFilter::DevToolsAgentFilter() |
28 : current_routing_id_(0) { | 34 : message_handled_(false) { |
29 WebDevToolsAgent::setMessageLoopDispatchHandler( | 35 WebDevToolsAgent::setMessageLoopDispatchHandler( |
30 &DevToolsAgentFilter::DispatchMessageLoop); | 36 &DevToolsAgentFilter::DispatchMessageLoop); |
31 } | 37 } |
32 | 38 |
33 DevToolsAgentFilter::~DevToolsAgentFilter() { | 39 DevToolsAgentFilter::~DevToolsAgentFilter() { |
34 } | 40 } |
35 | 41 |
36 bool DevToolsAgentFilter::OnMessageReceived(const IPC::Message& message) { | 42 bool DevToolsAgentFilter::OnMessageReceived(const IPC::Message& message) { |
37 // Dispatch debugger commands directly from IO. | 43 // Dispatch debugger commands directly from IO. |
38 bool handled = true; | 44 message_handled_ = true; |
39 current_routing_id_ = message.routing_id(); | 45 current_routing_id_ = message.routing_id(); |
40 IPC_BEGIN_MESSAGE_MAP(DevToolsAgentFilter, message) | 46 IPC_BEGIN_MESSAGE_MAP(DevToolsAgentFilter, message) |
41 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebuggerCommand, OnDebuggerCommand) | 47 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebuggerCommand, OnDebuggerCommand) |
42 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebuggerPauseScript, | 48 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebuggerPauseScript, |
43 OnDebuggerPauseScript) | 49 OnDebuggerPauseScript) |
44 IPC_MESSAGE_UNHANDLED(handled = false) | 50 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_RpcMessage, OnRpcMessage) |
| 51 IPC_MESSAGE_UNHANDLED(message_handled_ = false) |
45 IPC_END_MESSAGE_MAP() | 52 IPC_END_MESSAGE_MAP() |
46 return handled; | 53 return message_handled_; |
47 } | 54 } |
48 | 55 |
49 void DevToolsAgentFilter::OnDebuggerCommand(const std::string& command) { | 56 void DevToolsAgentFilter::OnDebuggerCommand(const std::string& command) { |
50 WebDevToolsAgent::executeDebuggerCommand( | 57 WebDevToolsAgent::executeDebuggerCommand( |
51 WebString::fromUTF8(command), current_routing_id_); | 58 WebString::fromUTF8(command), current_routing_id_); |
52 } | 59 } |
53 | 60 |
54 void DevToolsAgentFilter::OnDebuggerPauseScript() { | 61 void DevToolsAgentFilter::OnDebuggerPauseScript() { |
55 WebDevToolsAgent::debuggerPauseScript(); | 62 WebDevToolsAgent::debuggerPauseScript(); |
56 } | 63 } |
| 64 |
| 65 void DevToolsAgentFilter::OnRpcMessage(const std::string& class_name, |
| 66 const std::string& method_name, |
| 67 const std::string& param1, |
| 68 const std::string& param2, |
| 69 const std::string& param3) { |
| 70 message_handled_ = WebDevToolsAgent::dispatchMessageFromFrontendOnIOThread( |
| 71 WebString::fromUTF8(class_name), |
| 72 WebString::fromUTF8(method_name), |
| 73 WebString::fromUTF8(param1), |
| 74 WebString::fromUTF8(param2), |
| 75 WebString::fromUTF8(param3)); |
| 76 } |
| 77 |
| 78 // static |
| 79 void DevToolsAgentFilter::SendRpcMessage(const std::string& class_name, |
| 80 const std::string& method_name, |
| 81 const std::string& param1, |
| 82 const std::string& param2, |
| 83 const std::string& param3) { |
| 84 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( |
| 85 current_routing_id_, |
| 86 DevToolsClientMsg_RpcMessage( |
| 87 class_name, |
| 88 method_name, |
| 89 param1, |
| 90 param2, |
| 91 param3)); |
| 92 channel_->Send(m); |
| 93 } |
OLD | NEW |