| 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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { | 562 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { |
| 563 Instances::iterator it = std::find(g_instances.Get().begin(), | 563 Instances::iterator it = std::find(g_instances.Get().begin(), |
| 564 g_instances.Get().end(), | 564 g_instances.Get().end(), |
| 565 this); | 565 this); |
| 566 if (it != g_instances.Get().end()) | 566 if (it != g_instances.Get().end()) |
| 567 g_instances.Get().erase(it); | 567 g_instances.Get().erase(it); |
| 568 } | 568 } |
| 569 | 569 |
| 570 void RenderFrameDevToolsAgentHost::ReadyToCommitNavigation( | 570 void RenderFrameDevToolsAgentHost::ReadyToCommitNavigation( |
| 571 NavigationHandle* navigation_handle) { | 571 NavigationHandle* navigation_handle) { |
| 572 // CommitPending may destruct |this|. |
| 573 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 574 |
| 572 // TODO(clamy): Switch RenderFrameDevToolsAgentHost to always buffer messages | 575 // TODO(clamy): Switch RenderFrameDevToolsAgentHost to always buffer messages |
| 573 // until ReadyToCommitNavigation is called, now that it is also called in | 576 // until ReadyToCommitNavigation is called, now that it is also called in |
| 574 // non-PlzNavigate mode. | 577 // non-PlzNavigate mode. |
| 575 if (!IsBrowserSideNavigationEnabled()) | 578 if (!IsBrowserSideNavigationEnabled()) |
| 576 return; | 579 return; |
| 577 | 580 |
| 578 // If the navigation is not tracked, return; | 581 // If the navigation is not tracked, return; |
| 579 if (navigating_handles_.count(navigation_handle) == 0) | 582 if (navigating_handles_.count(navigation_handle) == 0) |
| 580 return; | 583 return; |
| 581 | 584 |
| 582 RenderFrameHostImpl* render_frame_host_impl = | 585 RenderFrameHostImpl* render_frame_host_impl = |
| 583 static_cast<RenderFrameHostImpl*>( | 586 static_cast<RenderFrameHostImpl*>( |
| 584 navigation_handle->GetRenderFrameHost()); | 587 navigation_handle->GetRenderFrameHost()); |
| 585 if (current_->host() != render_frame_host_impl || current_frame_crashed_) { | 588 if (current_->host() != render_frame_host_impl || current_frame_crashed_) { |
| 586 SetPending(render_frame_host_impl); | 589 SetPending(render_frame_host_impl); |
| 587 pending_handle_ = navigation_handle; | 590 pending_handle_ = navigation_handle; |
| 588 // Commit when navigating the same frame after crash, avoiding the same | 591 // Commit when navigating the same frame after crash, avoiding the same |
| 589 // host in current_ and pending_. | 592 // host in current_ and pending_. |
| 590 if (current_->host() == render_frame_host_impl) { | 593 if (current_->host() == render_frame_host_impl) { |
| 591 pending_handle_ = nullptr; | 594 pending_handle_ = nullptr; |
| 592 CommitPending(); | 595 CommitPending(); |
| 593 } | 596 } |
| 594 } | 597 } |
| 595 DCHECK(CheckConsistency()); | 598 DCHECK(CheckConsistency()); |
| 596 } | 599 } |
| 597 | 600 |
| 598 void RenderFrameDevToolsAgentHost::DidFinishNavigation( | 601 void RenderFrameDevToolsAgentHost::DidFinishNavigation( |
| 599 NavigationHandle* navigation_handle) { | 602 NavigationHandle* navigation_handle) { |
| 603 // CommitPending may destruct |this|. |
| 604 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 605 |
| 600 if (!IsBrowserSideNavigationEnabled()) | 606 if (!IsBrowserSideNavigationEnabled()) |
| 601 return; | 607 return; |
| 602 | 608 |
| 603 // If the navigation is not tracked, return; | 609 // If the navigation is not tracked, return; |
| 604 if (navigating_handles_.count(navigation_handle) == 0) | 610 if (navigating_handles_.count(navigation_handle) == 0) |
| 605 return; | 611 return; |
| 606 | 612 |
| 607 // Now that the navigation is finished, remove the handle from the list of | 613 // Now that the navigation is finished, remove the handle from the list of |
| 608 // navigating handles. | 614 // navigating handles. |
| 609 navigating_handles_.erase(navigation_handle); | 615 navigating_handles_.erase(navigation_handle); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 622 DispatchBufferedProtocolMessagesIfNecessary(); | 628 DispatchBufferedProtocolMessagesIfNecessary(); |
| 623 | 629 |
| 624 DCHECK(CheckConsistency()); | 630 DCHECK(CheckConsistency()); |
| 625 if (navigation_handle->HasCommitted()) | 631 if (navigation_handle->HasCommitted()) |
| 626 target_handler_->UpdateServiceWorkers(); | 632 target_handler_->UpdateServiceWorkers(); |
| 627 } | 633 } |
| 628 | 634 |
| 629 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( | 635 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( |
| 630 RenderFrameHost* old_host, | 636 RenderFrameHost* old_host, |
| 631 RenderFrameHost* new_host) { | 637 RenderFrameHost* new_host) { |
| 638 // CommitPending may destruct |this|. |
| 639 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 640 |
| 632 if (IsBrowserSideNavigationEnabled()) | 641 if (IsBrowserSideNavigationEnabled()) |
| 633 return; | 642 return; |
| 634 | 643 |
| 635 DCHECK(!pending_ || pending_->host() != old_host); | 644 DCHECK(!pending_ || pending_->host() != old_host); |
| 636 if (!current_ || current_->host() != old_host) { | 645 if (!current_ || current_->host() != old_host) { |
| 637 DCHECK(CheckConsistency()); | 646 DCHECK(CheckConsistency()); |
| 638 return; | 647 return; |
| 639 } | 648 } |
| 640 if (old_host == new_host && !current_frame_crashed_) { | 649 if (old_host == new_host && !current_frame_crashed_) { |
| 641 DCHECK(CheckConsistency()); | 650 DCHECK(CheckConsistency()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 655 if (!IsBrowserSideNavigationEnabled()) | 664 if (!IsBrowserSideNavigationEnabled()) |
| 656 return; | 665 return; |
| 657 DCHECK(current_); | 666 DCHECK(current_); |
| 658 navigating_handles_.insert(navigation_handle); | 667 navigating_handles_.insert(navigation_handle); |
| 659 DCHECK(CheckConsistency()); | 668 DCHECK(CheckConsistency()); |
| 660 } | 669 } |
| 661 | 670 |
| 662 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( | 671 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( |
| 663 RenderFrameHost* old_host, | 672 RenderFrameHost* old_host, |
| 664 RenderFrameHost* new_host) { | 673 RenderFrameHost* new_host) { |
| 674 // CommitPending may destruct |this|. |
| 675 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 676 |
| 665 target_handler_->UpdateFrames(); | 677 target_handler_->UpdateFrames(); |
| 666 | 678 |
| 667 if (IsBrowserSideNavigationEnabled()) | 679 if (IsBrowserSideNavigationEnabled()) |
| 668 return; | 680 return; |
| 669 | 681 |
| 670 DCHECK(!pending_ || pending_->host() != old_host); | 682 DCHECK(!pending_ || pending_->host() != old_host); |
| 671 if (!current_ || current_->host() != old_host) { | 683 if (!current_ || current_->host() != old_host) { |
| 672 DCHECK(CheckConsistency()); | 684 DCHECK(CheckConsistency()); |
| 673 return; | 685 return; |
| 674 } | 686 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 | 824 |
| 813 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { | 825 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { |
| 814 if (page_handler_) | 826 if (page_handler_) |
| 815 page_handler_->DidDetachInterstitialPage(); | 827 page_handler_->DidDetachInterstitialPage(); |
| 816 } | 828 } |
| 817 | 829 |
| 818 void RenderFrameDevToolsAgentHost::DidCommitProvisionalLoadForFrame( | 830 void RenderFrameDevToolsAgentHost::DidCommitProvisionalLoadForFrame( |
| 819 RenderFrameHost* render_frame_host, | 831 RenderFrameHost* render_frame_host, |
| 820 const GURL& url, | 832 const GURL& url, |
| 821 ui::PageTransition transition_type) { | 833 ui::PageTransition transition_type) { |
| 834 // CommitPending may destruct |this|. |
| 835 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 836 |
| 822 if (IsBrowserSideNavigationEnabled()) | 837 if (IsBrowserSideNavigationEnabled()) |
| 823 return; | 838 return; |
| 824 if (pending_ && pending_->host() == render_frame_host) | 839 if (pending_ && pending_->host() == render_frame_host) |
| 825 CommitPending(); | 840 CommitPending(); |
| 826 DCHECK(CheckConsistency()); | 841 DCHECK(CheckConsistency()); |
| 827 target_handler_->UpdateServiceWorkers(); | 842 target_handler_->UpdateServiceWorkers(); |
| 828 } | 843 } |
| 829 | 844 |
| 830 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( | 845 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( |
| 831 RenderFrameHost* render_frame_host, | 846 RenderFrameHost* render_frame_host, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 disconnected_ = std::move(current_); | 906 disconnected_ = std::move(current_); |
| 892 disconnected_->Detach(); | 907 disconnected_->Detach(); |
| 893 frame_tree_node_ = nullptr; | 908 frame_tree_node_ = nullptr; |
| 894 in_navigation_protocol_message_buffer_.clear(); | 909 in_navigation_protocol_message_buffer_.clear(); |
| 895 navigating_handles_.clear(); | 910 navigating_handles_.clear(); |
| 896 pending_handle_ = nullptr; | 911 pending_handle_ = nullptr; |
| 897 WebContentsObserver::Observe(nullptr); | 912 WebContentsObserver::Observe(nullptr); |
| 898 } | 913 } |
| 899 | 914 |
| 900 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { | 915 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { |
| 916 // CommitPending may destruct |this|. |
| 917 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 918 |
| 901 DCHECK(!current_); | 919 DCHECK(!current_); |
| 902 DCHECK(!pending_); | 920 DCHECK(!pending_); |
| 903 RenderFrameHostImpl* host = | 921 RenderFrameHostImpl* host = |
| 904 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); | 922 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); |
| 905 DCHECK(host); | 923 DCHECK(host); |
| 906 frame_tree_node_ = host->frame_tree_node(); | 924 frame_tree_node_ = host->frame_tree_node(); |
| 907 current_ = std::move(disconnected_); | 925 current_ = std::move(disconnected_); |
| 908 SetPending(host); | 926 SetPending(host); |
| 909 CommitPending(); | 927 CommitPending(); |
| 910 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); | 928 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 923 if (!contents) | 941 if (!contents) |
| 924 return ""; | 942 return ""; |
| 925 contents = contents->GetOuterWebContents(); | 943 contents = contents->GetOuterWebContents(); |
| 926 if (contents) | 944 if (contents) |
| 927 return DevToolsAgentHost::GetOrCreateFor(contents)->GetId(); | 945 return DevToolsAgentHost::GetOrCreateFor(contents)->GetId(); |
| 928 return ""; | 946 return ""; |
| 929 } | 947 } |
| 930 | 948 |
| 931 std::string RenderFrameDevToolsAgentHost::GetType() { | 949 std::string RenderFrameDevToolsAgentHost::GetType() { |
| 932 DevToolsManager* manager = DevToolsManager::GetInstance(); | 950 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 933 if (manager->delegate()) | 951 if (manager->delegate() && current_) { |
| 934 return manager->delegate()->GetTargetType(current_->host()); | 952 std::string result = manager->delegate()->GetTargetType(current_->host()); |
| 953 if (!result.empty()) |
| 954 return result; |
| 955 } |
| 935 if (IsChildFrame()) | 956 if (IsChildFrame()) |
| 936 return kTypeFrame; | 957 return kTypeFrame; |
| 937 return kTypePage; | 958 return kTypePage; |
| 938 } | 959 } |
| 939 | 960 |
| 940 std::string RenderFrameDevToolsAgentHost::GetTitle() { | 961 std::string RenderFrameDevToolsAgentHost::GetTitle() { |
| 941 DevToolsManager* manager = DevToolsManager::GetInstance(); | 962 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 942 std::string result; | 963 if (manager->delegate() && current_) { |
| 943 if (manager->delegate()) | 964 std::string result = manager->delegate()->GetTargetTitle(current_->host()); |
| 944 result = manager->delegate()->GetTargetTitle(current_->host()); | 965 if (!result.empty()) |
| 945 if (!result.empty()) | 966 return result; |
| 946 return result; | 967 } |
| 947 content::WebContents* web_contents = GetWebContents(); | 968 content::WebContents* web_contents = GetWebContents(); |
| 948 if (web_contents) | 969 if (web_contents) |
| 949 result = base::UTF16ToUTF8(web_contents->GetTitle()); | 970 return base::UTF16ToUTF8(web_contents->GetTitle()); |
| 950 return GetURL().spec(); | 971 return GetURL().spec(); |
| 951 } | 972 } |
| 952 | 973 |
| 953 std::string RenderFrameDevToolsAgentHost::GetDescription() { | 974 std::string RenderFrameDevToolsAgentHost::GetDescription() { |
| 954 DevToolsManager* manager = DevToolsManager::GetInstance(); | 975 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 955 if (manager->delegate()) | 976 if (manager->delegate() && current_) |
| 956 return manager->delegate()->GetTargetDescription(current_->host()); | 977 return manager->delegate()->GetTargetDescription(current_->host()); |
| 957 return ""; | 978 return ""; |
| 958 } | 979 } |
| 959 | 980 |
| 960 GURL RenderFrameDevToolsAgentHost::GetURL() { | 981 GURL RenderFrameDevToolsAgentHost::GetURL() { |
| 961 // Order is important here. | 982 // Order is important here. |
| 962 WebContents* web_contents = GetWebContents(); | 983 WebContents* web_contents = GetWebContents(); |
| 963 if (web_contents && !IsChildFrame()) | 984 if (web_contents && !IsChildFrame()) |
| 964 return web_contents->GetVisibleURL(); | 985 return web_contents->GetVisibleURL(); |
| 965 if (pending_) | 986 if (pending_) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 RenderFrameHost* host) { | 1094 RenderFrameHost* host) { |
| 1074 return (current_ && current_->host() == host) || | 1095 return (current_ && current_->host() == host) || |
| 1075 (pending_ && pending_->host() == host); | 1096 (pending_ && pending_->host() == host); |
| 1076 } | 1097 } |
| 1077 | 1098 |
| 1078 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1099 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 1079 return current_ && current_->host()->GetParent(); | 1100 return current_ && current_->host()->GetParent(); |
| 1080 } | 1101 } |
| 1081 | 1102 |
| 1082 } // namespace content | 1103 } // namespace content |
| OLD | NEW |