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/render_frame_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
6 | 6 |
7 #include <tuple> | 7 #include <tuple> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 if (ShouldForceCreation()) { | 388 if (ShouldForceCreation()) { |
389 // Force agent host. | 389 // Force agent host. |
390 DevToolsAgentHost::GetOrCreateFor(web_contents); | 390 DevToolsAgentHost::GetOrCreateFor(web_contents); |
391 } | 391 } |
392 } | 392 } |
393 | 393 |
394 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( | 394 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( |
395 RenderFrameHostImpl* host) | 395 RenderFrameHostImpl* host) |
396 : DevToolsAgentHostImpl(base::GenerateGUID()), | 396 : DevToolsAgentHostImpl(base::GenerateGUID()), |
397 input_handler_(new devtools::input::InputHandler()), | 397 input_handler_(new devtools::input::InputHandler()), |
398 target_handler_(new devtools::target::TargetHandler()), | |
399 frame_trace_recorder_(nullptr), | 398 frame_trace_recorder_(nullptr), |
400 protocol_handler_(new DevToolsProtocolHandler(this)), | 399 protocol_handler_(new DevToolsProtocolHandler(this)), |
401 handlers_frame_host_(nullptr), | 400 handlers_frame_host_(nullptr), |
402 current_frame_crashed_(false), | 401 current_frame_crashed_(false), |
403 pending_handle_(nullptr), | 402 pending_handle_(nullptr), |
404 frame_tree_node_(host->frame_tree_node()) { | 403 frame_tree_node_(host->frame_tree_node()) { |
405 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 404 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
406 dispatcher->SetInputHandler(input_handler_.get()); | 405 dispatcher->SetInputHandler(input_handler_.get()); |
407 dispatcher->SetTargetHandler(target_handler_.get()); | |
408 | 406 |
409 SetPending(host); | 407 SetPending(host); |
410 CommitPending(); | 408 CommitPending(); |
411 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); | 409 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); |
412 | 410 |
413 if (web_contents() && web_contents()->GetCrashedStatus() != | 411 if (web_contents() && web_contents()->GetCrashedStatus() != |
414 base::TERMINATION_STATUS_STILL_RUNNING) { | 412 base::TERMINATION_STATUS_STILL_RUNNING) { |
415 current_frame_crashed_ = true; | 413 current_frame_crashed_ = true; |
416 } | 414 } |
417 | 415 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 security_handler_->SetRenderFrameHost(handlers_frame_host_); | 504 security_handler_->SetRenderFrameHost(handlers_frame_host_); |
507 } | 505 } |
508 | 506 |
509 service_worker_handler_.reset(new protocol::ServiceWorkerHandler()); | 507 service_worker_handler_.reset(new protocol::ServiceWorkerHandler()); |
510 service_worker_handler_->Wire(session()->dispatcher()); | 508 service_worker_handler_->Wire(session()->dispatcher()); |
511 service_worker_handler_->SetRenderFrameHost(handlers_frame_host_); | 509 service_worker_handler_->SetRenderFrameHost(handlers_frame_host_); |
512 | 510 |
513 storage_handler_.reset(new protocol::StorageHandler()); | 511 storage_handler_.reset(new protocol::StorageHandler()); |
514 storage_handler_->Wire(session()->dispatcher()); | 512 storage_handler_->Wire(session()->dispatcher()); |
515 | 513 |
| 514 target_handler_.reset(new protocol::TargetHandler()); |
| 515 target_handler_->Wire(session()->dispatcher()); |
| 516 target_handler_->SetRenderFrameHost(handlers_frame_host_); |
| 517 |
516 tracing_handler_.reset(new protocol::TracingHandler( | 518 tracing_handler_.reset(new protocol::TracingHandler( |
517 protocol::TracingHandler::Renderer, | 519 protocol::TracingHandler::Renderer, |
518 frame_tree_node_->frame_tree_node_id(), | 520 frame_tree_node_->frame_tree_node_id(), |
519 GetIOContext())); | 521 GetIOContext())); |
520 tracing_handler_->Wire(session()->dispatcher()); | 522 tracing_handler_->Wire(session()->dispatcher()); |
521 | 523 |
522 if (current_) | 524 if (current_) |
523 current_->Attach(); | 525 current_->Attach(); |
524 if (pending_) | 526 if (pending_) |
525 pending_->Attach(); | 527 pending_->Attach(); |
(...skipping 20 matching lines...) Expand all Loading... |
546 schema_handler_->Disable(); | 548 schema_handler_->Disable(); |
547 schema_handler_.reset(); | 549 schema_handler_.reset(); |
548 if (security_handler_) { | 550 if (security_handler_) { |
549 security_handler_->Disable(); | 551 security_handler_->Disable(); |
550 security_handler_.reset(); | 552 security_handler_.reset(); |
551 } | 553 } |
552 service_worker_handler_->Disable(); | 554 service_worker_handler_->Disable(); |
553 service_worker_handler_.reset(); | 555 service_worker_handler_.reset(); |
554 storage_handler_->Disable(); | 556 storage_handler_->Disable(); |
555 storage_handler_.reset(); | 557 storage_handler_.reset(); |
| 558 target_handler_->Disable(); |
| 559 target_handler_.reset(); |
556 tracing_handler_->Disable(); | 560 tracing_handler_->Disable(); |
557 tracing_handler_.reset(); | 561 tracing_handler_.reset(); |
558 | 562 |
559 if (current_) | 563 if (current_) |
560 current_->Detach(); | 564 current_->Detach(); |
561 if (pending_) | 565 if (pending_) |
562 pending_->Detach(); | 566 pending_->Detach(); |
563 OnClientDetached(); | 567 OnClientDetached(); |
564 } | 568 } |
565 | 569 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 return; | 614 return; |
611 | 615 |
612 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); | 616 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); |
613 CreatePowerSaveBlocker(); | 617 CreatePowerSaveBlocker(); |
614 } | 618 } |
615 | 619 |
616 void RenderFrameDevToolsAgentHost::OnClientDetached() { | 620 void RenderFrameDevToolsAgentHost::OnClientDetached() { |
617 #if defined(OS_ANDROID) | 621 #if defined(OS_ANDROID) |
618 power_save_blocker_.reset(); | 622 power_save_blocker_.reset(); |
619 #endif | 623 #endif |
620 target_handler_->Detached(); | |
621 frame_trace_recorder_.reset(); | 624 frame_trace_recorder_.reset(); |
622 in_navigation_protocol_message_buffer_.clear(); | 625 in_navigation_protocol_message_buffer_.clear(); |
623 } | 626 } |
624 | 627 |
625 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { | 628 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { |
626 Instances::iterator it = std::find(g_instances.Get().begin(), | 629 Instances::iterator it = std::find(g_instances.Get().begin(), |
627 g_instances.Get().end(), | 630 g_instances.Get().end(), |
628 this); | 631 this); |
629 if (it != g_instances.Get().end()) | 632 if (it != g_instances.Get().end()) |
630 g_instances.Get().erase(it); | 633 g_instances.Get().erase(it); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 DCHECK(pending_->host() == navigation_handle->GetRenderFrameHost()); | 687 DCHECK(pending_->host() == navigation_handle->GetRenderFrameHost()); |
685 CommitPending(); | 688 CommitPending(); |
686 } else { | 689 } else { |
687 DiscardPending(); | 690 DiscardPending(); |
688 } | 691 } |
689 pending_handle_ = nullptr; | 692 pending_handle_ = nullptr; |
690 } | 693 } |
691 DispatchBufferedProtocolMessagesIfNecessary(); | 694 DispatchBufferedProtocolMessagesIfNecessary(); |
692 | 695 |
693 DCHECK(CheckConsistency()); | 696 DCHECK(CheckConsistency()); |
694 if (navigation_handle->HasCommitted()) | 697 if (target_handler_ && navigation_handle->HasCommitted()) |
695 target_handler_->UpdateServiceWorkers(); | 698 target_handler_->UpdateServiceWorkers(); |
696 } | 699 } |
697 | 700 |
698 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( | 701 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( |
699 RenderFrameHost* old_host, | 702 RenderFrameHost* old_host, |
700 RenderFrameHost* new_host) { | 703 RenderFrameHost* new_host) { |
701 // CommitPending may destruct |this|. | 704 // CommitPending may destruct |this|. |
702 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 705 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
703 | 706 |
704 if (IsBrowserSideNavigationEnabled()) | 707 if (IsBrowserSideNavigationEnabled()) |
(...skipping 25 matching lines...) Expand all Loading... |
730 navigating_handles_.insert(navigation_handle); | 733 navigating_handles_.insert(navigation_handle); |
731 DCHECK(CheckConsistency()); | 734 DCHECK(CheckConsistency()); |
732 } | 735 } |
733 | 736 |
734 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( | 737 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( |
735 RenderFrameHost* old_host, | 738 RenderFrameHost* old_host, |
736 RenderFrameHost* new_host) { | 739 RenderFrameHost* new_host) { |
737 // CommitPending may destruct |this|. | 740 // CommitPending may destruct |this|. |
738 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 741 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
739 | 742 |
740 target_handler_->UpdateFrames(); | 743 if (target_handler_) |
| 744 target_handler_->UpdateFrames(); |
741 | 745 |
742 if (IsBrowserSideNavigationEnabled()) | 746 if (IsBrowserSideNavigationEnabled()) |
743 return; | 747 return; |
744 | 748 |
745 DCHECK(!pending_ || pending_->host() != old_host); | 749 DCHECK(!pending_ || pending_->host() != old_host); |
746 if (!current_ || current_->host() != old_host) { | 750 if (!current_ || current_->host() != old_host) { |
747 DCHECK(CheckConsistency()); | 751 DCHECK(CheckConsistency()); |
748 return; | 752 return; |
749 } | 753 } |
750 | 754 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 const GURL& url, | 901 const GURL& url, |
898 ui::PageTransition transition_type) { | 902 ui::PageTransition transition_type) { |
899 // CommitPending may destruct |this|. | 903 // CommitPending may destruct |this|. |
900 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 904 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
901 | 905 |
902 if (IsBrowserSideNavigationEnabled()) | 906 if (IsBrowserSideNavigationEnabled()) |
903 return; | 907 return; |
904 if (pending_ && pending_->host() == render_frame_host) | 908 if (pending_ && pending_->host() == render_frame_host) |
905 CommitPending(); | 909 CommitPending(); |
906 DCHECK(CheckConsistency()); | 910 DCHECK(CheckConsistency()); |
907 target_handler_->UpdateServiceWorkers(); | 911 if (target_handler_) |
| 912 target_handler_->UpdateServiceWorkers(); |
908 } | 913 } |
909 | 914 |
910 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( | 915 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( |
911 RenderFrameHost* render_frame_host, | 916 RenderFrameHost* render_frame_host, |
912 const GURL& validated_url, | 917 const GURL& validated_url, |
913 int error_code, | 918 int error_code, |
914 const base::string16& error_description, | 919 const base::string16& error_description, |
915 bool was_ignored_by_handler) { | 920 bool was_ignored_by_handler) { |
916 if (IsBrowserSideNavigationEnabled()) | 921 if (IsBrowserSideNavigationEnabled()) |
917 return; | 922 return; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 if (network_handler_) | 969 if (network_handler_) |
965 network_handler_->SetRenderFrameHost(host); | 970 network_handler_->SetRenderFrameHost(host); |
966 if (page_handler_) | 971 if (page_handler_) |
967 page_handler_->SetRenderFrameHost(host); | 972 page_handler_->SetRenderFrameHost(host); |
968 if (service_worker_handler_) | 973 if (service_worker_handler_) |
969 service_worker_handler_->SetRenderFrameHost(host); | 974 service_worker_handler_->SetRenderFrameHost(host); |
970 if (security_handler_) | 975 if (security_handler_) |
971 security_handler_->SetRenderFrameHost(host); | 976 security_handler_->SetRenderFrameHost(host); |
972 if (storage_handler_) | 977 if (storage_handler_) |
973 storage_handler_->SetRenderFrameHost(host); | 978 storage_handler_->SetRenderFrameHost(host); |
974 target_handler_->SetRenderFrameHost(host); | 979 if (target_handler_) |
| 980 target_handler_->SetRenderFrameHost(host); |
975 } | 981 } |
976 | 982 |
977 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 983 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { |
978 if (pending_) | 984 if (pending_) |
979 DiscardPending(); | 985 DiscardPending(); |
980 UpdateProtocolHandlers(nullptr); | 986 UpdateProtocolHandlers(nullptr); |
981 disconnected_ = std::move(current_); | 987 disconnected_ = std::move(current_); |
982 disconnected_->Detach(); | 988 disconnected_->Detach(); |
983 frame_tree_node_ = nullptr; | 989 frame_tree_node_ = nullptr; |
984 in_navigation_protocol_message_buffer_.clear(); | 990 in_navigation_protocol_message_buffer_.clear(); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 RenderFrameHost* host) { | 1191 RenderFrameHost* host) { |
1186 return (current_ && current_->host() == host) || | 1192 return (current_ && current_->host() == host) || |
1187 (pending_ && pending_->host() == host); | 1193 (pending_ && pending_->host() == host); |
1188 } | 1194 } |
1189 | 1195 |
1190 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1196 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
1191 return current_ && current_->host()->GetParent(); | 1197 return current_ && current_->host()->GetParent(); |
1192 } | 1198 } |
1193 | 1199 |
1194 } // namespace content | 1200 } // namespace content |
OLD | NEW |