| 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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "content/browser/bad_message.h" | 13 #include "content/browser/bad_message.h" |
| 14 #include "content/browser/child_process_security_policy_impl.h" | 14 #include "content/browser/child_process_security_policy_impl.h" |
| 15 #include "content/browser/devtools/devtools_frame_trace_recorder.h" | 15 #include "content/browser/devtools/devtools_frame_trace_recorder.h" |
| 16 #include "content/browser/devtools/devtools_manager.h" | |
| 17 #include "content/browser/devtools/devtools_protocol_handler.h" | 16 #include "content/browser/devtools/devtools_protocol_handler.h" |
| 18 #include "content/browser/devtools/page_navigation_throttle.h" | 17 #include "content/browser/devtools/page_navigation_throttle.h" |
| 19 #include "content/browser/devtools/protocol/browser_handler.h" | 18 #include "content/browser/devtools/protocol/browser_handler.h" |
| 20 #include "content/browser/devtools/protocol/dom_handler.h" | 19 #include "content/browser/devtools/protocol/dom_handler.h" |
| 21 #include "content/browser/devtools/protocol/emulation_handler.h" | 20 #include "content/browser/devtools/protocol/emulation_handler.h" |
| 22 #include "content/browser/devtools/protocol/input_handler.h" | 21 #include "content/browser/devtools/protocol/input_handler.h" |
| 23 #include "content/browser/devtools/protocol/inspector_handler.h" | 22 #include "content/browser/devtools/protocol/inspector_handler.h" |
| 24 #include "content/browser/devtools/protocol/io_handler.h" | 23 #include "content/browser/devtools/protocol/io_handler.h" |
| 25 #include "content/browser/devtools/protocol/network_handler.h" | 24 #include "content/browser/devtools/protocol/network_handler.h" |
| 26 #include "content/browser/devtools/protocol/page_handler.h" | 25 #include "content/browser/devtools/protocol/page_handler.h" |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 RenderFrameHostImpl* host = | 850 RenderFrameHostImpl* host = |
| 852 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); | 851 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); |
| 853 DCHECK(host); | 852 DCHECK(host); |
| 854 frame_tree_node_ = host->frame_tree_node(); | 853 frame_tree_node_ = host->frame_tree_node(); |
| 855 current_ = std::move(disconnected_); | 854 current_ = std::move(disconnected_); |
| 856 SetPending(host); | 855 SetPending(host); |
| 857 CommitPending(); | 856 CommitPending(); |
| 858 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); | 857 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); |
| 859 } | 858 } |
| 860 | 859 |
| 861 std::string RenderFrameDevToolsAgentHost::GetParentId() { | 860 DevToolsAgentHost::Type RenderFrameDevToolsAgentHost::GetType() { |
| 862 if (IsChildFrame()) { | 861 return IsChildFrame() ? TYPE_FRAME : TYPE_WEB_CONTENTS; |
| 863 RenderFrameHostImpl* frame_host = current_->host(); | 862 } |
| 864 while (frame_host && !ShouldCreateDevToolsFor(frame_host)) | |
| 865 frame_host = frame_host->GetParent(); | |
| 866 if (frame_host) | |
| 867 return DevToolsAgentHost::GetOrCreateFor(frame_host)->GetId(); | |
| 868 } | |
| 869 | 863 |
| 870 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents()); | 864 std::string RenderFrameDevToolsAgentHost::GetTitle() { |
| 871 if (!contents) | 865 if (IsChildFrame()) |
| 872 return ""; | 866 return GetURL().spec(); |
| 873 contents = contents->GetOuterWebContents(); | 867 if (WebContents* web_contents = GetWebContents()) |
| 874 if (contents) | 868 return base::UTF16ToUTF8(web_contents->GetTitle()); |
| 875 return DevToolsAgentHost::GetOrCreateFor(contents)->GetId(); | |
| 876 return ""; | 869 return ""; |
| 877 } | 870 } |
| 878 | 871 |
| 879 std::string RenderFrameDevToolsAgentHost::GetType() { | |
| 880 DevToolsManager* manager = DevToolsManager::GetInstance(); | |
| 881 if (manager->delegate()) | |
| 882 return manager->delegate()->GetTargetType(current_->host()); | |
| 883 return kTypeOther; | |
| 884 } | |
| 885 | |
| 886 std::string RenderFrameDevToolsAgentHost::GetTitle() { | |
| 887 DevToolsManager* manager = DevToolsManager::GetInstance(); | |
| 888 std::string result; | |
| 889 if (manager->delegate()) | |
| 890 result = manager->delegate()->GetTargetTitle(current_->host()); | |
| 891 if (!result.empty()) | |
| 892 return result; | |
| 893 content::WebContents* web_contents = GetWebContents(); | |
| 894 if (web_contents) | |
| 895 result = base::UTF16ToUTF8(web_contents->GetTitle()); | |
| 896 return GetURL().spec(); | |
| 897 } | |
| 898 | |
| 899 std::string RenderFrameDevToolsAgentHost::GetDescription() { | |
| 900 return ""; | |
| 901 } | |
| 902 | |
| 903 GURL RenderFrameDevToolsAgentHost::GetURL() { | 872 GURL RenderFrameDevToolsAgentHost::GetURL() { |
| 904 // Order is important here. | 873 // Order is important here. |
| 905 WebContents* web_contents = GetWebContents(); | 874 WebContents* web_contents = GetWebContents(); |
| 906 if (web_contents && !IsChildFrame()) | 875 if (web_contents && !IsChildFrame()) |
| 907 return web_contents->GetVisibleURL(); | 876 return web_contents->GetVisibleURL(); |
| 908 if (pending_) | 877 if (pending_) |
| 909 return pending_->host()->GetLastCommittedURL(); | 878 return pending_->host()->GetLastCommittedURL(); |
| 910 if (current_) | 879 if (current_) |
| 911 return current_->host()->GetLastCommittedURL(); | 880 return current_->host()->GetLastCommittedURL(); |
| 912 return GURL(); | 881 return GURL(); |
| 913 } | 882 } |
| 914 | 883 |
| 915 GURL RenderFrameDevToolsAgentHost::GetFaviconURL() { | |
| 916 return GURL(); | |
| 917 } | |
| 918 | |
| 919 bool RenderFrameDevToolsAgentHost::Activate() { | 884 bool RenderFrameDevToolsAgentHost::Activate() { |
| 920 WebContentsImpl* wc = static_cast<WebContentsImpl*>(web_contents()); | 885 WebContentsImpl* wc = static_cast<WebContentsImpl*>(web_contents()); |
| 921 if (wc) { | 886 if (wc) { |
| 922 wc->Activate(); | 887 wc->Activate(); |
| 923 return true; | 888 return true; |
| 924 } | 889 } |
| 925 return false; | 890 return false; |
| 926 } | 891 } |
| 927 | 892 |
| 928 void RenderFrameDevToolsAgentHost::Reload() { | |
| 929 WebContentsImpl* wc = static_cast<WebContentsImpl*>(web_contents()); | |
| 930 if (wc) | |
| 931 wc->GetController().Reload(true); | |
| 932 } | |
| 933 | |
| 934 bool RenderFrameDevToolsAgentHost::Close() { | 893 bool RenderFrameDevToolsAgentHost::Close() { |
| 935 if (web_contents()) { | 894 if (web_contents()) { |
| 936 web_contents()->ClosePage(); | 895 web_contents()->ClosePage(); |
| 937 return true; | 896 return true; |
| 938 } | 897 } |
| 939 return false; | 898 return false; |
| 940 } | 899 } |
| 941 | 900 |
| 942 base::TimeTicks RenderFrameDevToolsAgentHost::GetLastActivityTime() { | |
| 943 if (content::WebContents* contents = web_contents()) | |
| 944 return contents->GetLastActiveTime(); | |
| 945 return base::TimeTicks(); | |
| 946 } | |
| 947 | |
| 948 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( | 901 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( |
| 949 const IPC::Message& message) { | 902 const IPC::Message& message) { |
| 950 ViewHostMsg_SwapCompositorFrame::Param param; | 903 ViewHostMsg_SwapCompositorFrame::Param param; |
| 951 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 904 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
| 952 return; | 905 return; |
| 953 if (page_handler_) | 906 if (page_handler_) |
| 954 page_handler_->OnSwapCompositorFrame( | 907 page_handler_->OnSwapCompositorFrame( |
| 955 std::move(std::get<1>(param).metadata)); | 908 std::move(std::get<1>(param).metadata)); |
| 956 if (input_handler_) | 909 if (input_handler_) |
| 957 input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata); | 910 input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 void RenderFrameDevToolsAgentHost::OnRequestNewWindow( | 945 void RenderFrameDevToolsAgentHost::OnRequestNewWindow( |
| 993 RenderFrameHost* sender, | 946 RenderFrameHost* sender, |
| 994 int new_routing_id) { | 947 int new_routing_id) { |
| 995 RenderFrameHostImpl* frame_host = RenderFrameHostImpl::FromID( | 948 RenderFrameHostImpl* frame_host = RenderFrameHostImpl::FromID( |
| 996 sender->GetProcess()->GetID(), new_routing_id); | 949 sender->GetProcess()->GetID(), new_routing_id); |
| 997 | 950 |
| 998 bool success = false; | 951 bool success = false; |
| 999 if (IsAttached() && sender->GetRoutingID() != new_routing_id && frame_host) { | 952 if (IsAttached() && sender->GetRoutingID() != new_routing_id && frame_host) { |
| 1000 scoped_refptr<DevToolsAgentHost> agent = | 953 scoped_refptr<DevToolsAgentHost> agent = |
| 1001 DevToolsAgentHost::GetOrCreateFor(frame_host); | 954 DevToolsAgentHost::GetOrCreateFor(frame_host); |
| 1002 success = agent->Inspect(); | 955 success = static_cast<DevToolsAgentHostImpl*>(agent.get())-> |
| 956 Inspect(agent->GetBrowserContext()); |
| 1003 } | 957 } |
| 1004 | 958 |
| 1005 sender->Send(new DevToolsAgentMsg_RequestNewWindow_ACK( | 959 sender->Send(new DevToolsAgentMsg_RequestNewWindow_ACK( |
| 1006 sender->GetRoutingID(), success)); | 960 sender->GetRoutingID(), success)); |
| 1007 } | 961 } |
| 1008 | 962 |
| 1009 bool RenderFrameDevToolsAgentHost::HasRenderFrameHost( | 963 bool RenderFrameDevToolsAgentHost::HasRenderFrameHost( |
| 1010 RenderFrameHost* host) { | 964 RenderFrameHost* host) { |
| 1011 return (current_ && current_->host() == host) || | 965 return (current_ && current_->host() == host) || |
| 1012 (pending_ && pending_->host() == host); | 966 (pending_ && pending_->host() == host); |
| 1013 } | 967 } |
| 1014 | 968 |
| 1015 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 969 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 1016 return current_ && current_->host()->GetParent(); | 970 return current_ && current_->host()->GetParent(); |
| 1017 } | 971 } |
| 1018 | 972 |
| 1019 } // namespace content | 973 } // namespace content |
| OLD | NEW |