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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 RenderFrameHostImpl* host = | 851 RenderFrameHostImpl* host = |
| 851 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); | 852 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); |
| 852 DCHECK(host); | 853 DCHECK(host); |
| 853 frame_tree_node_ = host->frame_tree_node(); | 854 frame_tree_node_ = host->frame_tree_node(); |
| 854 current_ = std::move(disconnected_); | 855 current_ = std::move(disconnected_); |
| 855 SetPending(host); | 856 SetPending(host); |
| 856 CommitPending(); | 857 CommitPending(); |
| 857 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); | 858 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); |
| 858 } | 859 } |
| 859 | 860 |
| 860 DevToolsAgentHost::Type RenderFrameDevToolsAgentHost::GetType() { | 861 std::string RenderFrameDevToolsAgentHost::GetParentId() { |
| 861 return IsChildFrame() ? TYPE_FRAME : TYPE_WEB_CONTENTS; | 862 if (IsChildFrame()) { |
| 863 RenderFrameHostImpl* frame_host = current_->host(); | |
| 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 | |
| 870 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents()); | |
| 871 if (!contents) | |
| 872 return ""; | |
| 873 contents = contents->GetOuterWebContents(); | |
| 874 if (contents) | |
| 875 return DevToolsAgentHost::GetOrCreateFor(contents)->GetId(); | |
| 876 return ""; | |
| 877 } | |
| 878 | |
| 879 std::string RenderFrameDevToolsAgentHost::GetType() { | |
|
dgozman
2016/08/22 23:09:07
Let's save it in constructor.
| |
| 880 DevToolsManager* manager = DevToolsManager::GetInstance(); | |
| 881 return manager->delegate()->GetTargetType(current_->host()); | |
|
dgozman
2016/08/22 23:09:07
There could be no delegate.
| |
| 862 } | 882 } |
| 863 | 883 |
| 864 std::string RenderFrameDevToolsAgentHost::GetTitle() { | 884 std::string RenderFrameDevToolsAgentHost::GetTitle() { |
| 865 if (IsChildFrame()) | 885 if (IsChildFrame()) |
| 866 return GetURL().spec(); | 886 return GetURL().spec(); |
| 867 if (WebContents* web_contents = GetWebContents()) | 887 if (WebContents* web_contents = GetWebContents()) |
| 868 return base::UTF16ToUTF8(web_contents->GetTitle()); | 888 return base::UTF16ToUTF8(web_contents->GetTitle()); |
| 869 return ""; | 889 return ""; |
| 870 } | 890 } |
| 871 | 891 |
| 892 std::string RenderFrameDevToolsAgentHost::GetDescription() { | |
| 893 return ""; | |
| 894 } | |
| 895 | |
| 872 GURL RenderFrameDevToolsAgentHost::GetURL() { | 896 GURL RenderFrameDevToolsAgentHost::GetURL() { |
| 873 // Order is important here. | 897 // Order is important here. |
| 874 WebContents* web_contents = GetWebContents(); | 898 WebContents* web_contents = GetWebContents(); |
| 875 if (web_contents && !IsChildFrame()) | 899 if (web_contents && !IsChildFrame()) |
| 876 return web_contents->GetVisibleURL(); | 900 return web_contents->GetVisibleURL(); |
| 877 if (pending_) | 901 if (pending_) |
| 878 return pending_->host()->GetLastCommittedURL(); | 902 return pending_->host()->GetLastCommittedURL(); |
| 879 if (current_) | 903 if (current_) |
| 880 return current_->host()->GetLastCommittedURL(); | 904 return current_->host()->GetLastCommittedURL(); |
| 881 return GURL(); | 905 return GURL(); |
| 882 } | 906 } |
| 883 | 907 |
| 908 GURL RenderFrameDevToolsAgentHost::GetFaviconURL() { | |
| 909 return GURL(); | |
| 910 } | |
| 911 | |
| 884 bool RenderFrameDevToolsAgentHost::Activate() { | 912 bool RenderFrameDevToolsAgentHost::Activate() { |
| 885 WebContentsImpl* wc = static_cast<WebContentsImpl*>(web_contents()); | 913 WebContentsImpl* wc = static_cast<WebContentsImpl*>(web_contents()); |
| 886 if (wc) { | 914 if (wc) { |
| 887 wc->Activate(); | 915 wc->Activate(); |
| 888 return true; | 916 return true; |
| 889 } | 917 } |
| 890 return false; | 918 return false; |
| 891 } | 919 } |
| 892 | 920 |
| 921 void RenderFrameDevToolsAgentHost::Reload() { | |
| 922 WebContentsImpl* wc = static_cast<WebContentsImpl*>(web_contents()); | |
| 923 if (wc) | |
| 924 wc->GetController().Reload(true); | |
| 925 } | |
| 926 | |
| 893 bool RenderFrameDevToolsAgentHost::Close() { | 927 bool RenderFrameDevToolsAgentHost::Close() { |
| 894 if (web_contents()) { | 928 if (web_contents()) { |
| 895 web_contents()->ClosePage(); | 929 web_contents()->ClosePage(); |
| 896 return true; | 930 return true; |
| 897 } | 931 } |
| 898 return false; | 932 return false; |
| 899 } | 933 } |
| 900 | 934 |
| 935 base::TimeTicks RenderFrameDevToolsAgentHost::GetLastActivityTime() { | |
| 936 if (content::WebContents* contents = web_contents()) | |
| 937 return contents->GetLastActiveTime(); | |
| 938 return base::TimeTicks(); | |
| 939 } | |
| 940 | |
| 901 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( | 941 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( |
| 902 const IPC::Message& message) { | 942 const IPC::Message& message) { |
| 903 ViewHostMsg_SwapCompositorFrame::Param param; | 943 ViewHostMsg_SwapCompositorFrame::Param param; |
| 904 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 944 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
| 905 return; | 945 return; |
| 906 if (page_handler_) | 946 if (page_handler_) |
| 907 page_handler_->OnSwapCompositorFrame( | 947 page_handler_->OnSwapCompositorFrame( |
| 908 std::move(std::get<1>(param).metadata)); | 948 std::move(std::get<1>(param).metadata)); |
| 909 if (input_handler_) | 949 if (input_handler_) |
| 910 input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata); | 950 input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 RenderFrameHost* host) { | 1004 RenderFrameHost* host) { |
| 965 return (current_ && current_->host() == host) || | 1005 return (current_ && current_->host() == host) || |
| 966 (pending_ && pending_->host() == host); | 1006 (pending_ && pending_->host() == host); |
| 967 } | 1007 } |
| 968 | 1008 |
| 969 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1009 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 970 return current_ && current_->host()->GetParent(); | 1010 return current_ && current_->host()->GetParent(); |
| 971 } | 1011 } |
| 972 | 1012 |
| 973 } // namespace content | 1013 } // namespace content |
| OLD | NEW |