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