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/child/child_thread.h"
8 #include "content/common/devtools_messages.h"
9 #include "content/renderer/render_thread_impl.h"
10 #include "third_party/WebKit/public/platform/WebCString.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
12 #include "third_party/WebKit/public/web/WebEmbeddedWorker.h"
14 using blink::WebEmbeddedWorker
;
15 using blink::WebString
;
19 EmbeddedWorkerDevToolsAgent::EmbeddedWorkerDevToolsAgent(
20 blink::WebEmbeddedWorker
* webworker
,
22 : webworker_(webworker
), route_id_(route_id
) {
23 RenderThreadImpl::current()->AddEmbeddedWorkerRoute(route_id_
, this);
26 EmbeddedWorkerDevToolsAgent::~EmbeddedWorkerDevToolsAgent() {
27 RenderThreadImpl::current()->RemoveEmbeddedWorkerRoute(route_id_
);
30 bool EmbeddedWorkerDevToolsAgent::OnMessageReceived(
31 const IPC::Message
& message
) {
33 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDevToolsAgent
, message
)
34 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach
, OnAttach
)
35 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Reattach
, OnReattach
)
36 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach
, OnDetach
)
37 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend
,
38 OnDispatchOnInspectorBackend
)
39 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_ResumeWorkerContext
,
40 OnResumeWorkerContext
)
41 IPC_MESSAGE_UNHANDLED(handled
= false)
46 void EmbeddedWorkerDevToolsAgent::OnAttach(const std::string
& host_id
) {
47 webworker_
->attachDevTools(WebString::fromUTF8(host_id
));
50 void EmbeddedWorkerDevToolsAgent::OnReattach(const std::string
& host_id
,
51 const std::string
& state
) {
52 webworker_
->reattachDevTools(WebString::fromUTF8(host_id
),
53 WebString::fromUTF8(state
));
56 void EmbeddedWorkerDevToolsAgent::OnDetach() {
57 webworker_
->detachDevTools();
60 void EmbeddedWorkerDevToolsAgent::OnDispatchOnInspectorBackend(
61 const std::string
& message
) {
62 webworker_
->dispatchDevToolsMessage(WebString::fromUTF8(message
));
65 void EmbeddedWorkerDevToolsAgent::OnResumeWorkerContext() {
66 webworker_
->resumeWorkerContext();
69 } // namespace content