Chromium Code Reviews| 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/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/json/json_writer.h" | |
| 12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 13 #include "content/browser/devtools/devtools_manager.h" | 14 #include "content/browser/devtools/devtools_manager.h" |
| 14 #include "content/browser/devtools/forwarding_agent_host.h" | 15 #include "content/browser/devtools/forwarding_agent_host.h" |
| 16 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" | |
| 15 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 17 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| 16 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 18 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
| 17 #include "content/browser/devtools/service_worker_devtools_manager.h" | 19 #include "content/browser/devtools/service_worker_devtools_manager.h" |
| 18 #include "content/browser/devtools/shared_worker_devtools_agent_host.h" | 20 #include "content/browser/devtools/shared_worker_devtools_agent_host.h" |
| 19 #include "content/browser/devtools/shared_worker_devtools_manager.h" | 21 #include "content/browser/devtools/shared_worker_devtools_manager.h" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/devtools_manager_delegate.h" | 23 #include "content/public/browser/devtools_manager_delegate.h" |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 SharedWorkerDevToolsManager::GetInstance() | 60 SharedWorkerDevToolsManager::GetInstance() |
| 59 ->GetDevToolsAgentHostForWorker(worker_process_id, | 61 ->GetDevToolsAgentHostForWorker(worker_process_id, |
| 60 worker_route_id)) { | 62 worker_route_id)) { |
| 61 return host; | 63 return host; |
| 62 } | 64 } |
| 63 return ServiceWorkerDevToolsManager::GetInstance() | 65 return ServiceWorkerDevToolsManager::GetInstance() |
| 64 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); | 66 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); |
| 65 } | 67 } |
| 66 | 68 |
| 67 DevToolsAgentHostImpl::DevToolsAgentHostImpl() | 69 DevToolsAgentHostImpl::DevToolsAgentHostImpl() |
| 68 : id_(base::GenerateGUID()), | 70 : protocol_handler_(new DevToolsProtocolHandler( |
| 71 base::Bind(&DevToolsAgentHostImpl::DispatchOnInspectorFrontend, | |
| 72 base::Unretained(this)))), | |
| 73 id_(base::GenerateGUID()), | |
| 69 client_(NULL) { | 74 client_(NULL) { |
| 70 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 71 g_instances.Get()[id_] = this; | 76 g_instances.Get()[id_] = this; |
| 72 } | 77 } |
| 73 | 78 |
| 74 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 79 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 80 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 76 g_instances.Get().erase(g_instances.Get().find(id_)); | 81 g_instances.Get().erase(g_instances.Get().find(id_)); |
| 77 } | 82 } |
| 78 | 83 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 for (AgentStateCallbacks::iterator it = copy.begin(); it != copy.end(); ++it) | 217 for (AgentStateCallbacks::iterator it = copy.begin(); it != copy.end(); ++it) |
| 213 (*it)->Run(agent_host, attached); | 218 (*it)->Run(agent_host, attached); |
| 214 } | 219 } |
| 215 | 220 |
| 216 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { | 221 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { |
| 217 DevToolsManager* manager = DevToolsManager::GetInstance(); | 222 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 218 if (manager->delegate()) | 223 if (manager->delegate()) |
| 219 manager->delegate()->Inspect(browser_context, this); | 224 manager->delegate()->Inspect(browser_context, this); |
| 220 } | 225 } |
| 221 | 226 |
| 227 bool DevToolsAgentHostImpl::DispatchProtocolMessage( | |
| 228 const std::string& message) { | |
| 229 scoped_ptr<base::DictionaryValue> command = | |
| 230 protocol_handler_->ParseCommand(message); | |
| 231 if (!command) | |
| 232 return false; | |
|
pfeldman
2015/03/23 09:59:00
See my comment below, this should be "true" since
Kunihiko Sakamoto
2015/03/23 10:23:58
Done.
| |
| 233 | |
| 234 DevToolsManagerDelegate* delegate = | |
| 235 DevToolsManager::GetInstance()->delegate(); | |
| 236 if (delegate) { | |
| 237 scoped_ptr<base::DictionaryValue> response( | |
| 238 delegate->HandleCommand(this, command.get())); | |
| 239 if (response) { | |
| 240 std::string json_response; | |
| 241 base::JSONWriter::Write(response.get(), &json_response); | |
| 242 DispatchOnInspectorFrontend(json_response); | |
| 243 return true; | |
| 244 } | |
| 245 } | |
| 246 | |
| 247 if (protocol_handler_->HandleOptionalCommand(command.Pass())) | |
| 248 return true; | |
| 249 | |
| 250 return false; | |
| 251 } | |
| 252 | |
| 253 void DevToolsAgentHostImpl::DispatchOnInspectorFrontend( | |
| 254 const std::string& message) { | |
| 255 if (!IsAttached()) | |
|
pfeldman
2015/03/23 09:59:00
This check is already present in SendMessageToClie
| |
| 256 return; | |
| 257 SendMessageToClient(message); | |
| 258 } | |
| 259 | |
| 222 } // namespace content | 260 } // namespace content |
| OLD | NEW |