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.
4
5 #include "content/renderer/service_worker/embedded_worker_devtools_agent.h"
6
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"
13
14 using blink::WebEmbeddedWorker;
15 using blink::WebString;
16
17 namespace content {
18
EmbeddedWorkerDevToolsAgent(blink::WebEmbeddedWorker * webworker,int route_id)19 EmbeddedWorkerDevToolsAgent::EmbeddedWorkerDevToolsAgent(
20 blink::WebEmbeddedWorker* webworker,
21 int route_id)
22 : webworker_(webworker), route_id_(route_id) {
23 RenderThreadImpl::current()->AddEmbeddedWorkerRoute(route_id_, this);
24 }
25
~EmbeddedWorkerDevToolsAgent()26 EmbeddedWorkerDevToolsAgent::~EmbeddedWorkerDevToolsAgent() {
27 RenderThreadImpl::current()->RemoveEmbeddedWorkerRoute(route_id_);
28 }
29
OnMessageReceived(const IPC::Message & message)30 bool EmbeddedWorkerDevToolsAgent::OnMessageReceived(
31 const IPC::Message& message) {
32 bool handled = true;
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)
42 IPC_END_MESSAGE_MAP()
43 return handled;
44 }
45
OnAttach(const std::string & host_id)46 void EmbeddedWorkerDevToolsAgent::OnAttach(const std::string& host_id) {
47 webworker_->attachDevTools(WebString::fromUTF8(host_id));
48 }
49
OnReattach(const std::string & host_id,const std::string & state)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));
54 }
55
OnDetach()56 void EmbeddedWorkerDevToolsAgent::OnDetach() {
57 webworker_->detachDevTools();
58 }
59
OnDispatchOnInspectorBackend(const std::string & message)60 void EmbeddedWorkerDevToolsAgent::OnDispatchOnInspectorBackend(
61 const std::string& message) {
62 webworker_->dispatchDevToolsMessage(WebString::fromUTF8(message));
63 }
64
OnResumeWorkerContext()65 void EmbeddedWorkerDevToolsAgent::OnResumeWorkerContext() {
66 webworker_->resumeWorkerContext();
67 }
68
69 } // namespace content
70