1 // Copyright 2014 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/service_worker/embedded_worker_devtools_agent.h"
7 #include "content/common/devtools_messages.h"
8 #include "content/renderer/render_thread_impl.h"
9 #include "third_party/WebKit/public/platform/WebCString.h"
10 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/web/WebEmbeddedWorker.h"
13 using blink::WebEmbeddedWorker
;
14 using blink::WebString
;
18 EmbeddedWorkerDevToolsAgent::EmbeddedWorkerDevToolsAgent(
19 blink::WebEmbeddedWorker
* webworker
,
21 : webworker_(webworker
), route_id_(route_id
) {
22 RenderThreadImpl::current()->AddEmbeddedWorkerRoute(route_id_
, this);
25 EmbeddedWorkerDevToolsAgent::~EmbeddedWorkerDevToolsAgent() {
26 RenderThreadImpl::current()->RemoveEmbeddedWorkerRoute(route_id_
);
29 bool EmbeddedWorkerDevToolsAgent::OnMessageReceived(
30 const IPC::Message
& message
) {
32 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDevToolsAgent
, message
)
33 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach
, OnAttach
)
34 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Reattach
, OnReattach
)
35 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach
, OnDetach
)
36 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend
,
37 OnDispatchOnInspectorBackend
)
38 IPC_MESSAGE_UNHANDLED(handled
= false)
43 void EmbeddedWorkerDevToolsAgent::OnAttach(const std::string
& host_id
) {
44 webworker_
->attachDevTools(WebString::fromUTF8(host_id
));
47 void EmbeddedWorkerDevToolsAgent::OnReattach(const std::string
& host_id
,
48 const std::string
& state
) {
49 webworker_
->reattachDevTools(WebString::fromUTF8(host_id
),
50 WebString::fromUTF8(state
));
53 void EmbeddedWorkerDevToolsAgent::OnDetach() {
54 webworker_
->detachDevTools();
57 void EmbeddedWorkerDevToolsAgent::OnDispatchOnInspectorBackend(
58 const std::string
& message
) {
59 webworker_
->dispatchDevToolsMessage(WebString::fromUTF8(message
));
62 } // namespace content