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