OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/devtools/devtools_agent_host_impl.h" | 5 #include "content/browser/devtools/devtools_agent_host_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/guid.h" | |
11 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
12 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
13 #include "content/browser/devtools/devtools_manager.h" | 12 #include "content/browser/devtools/devtools_manager.h" |
14 #include "content/browser/devtools/forwarding_agent_host.h" | 13 #include "content/browser/devtools/forwarding_agent_host.h" |
15 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" | 14 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" |
16 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 15 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
17 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 16 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
18 #include "content/browser/devtools/service_worker_devtools_manager.h" | 17 #include "content/browser/devtools/service_worker_devtools_manager.h" |
19 #include "content/browser/devtools/shared_worker_devtools_agent_host.h" | 18 #include "content/browser/devtools/shared_worker_devtools_agent_host.h" |
20 #include "content/browser/devtools/shared_worker_devtools_manager.h" | 19 #include "content/browser/devtools/shared_worker_devtools_manager.h" |
21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
22 | 21 |
23 namespace content { | 22 namespace content { |
24 | 23 |
25 namespace { | 24 namespace { |
26 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; | 25 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; |
27 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; | 26 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; |
28 | 27 |
29 typedef std::vector<const DevToolsAgentHost::AgentStateCallback*> | 28 typedef std::vector<const DevToolsAgentHost::AgentStateCallback*> |
30 AgentStateCallbacks; | 29 AgentStateCallbacks; |
31 base::LazyInstance<AgentStateCallbacks>::Leaky g_callbacks = | 30 base::LazyInstance<AgentStateCallbacks>::Leaky g_callbacks = |
32 LAZY_INSTANCE_INITIALIZER; | 31 LAZY_INSTANCE_INITIALIZER; |
33 } // namespace | 32 } // namespace |
34 | 33 |
| 34 char DevToolsAgentHost::kTypePage[] = "page"; |
| 35 char DevToolsAgentHost::kTypeFrame[] = "frame"; |
| 36 char DevToolsAgentHost::kTypeSharedWorker[] = "shared_worker"; |
| 37 char DevToolsAgentHost::kTypeServiceWorker[] = "service_worker"; |
| 38 char DevToolsAgentHost::kTypeExternal[] = "external"; |
| 39 char DevToolsAgentHost::kTypeBrowser[] = "browser"; |
| 40 char DevToolsAgentHost::kTypeOther[] = "other"; |
| 41 |
35 // static | 42 // static |
36 std::string DevToolsAgentHost::GetProtocolVersion() { | 43 std::string DevToolsAgentHost::GetProtocolVersion() { |
37 return std::string(devtools::kProtocolVersion); | 44 return std::string(devtools::kProtocolVersion); |
38 } | 45 } |
39 | 46 |
40 // static | 47 // static |
41 bool DevToolsAgentHost::IsSupportedProtocolVersion(const std::string& version) { | 48 bool DevToolsAgentHost::IsSupportedProtocolVersion(const std::string& version) { |
42 return devtools::IsSupportedProtocolVersion(version); | 49 return devtools::IsSupportedProtocolVersion(version); |
43 } | 50 } |
44 | 51 |
(...skipping 22 matching lines...) Expand all Loading... |
67 if (scoped_refptr<DevToolsAgentHost> host = | 74 if (scoped_refptr<DevToolsAgentHost> host = |
68 SharedWorkerDevToolsManager::GetInstance() | 75 SharedWorkerDevToolsManager::GetInstance() |
69 ->GetDevToolsAgentHostForWorker(worker_process_id, | 76 ->GetDevToolsAgentHostForWorker(worker_process_id, |
70 worker_route_id)) { | 77 worker_route_id)) { |
71 return host; | 78 return host; |
72 } | 79 } |
73 return ServiceWorkerDevToolsManager::GetInstance() | 80 return ServiceWorkerDevToolsManager::GetInstance() |
74 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); | 81 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); |
75 } | 82 } |
76 | 83 |
77 DevToolsAgentHostImpl::DevToolsAgentHostImpl() | 84 DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id) |
78 : id_(base::GenerateGUID()), session_id_(0), client_(NULL) { | 85 : id_(id), |
| 86 session_id_(0), |
| 87 description_(""), |
| 88 client_(NULL) { |
79 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
80 g_instances.Get()[id_] = this; | 90 g_instances.Get()[id_] = this; |
81 } | 91 } |
82 | 92 |
83 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 93 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
84 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 94 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
85 g_instances.Get().erase(g_instances.Get().find(id_)); | 95 g_instances.Get().erase(g_instances.Get().find(id_)); |
86 } | 96 } |
87 | 97 |
88 // static | 98 // static |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 int y) { | 169 int y) { |
160 if (!client_ || client_ != client) | 170 if (!client_ || client_ != client) |
161 return; | 171 return; |
162 InspectElement(x, y); | 172 InspectElement(x, y); |
163 } | 173 } |
164 | 174 |
165 std::string DevToolsAgentHostImpl::GetId() { | 175 std::string DevToolsAgentHostImpl::GetId() { |
166 return id_; | 176 return id_; |
167 } | 177 } |
168 | 178 |
| 179 std::string DevToolsAgentHostImpl::GetParentId() { |
| 180 return ""; |
| 181 } |
| 182 |
| 183 std::string DevToolsAgentHostImpl::GetDescription() { |
| 184 return description_; |
| 185 } |
| 186 |
| 187 void DevToolsAgentHostImpl::SetDescriptionOverride( |
| 188 const std::string& description) { |
| 189 description_ = description; |
| 190 } |
| 191 |
| 192 GURL DevToolsAgentHostImpl::GetFaviconURL() { |
| 193 return GURL(); |
| 194 } |
| 195 |
| 196 base::TimeTicks DevToolsAgentHostImpl::GetLastActivityTime() { |
| 197 return base::TimeTicks(); |
| 198 } |
| 199 |
169 BrowserContext* DevToolsAgentHostImpl::GetBrowserContext() { | 200 BrowserContext* DevToolsAgentHostImpl::GetBrowserContext() { |
170 return nullptr; | 201 return nullptr; |
171 } | 202 } |
172 | 203 |
173 WebContents* DevToolsAgentHostImpl::GetWebContents() { | 204 WebContents* DevToolsAgentHostImpl::GetWebContents() { |
174 return NULL; | 205 return NULL; |
175 } | 206 } |
176 | 207 |
177 void DevToolsAgentHostImpl::DisconnectWebContents() { | 208 void DevToolsAgentHostImpl::DisconnectWebContents() { |
178 } | 209 } |
179 | 210 |
180 void DevToolsAgentHostImpl::ConnectWebContents(WebContents* wc) { | 211 void DevToolsAgentHostImpl::ConnectWebContents(WebContents* wc) { |
181 } | 212 } |
182 | 213 |
| 214 bool DevToolsAgentHostImpl::Inspect() { |
| 215 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 216 if (manager->delegate()) { |
| 217 manager->delegate()->Inspect(this); |
| 218 return true; |
| 219 } |
| 220 return false; |
| 221 } |
| 222 |
183 void DevToolsAgentHostImpl::SendProtocolResponse(int session_id, | 223 void DevToolsAgentHostImpl::SendProtocolResponse(int session_id, |
184 const std::string& message) { | 224 const std::string& message) { |
185 SendMessageToClient(session_id, message); | 225 SendMessageToClient(session_id, message); |
186 } | 226 } |
187 | 227 |
188 void DevToolsAgentHostImpl::SendProtocolNotification( | 228 void DevToolsAgentHostImpl::SendProtocolNotification( |
189 const std::string& message) { | 229 const std::string& message) { |
190 SendMessageToClient(session_id_, message); | 230 SendMessageToClient(session_id_, message); |
191 } | 231 } |
192 | 232 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 DevToolsAgentHostImpl* agent_host, bool attached) { | 299 DevToolsAgentHostImpl* agent_host, bool attached) { |
260 AgentStateCallbacks copy(g_callbacks.Get()); | 300 AgentStateCallbacks copy(g_callbacks.Get()); |
261 DevToolsManager* manager = DevToolsManager::GetInstance(); | 301 DevToolsManager* manager = DevToolsManager::GetInstance(); |
262 manager->AgentHostStateChanged(agent_host, attached); | 302 manager->AgentHostStateChanged(agent_host, attached); |
263 if (manager->delegate()) | 303 if (manager->delegate()) |
264 manager->delegate()->DevToolsAgentStateChanged(agent_host, attached); | 304 manager->delegate()->DevToolsAgentStateChanged(agent_host, attached); |
265 for (AgentStateCallbacks::iterator it = copy.begin(); it != copy.end(); ++it) | 305 for (AgentStateCallbacks::iterator it = copy.begin(); it != copy.end(); ++it) |
266 (*it)->Run(agent_host, attached); | 306 (*it)->Run(agent_host, attached); |
267 } | 307 } |
268 | 308 |
269 bool DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { | |
270 DevToolsManager* manager = DevToolsManager::GetInstance(); | |
271 if (manager->delegate()) { | |
272 manager->delegate()->Inspect(browser_context, this); | |
273 return true; | |
274 } | |
275 return false; | |
276 } | |
277 | |
278 // DevToolsMessageChunkProcessor ----------------------------------------------- | 309 // DevToolsMessageChunkProcessor ----------------------------------------------- |
279 | 310 |
280 DevToolsMessageChunkProcessor::DevToolsMessageChunkProcessor( | 311 DevToolsMessageChunkProcessor::DevToolsMessageChunkProcessor( |
281 const SendMessageCallback& callback) | 312 const SendMessageCallback& callback) |
282 : callback_(callback), | 313 : callback_(callback), |
283 message_buffer_size_(0), | 314 message_buffer_size_(0), |
284 last_call_id_(0) { | 315 last_call_id_(0) { |
285 } | 316 } |
286 | 317 |
287 DevToolsMessageChunkProcessor::~DevToolsMessageChunkProcessor() { | 318 DevToolsMessageChunkProcessor::~DevToolsMessageChunkProcessor() { |
(...skipping 27 matching lines...) Expand all Loading... |
315 if (message_buffer_.size() != message_buffer_size_) | 346 if (message_buffer_.size() != message_buffer_size_) |
316 return false; | 347 return false; |
317 callback_.Run(chunk.session_id, message_buffer_); | 348 callback_.Run(chunk.session_id, message_buffer_); |
318 message_buffer_ = std::string(); | 349 message_buffer_ = std::string(); |
319 message_buffer_size_ = 0; | 350 message_buffer_size_ = 0; |
320 } | 351 } |
321 return true; | 352 return true; |
322 } | 353 } |
323 | 354 |
324 } // namespace content | 355 } // namespace content |
OLD | NEW |