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