1 // Copyright (c) 2011 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/worker/shared_worker_devtools_agent.h"
7 #include "content/common/devtools_messages.h"
8 #include "content/worker/worker_thread.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/WebSharedWorker.h"
13 using blink::WebSharedWorker
;
14 using blink::WebString
;
18 SharedWorkerDevToolsAgent::SharedWorkerDevToolsAgent(
20 WebSharedWorker
* webworker
)
21 : route_id_(route_id
),
22 webworker_(webworker
) {
25 SharedWorkerDevToolsAgent::~SharedWorkerDevToolsAgent() {
28 // Called on the Worker thread.
29 bool SharedWorkerDevToolsAgent::OnMessageReceived(const IPC::Message
& message
) {
31 IPC_BEGIN_MESSAGE_MAP(SharedWorkerDevToolsAgent
, message
)
32 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach
, OnAttach
)
33 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Reattach
, OnReattach
)
34 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach
, OnDetach
)
35 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend
,
36 OnDispatchOnInspectorBackend
)
37 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_PauseWorkerContextOnStart
,
38 OnPauseWorkerContextOnStart
)
39 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_ResumeWorkerContext
,
40 OnResumeWorkerContext
)
41 IPC_MESSAGE_UNHANDLED(handled
= false)
46 void SharedWorkerDevToolsAgent::SendDevToolsMessage(
47 const blink::WebString
& message
) {
48 Send(new DevToolsClientMsg_DispatchOnInspectorFrontend(
53 void SharedWorkerDevToolsAgent::SaveDevToolsAgentState(
54 const blink::WebString
& state
) {
55 Send(new DevToolsHostMsg_SaveAgentRuntimeState(route_id_
,
59 void SharedWorkerDevToolsAgent::OnAttach() {
60 webworker_
->attachDevTools();
63 void SharedWorkerDevToolsAgent::OnReattach(const std::string
& state
) {
64 webworker_
->reattachDevTools(WebString::fromUTF8(state
));
67 void SharedWorkerDevToolsAgent::OnDetach() {
68 webworker_
->detachDevTools();
71 void SharedWorkerDevToolsAgent::OnDispatchOnInspectorBackend(
72 const std::string
& message
) {
73 webworker_
->dispatchDevToolsMessage(WebString::fromUTF8(message
));
76 void SharedWorkerDevToolsAgent::OnPauseWorkerContextOnStart() {
77 webworker_
->pauseWorkerContextOnStart();
80 void SharedWorkerDevToolsAgent::OnResumeWorkerContext() {
81 webworker_
->resumeWorkerContext();
84 bool SharedWorkerDevToolsAgent::Send(IPC::Message
* message
) {
85 return WorkerThread::current()->Send(message
);
88 } // namespace content