| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/devtools_agent_filter.h" | 5 #include "content/renderer/devtools_agent_filter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "content/common/devtools_messages.h" | 9 #include "content/common/devtools_messages.h" |
| 10 #include "content/renderer/devtools_agent.h" | 10 #include "content/renderer/devtools_agent.h" |
| 11 #include "content/renderer/plugin_channel_host.h" | 11 #include "content/renderer/plugin_channel_host.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 14 | 14 |
| 15 using WebKit::WebDevToolsAgent; | 15 using WebKit::WebDevToolsAgent; |
| 16 using WebKit::WebString; | 16 using WebKit::WebString; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class MessageImpl : public WebDevToolsAgent::MessageDescriptor { | 20 class MessageImpl : public WebDevToolsAgent::MessageDescriptor { |
| 21 public: | 21 public: |
| 22 MessageImpl(const std::string& message, int host_id) | 22 MessageImpl(const std::string& message, int host_id) |
| 23 : msg(message), | 23 : msg(message), |
| 24 host_id(host_id) {} | 24 host_id(host_id) { |
| 25 } |
| 25 virtual ~MessageImpl() {} | 26 virtual ~MessageImpl() {} |
| 26 virtual WebDevToolsAgent* agent() { | 27 virtual WebDevToolsAgent* agent() { |
| 27 DevToolsAgent* agent = DevToolsAgent::FromHostId(host_id); | 28 DevToolsAgent* agent = DevToolsAgent::FromHostId(host_id); |
| 28 if (!agent) | 29 if (!agent) |
| 29 return 0; | 30 return 0; |
| 30 return agent->GetWebAgent(); | 31 return agent->GetWebAgent(); |
| 31 } | 32 } |
| 32 virtual WebString message() { return WebString::fromUTF8(msg); } | 33 virtual WebString message() { return WebString::fromUTF8(msg); } |
| 33 private: | 34 private: |
| 34 std::string msg; | 35 std::string msg; |
| 35 int host_id; | 36 int host_id; |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 } | 39 // Made static to allow DevToolsAgent to use it for replying directly |
| 40 // from IO thread. |
| 41 int g_current_routing_id = 0; |
| 39 | 42 |
| 40 // static | 43 } // namespace |
| 41 IPC::Channel* DevToolsAgentFilter::channel_ = NULL; | |
| 42 // static | |
| 43 int DevToolsAgentFilter::current_routing_id_ = 0; | |
| 44 | 44 |
| 45 DevToolsAgentFilter::DevToolsAgentFilter() | 45 DevToolsAgentFilter::DevToolsAgentFilter() |
| 46 : message_handled_(false), | 46 : message_handled_(false), |
| 47 render_thread_loop_(MessageLoop::current()) { | 47 render_thread_loop_(MessageLoop::current()) { |
| 48 } | 48 } |
| 49 | 49 |
| 50 DevToolsAgentFilter::~DevToolsAgentFilter() { | |
| 51 } | |
| 52 | |
| 53 bool DevToolsAgentFilter::OnMessageReceived(const IPC::Message& message) { | 50 bool DevToolsAgentFilter::OnMessageReceived(const IPC::Message& message) { |
| 54 // Dispatch debugger commands directly from IO. | 51 // Dispatch debugger commands directly from IO. |
| 55 message_handled_ = true; | 52 message_handled_ = true; |
| 56 current_routing_id_ = message.routing_id(); | 53 g_current_routing_id = message.routing_id(); |
| 57 IPC_BEGIN_MESSAGE_MAP(DevToolsAgentFilter, message) | 54 IPC_BEGIN_MESSAGE_MAP(DevToolsAgentFilter, message) |
| 58 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, | 55 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, |
| 59 OnDispatchOnInspectorBackend) | 56 OnDispatchOnInspectorBackend) |
| 60 IPC_MESSAGE_UNHANDLED(message_handled_ = false) | 57 IPC_MESSAGE_UNHANDLED(message_handled_ = false) |
| 61 IPC_END_MESSAGE_MAP() | 58 IPC_END_MESSAGE_MAP() |
| 62 return message_handled_; | 59 return message_handled_; |
| 63 } | 60 } |
| 64 | 61 |
| 65 void DevToolsAgentFilter::OnFilterAdded(IPC::Channel* channel) { | 62 DevToolsAgentFilter::~DevToolsAgentFilter() {} |
| 66 channel_ = channel; | |
| 67 } | |
| 68 | 63 |
| 69 void DevToolsAgentFilter::OnDispatchOnInspectorBackend( | 64 void DevToolsAgentFilter::OnDispatchOnInspectorBackend( |
| 70 const std::string& message) { | 65 const std::string& message) { |
| 71 if (!WebDevToolsAgent::shouldInterruptForMessage( | 66 if (!WebDevToolsAgent::shouldInterruptForMessage( |
| 72 WebString::fromUTF8(message))) { | 67 WebString::fromUTF8(message))) { |
| 73 message_handled_ = false; | 68 message_handled_ = false; |
| 74 return; | 69 return; |
| 75 } | 70 } |
| 76 WebDevToolsAgent::interruptAndDispatch( | 71 WebDevToolsAgent::interruptAndDispatch( |
| 77 new MessageImpl(message, current_routing_id_)); | 72 new MessageImpl(message, g_current_routing_id)); |
| 78 | 73 |
| 79 render_thread_loop_->PostTask( | 74 render_thread_loop_->PostTask( |
| 80 FROM_HERE, base::Bind(&WebDevToolsAgent::processPendingMessages)); | 75 FROM_HERE, base::Bind(&WebDevToolsAgent::processPendingMessages)); |
| 81 } | 76 } |
| OLD | NEW |