| 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/render_frame_devtools_agent_host.h" | 9 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| 10 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 10 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 return result; | 83 return result; |
| 84 } | 84 } |
| 85 | 85 |
| 86 std::unique_ptr<Target::TargetInfo> CreateInfo(DevToolsAgentHost* host) { | 86 std::unique_ptr<Target::TargetInfo> CreateInfo(DevToolsAgentHost* host) { |
| 87 return Target::TargetInfo::Create() | 87 return Target::TargetInfo::Create() |
| 88 .SetTargetId(host->GetId()) | 88 .SetTargetId(host->GetId()) |
| 89 .SetTitle(host->GetTitle()) | 89 .SetTitle(host->GetTitle()) |
| 90 .SetUrl(host->GetURL().spec()) | 90 .SetUrl(host->GetURL().spec()) |
| 91 .SetType(host->GetType()) | 91 .SetType(host->GetType()) |
| 92 .SetAttached(host->IsAttached()) |
| 92 .Build(); | 93 .Build(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 } // namespace | 96 } // namespace |
| 96 | 97 |
| 97 TargetHandler::TargetHandler() | 98 TargetHandler::TargetHandler() |
| 98 : DevToolsDomainHandler(Target::Metainfo::domainName), | 99 : DevToolsDomainHandler(Target::Metainfo::domainName), |
| 99 discover_(false), | 100 discover_(false), |
| 100 auto_attach_(false), | 101 auto_attach_(false), |
| 101 wait_for_debugger_on_start_(false), | 102 wait_for_debugger_on_start_(false), |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 | 209 |
| 209 void TargetHandler::TargetCreatedInternal(DevToolsAgentHost* host) { | 210 void TargetHandler::TargetCreatedInternal(DevToolsAgentHost* host) { |
| 210 if (reported_hosts_.find(host->GetId()) != reported_hosts_.end()) | 211 if (reported_hosts_.find(host->GetId()) != reported_hosts_.end()) |
| 211 return; | 212 return; |
| 212 frontend_->TargetCreated(CreateInfo(host)); | 213 frontend_->TargetCreated(CreateInfo(host)); |
| 213 reported_hosts_[host->GetId()] = host; | 214 reported_hosts_[host->GetId()] = host; |
| 214 } | 215 } |
| 215 | 216 |
| 216 void TargetHandler::TargetDestroyedInternal( | 217 void TargetHandler::TargetInfoChangedInternal(DevToolsAgentHost* host) { |
| 217 DevToolsAgentHost* host) { | 218 if (reported_hosts_.find(host->GetId()) == reported_hosts_.end()) |
| 219 return; |
| 220 frontend_->TargetInfoChanged(CreateInfo(host)); |
| 221 } |
| 222 |
| 223 void TargetHandler::TargetDestroyedInternal(DevToolsAgentHost* host) { |
| 218 auto it = reported_hosts_.find(host->GetId()); | 224 auto it = reported_hosts_.find(host->GetId()); |
| 219 if (it == reported_hosts_.end()) | 225 if (it == reported_hosts_.end()) |
| 220 return; | 226 return; |
| 221 if (discover_) | 227 if (discover_) |
| 222 frontend_->TargetDestroyed(host->GetId()); | 228 frontend_->TargetDestroyed(host->GetId()); |
| 223 reported_hosts_.erase(it); | 229 reported_hosts_.erase(it); |
| 224 } | 230 } |
| 225 | 231 |
| 226 bool TargetHandler::AttachToTargetInternal( | 232 bool TargetHandler::AttachToTargetInternal( |
| 227 DevToolsAgentHost* host, bool waiting_for_debugger) { | 233 DevToolsAgentHost* host, bool waiting_for_debugger) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 attached_hosts_.erase(host->GetId()); | 418 attached_hosts_.erase(host->GetId()); |
| 413 } | 419 } |
| 414 | 420 |
| 415 // -------------- DevToolsAgentHostObserver ----------------- | 421 // -------------- DevToolsAgentHostObserver ----------------- |
| 416 | 422 |
| 417 bool TargetHandler::ShouldForceDevToolsAgentHostCreation() { | 423 bool TargetHandler::ShouldForceDevToolsAgentHostCreation() { |
| 418 return true; | 424 return true; |
| 419 } | 425 } |
| 420 | 426 |
| 421 void TargetHandler::DevToolsAgentHostCreated(DevToolsAgentHost* agent_host) { | 427 void TargetHandler::DevToolsAgentHostCreated(DevToolsAgentHost* agent_host) { |
| 422 if (agent_host->GetType() == "node" && agent_host->IsAttached()) | |
| 423 return; | |
| 424 // If we start discovering late, all existing agent hosts will be reported, | 428 // If we start discovering late, all existing agent hosts will be reported, |
| 425 // but we could have already attached to some. | 429 // but we could have already attached to some. |
| 426 TargetCreatedInternal(agent_host); | 430 TargetCreatedInternal(agent_host); |
| 427 } | 431 } |
| 428 | 432 |
| 429 void TargetHandler::DevToolsAgentHostDestroyed(DevToolsAgentHost* agent_host) { | 433 void TargetHandler::DevToolsAgentHostDestroyed(DevToolsAgentHost* agent_host) { |
| 430 DCHECK(attached_hosts_.find(agent_host->GetId()) == attached_hosts_.end()); | 434 DCHECK(attached_hosts_.find(agent_host->GetId()) == attached_hosts_.end()); |
| 431 TargetDestroyedInternal(agent_host); | 435 TargetDestroyedInternal(agent_host); |
| 432 } | 436 } |
| 433 | 437 |
| 434 void TargetHandler::DevToolsAgentHostAttached(DevToolsAgentHost* host) { | 438 void TargetHandler::DevToolsAgentHostAttached(DevToolsAgentHost* host) { |
| 435 if (host->GetType() == "node" && | 439 TargetInfoChangedInternal(host); |
| 436 reported_hosts_.find(host->GetId()) != reported_hosts_.end() && | |
| 437 attached_hosts_.find(host->GetId()) == attached_hosts_.end()) { | |
| 438 TargetDestroyedInternal(host); | |
| 439 } | |
| 440 } | 440 } |
| 441 | 441 |
| 442 void TargetHandler::DevToolsAgentHostDetached(DevToolsAgentHost* host) { | 442 void TargetHandler::DevToolsAgentHostDetached(DevToolsAgentHost* host) { |
| 443 if (host->GetType() == "node" && | 443 TargetInfoChangedInternal(host); |
| 444 reported_hosts_.find(host->GetId()) == reported_hosts_.end() && | |
| 445 attached_hosts_.find(host->GetId()) == attached_hosts_.end()) { | |
| 446 TargetCreatedInternal(host); | |
| 447 } | |
| 448 } | 444 } |
| 449 | 445 |
| 450 // -------- ServiceWorkerDevToolsManager::Observer ---------- | 446 // -------- ServiceWorkerDevToolsManager::Observer ---------- |
| 451 | 447 |
| 452 void TargetHandler::WorkerCreated( | 448 void TargetHandler::WorkerCreated( |
| 453 ServiceWorkerDevToolsAgentHost* host) { | 449 ServiceWorkerDevToolsAgentHost* host) { |
| 454 BrowserContext* browser_context = nullptr; | 450 BrowserContext* browser_context = nullptr; |
| 455 if (render_frame_host_) | 451 if (render_frame_host_) |
| 456 browser_context = render_frame_host_->GetProcess()->GetBrowserContext(); | 452 browser_context = render_frame_host_->GetProcess()->GetBrowserContext(); |
| 457 auto hosts = GetMatchingServiceWorkers(browser_context, frame_urls_); | 453 auto hosts = GetMatchingServiceWorkers(browser_context, frame_urls_); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 483 UpdateServiceWorkers(); | 479 UpdateServiceWorkers(); |
| 484 } | 480 } |
| 485 | 481 |
| 486 void TargetHandler::WorkerDestroyed( | 482 void TargetHandler::WorkerDestroyed( |
| 487 ServiceWorkerDevToolsAgentHost* host) { | 483 ServiceWorkerDevToolsAgentHost* host) { |
| 488 UpdateServiceWorkers(); | 484 UpdateServiceWorkers(); |
| 489 } | 485 } |
| 490 | 486 |
| 491 } // namespace protocol | 487 } // namespace protocol |
| 492 } // namespace content | 488 } // namespace content |
| OLD | NEW |