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/bind.h" | 10 #include "base/bind.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "content/browser/devtools/devtools_manager.h" | 15 #include "content/browser/devtools/devtools_manager.h" |
| 16 #include "content/browser/devtools/devtools_session.h" |
16 #include "content/browser/devtools/forwarding_agent_host.h" | 17 #include "content/browser/devtools/forwarding_agent_host.h" |
17 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" | 18 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" |
18 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 19 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
19 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 20 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
20 #include "content/browser/devtools/service_worker_devtools_manager.h" | 21 #include "content/browser/devtools/service_worker_devtools_manager.h" |
21 #include "content/browser/devtools/shared_worker_devtools_agent_host.h" | 22 #include "content/browser/devtools/shared_worker_devtools_agent_host.h" |
22 #include "content/browser/devtools/shared_worker_devtools_manager.h" | 23 #include "content/browser/devtools/shared_worker_devtools_manager.h" |
23 #include "content/browser/loader/netlog_observer.h" | 24 #include "content/browser/loader/netlog_observer.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 ->GetDevToolsAgentHostForWorker(worker_process_id, | 97 ->GetDevToolsAgentHostForWorker(worker_process_id, |
97 worker_route_id)) { | 98 worker_route_id)) { |
98 return host; | 99 return host; |
99 } | 100 } |
100 return ServiceWorkerDevToolsManager::GetInstance() | 101 return ServiceWorkerDevToolsManager::GetInstance() |
101 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); | 102 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); |
102 } | 103 } |
103 | 104 |
104 DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id) | 105 DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id) |
105 : id_(id), | 106 : id_(id), |
106 session_id_(0), | 107 last_session_id_(0), |
107 client_(NULL) { | 108 client_(NULL) { |
108 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 109 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
109 } | 110 } |
110 | 111 |
111 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 112 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
112 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 113 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
113 NotifyDestroyed(); | 114 NotifyDestroyed(); |
114 } | 115 } |
115 | 116 |
116 // static | 117 // static |
(...skipping 16 matching lines...) Expand all Loading... |
133 return result; | 134 return result; |
134 return new ForwardingAgentHost(id, std::move(delegate)); | 135 return new ForwardingAgentHost(id, std::move(delegate)); |
135 } | 136 } |
136 | 137 |
137 bool DevToolsAgentHostImpl::InnerAttach(DevToolsAgentHostClient* client, | 138 bool DevToolsAgentHostImpl::InnerAttach(DevToolsAgentHostClient* client, |
138 bool force) { | 139 bool force) { |
139 if (client_ && !force) | 140 if (client_ && !force) |
140 return false; | 141 return false; |
141 | 142 |
142 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 143 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
143 ++session_id_; | |
144 if (client_) { | 144 if (client_) { |
145 client_->AgentHostClosed(this, true); | 145 client_->AgentHostClosed(this, true); |
146 InnerDetach(); | 146 InnerDetach(); |
147 } | 147 } |
148 client_ = client; | 148 client_ = client; |
| 149 session_.reset(new DevToolsSession(this, ++last_session_id_)); |
149 Attach(); | 150 Attach(); |
150 NotifyAttached(); | 151 NotifyAttached(); |
151 return true; | 152 return true; |
152 } | 153 } |
153 | 154 |
154 bool DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { | 155 bool DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { |
155 return InnerAttach(client, false); | 156 return InnerAttach(client, false); |
156 } | 157 } |
157 | 158 |
158 void DevToolsAgentHostImpl::ForceAttachClient(DevToolsAgentHostClient* client) { | 159 void DevToolsAgentHostImpl::ForceAttachClient(DevToolsAgentHostClient* client) { |
(...skipping 14 matching lines...) Expand all Loading... |
173 DevToolsAgentHostClient* client, | 174 DevToolsAgentHostClient* client, |
174 const std::string& message) { | 175 const std::string& message) { |
175 if (!client_ || client_ != client) | 176 if (!client_ || client_ != client) |
176 return false; | 177 return false; |
177 return DispatchProtocolMessage(message); | 178 return DispatchProtocolMessage(message); |
178 } | 179 } |
179 | 180 |
180 void DevToolsAgentHostImpl::InnerDetach() { | 181 void DevToolsAgentHostImpl::InnerDetach() { |
181 Detach(); | 182 Detach(); |
182 io_context_.DiscardAllStreams(); | 183 io_context_.DiscardAllStreams(); |
| 184 session_.reset(); |
183 NotifyDetached(); | 185 NotifyDetached(); |
184 } | 186 } |
185 | 187 |
186 bool DevToolsAgentHostImpl::IsAttached() { | 188 bool DevToolsAgentHostImpl::IsAttached() { |
187 return !!client_; | 189 return !!client_; |
188 } | 190 } |
189 | 191 |
190 void DevToolsAgentHostImpl::InspectElement( | 192 void DevToolsAgentHostImpl::InspectElement( |
191 DevToolsAgentHostClient* client, | 193 DevToolsAgentHostClient* client, |
192 int x, | 194 int x, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return false; | 245 return false; |
244 } | 246 } |
245 | 247 |
246 void DevToolsAgentHostImpl::SendProtocolResponse(int session_id, | 248 void DevToolsAgentHostImpl::SendProtocolResponse(int session_id, |
247 const std::string& message) { | 249 const std::string& message) { |
248 SendMessageToClient(session_id, message); | 250 SendMessageToClient(session_id, message); |
249 } | 251 } |
250 | 252 |
251 void DevToolsAgentHostImpl::SendProtocolNotification( | 253 void DevToolsAgentHostImpl::SendProtocolNotification( |
252 const std::string& message) { | 254 const std::string& message) { |
253 SendMessageToClient(session_id_, message); | 255 SendMessageToClient(session_ ? session_->session_id() : 0, message); |
254 } | 256 } |
255 | 257 |
256 void DevToolsAgentHostImpl::HostClosed() { | 258 void DevToolsAgentHostImpl::HostClosed() { |
257 if (!client_) | 259 if (!client_) |
258 return; | 260 return; |
259 | 261 |
260 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 262 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
261 // Clear |client_| before notifying it. | 263 // Clear |client_| before notifying it. |
262 DevToolsAgentHostClient* client = client_; | 264 DevToolsAgentHostClient* client = client_; |
263 client_ = NULL; | 265 client_ = NULL; |
264 client->AgentHostClosed(this, false); | 266 client->AgentHostClosed(this, false); |
265 NotifyDetached(); | 267 NotifyDetached(); |
266 } | 268 } |
267 | 269 |
268 void DevToolsAgentHostImpl::InspectElement(int x, int y) { | 270 void DevToolsAgentHostImpl::InspectElement(int x, int y) { |
269 } | 271 } |
270 | 272 |
271 void DevToolsAgentHostImpl::SendMessageToClient(int session_id, | 273 void DevToolsAgentHostImpl::SendMessageToClient(int session_id, |
272 const std::string& message) { | 274 const std::string& message) { |
273 if (!client_) | 275 if (!client_) |
274 return; | 276 return; |
275 // Filter any messages from previous sessions. | 277 // Filter any messages from previous sessions. |
276 if (session_id != session_id_) | 278 if (!session_ || session_id != session_->session_id()) |
277 return; | 279 return; |
278 client_->DispatchProtocolMessage(this, message); | 280 client_->DispatchProtocolMessage(this, message); |
279 } | 281 } |
280 | 282 |
281 // static | 283 // static |
282 void DevToolsAgentHost::DetachAllClients() { | 284 void DevToolsAgentHost::DetachAllClients() { |
283 if (g_instances == NULL) | 285 if (g_instances == NULL) |
284 return; | 286 return; |
285 | 287 |
286 // Make a copy, since detaching may lead to agent destruction, which | 288 // Make a copy, since detaching may lead to agent destruction, which |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 if (message_buffer_.size() != message_buffer_size_) | 409 if (message_buffer_.size() != message_buffer_size_) |
408 return false; | 410 return false; |
409 callback_.Run(chunk.session_id, message_buffer_); | 411 callback_.Run(chunk.session_id, message_buffer_); |
410 message_buffer_ = std::string(); | 412 message_buffer_ = std::string(); |
411 message_buffer_size_ = 0; | 413 message_buffer_size_ = 0; |
412 } | 414 } |
413 return true; | 415 return true; |
414 } | 416 } |
415 | 417 |
416 } // namespace content | 418 } // namespace content |
OLD | NEW |