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