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->Send( | |
861 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID())); | |
862 } | |
863 | |
864 CheckWebUIRendererDoesNotDisplayNormalURL( | |
865 render_frame_host, navigation_request->common_params().url); | |
866 | |
867 navigation_request->TransferNavigationHandleOwnership(render_frame_host); | |
868 render_frame_host->navigation_handle()->ReadyToCommitNavigation( | |
869 render_frame_host, response ? response->head.headers : nullptr); | |
870 render_frame_host->CommitNavigation(response, std::move(body), | |
871 navigation_request->common_params(), | |
872 navigation_request->request_params()); | |
873 } | |
874 | |
875 // PlzNavigate | |
876 void NavigatorImpl::FailedNavigation(FrameTreeNode* frame_tree_node, | 849 void NavigatorImpl::FailedNavigation(FrameTreeNode* frame_tree_node, |
877 bool has_stale_copy_in_cache, | 850 bool has_stale_copy_in_cache, |
878 int error_code) { | 851 int error_code) { |
879 CHECK(IsBrowserSideNavigationEnabled()); | 852 CHECK(IsBrowserSideNavigationEnabled()); |
880 | 853 |
881 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 854 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
882 DCHECK(navigation_request); | 855 DCHECK(navigation_request); |
883 | 856 |
884 DiscardPendingEntryOnFailureIfNeeded(navigation_request->navigation_handle()); | 857 DiscardPendingEntryOnFailureIfNeeded(navigation_request->navigation_handle()); |
885 | 858 |
886 // 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. |
887 if (error_code == net::ERR_ABORTED) { | 860 if (error_code == net::ERR_ABORTED) { |
888 frame_tree_node->ResetNavigationRequest(false); | 861 frame_tree_node->ResetNavigationRequest(false); |
889 return; | 862 return; |
890 } | 863 } |
891 | 864 |
892 // Select an appropriate renderer to show the error page. | 865 // Select an appropriate renderer to show the error page. |
893 RenderFrameHostImpl* render_frame_host = | 866 RenderFrameHostImpl* render_frame_host = |
894 frame_tree_node->render_manager()->GetFrameHostForNavigation( | 867 frame_tree_node->render_manager()->GetFrameHostForNavigation( |
895 *navigation_request); | 868 *navigation_request); |
896 CheckWebUIRendererDoesNotDisplayNormalURL( | 869 CheckWebUIRendererDoesNotDisplayNormalURL( |
897 render_frame_host, navigation_request->common_params().url); | 870 render_frame_host, navigation_request->common_params().url); |
898 | 871 |
899 navigation_request->TransferNavigationHandleOwnership(render_frame_host); | 872 navigation_request->TransferNavigationHandleOwnership(render_frame_host); |
900 render_frame_host->navigation_handle()->ReadyToCommitNavigation( | 873 render_frame_host->navigation_handle()->ReadyToCommitNavigation( |
901 render_frame_host, scoped_refptr<net::HttpResponseHeaders>()); | 874 render_frame_host); |
902 render_frame_host->FailedNavigation(navigation_request->common_params(), | 875 render_frame_host->FailedNavigation(navigation_request->common_params(), |
903 navigation_request->request_params(), | 876 navigation_request->request_params(), |
904 has_stale_copy_in_cache, error_code); | 877 has_stale_copy_in_cache, error_code); |
905 } | 878 } |
906 | 879 |
907 // PlzNavigate | 880 // PlzNavigate |
908 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { | 881 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { |
909 CHECK(IsBrowserSideNavigationEnabled()); | 882 CHECK(IsBrowserSideNavigationEnabled()); |
910 frame_tree_node->ResetNavigationRequest(false); | 883 frame_tree_node->ResetNavigationRequest(false); |
911 if (frame_tree_node->IsMainFrame()) | 884 if (frame_tree_node->IsMainFrame()) |
(...skipping 15 matching lines...) Expand all Loading... |
927 const base::TimeTicks& renderer_before_unload_end_time) { | 900 const base::TimeTicks& renderer_before_unload_end_time) { |
928 // 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 |
929 // navigation and it happened later than the navigation request. | 902 // navigation and it happened later than the navigation request. |
930 if (navigation_data_ && | 903 if (navigation_data_ && |
931 renderer_before_unload_start_time > navigation_data_->start_time_) { | 904 renderer_before_unload_start_time > navigation_data_->start_time_) { |
932 navigation_data_->before_unload_delay_ = | 905 navigation_data_->before_unload_delay_ = |
933 renderer_before_unload_end_time - renderer_before_unload_start_time; | 906 renderer_before_unload_end_time - renderer_before_unload_start_time; |
934 } | 907 } |
935 } | 908 } |
936 | 909 |
937 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( | |
938 RenderFrameHostImpl* render_frame_host, | |
939 const GURL& url) { | |
940 int enabled_bindings = | |
941 render_frame_host->render_view_host()->GetEnabledBindings(); | |
942 bool is_allowed_in_web_ui_renderer = | |
943 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | |
944 controller_->GetBrowserContext(), url); | |
945 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | |
946 !is_allowed_in_web_ui_renderer) { | |
947 // Log the URL to help us diagnose any future failures of this CHECK. | |
948 GetContentClient()->SetActiveURL(url); | |
949 CHECK(0); | |
950 } | |
951 } | |
952 | |
953 // PlzNavigate | 910 // PlzNavigate |
954 void NavigatorImpl::RequestNavigation( | 911 void NavigatorImpl::RequestNavigation( |
955 FrameTreeNode* frame_tree_node, | 912 FrameTreeNode* frame_tree_node, |
956 const GURL& dest_url, | 913 const GURL& dest_url, |
957 const Referrer& dest_referrer, | 914 const Referrer& dest_referrer, |
958 const FrameNavigationEntry& frame_entry, | 915 const FrameNavigationEntry& frame_entry, |
959 const NavigationEntryImpl& entry, | 916 const NavigationEntryImpl& entry, |
960 NavigationController::ReloadType reload_type, | 917 NavigationController::ReloadType reload_type, |
961 LoFiState lofi_state, | 918 LoFiState lofi_state, |
962 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... |
1131 if (pending_entry != controller_->GetVisibleEntry() || | 1088 if (pending_entry != controller_->GetVisibleEntry() || |
1132 !should_preserve_entry) { | 1089 !should_preserve_entry) { |
1133 controller_->DiscardPendingEntry(true); | 1090 controller_->DiscardPendingEntry(true); |
1134 | 1091 |
1135 // Also force the UI to refresh. | 1092 // Also force the UI to refresh. |
1136 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); | 1093 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
1137 } | 1094 } |
1138 } | 1095 } |
1139 | 1096 |
1140 } // namespace content | 1097 } // namespace content |
OLD | NEW |