OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/worker/worker_devtools_agent.h" |
| 6 |
| 7 #include "chrome/common/devtools_messages.h" |
| 8 #include "content/worker/worker_thread.h" |
| 9 #include "ipc/ipc_message.h" |
| 10 #include "ipc/ipc_message_macros.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" |
| 14 |
| 15 using WebKit::WebString; |
| 16 using WebKit::WebCString; |
| 17 using WebKit::WebWorker; |
| 18 |
| 19 WorkerDevToolsAgent::WorkerDevToolsAgent(int route_id, WebWorker* webworker) |
| 20 : route_id_(route_id) |
| 21 , webworker_(webworker) { |
| 22 } |
| 23 |
| 24 WorkerDevToolsAgent::~WorkerDevToolsAgent() { |
| 25 } |
| 26 |
| 27 // Called on the Worker thread. |
| 28 bool WorkerDevToolsAgent::OnMessageReceived(const IPC::Message& message) { |
| 29 bool handled = true; |
| 30 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgent, message) |
| 31 IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Attach, OnAttach) |
| 32 IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Detach, OnDetach) |
| 33 IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_DispatchOnInspectorBackend, |
| 34 OnDispatchOnInspectorBackend) |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) |
| 36 IPC_END_MESSAGE_MAP() |
| 37 return handled; |
| 38 } |
| 39 |
| 40 void WorkerDevToolsAgent::WebWorkerStubDestroyed() { |
| 41 delete this; |
| 42 } |
| 43 |
| 44 void WorkerDevToolsAgent::OnAttach() { |
| 45 webworker_->attachDevTools(); |
| 46 } |
| 47 |
| 48 void WorkerDevToolsAgent::OnDetach() { |
| 49 webworker_->detachDevTools(); |
| 50 } |
| 51 |
| 52 void WorkerDevToolsAgent::OnDispatchOnInspectorBackend( |
| 53 const std::string& message) { |
| 54 webworker_->dispatchDevToolsMessage(WebString::fromUTF8(message)); |
| 55 } |
| 56 |
| 57 bool WorkerDevToolsAgent::Send(IPC::Message* message) { |
| 58 return WorkerThread::current()->Send(message); |
| 59 } |
| 60 |
| 61 void WorkerDevToolsAgent::SendDevToolsMessage(const WebString& message) |
| 62 { |
| 63 Send(new DevToolsAgentMsg_DispatchMessageFromWorker(route_id_, |
| 64 message.utf8())); |
| 65 } |
OLD | NEW |