OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/worker/worker_devtools_agent.h" | 5 #include "content/worker/worker_devtools_agent.h" |
6 | 6 |
7 #include "content/common/devtools_messages.h" | 7 #include "content/common/devtools_messages.h" |
8 #include "content/worker/worker_thread.h" | 8 #include "content/worker/worker_thread.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorker.h" | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" |
12 | 13 |
14 using WebKit::WebSharedWorker; | |
13 using WebKit::WebString; | 15 using WebKit::WebString; |
14 using WebKit::WebWorker; | 16 using WebKit::WebWorker; |
15 | 17 |
16 WorkerDevToolsAgent::WorkerDevToolsAgent(int route_id, WebWorker* webworker) | 18 namespace { |
17 : route_id_(route_id), | 19 |
18 webworker_(webworker) { | 20 template<class T> |
21 class WorkerDevToolsAgentImpl : public WorkerDevToolsAgent { | |
22 public: | |
23 WorkerDevToolsAgentImpl(int route_id, T* webworker) | |
24 : WorkerDevToolsAgent(route_id), | |
25 webworker_(webworker) {} | |
26 | |
27 private: | |
28 virtual ~WorkerDevToolsAgentImpl() {} | |
29 | |
30 // Called on the Worker thread. | |
31 virtual bool OnMessageReceived(const IPC::Message& message) { | |
32 bool handled = true; | |
33 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentImpl, message) | |
34 IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Attach, OnAttach) | |
35 IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Detach, OnDetach) | |
36 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, | |
37 OnDispatchOnInspectorBackend) | |
38 IPC_MESSAGE_UNHANDLED(handled = false) | |
39 IPC_END_MESSAGE_MAP() | |
40 return handled; | |
41 } | |
42 | |
43 virtual void SendDevToolsMessage(const WebKit::WebString& message); | |
44 | |
45 void OnAttach() { | |
46 webworker_->attachDevTools(); | |
47 } | |
48 | |
49 void OnDetach() { | |
50 webworker_->detachDevTools(); | |
51 } | |
52 | |
53 void OnDispatchOnInspectorBackend( | |
54 const std::string& message) { | |
55 webworker_->dispatchDevToolsMessage(WebString::fromUTF8(message)); | |
56 } | |
57 | |
58 T* webworker_; | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsAgentImpl); | |
61 }; | |
62 | |
63 | |
64 template<> | |
65 void WorkerDevToolsAgentImpl<WebWorker>::SendDevToolsMessage( | |
jam
2011/07/12 18:19:55
nit: it might be easier to read if the constructor
| |
66 const WebKit::WebString& message) { | |
67 Send(new DevToolsAgentMsg_DispatchMessageFromWorker(route_id_, | |
68 message.utf8())); | |
69 } | |
70 | |
71 template<> | |
72 void WorkerDevToolsAgentImpl<WebSharedWorker>::SendDevToolsMessage( | |
73 const WebKit::WebString& message) { | |
74 IPC::Message m = DevToolsClientMsg_DispatchOnInspectorFrontend( | |
75 message.utf8()); | |
76 m.set_routing_id(route_id_); | |
77 Send(new DevToolsHostMsg_ForwardToClient(route_id_, m)); | |
78 } | |
79 | |
80 } // namespace | |
81 | |
82 WorkerDevToolsAgent::WorkerDevToolsAgent(int route_id) | |
83 : route_id_(route_id) { | |
84 } | |
85 | |
86 WorkerDevToolsAgent* WorkerDevToolsAgent::CreateForDedicatedWorker( | |
87 int route_id, | |
88 WebWorker* webworker) { | |
89 return new WorkerDevToolsAgentImpl<WebWorker>(route_id, webworker); | |
90 } | |
91 | |
92 WorkerDevToolsAgent* WorkerDevToolsAgent::CreateForSharedWorker( | |
93 int route_id, | |
94 WebSharedWorker* webshared_worker) { | |
95 return new WorkerDevToolsAgentImpl<WebSharedWorker>(route_id, | |
96 webshared_worker); | |
19 } | 97 } |
20 | 98 |
21 WorkerDevToolsAgent::~WorkerDevToolsAgent() { | 99 WorkerDevToolsAgent::~WorkerDevToolsAgent() { |
22 } | 100 } |
23 | 101 |
24 // Called on the Worker thread. | |
25 bool WorkerDevToolsAgent::OnMessageReceived(const IPC::Message& message) { | |
26 bool handled = true; | |
27 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgent, message) | |
28 IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Attach, OnAttach) | |
29 IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Detach, OnDetach) | |
30 IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_DispatchOnInspectorBackend, | |
31 OnDispatchOnInspectorBackend) | |
32 IPC_MESSAGE_UNHANDLED(handled = false) | |
33 IPC_END_MESSAGE_MAP() | |
34 return handled; | |
35 } | |
36 | |
37 void WorkerDevToolsAgent::OnAttach() { | |
38 webworker_->attachDevTools(); | |
39 } | |
40 | |
41 void WorkerDevToolsAgent::OnDetach() { | |
42 webworker_->detachDevTools(); | |
43 } | |
44 | |
45 void WorkerDevToolsAgent::OnDispatchOnInspectorBackend( | |
46 const std::string& message) { | |
47 webworker_->dispatchDevToolsMessage(WebString::fromUTF8(message)); | |
48 } | |
49 | |
50 bool WorkerDevToolsAgent::Send(IPC::Message* message) { | 102 bool WorkerDevToolsAgent::Send(IPC::Message* message) { |
51 return WorkerThread::current()->Send(message); | 103 return WorkerThread::current()->Send(message); |
52 } | 104 } |
53 | |
54 void WorkerDevToolsAgent::SendDevToolsMessage(const WebString& message) { | |
55 Send(new DevToolsAgentMsg_DispatchMessageFromWorker(route_id_, | |
56 message.utf8())); | |
57 } | |
OLD | NEW |