| 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/renderer/devtools/devtools_agent.h" | 5 #include "content/renderer/devtools/devtools_agent.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 typedef std::map<int, DevToolsAgent*> IdToAgentMap; | 78 typedef std::map<int, DevToolsAgent*> IdToAgentMap; |
| 79 base::LazyInstance<IdToAgentMap>::Leaky | 79 base::LazyInstance<IdToAgentMap>::Leaky |
| 80 g_agent_for_routing_id = LAZY_INSTANCE_INITIALIZER; | 80 g_agent_for_routing_id = LAZY_INSTANCE_INITIALIZER; |
| 81 | 81 |
| 82 } // namespace | 82 } // namespace |
| 83 | 83 |
| 84 DevToolsAgent::DevToolsAgent(RenderFrameImpl* frame) | 84 DevToolsAgent::DevToolsAgent(RenderFrameImpl* frame) |
| 85 : RenderFrameObserver(frame), | 85 : RenderFrameObserver(frame), |
| 86 is_attached_(false), | |
| 87 is_devtools_client_(false), | 86 is_devtools_client_(false), |
| 88 paused_(false), | 87 paused_(false), |
| 89 frame_(frame), | 88 frame_(frame), |
| 90 cpu_throttler_(new DevToolsCPUThrottler()), | 89 cpu_throttler_(new DevToolsCPUThrottler()), |
| 91 weak_factory_(this) { | 90 weak_factory_(this) { |
| 92 g_agent_for_routing_id.Get()[routing_id()] = this; | 91 g_agent_for_routing_id.Get()[routing_id()] = this; |
| 93 frame_->GetWebFrame()->SetDevToolsAgentClient(this); | 92 frame_->GetWebFrame()->SetDevToolsAgentClient(this); |
| 94 } | 93 } |
| 95 | 94 |
| 96 DevToolsAgent::~DevToolsAgent() { | 95 DevToolsAgent::~DevToolsAgent() { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 chunk.data = message.substr(pos, kMaxMessageChunkSize); | 227 chunk.data = message.substr(pos, kMaxMessageChunkSize); |
| 229 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( | 228 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( |
| 230 routing_id, chunk)); | 229 routing_id, chunk)); |
| 231 chunk.is_first = false; | 230 chunk.is_first = false; |
| 232 chunk.message_size = 0; | 231 chunk.message_size = 0; |
| 233 } | 232 } |
| 234 } | 233 } |
| 235 | 234 |
| 236 void DevToolsAgent::OnAttach(const std::string& host_id, int session_id) { | 235 void DevToolsAgent::OnAttach(const std::string& host_id, int session_id) { |
| 237 GetWebAgent()->Attach(WebString::FromUTF8(host_id), session_id); | 236 GetWebAgent()->Attach(WebString::FromUTF8(host_id), session_id); |
| 238 is_attached_ = true; | 237 session_ids_.insert(session_id); |
| 239 } | 238 } |
| 240 | 239 |
| 241 void DevToolsAgent::OnReattach(const std::string& host_id, | 240 void DevToolsAgent::OnReattach(const std::string& host_id, |
| 242 int session_id, | 241 int session_id, |
| 243 const std::string& agent_state) { | 242 const std::string& agent_state) { |
| 244 GetWebAgent()->Reattach(WebString::FromUTF8(host_id), session_id, | 243 GetWebAgent()->Reattach(WebString::FromUTF8(host_id), session_id, |
| 245 WebString::FromUTF8(agent_state)); | 244 WebString::FromUTF8(agent_state)); |
| 246 is_attached_ = true; | 245 session_ids_.insert(session_id); |
| 247 } | 246 } |
| 248 | 247 |
| 249 void DevToolsAgent::OnDetach() { | 248 void DevToolsAgent::OnDetach(int session_id) { |
| 250 GetWebAgent()->Detach(); | 249 GetWebAgent()->Detach(session_id); |
| 251 is_attached_ = false; | 250 session_ids_.erase(session_id); |
| 252 } | 251 } |
| 253 | 252 |
| 254 void DevToolsAgent::OnDispatchOnInspectorBackend(int session_id, | 253 void DevToolsAgent::OnDispatchOnInspectorBackend(int session_id, |
| 255 int call_id, | 254 int call_id, |
| 256 const std::string& method, | 255 const std::string& method, |
| 257 const std::string& message) { | 256 const std::string& message) { |
| 258 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend"); | 257 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend"); |
| 259 if (method == kPageGetAppManifest) { | 258 if (method == kPageGetAppManifest) { |
| 260 ManifestManager* manager = frame_->manifest_manager(); | 259 ManifestManager* manager = frame_->manifest_manager(); |
| 261 manager->GetManifest( | 260 manager->GetManifest( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 292 return; | 291 return; |
| 293 is_devtools_client_ = true; | 292 is_devtools_client_ = true; |
| 294 new DevToolsClient(frame_, compatibility_script); | 293 new DevToolsClient(frame_, compatibility_script); |
| 295 } | 294 } |
| 296 | 295 |
| 297 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 296 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
| 298 return frame_->GetWebFrame()->DevToolsAgent(); | 297 return frame_->GetWebFrame()->DevToolsAgent(); |
| 299 } | 298 } |
| 300 | 299 |
| 301 bool DevToolsAgent::IsAttached() { | 300 bool DevToolsAgent::IsAttached() { |
| 302 return is_attached_; | 301 return !!session_ids_.size(); |
| 302 } |
| 303 |
| 304 void DevToolsAgent::DetachAllSessions() { |
| 305 for (int session_id : session_ids_) |
| 306 GetWebAgent()->Detach(session_id); |
| 307 session_ids_.clear(); |
| 303 } | 308 } |
| 304 | 309 |
| 305 void DevToolsAgent::GotManifest(int session_id, | 310 void DevToolsAgent::GotManifest(int session_id, |
| 306 int call_id, | 311 int call_id, |
| 307 const GURL& manifest_url, | 312 const GURL& manifest_url, |
| 308 const Manifest& manifest, | 313 const Manifest& manifest, |
| 309 const ManifestDebugInfo& debug_info) { | 314 const ManifestDebugInfo& debug_info) { |
| 310 if (!is_attached_) | 315 if (!IsAttached()) |
| 311 return; | 316 return; |
| 312 | 317 |
| 313 std::unique_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | 318 std::unique_ptr<base::DictionaryValue> response(new base::DictionaryValue()); |
| 314 response->SetInteger("id", call_id); | 319 response->SetInteger("id", call_id); |
| 315 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 320 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 316 std::unique_ptr<base::ListValue> errors(new base::ListValue()); | 321 std::unique_ptr<base::ListValue> errors(new base::ListValue()); |
| 317 | 322 |
| 318 bool failed = false; | 323 bool failed = false; |
| 319 for (const auto& error : debug_info.errors) { | 324 for (const auto& error : debug_info.errors) { |
| 320 std::unique_ptr<base::DictionaryValue> error_value( | 325 std::unique_ptr<base::DictionaryValue> error_value( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 336 result->Set("errors", errors.release()); | 341 result->Set("errors", errors.release()); |
| 337 response->Set("result", result.release()); | 342 response->Set("result", result.release()); |
| 338 | 343 |
| 339 std::string json_message; | 344 std::string json_message; |
| 340 base::JSONWriter::Write(*response, &json_message); | 345 base::JSONWriter::Write(*response, &json_message); |
| 341 SendChunkedProtocolMessage(this, routing_id(), session_id, call_id, | 346 SendChunkedProtocolMessage(this, routing_id(), session_id, call_id, |
| 342 json_message, std::string()); | 347 json_message, std::string()); |
| 343 } | 348 } |
| 344 | 349 |
| 345 } // namespace content | 350 } // namespace content |
| OLD | NEW |