OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/protocol/target_handler.h" | 5 #include "content/browser/devtools/protocol/target_handler.h" |
6 | 6 |
7 #include "content/browser/devtools/devtools_manager.h" | 7 #include "content/browser/devtools/devtools_manager.h" |
8 #include "content/browser/devtools/devtools_session.h" | 8 #include "content/browser/devtools/devtools_session.h" |
9 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 9 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
10 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 DevToolsAgentHost* host) { | 216 DevToolsAgentHost* host) { |
217 auto it = reported_hosts_.find(host->GetId()); | 217 auto it = reported_hosts_.find(host->GetId()); |
218 if (it == reported_hosts_.end()) | 218 if (it == reported_hosts_.end()) |
219 return; | 219 return; |
220 frontend_->TargetDestroyed(host->GetId()); | 220 frontend_->TargetDestroyed(host->GetId()); |
221 reported_hosts_.erase(it); | 221 reported_hosts_.erase(it); |
222 } | 222 } |
223 | 223 |
224 bool TargetHandler::AttachToTargetInternal( | 224 bool TargetHandler::AttachToTargetInternal( |
225 DevToolsAgentHost* host, bool waiting_for_debugger) { | 225 DevToolsAgentHost* host, bool waiting_for_debugger) { |
226 if (!host->AttachClient(this)) | 226 attached_hosts_[host->GetId()] = host; |
| 227 if (!host->AttachClient(this)) { |
| 228 attached_hosts_.erase(host->GetId()); |
227 return false; | 229 return false; |
228 attached_hosts_[host->GetId()] = host; | 230 } |
229 frontend_->AttachedToTarget(CreateInfo(host), waiting_for_debugger); | 231 frontend_->AttachedToTarget(CreateInfo(host), waiting_for_debugger); |
230 return true; | 232 return true; |
231 } | 233 } |
232 | 234 |
233 void TargetHandler::DetachFromTargetInternal(DevToolsAgentHost* host) { | 235 void TargetHandler::DetachFromTargetInternal(DevToolsAgentHost* host) { |
234 auto it = attached_hosts_.find(host->GetId()); | 236 auto it = attached_hosts_.find(host->GetId()); |
235 if (it == attached_hosts_.end()) | 237 if (it == attached_hosts_.end()) |
236 return; | 238 return; |
237 host->DetachClient(this); | 239 host->DetachClient(this); |
238 frontend_->DetachedFromTarget(host->GetId()); | 240 frontend_->DetachedFromTarget(host->GetId()); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 attached_hosts_.erase(host->GetId()); | 410 attached_hosts_.erase(host->GetId()); |
409 } | 411 } |
410 | 412 |
411 // -------------- DevToolsAgentHostObserver ----------------- | 413 // -------------- DevToolsAgentHostObserver ----------------- |
412 | 414 |
413 bool TargetHandler::ShouldForceDevToolsAgentHostCreation() { | 415 bool TargetHandler::ShouldForceDevToolsAgentHostCreation() { |
414 return true; | 416 return true; |
415 } | 417 } |
416 | 418 |
417 void TargetHandler::DevToolsAgentHostCreated(DevToolsAgentHost* agent_host) { | 419 void TargetHandler::DevToolsAgentHostCreated(DevToolsAgentHost* agent_host) { |
| 420 if (agent_host->GetType() == "node" && agent_host->IsAttached()) |
| 421 return; |
418 // If we start discovering late, all existing agent hosts will be reported, | 422 // If we start discovering late, all existing agent hosts will be reported, |
419 // but we could have already attached to some. | 423 // but we could have already attached to some. |
420 TargetCreatedInternal(agent_host); | 424 TargetCreatedInternal(agent_host); |
421 } | 425 } |
422 | 426 |
423 void TargetHandler::DevToolsAgentHostDestroyed(DevToolsAgentHost* agent_host) { | 427 void TargetHandler::DevToolsAgentHostDestroyed(DevToolsAgentHost* agent_host) { |
424 DCHECK(attached_hosts_.find(agent_host->GetId()) == attached_hosts_.end()); | 428 DCHECK(attached_hosts_.find(agent_host->GetId()) == attached_hosts_.end()); |
425 TargetDestroyedInternal(agent_host); | 429 TargetDestroyedInternal(agent_host); |
426 } | 430 } |
427 | 431 |
| 432 void TargetHandler::DevToolsAgentHostAttached(DevToolsAgentHost* host) { |
| 433 if (host->GetType() == "node" && |
| 434 reported_hosts_.find(host->GetId()) != reported_hosts_.end() && |
| 435 attached_hosts_.find(host->GetId()) == attached_hosts_.end()) { |
| 436 TargetDestroyedInternal(host); |
| 437 } |
| 438 } |
| 439 |
| 440 void TargetHandler::DevToolsAgentHostDetached(DevToolsAgentHost* host) { |
| 441 if (host->GetType() == "node" && |
| 442 reported_hosts_.find(host->GetId()) == reported_hosts_.end() && |
| 443 attached_hosts_.find(host->GetId()) == attached_hosts_.end()) { |
| 444 TargetCreatedInternal(host); |
| 445 } |
| 446 } |
| 447 |
428 // -------- ServiceWorkerDevToolsManager::Observer ---------- | 448 // -------- ServiceWorkerDevToolsManager::Observer ---------- |
429 | 449 |
430 void TargetHandler::WorkerCreated( | 450 void TargetHandler::WorkerCreated( |
431 ServiceWorkerDevToolsAgentHost* host) { | 451 ServiceWorkerDevToolsAgentHost* host) { |
432 BrowserContext* browser_context = nullptr; | 452 BrowserContext* browser_context = nullptr; |
433 if (render_frame_host_) | 453 if (render_frame_host_) |
434 browser_context = render_frame_host_->GetProcess()->GetBrowserContext(); | 454 browser_context = render_frame_host_->GetProcess()->GetBrowserContext(); |
435 auto hosts = GetMatchingServiceWorkers(browser_context, frame_urls_); | 455 auto hosts = GetMatchingServiceWorkers(browser_context, frame_urls_); |
436 if (hosts.find(host->GetId()) != hosts.end() && !host->IsAttached() && | 456 if (hosts.find(host->GetId()) != hosts.end() && !host->IsAttached() && |
437 !host->IsPausedForDebugOnStart() && wait_for_debugger_on_start_) { | 457 !host->IsPausedForDebugOnStart() && wait_for_debugger_on_start_) { |
(...skipping 23 matching lines...) Expand all Loading... |
461 UpdateServiceWorkers(); | 481 UpdateServiceWorkers(); |
462 } | 482 } |
463 | 483 |
464 void TargetHandler::WorkerDestroyed( | 484 void TargetHandler::WorkerDestroyed( |
465 ServiceWorkerDevToolsAgentHost* host) { | 485 ServiceWorkerDevToolsAgentHost* host) { |
466 UpdateServiceWorkers(); | 486 UpdateServiceWorkers(); |
467 } | 487 } |
468 | 488 |
469 } // namespace protocol | 489 } // namespace protocol |
470 } // namespace content | 490 } // namespace content |
OLD | NEW |