OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser_devtools_agent_host.h" | 5 #include "content/browser/devtools/browser_devtools_agent_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/json/json_reader.h" |
9 #include "content/browser/devtools/devtools_protocol_handler.h" | 10 #include "content/browser/devtools/devtools_protocol_handler.h" |
10 #include "content/browser/devtools/devtools_session.h" | 11 #include "content/browser/devtools/devtools_session.h" |
11 #include "content/browser/devtools/protocol/io_handler.h" | 12 #include "content/browser/devtools/protocol/io_handler.h" |
12 #include "content/browser/devtools/protocol/memory_handler.h" | 13 #include "content/browser/devtools/protocol/memory_handler.h" |
| 14 #include "content/browser/devtools/protocol/protocol.h" |
13 #include "content/browser/devtools/protocol/system_info_handler.h" | 15 #include "content/browser/devtools/protocol/system_info_handler.h" |
14 #include "content/browser/devtools/protocol/tethering_handler.h" | 16 #include "content/browser/devtools/protocol/tethering_handler.h" |
15 #include "content/browser/devtools/protocol/tracing_handler.h" | 17 #include "content/browser/devtools/protocol/tracing_handler.h" |
16 #include "content/browser/frame_host/frame_tree_node.h" | 18 #include "content/browser/frame_host/frame_tree_node.h" |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 | 21 |
20 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::CreateForBrowser( | 22 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::CreateForBrowser( |
21 scoped_refptr<base::SingleThreadTaskRunner> tethering_task_runner, | 23 scoped_refptr<base::SingleThreadTaskRunner> tethering_task_runner, |
22 const CreateServerSocketCallback& socket_callback) { | 24 const CreateServerSocketCallback& socket_callback) { |
23 return new BrowserDevToolsAgentHost(tethering_task_runner, socket_callback); | 25 return new BrowserDevToolsAgentHost(tethering_task_runner, socket_callback); |
24 } | 26 } |
25 | 27 |
26 BrowserDevToolsAgentHost::BrowserDevToolsAgentHost( | 28 BrowserDevToolsAgentHost::BrowserDevToolsAgentHost( |
27 scoped_refptr<base::SingleThreadTaskRunner> tethering_task_runner, | 29 scoped_refptr<base::SingleThreadTaskRunner> tethering_task_runner, |
28 const CreateServerSocketCallback& socket_callback) | 30 const CreateServerSocketCallback& socket_callback) |
29 : DevToolsAgentHostImpl(base::GenerateGUID()), | 31 : DevToolsAgentHostImpl(base::GenerateGUID()), |
30 io_handler_(new devtools::io::IOHandler(GetIOContext())), | |
31 memory_handler_(new devtools::memory::MemoryHandler()), | 32 memory_handler_(new devtools::memory::MemoryHandler()), |
32 system_info_handler_(new devtools::system_info::SystemInfoHandler()), | 33 system_info_handler_(new devtools::system_info::SystemInfoHandler()), |
33 tethering_handler_( | 34 tethering_handler_( |
34 new devtools::tethering::TetheringHandler(socket_callback, | 35 new devtools::tethering::TetheringHandler(socket_callback, |
35 tethering_task_runner)), | 36 tethering_task_runner)), |
36 tracing_handler_(new devtools::tracing::TracingHandler( | |
37 devtools::tracing::TracingHandler::Browser, | |
38 FrameTreeNode::kFrameTreeNodeInvalidId, | |
39 GetIOContext())), | |
40 protocol_handler_(new DevToolsProtocolHandler(this)) { | 37 protocol_handler_(new DevToolsProtocolHandler(this)) { |
41 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 38 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
42 dispatcher->SetIOHandler(io_handler_.get()); | |
43 dispatcher->SetMemoryHandler(memory_handler_.get()); | 39 dispatcher->SetMemoryHandler(memory_handler_.get()); |
44 dispatcher->SetSystemInfoHandler(system_info_handler_.get()); | 40 dispatcher->SetSystemInfoHandler(system_info_handler_.get()); |
45 dispatcher->SetTetheringHandler(tethering_handler_.get()); | 41 dispatcher->SetTetheringHandler(tethering_handler_.get()); |
46 dispatcher->SetTracingHandler(tracing_handler_.get()); | |
47 NotifyCreated(); | 42 NotifyCreated(); |
48 } | 43 } |
49 | 44 |
50 BrowserDevToolsAgentHost::~BrowserDevToolsAgentHost() { | 45 BrowserDevToolsAgentHost::~BrowserDevToolsAgentHost() { |
51 } | 46 } |
52 | 47 |
53 void BrowserDevToolsAgentHost::Attach() { | 48 void BrowserDevToolsAgentHost::Attach() { |
| 49 session()->dispatcher()->setFallThroughForNotFound(true); |
| 50 io_handler_.reset(new protocol::IOHandler(GetIOContext())); |
| 51 io_handler_->Wire(session()->dispatcher()); |
| 52 |
| 53 tracing_handler_.reset(new protocol::TracingHandler( |
| 54 protocol::TracingHandler::Browser, |
| 55 FrameTreeNode::kFrameTreeNodeInvalidId, |
| 56 GetIOContext())); |
| 57 tracing_handler_->Wire(session()->dispatcher()); |
54 } | 58 } |
55 | 59 |
56 void BrowserDevToolsAgentHost::Detach() { | 60 void BrowserDevToolsAgentHost::Detach() { |
| 61 io_handler_.reset(); |
| 62 tracing_handler_.reset(); |
57 } | 63 } |
58 | 64 |
59 std::string BrowserDevToolsAgentHost::GetType() { | 65 std::string BrowserDevToolsAgentHost::GetType() { |
60 return kTypeBrowser; | 66 return kTypeBrowser; |
61 } | 67 } |
62 | 68 |
63 std::string BrowserDevToolsAgentHost::GetTitle() { | 69 std::string BrowserDevToolsAgentHost::GetTitle() { |
64 return ""; | 70 return ""; |
65 } | 71 } |
66 | 72 |
67 GURL BrowserDevToolsAgentHost::GetURL() { | 73 GURL BrowserDevToolsAgentHost::GetURL() { |
68 return GURL(); | 74 return GURL(); |
69 } | 75 } |
70 | 76 |
71 bool BrowserDevToolsAgentHost::Activate() { | 77 bool BrowserDevToolsAgentHost::Activate() { |
72 return false; | 78 return false; |
73 } | 79 } |
74 | 80 |
75 bool BrowserDevToolsAgentHost::Close() { | 81 bool BrowserDevToolsAgentHost::Close() { |
76 return false; | 82 return false; |
77 } | 83 } |
78 | 84 |
79 void BrowserDevToolsAgentHost::Reload() { | 85 void BrowserDevToolsAgentHost::Reload() { |
80 } | 86 } |
81 | 87 |
82 bool BrowserDevToolsAgentHost::DispatchProtocolMessage( | 88 bool BrowserDevToolsAgentHost::DispatchProtocolMessage( |
83 const std::string& message) { | 89 const std::string& message) { |
84 protocol_handler_->HandleMessage(session() ? session()->session_id() : 0, | 90 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); |
85 message); | 91 std::unique_ptr<protocol::Value> protocolValue = |
| 92 protocol::toProtocolValue(value.get(), 1000); |
| 93 if (session()->dispatcher()->dispatch(std::move(protocolValue)) == |
| 94 protocol::Response::kFallThrough) { |
| 95 protocol_handler_->HandleMessage(session()->session_id(), std::move(value)); |
| 96 } |
86 return true; | 97 return true; |
87 } | 98 } |
88 | 99 |
89 } // content | 100 } // content |
OLD | NEW |