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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 | 71 |
72 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { | 72 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { |
73 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 73 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
74 switches::kSitePerProcess)) | 74 switches::kSitePerProcess)) |
75 return rfh->frame_tree_node()->render_manager(); | 75 return rfh->frame_tree_node()->render_manager(); |
76 | 76 |
77 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); | 77 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
78 } | 78 } |
79 | 79 |
80 HistoryNavigationParams MakeHistoryParams( | |
81 const NavigationEntryImpl& entry, | |
82 NavigationControllerImpl* controller) { | |
83 int pending_history_list_offset = controller->GetIndexOfEntry(&entry); | |
84 int current_history_list_offset = controller->GetLastCommittedEntryIndex(); | |
85 int current_history_list_length = controller->GetEntryCount(); | |
86 if (entry.should_clear_history_list()) { | |
87 // Set the history list related parameters to the same values a | |
88 // NavigationController would return before its first navigation. This will | |
89 // fully clear the RenderView's view of the session history. | |
90 pending_history_list_offset = -1; | |
91 current_history_list_offset = -1; | |
92 current_history_list_length = 0; | |
93 } | |
94 return HistoryNavigationParams( | |
95 entry.GetPageState(), entry.GetPageID(), pending_history_list_offset, | |
96 current_history_list_offset, current_history_list_length, | |
97 entry.should_clear_history_list()); | |
98 } | |
99 | |
100 void MakeNavigateParams(const NavigationEntryImpl& entry, | |
101 NavigationControllerImpl* controller, | |
102 NavigationController::ReloadType reload_type, | |
103 base::TimeTicks navigation_start, | |
104 FrameMsg_Navigate_Params* params) { | |
105 FrameMsg_UILoadMetricsReportType::Value report_type = | |
106 FrameMsg_UILoadMetricsReportType::NO_REPORT; | |
107 base::TimeTicks ui_timestamp = base::TimeTicks(); | |
108 #if defined(OS_ANDROID) | |
109 if (!entry.intent_received_timestamp().is_null()) | |
110 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; | |
111 ui_timestamp = entry.intent_received_timestamp(); | |
112 #endif | |
113 | |
114 params->common_params = CommonNavigationParams( | |
115 entry.GetURL(), entry.GetReferrer(), entry.GetTransitionType(), | |
116 GetNavigationType(controller->GetBrowserContext(), entry, reload_type), | |
117 !entry.IsViewSourceMode(), ui_timestamp, report_type, | |
118 entry.GetBaseURLForDataURL(), entry.GetHistoryURLForDataURL()); | |
119 params->commit_params = CommitNavigationParams( | |
120 entry.GetIsOverridingUserAgent(), navigation_start); | |
121 params->history_params = MakeHistoryParams(entry, controller); | |
122 | |
123 params->is_post = entry.GetHasPostData(); | |
124 params->extra_headers = entry.extra_headers(); | |
125 if (entry.GetBrowserInitiatedPostData()) { | |
126 params->browser_initiated_post_data.assign( | |
127 entry.GetBrowserInitiatedPostData()->front(), | |
128 entry.GetBrowserInitiatedPostData()->front() + | |
129 entry.GetBrowserInitiatedPostData()->size()); | |
130 } | |
131 | |
132 params->should_replace_current_entry = entry.should_replace_entry(); | |
133 // This is used by the old performance infrastructure to set up DocumentState | |
134 // associated with the RenderView. | |
135 // TODO(ppi): make it go away. | |
136 params->request_time = base::Time::Now(); | |
137 params->transferred_request_child_id = | |
138 entry.transferred_global_request_id().child_id; | |
139 params->transferred_request_request_id = | |
140 entry.transferred_global_request_id().request_id; | |
141 | |
142 // Set the redirect chain to the navigation's redirects, unless we are | |
143 // returning to a completed navigation (whose previous redirects don't apply). | |
144 if (ui::PageTransitionIsNewNavigation(params->common_params.transition)) { | |
145 params->redirects = entry.GetRedirectChain(); | |
146 } else { | |
147 params->redirects.clear(); | |
148 } | |
149 | |
150 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | |
151 params->frame_to_navigate = entry.GetFrameToNavigate(); | |
152 } | |
153 | |
154 } // namespace | 80 } // namespace |
155 | 81 |
156 struct NavigatorImpl::NavigationMetricsData { | 82 struct NavigatorImpl::NavigationMetricsData { |
157 NavigationMetricsData(base::TimeTicks start_time, | 83 NavigationMetricsData(base::TimeTicks start_time, |
158 GURL url, | 84 GURL url, |
159 NavigationEntryImpl::RestoreType restore_type) | 85 NavigationEntryImpl::RestoreType restore_type) |
160 : start_time_(start_time), url_(url) { | 86 : start_time_(start_time), url_(url) { |
161 is_restoring_from_last_session_ = | 87 is_restoring_from_last_session_ = |
162 (restore_type == | 88 (restore_type == |
163 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY || | 89 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY || |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 // Double check that here. | 291 // Double check that here. |
366 CheckWebUIRendererDoesNotDisplayNormalURL( | 292 CheckWebUIRendererDoesNotDisplayNormalURL( |
367 dest_render_frame_host, entry.GetURL()); | 293 dest_render_frame_host, entry.GetURL()); |
368 | 294 |
369 // Notify observers that we will navigate in this RenderFrame. | 295 // Notify observers that we will navigate in this RenderFrame. |
370 if (delegate_) { | 296 if (delegate_) { |
371 delegate_->AboutToNavigateRenderFrame(frame_tree_node->current_frame_host(), | 297 delegate_->AboutToNavigateRenderFrame(frame_tree_node->current_frame_host(), |
372 dest_render_frame_host); | 298 dest_render_frame_host); |
373 } | 299 } |
374 | 300 |
375 // Create the navigation parameters. | |
376 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once | |
377 // http://crbug.com/408684 is fixed. | |
378 FrameMsg_Navigate_Params navigate_params; | |
379 MakeNavigateParams( | |
380 entry, controller_, reload_type, navigation_start, &navigate_params); | |
381 | |
382 // Navigate in the desired RenderFrameHost. | 301 // Navigate in the desired RenderFrameHost. |
383 // We can skip this step in the rare case that this is a transfer navigation | 302 // We can skip this step in the rare case that this is a transfer navigation |
384 // which began in the chosen RenderFrameHost, since the request has already | 303 // which began in the chosen RenderFrameHost, since the request has already |
385 // been issued. In that case, simply resume the response. | 304 // been issued. In that case, simply resume the response. |
386 bool is_transfer_to_same = | 305 bool is_transfer_to_same = |
387 navigate_params.transferred_request_child_id != -1 && | 306 entry.transferred_global_request_id().child_id != -1 && |
388 navigate_params.transferred_request_child_id == | 307 entry.transferred_global_request_id().child_id == |
389 dest_render_frame_host->GetProcess()->GetID(); | 308 dest_render_frame_host->GetProcess()->GetID(); |
390 if (!is_transfer_to_same) { | 309 if (!is_transfer_to_same) { |
391 navigation_data_.reset(new NavigationMetricsData( | 310 navigation_data_.reset(new NavigationMetricsData( |
392 navigation_start, entry.GetURL(), entry.restore_type())); | 311 navigation_start, entry.GetURL(), entry.restore_type())); |
393 dest_render_frame_host->Navigate(navigate_params); | 312 // Create the navigation parameters. |
| 313 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once |
| 314 // http://crbug.com/408684 is fixed. |
| 315 FrameMsg_Navigate_Type::Value navigation_type = |
| 316 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
| 317 dest_render_frame_host->Navigate( |
| 318 entry.ConstructCommonNavigationParams(navigation_type), |
| 319 entry.ConstructStartNavigationParams(), |
| 320 entry.ConstructCommitNavigationParams(navigation_start), |
| 321 entry.ConstructHistoryNavigationParams(controller_)); |
394 } else { | 322 } else { |
395 // No need to navigate again. Just resume the deferred request. | 323 // No need to navigate again. Just resume the deferred request. |
396 dest_render_frame_host->GetProcess()->ResumeDeferredNavigation( | 324 dest_render_frame_host->GetProcess()->ResumeDeferredNavigation( |
397 GlobalRequestID(navigate_params.transferred_request_child_id, | 325 entry.transferred_global_request_id()); |
398 navigate_params.transferred_request_request_id)); | |
399 } | 326 } |
400 | 327 |
401 // Make sure no code called via RFH::Navigate clears the pending entry. | 328 // Make sure no code called via RFH::Navigate clears the pending entry. |
402 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 329 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
403 | 330 |
404 if (entry.GetPageID() == -1) { | 331 if (entry.GetPageID() == -1) { |
405 // HACK!! This code suppresses javascript: URLs from being added to | 332 // HACK!! This code suppresses javascript: URLs from being added to |
406 // session history, which is what we want to do for javascript: URLs that | 333 // session history, which is what we want to do for javascript: URLs that |
407 // do not generate content. What we really need is a message from the | 334 // do not generate content. What we really need is a message from the |
408 // renderer telling us that a new page was not created. The same message | 335 // renderer telling us that a new page was not created. The same message |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 const NavigationEntryImpl& entry, | 775 const NavigationEntryImpl& entry, |
849 NavigationController::ReloadType reload_type, | 776 NavigationController::ReloadType reload_type, |
850 base::TimeTicks navigation_start) { | 777 base::TimeTicks navigation_start) { |
851 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 778 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
852 switches::kEnableBrowserSideNavigation)); | 779 switches::kEnableBrowserSideNavigation)); |
853 DCHECK(frame_tree_node); | 780 DCHECK(frame_tree_node); |
854 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); | 781 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); |
855 FrameMsg_Navigate_Type::Value navigation_type = | 782 FrameMsg_Navigate_Type::Value navigation_type = |
856 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); | 783 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
857 scoped_ptr<NavigationRequest> navigation_request = | 784 scoped_ptr<NavigationRequest> navigation_request = |
858 NavigationRequest::CreateBrowserInitiated( | 785 NavigationRequest::CreateBrowserInitiated(frame_tree_node, entry, |
859 frame_tree_node, entry, navigation_type, navigation_start, | 786 navigation_type, |
860 MakeHistoryParams(entry, controller_)); | 787 navigation_start, controller_); |
861 // TODO(clamy): Check if navigations are blocked and if so store the | 788 // TODO(clamy): Check if navigations are blocked and if so store the |
862 // parameters. | 789 // parameters. |
863 | 790 |
864 // If there is an ongoing request, replace it. | 791 // If there is an ongoing request, replace it. |
865 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); | 792 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); |
866 | 793 |
867 // Have the current renderer execute its beforeUnload event if needed. If it | 794 // Have the current renderer execute its beforeUnload event if needed. If it |
868 // is not needed (eg. the renderer is not live), BeginNavigation should get | 795 // is not needed (eg. the renderer is not live), BeginNavigation should get |
869 // called. | 796 // called. |
870 NavigationRequest* request_to_send = | 797 NavigationRequest* request_to_send = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", | 866 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", |
940 time_to_commit); | 867 time_to_commit); |
941 UMA_HISTOGRAM_TIMES( | 868 UMA_HISTOGRAM_TIMES( |
942 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", | 869 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", |
943 time_to_network); | 870 time_to_network); |
944 } | 871 } |
945 navigation_data_.reset(); | 872 navigation_data_.reset(); |
946 } | 873 } |
947 | 874 |
948 } // namespace content | 875 } // namespace content |
OLD | NEW |