Chromium Code Reviews| Index: content/browser/devtools/devtools_agent_host_impl.cc |
| diff --git a/content/browser/devtools/devtools_agent_host_impl.cc b/content/browser/devtools/devtools_agent_host_impl.cc |
| index 2c55fade8043bee655e5c7291de4e23dd5b520e2..894c8cf1e09fd518478e9eddac6e5f76fc2f5f85 100644 |
| --- a/content/browser/devtools/devtools_agent_host_impl.cc |
| +++ b/content/browser/devtools/devtools_agent_host_impl.cc |
| @@ -9,9 +9,11 @@ |
| #include "base/basictypes.h" |
| #include "base/guid.h" |
| +#include "base/json/json_writer.h" |
| #include "base/lazy_instance.h" |
| #include "content/browser/devtools/devtools_manager.h" |
| #include "content/browser/devtools/forwarding_agent_host.h" |
| +#include "content/browser/devtools/protocol/devtools_protocol_handler.h" |
| #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
| #include "content/browser/devtools/service_worker_devtools_manager.h" |
| @@ -65,7 +67,10 @@ scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForWorker( |
| } |
| DevToolsAgentHostImpl::DevToolsAgentHostImpl() |
| - : id_(base::GenerateGUID()), |
| + : protocol_handler_(new DevToolsProtocolHandler( |
| + base::Bind(&DevToolsAgentHostImpl::SendMessageToClient, |
| + base::Unretained(this)))), |
| + id_(base::GenerateGUID()), |
| client_(NULL) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| g_instances.Get()[id_] = this; |
| @@ -219,4 +224,30 @@ void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { |
| manager->delegate()->Inspect(browser_context, this); |
| } |
| +bool DevToolsAgentHostImpl::DispatchProtocolMessage( |
| + const std::string& message) { |
| + scoped_ptr<base::DictionaryValue> command = |
| + protocol_handler_->ParseCommand(message); |
| + if (!command) |
| + return true; |
| + |
| + DevToolsManagerDelegate* delegate = |
| + DevToolsManager::GetInstance()->delegate(); |
| + if (delegate) { |
| + scoped_ptr<base::DictionaryValue> response( |
| + delegate->HandleCommand(this, command.get())); |
| + if (response) { |
| + std::string json_response; |
| + base::JSONWriter::Write(response.get(), &json_response); |
| + SendMessageToClient(json_response); |
| + return true; |
| + } |
| + } |
| + |
| + if (protocol_handler_->HandleOptionalCommand(command.Pass())) |
|
pfeldman
2015/03/23 10:31:37
nit: return protocol_handler_->HandleOptionalComma
Kunihiko Sakamoto
2015/03/23 10:45:51
Done.
|
| + return true; |
| + |
| + return false; |
| +} |
| + |
| } // namespace content |