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" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/process/process_handle.h" | |
15 #include "base/strings/string_number_conversions.h" | |
14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
15 #include "build/build_config.h" | 17 #include "build/build_config.h" |
16 #include "content/browser/bad_message.h" | 18 #include "content/browser/bad_message.h" |
17 #include "content/browser/child_process_security_policy_impl.h" | 19 #include "content/browser/child_process_security_policy_impl.h" |
18 #include "content/browser/devtools/devtools_frame_trace_recorder.h" | 20 #include "content/browser/devtools/devtools_frame_trace_recorder.h" |
19 #include "content/browser/devtools/devtools_manager.h" | 21 #include "content/browser/devtools/devtools_manager.h" |
20 #include "content/browser/devtools/devtools_session.h" | 22 #include "content/browser/devtools/devtools_session.h" |
21 #include "content/browser/devtools/page_navigation_throttle.h" | 23 #include "content/browser/devtools/page_navigation_throttle.h" |
22 #include "content/browser/devtools/protocol/dom_handler.h" | 24 #include "content/browser/devtools/protocol/dom_handler.h" |
23 #include "content/browser/devtools/protocol/emulation_handler.h" | 25 #include "content/browser/devtools/protocol/emulation_handler.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
40 #include "content/browser/renderer_host/render_view_host_impl.h" | 42 #include "content/browser/renderer_host/render_view_host_impl.h" |
41 #include "content/browser/site_instance_impl.h" | 43 #include "content/browser/site_instance_impl.h" |
42 #include "content/browser/web_contents/web_contents_impl.h" | 44 #include "content/browser/web_contents/web_contents_impl.h" |
43 #include "content/common/view_messages.h" | 45 #include "content/common/view_messages.h" |
44 #include "content/public/browser/browser_context.h" | 46 #include "content/public/browser/browser_context.h" |
45 #include "content/public/browser/content_browser_client.h" | 47 #include "content/public/browser/content_browser_client.h" |
46 #include "content/public/browser/navigation_handle.h" | 48 #include "content/public/browser/navigation_handle.h" |
47 #include "content/public/browser/render_widget_host_iterator.h" | 49 #include "content/public/browser/render_widget_host_iterator.h" |
48 #include "content/public/browser/web_contents_delegate.h" | 50 #include "content/public/browser/web_contents_delegate.h" |
49 #include "content/public/common/browser_side_navigation_policy.h" | 51 #include "content/public/common/browser_side_navigation_policy.h" |
52 #include "net/base/net_errors.h" | |
50 | 53 |
51 #if defined(OS_ANDROID) | 54 #if defined(OS_ANDROID) |
52 #include "content/public/browser/render_widget_host_view.h" | 55 #include "content/public/browser/render_widget_host_view.h" |
53 #include "device/power_save_blocker/power_save_blocker.h" | 56 #include "device/power_save_blocker/power_save_blocker.h" |
54 #endif | 57 #endif |
55 | 58 |
56 namespace content { | 59 namespace content { |
57 | 60 |
58 typedef std::vector<RenderFrameDevToolsAgentHost*> Instances; | 61 typedef std::vector<RenderFrameDevToolsAgentHost*> Instances; |
59 | 62 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 void RenderFrameDevToolsAgentHost::OnBeforeNavigation( | 378 void RenderFrameDevToolsAgentHost::OnBeforeNavigation( |
376 NavigationHandle* navigation_handle) { | 379 NavigationHandle* navigation_handle) { |
377 FrameTreeNode* frame_tree_node = | 380 FrameTreeNode* frame_tree_node = |
378 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); | 381 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); |
379 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 382 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); |
380 if (agent_host) | 383 if (agent_host) |
381 agent_host->AboutToNavigate(navigation_handle); | 384 agent_host->AboutToNavigate(navigation_handle); |
382 } | 385 } |
383 | 386 |
384 // static | 387 // static |
388 void RenderFrameDevToolsAgentHost::OnFailedNavigation(RenderFrameHost* host, | |
389 net::Error error_code) { | |
390 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(host); | |
391 if (agent_host) | |
392 agent_host->OnFailedNavigation(error_code); | |
393 } | |
394 | |
395 // static | |
385 std::unique_ptr<NavigationThrottle> | 396 std::unique_ptr<NavigationThrottle> |
386 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation( | 397 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation( |
387 NavigationHandle* navigation_handle) { | 398 NavigationHandle* navigation_handle) { |
388 FrameTreeNode* frame_tree_node = | 399 FrameTreeNode* frame_tree_node = |
389 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); | 400 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); |
390 while (frame_tree_node && frame_tree_node->parent()) { | 401 while (frame_tree_node && frame_tree_node->parent()) { |
391 frame_tree_node = frame_tree_node->parent(); | 402 frame_tree_node = frame_tree_node->parent(); |
392 } | 403 } |
393 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 404 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); |
394 // Note Page.setControlNavigations is intended to control navigations in the | 405 // Note Page.setControlNavigations is intended to control navigations in the |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 void RenderFrameDevToolsAgentHost::AboutToNavigate( | 724 void RenderFrameDevToolsAgentHost::AboutToNavigate( |
714 NavigationHandle* navigation_handle) { | 725 NavigationHandle* navigation_handle) { |
715 if (!IsBrowserSideNavigationEnabled()) | 726 if (!IsBrowserSideNavigationEnabled()) |
716 return; | 727 return; |
717 DCHECK(current_); | 728 DCHECK(current_); |
718 navigating_handles_.insert(navigation_handle); | 729 navigating_handles_.insert(navigation_handle); |
719 current_->Suspend(); | 730 current_->Suspend(); |
720 DCHECK(CheckConsistency()); | 731 DCHECK(CheckConsistency()); |
721 } | 732 } |
722 | 733 |
734 void RenderFrameDevToolsAgentHost::OnFailedNavigation(net::Error error_code) { | |
735 DCHECK(IsBrowserSideNavigationEnabled()); | |
736 if (!session()) | |
737 return; | |
738 | |
739 protocol::NetworkHandler* handler = | |
740 protocol::NetworkHandler::FromSession(session()); | |
741 if (!handler) | |
742 return; | |
743 | |
744 static int next_id = 0; | |
745 std::string request_id = base::IntToString(base::GetCurrentProcId()) + "." + | |
dgozman
2017/02/27 17:31:31
I'd move protocol-specific code (like request id g
jam
2017/02/27 20:47:35
Done.
| |
746 base::IntToString(++next_id); | |
747 std::string error_string = net::ErrorToString(error_code); | |
748 bool cancelled = error_code == net::Error::ERR_ABORTED; | |
749 handler->NavigationFailed(request_id, error_string, cancelled); | |
750 } | |
751 | |
723 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( | 752 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( |
724 RenderFrameHost* old_host, | 753 RenderFrameHost* old_host, |
725 RenderFrameHost* new_host) { | 754 RenderFrameHost* new_host) { |
726 // CommitPending may destruct |this|. | 755 // CommitPending may destruct |this|. |
727 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 756 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
728 | 757 |
729 if (session()) | 758 if (session()) |
730 protocol::TargetHandler::FromSession(session())->UpdateFrames(); | 759 protocol::TargetHandler::FromSession(session())->UpdateFrames(); |
731 | 760 |
732 if (IsBrowserSideNavigationEnabled()) | 761 if (IsBrowserSideNavigationEnabled()) |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 RenderFrameHost* host) { | 1181 RenderFrameHost* host) { |
1153 return (current_ && current_->host() == host) || | 1182 return (current_ && current_->host() == host) || |
1154 (pending_ && pending_->host() == host); | 1183 (pending_ && pending_->host() == host); |
1155 } | 1184 } |
1156 | 1185 |
1157 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1186 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
1158 return current_ && current_->host()->GetParent(); | 1187 return current_ && current_->host()->GetParent(); |
1159 } | 1188 } |
1160 | 1189 |
1161 } // namespace content | 1190 } // namespace content |
OLD | NEW |