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/child/shared_worker_devtools_agent.h" 6 7 #include "content/child/child_thread.h" 8 #include "content/common/devtools_messages.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" 12 13 using blink::WebSharedWorker; 14 using blink::WebString; 15 16 namespace content { 17 18 SharedWorkerDevToolsAgent::SharedWorkerDevToolsAgent( 19 int route_id, 20 WebSharedWorker* webworker) 21 : route_id_(route_id), 22 webworker_(webworker) { 23 } 24 25 SharedWorkerDevToolsAgent::~SharedWorkerDevToolsAgent() { 26 } 27 28 // Called on the Worker thread. 29 bool SharedWorkerDevToolsAgent::OnMessageReceived(const IPC::Message& message) { 30 bool handled = true; 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_ResumeWorkerContext, 38 OnResumeWorkerContext) 39 IPC_MESSAGE_UNHANDLED(handled = false) 40 IPC_END_MESSAGE_MAP() 41 return handled; 42 } 43 44 void SharedWorkerDevToolsAgent::SendDevToolsMessage( 45 const blink::WebString& message) { 46 Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( 47 route_id_, 48 message.utf8())); 49 } 50 51 void SharedWorkerDevToolsAgent::SaveDevToolsAgentState( 52 const blink::WebString& state) { 53 Send(new DevToolsHostMsg_SaveAgentRuntimeState(route_id_, 54 state.utf8())); 55 } 56 57 void SharedWorkerDevToolsAgent::OnAttach(const std::string& host_id) { 58 webworker_->attachDevTools(); 59 } 60 61 void SharedWorkerDevToolsAgent::OnReattach(const std::string& host_id, 62 const std::string& state) { 63 webworker_->reattachDevTools(WebString::fromUTF8(state)); 64 } 65 66 void SharedWorkerDevToolsAgent::OnDetach() { 67 webworker_->detachDevTools(); 68 } 69 70 void SharedWorkerDevToolsAgent::OnDispatchOnInspectorBackend( 71 const std::string& message) { 72 webworker_->dispatchDevToolsMessage(WebString::fromUTF8(message)); 73 } 74 75 void SharedWorkerDevToolsAgent::OnResumeWorkerContext() { 76 webworker_->resumeWorkerContext(); 77 } 78 79 bool SharedWorkerDevToolsAgent::Send(IPC::Message* message) { 80 return ChildThread::current()->Send(message); 81 } 82 83 } // namespace content 84