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.
5 #include "content/renderer/devtools/devtools_agent_filter.h"
8 #include "base/message_loop/message_loop.h"
9 #include "content/child/child_process.h"
10 #include "content/common/devtools_messages.h"
11 #include "content/renderer/devtools/devtools_agent.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
13 #include "third_party/WebKit/public/web/WebDevToolsAgent.h"
15 using blink::WebDevToolsAgent
;
16 using blink::WebString
;
22 class MessageImpl
: public WebDevToolsAgent::MessageDescriptor
{
24 MessageImpl(const std::string
& message
, int routing_id
)
26 routing_id_(routing_id
) {
28 virtual ~MessageImpl() {}
29 virtual WebDevToolsAgent
* agent() {
30 DevToolsAgent
* agent
= DevToolsAgent::FromRoutingId(routing_id_
);
33 return agent
->GetWebAgent();
35 virtual WebString
message() { return WebString::fromUTF8(msg_
); }
43 DevToolsAgentFilter::DevToolsAgentFilter()
44 : message_handled_(false),
45 render_thread_loop_(base::MessageLoop::current()),
46 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()),
47 current_routing_id_(0) {}
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)
58 return message_handled_
;
61 DevToolsAgentFilter::~DevToolsAgentFilter() {}
63 void DevToolsAgentFilter::OnDispatchOnInspectorBackend(
64 const std::string
& message
) {
65 if (embedded_worker_routes_
.find(current_routing_id_
) !=
66 embedded_worker_routes_
.end()) {
67 message_handled_
= false;
70 if (!WebDevToolsAgent::shouldInterruptForMessage(
71 WebString::fromUTF8(message
))) {
72 message_handled_
= false;
75 WebDevToolsAgent::interruptAndDispatch(
76 new MessageImpl(message
, current_routing_id_
));
78 render_thread_loop_
->PostTask(
79 FROM_HERE
, base::Bind(&WebDevToolsAgent::processPendingMessages
));
82 void DevToolsAgentFilter::AddEmbeddedWorkerRouteOnMainThread(int32 routing_id
) {
83 io_message_loop_proxy_
->PostTask(
86 &DevToolsAgentFilter::AddEmbeddedWorkerRoute
, this, routing_id
));
89 void DevToolsAgentFilter::RemoveEmbeddedWorkerRouteOnMainThread(
91 io_message_loop_proxy_
->PostTask(
94 &DevToolsAgentFilter::RemoveEmbeddedWorkerRoute
, this, routing_id
));
97 void DevToolsAgentFilter::AddEmbeddedWorkerRoute(int32 routing_id
) {
98 embedded_worker_routes_
.insert(routing_id
);
101 void DevToolsAgentFilter::RemoveEmbeddedWorkerRoute(int32 routing_id
) {
102 embedded_worker_routes_
.erase(routing_id
);
105 } // namespace content