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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 storage_handler_->SetRenderFrameHost(handlers_frame_host_); | 513 storage_handler_->SetRenderFrameHost(handlers_frame_host_); |
516 | 514 |
| 515 target_handler_.reset(new protocol::TargetHandler()); |
| 516 target_handler_->Wire(session()->dispatcher()); |
| 517 target_handler_->SetRenderFrameHost(handlers_frame_host_); |
| 518 |
517 tracing_handler_.reset(new protocol::TracingHandler( | 519 tracing_handler_.reset(new protocol::TracingHandler( |
518 protocol::TracingHandler::Renderer, | 520 protocol::TracingHandler::Renderer, |
519 frame_tree_node_->frame_tree_node_id(), | 521 frame_tree_node_->frame_tree_node_id(), |
520 GetIOContext())); | 522 GetIOContext())); |
521 tracing_handler_->Wire(session()->dispatcher()); | 523 tracing_handler_->Wire(session()->dispatcher()); |
522 | 524 |
523 if (current_) | 525 if (current_) |
524 current_->Attach(); | 526 current_->Attach(); |
525 if (pending_) | 527 if (pending_) |
526 pending_->Attach(); | 528 pending_->Attach(); |
(...skipping 20 matching lines...) Expand all Loading... |
547 schema_handler_->Disable(); | 549 schema_handler_->Disable(); |
548 schema_handler_.reset(); | 550 schema_handler_.reset(); |
549 if (security_handler_) { | 551 if (security_handler_) { |
550 security_handler_->Disable(); | 552 security_handler_->Disable(); |
551 security_handler_.reset(); | 553 security_handler_.reset(); |
552 } | 554 } |
553 service_worker_handler_->Disable(); | 555 service_worker_handler_->Disable(); |
554 service_worker_handler_.reset(); | 556 service_worker_handler_.reset(); |
555 storage_handler_->Disable(); | 557 storage_handler_->Disable(); |
556 storage_handler_.reset(); | 558 storage_handler_.reset(); |
| 559 target_handler_->Disable(); |
| 560 target_handler_.reset(); |
557 tracing_handler_->Disable(); | 561 tracing_handler_->Disable(); |
558 tracing_handler_.reset(); | 562 tracing_handler_.reset(); |
559 | 563 |
560 if (current_) | 564 if (current_) |
561 current_->Detach(); | 565 current_->Detach(); |
562 if (pending_) | 566 if (pending_) |
563 pending_->Detach(); | 567 pending_->Detach(); |
564 OnClientDetached(); | 568 OnClientDetached(); |
565 } | 569 } |
566 | 570 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 return; | 615 return; |
612 | 616 |
613 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); | 617 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); |
614 CreatePowerSaveBlocker(); | 618 CreatePowerSaveBlocker(); |
615 } | 619 } |
616 | 620 |
617 void RenderFrameDevToolsAgentHost::OnClientDetached() { | 621 void RenderFrameDevToolsAgentHost::OnClientDetached() { |
618 #if defined(OS_ANDROID) | 622 #if defined(OS_ANDROID) |
619 power_save_blocker_.reset(); | 623 power_save_blocker_.reset(); |
620 #endif | 624 #endif |
621 target_handler_->Detached(); | |
622 frame_trace_recorder_.reset(); | 625 frame_trace_recorder_.reset(); |
623 in_navigation_protocol_message_buffer_.clear(); | 626 in_navigation_protocol_message_buffer_.clear(); |
624 } | 627 } |
625 | 628 |
626 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { | 629 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { |
627 Instances::iterator it = std::find(g_instances.Get().begin(), | 630 Instances::iterator it = std::find(g_instances.Get().begin(), |
628 g_instances.Get().end(), | 631 g_instances.Get().end(), |
629 this); | 632 this); |
630 if (it != g_instances.Get().end()) | 633 if (it != g_instances.Get().end()) |
631 g_instances.Get().erase(it); | 634 g_instances.Get().erase(it); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 DCHECK(pending_->host() == navigation_handle->GetRenderFrameHost()); | 688 DCHECK(pending_->host() == navigation_handle->GetRenderFrameHost()); |
686 CommitPending(); | 689 CommitPending(); |
687 } else { | 690 } else { |
688 DiscardPending(); | 691 DiscardPending(); |
689 } | 692 } |
690 pending_handle_ = nullptr; | 693 pending_handle_ = nullptr; |
691 } | 694 } |
692 DispatchBufferedProtocolMessagesIfNecessary(); | 695 DispatchBufferedProtocolMessagesIfNecessary(); |
693 | 696 |
694 DCHECK(CheckConsistency()); | 697 DCHECK(CheckConsistency()); |
695 if (navigation_handle->HasCommitted()) | 698 if (target_handler_ && navigation_handle->HasCommitted()) |
696 target_handler_->UpdateServiceWorkers(); | 699 target_handler_->UpdateServiceWorkers(); |
697 } | 700 } |
698 | 701 |
699 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( | 702 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( |
700 RenderFrameHost* old_host, | 703 RenderFrameHost* old_host, |
701 RenderFrameHost* new_host) { | 704 RenderFrameHost* new_host) { |
702 // CommitPending may destruct |this|. | 705 // CommitPending may destruct |this|. |
703 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 706 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
704 | 707 |
705 if (IsBrowserSideNavigationEnabled()) | 708 if (IsBrowserSideNavigationEnabled()) |
(...skipping 25 matching lines...) Expand all Loading... |
731 navigating_handles_.insert(navigation_handle); | 734 navigating_handles_.insert(navigation_handle); |
732 DCHECK(CheckConsistency()); | 735 DCHECK(CheckConsistency()); |
733 } | 736 } |
734 | 737 |
735 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( | 738 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( |
736 RenderFrameHost* old_host, | 739 RenderFrameHost* old_host, |
737 RenderFrameHost* new_host) { | 740 RenderFrameHost* new_host) { |
738 // CommitPending may destruct |this|. | 741 // CommitPending may destruct |this|. |
739 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 742 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
740 | 743 |
741 target_handler_->UpdateFrames(); | 744 if (target_handler_) |
| 745 target_handler_->UpdateFrames(); |
742 | 746 |
743 if (IsBrowserSideNavigationEnabled()) | 747 if (IsBrowserSideNavigationEnabled()) |
744 return; | 748 return; |
745 | 749 |
746 DCHECK(!pending_ || pending_->host() != old_host); | 750 DCHECK(!pending_ || pending_->host() != old_host); |
747 if (!current_ || current_->host() != old_host) { | 751 if (!current_ || current_->host() != old_host) { |
748 DCHECK(CheckConsistency()); | 752 DCHECK(CheckConsistency()); |
749 return; | 753 return; |
750 } | 754 } |
751 | 755 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 const GURL& url, | 902 const GURL& url, |
899 ui::PageTransition transition_type) { | 903 ui::PageTransition transition_type) { |
900 // CommitPending may destruct |this|. | 904 // CommitPending may destruct |this|. |
901 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 905 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
902 | 906 |
903 if (IsBrowserSideNavigationEnabled()) | 907 if (IsBrowserSideNavigationEnabled()) |
904 return; | 908 return; |
905 if (pending_ && pending_->host() == render_frame_host) | 909 if (pending_ && pending_->host() == render_frame_host) |
906 CommitPending(); | 910 CommitPending(); |
907 DCHECK(CheckConsistency()); | 911 DCHECK(CheckConsistency()); |
908 target_handler_->UpdateServiceWorkers(); | 912 if (target_handler_) |
| 913 target_handler_->UpdateServiceWorkers(); |
909 } | 914 } |
910 | 915 |
911 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( | 916 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( |
912 RenderFrameHost* render_frame_host, | 917 RenderFrameHost* render_frame_host, |
913 const GURL& validated_url, | 918 const GURL& validated_url, |
914 int error_code, | 919 int error_code, |
915 const base::string16& error_description, | 920 const base::string16& error_description, |
916 bool was_ignored_by_handler) { | 921 bool was_ignored_by_handler) { |
917 if (IsBrowserSideNavigationEnabled()) | 922 if (IsBrowserSideNavigationEnabled()) |
918 return; | 923 return; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 if (network_handler_) | 970 if (network_handler_) |
966 network_handler_->SetRenderFrameHost(host); | 971 network_handler_->SetRenderFrameHost(host); |
967 if (page_handler_) | 972 if (page_handler_) |
968 page_handler_->SetRenderFrameHost(host); | 973 page_handler_->SetRenderFrameHost(host); |
969 if (service_worker_handler_) | 974 if (service_worker_handler_) |
970 service_worker_handler_->SetRenderFrameHost(host); | 975 service_worker_handler_->SetRenderFrameHost(host); |
971 if (security_handler_) | 976 if (security_handler_) |
972 security_handler_->SetRenderFrameHost(host); | 977 security_handler_->SetRenderFrameHost(host); |
973 if (storage_handler_) | 978 if (storage_handler_) |
974 storage_handler_->SetRenderFrameHost(host); | 979 storage_handler_->SetRenderFrameHost(host); |
975 target_handler_->SetRenderFrameHost(host); | 980 if (target_handler_) |
| 981 target_handler_->SetRenderFrameHost(host); |
976 } | 982 } |
977 | 983 |
978 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 984 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { |
979 if (pending_) | 985 if (pending_) |
980 DiscardPending(); | 986 DiscardPending(); |
981 UpdateProtocolHandlers(nullptr); | 987 UpdateProtocolHandlers(nullptr); |
982 disconnected_ = std::move(current_); | 988 disconnected_ = std::move(current_); |
983 disconnected_->Detach(); | 989 disconnected_->Detach(); |
984 frame_tree_node_ = nullptr; | 990 frame_tree_node_ = nullptr; |
985 in_navigation_protocol_message_buffer_.clear(); | 991 in_navigation_protocol_message_buffer_.clear(); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 RenderFrameHost* host) { | 1192 RenderFrameHost* host) { |
1187 return (current_ && current_->host() == host) || | 1193 return (current_ && current_->host() == host) || |
1188 (pending_ && pending_->host() == host); | 1194 (pending_ && pending_->host() == host); |
1189 } | 1195 } |
1190 | 1196 |
1191 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1197 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
1192 return current_ && current_->host()->GetParent(); | 1198 return current_ && current_->host()->GetParent(); |
1193 } | 1199 } |
1194 | 1200 |
1195 } // namespace content | 1201 } // namespace content |
OLD | NEW |