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