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