OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame_host/navigator_impl.h" | 5 #include "content/browser/frame_host/navigator_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 NavigatorImpl::NavigatorImpl( | 98 NavigatorImpl::NavigatorImpl( |
99 NavigationControllerImpl* navigation_controller, | 99 NavigationControllerImpl* navigation_controller, |
100 NavigatorDelegate* delegate) | 100 NavigatorDelegate* delegate) |
101 : controller_(navigation_controller), | 101 : controller_(navigation_controller), |
102 delegate_(delegate) { | 102 delegate_(delegate) { |
103 } | 103 } |
104 | 104 |
105 NavigatorImpl::~NavigatorImpl() {} | 105 NavigatorImpl::~NavigatorImpl() {} |
106 | 106 |
| 107 // static |
| 108 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
| 109 RenderFrameHostImpl* render_frame_host, |
| 110 const GURL& url) { |
| 111 int enabled_bindings = |
| 112 render_frame_host->render_view_host()->GetEnabledBindings(); |
| 113 bool is_allowed_in_web_ui_renderer = |
| 114 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
| 115 render_frame_host->frame_tree_node() |
| 116 ->navigator() |
| 117 ->GetController() |
| 118 ->GetBrowserContext(), |
| 119 url); |
| 120 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
| 121 !is_allowed_in_web_ui_renderer) { |
| 122 // Log the URL to help us diagnose any future failures of this CHECK. |
| 123 GetContentClient()->SetActiveURL(url); |
| 124 CHECK(0); |
| 125 } |
| 126 } |
| 127 |
107 NavigatorDelegate* NavigatorImpl::GetDelegate() { | 128 NavigatorDelegate* NavigatorImpl::GetDelegate() { |
108 return delegate_; | 129 return delegate_; |
109 } | 130 } |
110 | 131 |
111 NavigationController* NavigatorImpl::GetController() { | 132 NavigationController* NavigatorImpl::GetController() { |
112 return controller_; | 133 return controller_; |
113 } | 134 } |
114 | 135 |
115 void NavigatorImpl::DidStartProvisionalLoad( | 136 void NavigatorImpl::DidStartProvisionalLoad( |
116 RenderFrameHostImpl* render_frame_host, | 137 RenderFrameHostImpl* render_frame_host, |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 // For main frames, NavigationHandle will be created after the call to | 839 // For main frames, NavigationHandle will be created after the call to |
819 // |DidStartMainFrameNavigation|, so it receives the most up to date pending | 840 // |DidStartMainFrameNavigation|, so it receives the most up to date pending |
820 // entry from the NavigationController. | 841 // entry from the NavigationController. |
821 NavigationEntry* pending_entry = controller_->GetPendingEntry(); | 842 NavigationEntry* pending_entry = controller_->GetPendingEntry(); |
822 navigation_request->CreateNavigationHandle( | 843 navigation_request->CreateNavigationHandle( |
823 pending_entry ? pending_entry->GetUniqueID() : 0); | 844 pending_entry ? pending_entry->GetUniqueID() : 0); |
824 navigation_request->BeginNavigation(); | 845 navigation_request->BeginNavigation(); |
825 } | 846 } |
826 | 847 |
827 // PlzNavigate | 848 // PlzNavigate |
828 void NavigatorImpl::CommitNavigation(NavigationRequest* navigation_request, | |
829 ResourceResponse* response, | |
830 scoped_ptr<StreamHandle> body) { | |
831 CHECK(IsBrowserSideNavigationEnabled()); | |
832 | |
833 DCHECK(navigation_request); | |
834 FrameTreeNode* frame_tree_node = navigation_request->frame_tree_node(); | |
835 DCHECK(frame_tree_node); | |
836 DCHECK(response || | |
837 !ShouldMakeNetworkRequestForURL( | |
838 navigation_request->common_params().url)); | |
839 | |
840 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not | |
841 // commit; they leave the frame showing the previous page. | |
842 if (response && response->head.headers.get() && | |
843 (response->head.headers->response_code() == 204 || | |
844 response->head.headers->response_code() == 205)) { | |
845 CancelNavigation(frame_tree_node); | |
846 return; | |
847 } | |
848 | |
849 // Select an appropriate renderer to commit the navigation. | |
850 RenderFrameHostImpl* render_frame_host = | |
851 frame_tree_node->render_manager()->GetFrameHostForNavigation( | |
852 *navigation_request); | |
853 | |
854 // The renderer can exit view source mode when any error or cancellation | |
855 // happen. When reusing the same renderer, overwrite to recover the mode. | |
856 if (navigation_request->is_view_source() && | |
857 render_frame_host == | |
858 frame_tree_node->render_manager()->current_frame_host()) { | |
859 DCHECK(!render_frame_host->GetParent()); | |
860 render_frame_host->render_view_host()->Send( | |
861 new ViewMsg_EnableViewSourceMode( | |
862 render_frame_host->render_view_host()->GetRoutingID())); | |
863 } | |
864 | |
865 CheckWebUIRendererDoesNotDisplayNormalURL( | |
866 render_frame_host, navigation_request->common_params().url); | |
867 | |
868 navigation_request->TransferNavigationHandleOwnership(render_frame_host); | |
869 render_frame_host->navigation_handle()->ReadyToCommitNavigation( | |
870 render_frame_host, response ? response->head.headers : nullptr); | |
871 render_frame_host->CommitNavigation(response, std::move(body), | |
872 navigation_request->common_params(), | |
873 navigation_request->request_params()); | |
874 } | |
875 | |
876 // PlzNavigate | |
877 void NavigatorImpl::FailedNavigation(FrameTreeNode* frame_tree_node, | 849 void NavigatorImpl::FailedNavigation(FrameTreeNode* frame_tree_node, |
878 bool has_stale_copy_in_cache, | 850 bool has_stale_copy_in_cache, |
879 int error_code) { | 851 int error_code) { |
880 CHECK(IsBrowserSideNavigationEnabled()); | 852 CHECK(IsBrowserSideNavigationEnabled()); |
881 | 853 |
882 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 854 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
883 DCHECK(navigation_request); | 855 DCHECK(navigation_request); |
884 | 856 |
885 DiscardPendingEntryOnFailureIfNeeded(navigation_request->navigation_handle()); | 857 DiscardPendingEntryOnFailureIfNeeded(navigation_request->navigation_handle()); |
886 | 858 |
887 // If the request was canceled by the user do not show an error page. | 859 // If the request was canceled by the user do not show an error page. |
888 if (error_code == net::ERR_ABORTED) { | 860 if (error_code == net::ERR_ABORTED) { |
889 frame_tree_node->ResetNavigationRequest(false); | 861 frame_tree_node->ResetNavigationRequest(false); |
890 return; | 862 return; |
891 } | 863 } |
892 | 864 |
893 // Select an appropriate renderer to show the error page. | 865 // Select an appropriate renderer to show the error page. |
894 RenderFrameHostImpl* render_frame_host = | 866 RenderFrameHostImpl* render_frame_host = |
895 frame_tree_node->render_manager()->GetFrameHostForNavigation( | 867 frame_tree_node->render_manager()->GetFrameHostForNavigation( |
896 *navigation_request); | 868 *navigation_request); |
897 CheckWebUIRendererDoesNotDisplayNormalURL( | 869 CheckWebUIRendererDoesNotDisplayNormalURL( |
898 render_frame_host, navigation_request->common_params().url); | 870 render_frame_host, navigation_request->common_params().url); |
899 | 871 |
900 navigation_request->TransferNavigationHandleOwnership(render_frame_host); | 872 navigation_request->TransferNavigationHandleOwnership(render_frame_host); |
901 render_frame_host->navigation_handle()->ReadyToCommitNavigation( | 873 render_frame_host->navigation_handle()->ReadyToCommitNavigation( |
902 render_frame_host, scoped_refptr<net::HttpResponseHeaders>()); | 874 render_frame_host); |
903 render_frame_host->FailedNavigation(navigation_request->common_params(), | 875 render_frame_host->FailedNavigation(navigation_request->common_params(), |
904 navigation_request->request_params(), | 876 navigation_request->request_params(), |
905 has_stale_copy_in_cache, error_code); | 877 has_stale_copy_in_cache, error_code); |
906 } | 878 } |
907 | 879 |
908 // PlzNavigate | 880 // PlzNavigate |
909 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { | 881 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { |
910 CHECK(IsBrowserSideNavigationEnabled()); | 882 CHECK(IsBrowserSideNavigationEnabled()); |
911 frame_tree_node->ResetNavigationRequest(false); | 883 frame_tree_node->ResetNavigationRequest(false); |
912 if (frame_tree_node->IsMainFrame()) | 884 if (frame_tree_node->IsMainFrame()) |
(...skipping 15 matching lines...) Expand all Loading... |
928 const base::TimeTicks& renderer_before_unload_end_time) { | 900 const base::TimeTicks& renderer_before_unload_end_time) { |
929 // Only stores the beforeunload delay if we're tracking a browser initiated | 901 // Only stores the beforeunload delay if we're tracking a browser initiated |
930 // navigation and it happened later than the navigation request. | 902 // navigation and it happened later than the navigation request. |
931 if (navigation_data_ && | 903 if (navigation_data_ && |
932 renderer_before_unload_start_time > navigation_data_->start_time_) { | 904 renderer_before_unload_start_time > navigation_data_->start_time_) { |
933 navigation_data_->before_unload_delay_ = | 905 navigation_data_->before_unload_delay_ = |
934 renderer_before_unload_end_time - renderer_before_unload_start_time; | 906 renderer_before_unload_end_time - renderer_before_unload_start_time; |
935 } | 907 } |
936 } | 908 } |
937 | 909 |
938 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( | |
939 RenderFrameHostImpl* render_frame_host, | |
940 const GURL& url) { | |
941 int enabled_bindings = | |
942 render_frame_host->render_view_host()->GetEnabledBindings(); | |
943 bool is_allowed_in_web_ui_renderer = | |
944 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | |
945 controller_->GetBrowserContext(), url); | |
946 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | |
947 !is_allowed_in_web_ui_renderer) { | |
948 // Log the URL to help us diagnose any future failures of this CHECK. | |
949 GetContentClient()->SetActiveURL(url); | |
950 CHECK(0); | |
951 } | |
952 } | |
953 | |
954 // PlzNavigate | 910 // PlzNavigate |
955 void NavigatorImpl::RequestNavigation( | 911 void NavigatorImpl::RequestNavigation( |
956 FrameTreeNode* frame_tree_node, | 912 FrameTreeNode* frame_tree_node, |
957 const GURL& dest_url, | 913 const GURL& dest_url, |
958 const Referrer& dest_referrer, | 914 const Referrer& dest_referrer, |
959 const FrameNavigationEntry& frame_entry, | 915 const FrameNavigationEntry& frame_entry, |
960 const NavigationEntryImpl& entry, | 916 const NavigationEntryImpl& entry, |
961 NavigationController::ReloadType reload_type, | 917 NavigationController::ReloadType reload_type, |
962 LoFiState lofi_state, | 918 LoFiState lofi_state, |
963 bool is_same_document_history_load, | 919 bool is_same_document_history_load, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 if (pending_entry != controller_->GetVisibleEntry() || | 1088 if (pending_entry != controller_->GetVisibleEntry() || |
1133 !should_preserve_entry) { | 1089 !should_preserve_entry) { |
1134 controller_->DiscardPendingEntry(true); | 1090 controller_->DiscardPendingEntry(true); |
1135 | 1091 |
1136 // Also force the UI to refresh. | 1092 // Also force the UI to refresh. |
1137 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); | 1093 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
1138 } | 1094 } |
1139 } | 1095 } |
1140 | 1096 |
1141 } // namespace content | 1097 } // namespace content |
OLD | NEW |