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