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" |
11 #include "content/browser/frame_host/frame_tree_node.h" | 11 #include "content/browser/frame_host/frame_tree_node.h" |
12 #include "content/browser/frame_host/navigation_before_commit_info.h" | 12 #include "content/browser/frame_host/navigation_before_commit_info.h" |
13 #include "content/browser/frame_host/navigation_controller_impl.h" | 13 #include "content/browser/frame_host/navigation_controller_impl.h" |
14 #include "content/browser/frame_host/navigation_entry_impl.h" | 14 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 15 #include "content/browser/frame_host/navigation_request.h" |
15 #include "content/browser/frame_host/navigator_delegate.h" | 16 #include "content/browser/frame_host/navigator_delegate.h" |
16 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
17 #include "content/browser/renderer_host/render_view_host_impl.h" | 18 #include "content/browser/renderer_host/render_view_host_impl.h" |
18 #include "content/browser/site_instance_impl.h" | 19 #include "content/browser/site_instance_impl.h" |
19 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 20 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
20 #include "content/browser/webui/web_ui_impl.h" | 21 #include "content/browser/webui/web_ui_impl.h" |
21 #include "content/common/frame_messages.h" | 22 #include "content/common/frame_messages.h" |
| 23 #include "content/common/navigation_params.h" |
22 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
23 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
25 #include "content/public/browser/global_request_id.h" | 27 #include "content/public/browser/global_request_id.h" |
26 #include "content/public/browser/invalidate_type.h" | 28 #include "content/public/browser/invalidate_type.h" |
27 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
28 #include "content/public/browser/navigation_details.h" | 30 #include "content/public/browser/navigation_details.h" |
29 #include "content/public/browser/page_navigator.h" | 31 #include "content/public/browser/page_navigator.h" |
30 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
31 #include "content/public/common/bindings_policy.h" | 33 #include "content/public/common/bindings_policy.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 67 } |
66 | 68 |
67 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { | 69 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { |
68 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 70 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
69 switches::kSitePerProcess)) | 71 switches::kSitePerProcess)) |
70 return rfh->frame_tree_node()->render_manager(); | 72 return rfh->frame_tree_node()->render_manager(); |
71 | 73 |
72 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); | 74 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
73 } | 75 } |
74 | 76 |
75 } // namespace | 77 void MakeNavigateParams(const NavigationEntryImpl& entry, |
| 78 NavigationControllerImpl* controller, |
| 79 NavigationController::ReloadType reload_type, |
| 80 base::TimeTicks navigation_start, |
| 81 FrameMsg_Navigate_Params* params) { |
| 82 params->common_params = CommonNavigationParams( |
| 83 entry.GetURL(), entry.GetReferrer(), entry.GetTransitionType(), |
| 84 GetNavigationType(controller->GetBrowserContext(), entry, reload_type), |
| 85 !entry.IsViewSourceMode()); |
| 86 params->request_params = RequestNavigationParams( |
| 87 entry.GetHasPostData(), |
| 88 entry.extra_headers(), |
| 89 entry.GetBrowserInitiatedPostData()); |
| 90 params->commit_params = CommitNavigationParams( |
| 91 entry.GetPageState(), entry.GetIsOverridingUserAgent(), navigation_start); |
| 92 if (!entry.GetBaseURLForDataURL().is_empty()) { |
| 93 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); |
| 94 params->history_url_for_data_url = entry.GetVirtualURL(); |
| 95 } |
| 96 params->should_replace_current_entry = entry.should_replace_entry(); |
| 97 // This is used by the old performance infrastructure to set up DocumentState |
| 98 // associated with the RenderView. |
| 99 // TODO(ppi): make it go away. |
| 100 params->request_time = base::Time::Now(); |
| 101 params->transferred_request_child_id = |
| 102 entry.transferred_global_request_id().child_id; |
| 103 params->transferred_request_request_id = |
| 104 entry.transferred_global_request_id().request_id; |
76 | 105 |
77 | |
78 NavigatorImpl::NavigatorImpl( | |
79 NavigationControllerImpl* navigation_controller, | |
80 NavigatorDelegate* delegate) | |
81 : controller_(navigation_controller), | |
82 delegate_(delegate) { | |
83 } | |
84 | |
85 NavigatorImpl::~NavigatorImpl() { | |
86 } | |
87 | |
88 // static. | |
89 void NavigatorImpl::MakeNavigateParams( | |
90 const NavigationEntryImpl& entry, | |
91 const NavigationControllerImpl& controller, | |
92 NavigationController::ReloadType reload_type, | |
93 base::TimeTicks navigation_start, | |
94 FrameMsg_Navigate_Params* params) { | |
95 params->page_id = entry.GetPageID(); | 106 params->page_id = entry.GetPageID(); |
96 params->should_clear_history_list = entry.should_clear_history_list(); | 107 params->should_clear_history_list = entry.should_clear_history_list(); |
97 params->should_replace_current_entry = entry.should_replace_entry(); | |
98 if (entry.should_clear_history_list()) { | 108 if (entry.should_clear_history_list()) { |
99 // Set the history list related parameters to the same values a | 109 // Set the history list related parameters to the same values a |
100 // NavigationController would return before its first navigation. This will | 110 // NavigationController would return before its first navigation. This will |
101 // fully clear the RenderView's view of the session history. | 111 // fully clear the RenderView's view of the session history. |
102 params->pending_history_list_offset = -1; | 112 params->pending_history_list_offset = -1; |
103 params->current_history_list_offset = -1; | 113 params->current_history_list_offset = -1; |
104 params->current_history_list_length = 0; | 114 params->current_history_list_length = 0; |
105 } else { | 115 } else { |
106 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); | 116 params->pending_history_list_offset = controller->GetIndexOfEntry(&entry); |
107 params->current_history_list_offset = | 117 params->current_history_list_offset = |
108 controller.GetLastCommittedEntryIndex(); | 118 controller->GetLastCommittedEntryIndex(); |
109 params->current_history_list_length = controller.GetEntryCount(); | 119 params->current_history_list_length = controller->GetEntryCount(); |
110 } | 120 } |
111 params->url = entry.GetURL(); | |
112 if (!entry.GetBaseURLForDataURL().is_empty()) { | |
113 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); | |
114 params->history_url_for_data_url = entry.GetVirtualURL(); | |
115 } | |
116 params->referrer = entry.GetReferrer(); | |
117 params->transition = entry.GetTransitionType(); | |
118 params->page_state = entry.GetPageState(); | |
119 params->navigation_type = | |
120 GetNavigationType(controller.GetBrowserContext(), entry, reload_type); | |
121 // This is used by the old performance infrastructure to set up DocumentState | |
122 // associated with the RenderView. | |
123 // TODO(ppi): make it go away. | |
124 params->request_time = base::Time::Now(); | |
125 params->extra_headers = entry.extra_headers(); | |
126 params->transferred_request_child_id = | |
127 entry.transferred_global_request_id().child_id; | |
128 params->transferred_request_request_id = | |
129 entry.transferred_global_request_id().request_id; | |
130 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent(); | |
131 // Avoid downloading when in view-source mode. | |
132 params->allow_download = !entry.IsViewSourceMode(); | |
133 params->is_post = entry.GetHasPostData(); | |
134 if (entry.GetBrowserInitiatedPostData()) { | |
135 params->browser_initiated_post_data.assign( | |
136 entry.GetBrowserInitiatedPostData()->front(), | |
137 entry.GetBrowserInitiatedPostData()->front() + | |
138 entry.GetBrowserInitiatedPostData()->size()); | |
139 } | |
140 | |
141 // Set the redirect chain to the navigation's redirects, unless we are | 121 // Set the redirect chain to the navigation's redirects, unless we are |
142 // returning to a completed navigation (whose previous redirects don't apply). | 122 // returning to a completed navigation (whose previous redirects don't apply). |
143 if (ui::PageTransitionIsNewNavigation(params->transition)) { | 123 if (ui::PageTransitionIsNewNavigation(params->common_params.transition)) { |
144 params->redirects = entry.GetRedirectChain(); | 124 params->redirects = entry.GetRedirectChain(); |
145 } else { | 125 } else { |
146 params->redirects.clear(); | 126 params->redirects.clear(); |
147 } | 127 } |
148 | 128 |
149 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | 129 params->can_load_local_resources = entry.GetCanLoadLocalResources(); |
150 params->frame_to_navigate = entry.GetFrameToNavigate(); | 130 params->frame_to_navigate = entry.GetFrameToNavigate(); |
151 params->browser_navigation_start = navigation_start; | |
152 } | 131 } |
153 | 132 |
| 133 } // namespace |
| 134 |
| 135 |
| 136 NavigatorImpl::NavigatorImpl( |
| 137 NavigationControllerImpl* navigation_controller, |
| 138 NavigatorDelegate* delegate) |
| 139 : controller_(navigation_controller), |
| 140 delegate_(delegate) { |
| 141 } |
| 142 |
| 143 NavigatorImpl::~NavigatorImpl() {} |
| 144 |
154 NavigationController* NavigatorImpl::GetController() { | 145 NavigationController* NavigatorImpl::GetController() { |
155 return controller_; | 146 return controller_; |
156 } | 147 } |
157 | 148 |
158 void NavigatorImpl::DidStartProvisionalLoad( | 149 void NavigatorImpl::DidStartProvisionalLoad( |
159 RenderFrameHostImpl* render_frame_host, | 150 RenderFrameHostImpl* render_frame_host, |
160 const GURL& url, | 151 const GURL& url, |
161 bool is_transition_navigation) { | 152 bool is_transition_navigation) { |
162 bool is_error_page = (url.spec() == kUnreachableWebDataURL); | 153 bool is_error_page = (url.spec() == kUnreachableWebDataURL); |
163 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); | 154 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 << " characters."; | 301 << " characters."; |
311 return false; | 302 return false; |
312 } | 303 } |
313 | 304 |
314 // This will be used to set the Navigation Timing API navigationStart | 305 // This will be used to set the Navigation Timing API navigationStart |
315 // parameter for browser navigations in new tabs (intents, tabs opened through | 306 // parameter for browser navigations in new tabs (intents, tabs opened through |
316 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to | 307 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to |
317 // capture the time needed for the RenderFrameHost initialization. | 308 // capture the time needed for the RenderFrameHost initialization. |
318 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 309 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
319 | 310 |
320 FrameMsg_Navigate_Params navigate_params; | |
321 RenderFrameHostManager* manager = | 311 RenderFrameHostManager* manager = |
322 render_frame_host->frame_tree_node()->render_manager(); | 312 render_frame_host->frame_tree_node()->render_manager(); |
323 | 313 |
324 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead | 314 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead |
325 // the RenderFrameHostManager handles the navigation requests for that frame | 315 // the RenderFrameHostManager handles the navigation requests for that frame |
326 // node. | 316 // node. |
327 if (CommandLine::ForCurrentProcess()->HasSwitch( | 317 if (CommandLine::ForCurrentProcess()->HasSwitch( |
328 switches::kEnableBrowserSideNavigation)) { | 318 switches::kEnableBrowserSideNavigation)) { |
329 navigation_start_time_and_url = MakeTuple(navigation_start, entry.GetURL()); | 319 navigation_start_time_and_url = MakeTuple(navigation_start, entry.GetURL()); |
330 // Create the navigation parameters. | 320 FrameMsg_Navigate_Type::Value navigation_type = |
331 MakeNavigateParams( | 321 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
332 entry, *controller_, reload_type, navigation_start, &navigate_params); | 322 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
333 return manager->RequestNavigation(entry, navigate_params); | 323 render_frame_host->frame_tree_node()->frame_tree_node_id(), |
| 324 CommonNavigationParams(entry.GetURL(), |
| 325 entry.GetReferrer(), |
| 326 entry.GetTransitionType(), |
| 327 navigation_type, |
| 328 !entry.IsViewSourceMode()), |
| 329 CommitNavigationParams(entry.GetPageState(), |
| 330 entry.GetIsOverridingUserAgent(), |
| 331 navigation_start))); |
| 332 RequestNavigationParams request_params(entry.GetHasPostData(), |
| 333 entry.extra_headers(), |
| 334 entry.GetBrowserInitiatedPostData()); |
| 335 return manager->RequestNavigation(navigation_request.Pass(), |
| 336 request_params); |
334 } | 337 } |
335 | 338 |
336 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 339 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
337 if (!dest_render_frame_host) | 340 if (!dest_render_frame_host) |
338 return false; // Unable to create the desired RenderFrameHost. | 341 return false; // Unable to create the desired RenderFrameHost. |
339 | 342 |
340 // Make sure no code called via RFHM::Navigate clears the pending entry. | 343 // Make sure no code called via RFHM::Navigate clears the pending entry. |
341 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 344 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
342 | 345 |
343 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 346 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
344 // Double check that here. | 347 // Double check that here. |
345 CheckWebUIRendererDoesNotDisplayNormalURL( | 348 CheckWebUIRendererDoesNotDisplayNormalURL( |
346 dest_render_frame_host, entry.GetURL()); | 349 dest_render_frame_host, entry.GetURL()); |
347 | 350 |
348 // Notify observers that we will navigate in this RenderFrame. | 351 // Notify observers that we will navigate in this RenderFrame. |
349 if (delegate_) | 352 if (delegate_) |
350 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); | 353 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); |
351 | 354 |
352 // Create the navigation parameters. | 355 // Create the navigation parameters. |
353 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once | 356 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once |
354 // http://crbug.com/408684 is fixed. | 357 // http://crbug.com/408684 is fixed. |
| 358 FrameMsg_Navigate_Params navigate_params; |
355 MakeNavigateParams( | 359 MakeNavigateParams( |
356 entry, *controller_, reload_type, navigation_start, &navigate_params); | 360 entry, controller_, reload_type, navigation_start, &navigate_params); |
357 | 361 |
358 // Navigate in the desired RenderFrameHost. | 362 // Navigate in the desired RenderFrameHost. |
359 // We can skip this step in the rare case that this is a transfer navigation | 363 // We can skip this step in the rare case that this is a transfer navigation |
360 // which began in the chosen RenderFrameHost, since the request has already | 364 // which began in the chosen RenderFrameHost, since the request has already |
361 // been issued. In that case, simply resume the response. | 365 // been issued. In that case, simply resume the response. |
362 bool is_transfer_to_same = | 366 bool is_transfer_to_same = |
363 navigate_params.transferred_request_child_id != -1 && | 367 navigate_params.transferred_request_child_id != -1 && |
364 navigate_params.transferred_request_child_id == | 368 navigate_params.transferred_request_child_id == |
365 dest_render_frame_host->GetProcess()->GetID(); | 369 dest_render_frame_host->GetProcess()->GetID(); |
366 if (!is_transfer_to_same) { | 370 if (!is_transfer_to_same) { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 // Navigations in Web UI pages count as browser-initiated navigations. | 651 // Navigations in Web UI pages count as browser-initiated navigations. |
648 params.is_renderer_initiated = false; | 652 params.is_renderer_initiated = false; |
649 } | 653 } |
650 | 654 |
651 if (delegate_) | 655 if (delegate_) |
652 delegate_->RequestOpenURL(render_frame_host, params); | 656 delegate_->RequestOpenURL(render_frame_host, params); |
653 } | 657 } |
654 | 658 |
655 void NavigatorImpl::CommitNavigation( | 659 void NavigatorImpl::CommitNavigation( |
656 RenderFrameHostImpl* render_frame_host, | 660 RenderFrameHostImpl* render_frame_host, |
657 const NavigationBeforeCommitInfo& info) { | 661 const GURL& stream_url, |
658 CheckWebUIRendererDoesNotDisplayNormalURL( | 662 const CommonNavigationParams& common_params, |
659 render_frame_host, info.navigation_url); | 663 const CommitNavigationParams& commit_params) { |
660 // TODO(clamy): the render_frame_host should now send a commit IPC to the | 664 CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, |
661 // renderer. | 665 common_params.url); |
| 666 render_frame_host->CommitNavigation(stream_url, common_params, commit_params); |
662 } | 667 } |
663 | 668 |
664 void NavigatorImpl::LogResourceRequestTime( | 669 void NavigatorImpl::LogResourceRequestTime( |
665 base::TimeTicks timestamp, const GURL& url) { | 670 base::TimeTicks timestamp, const GURL& url) { |
666 if (navigation_start_time_and_url.a.ToInternalValue() != 0 | 671 if (navigation_start_time_and_url.a.ToInternalValue() != 0 |
667 && navigation_start_time_and_url.b == url) { | 672 && navigation_start_time_and_url.b == url) { |
668 base::TimeDelta time_to_network = | 673 base::TimeDelta time_to_network = |
669 timestamp - navigation_start_time_and_url.a; | 674 timestamp - navigation_start_time_and_url.a; |
670 UMA_HISTOGRAM_TIMES("Navigation.TimeToURLJobStart", time_to_network); | 675 UMA_HISTOGRAM_TIMES("Navigation.TimeToURLJobStart", time_to_network); |
671 } | 676 } |
672 } | 677 } |
673 | 678 |
674 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( | 679 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
675 RenderFrameHostImpl* render_frame_host, | 680 RenderFrameHostImpl* render_frame_host, |
676 const GURL& url) { | 681 const GURL& url) { |
677 int enabled_bindings = | 682 int enabled_bindings = |
678 render_frame_host->render_view_host()->GetEnabledBindings(); | 683 render_frame_host->render_view_host()->GetEnabledBindings(); |
679 bool is_allowed_in_web_ui_renderer = | 684 bool is_allowed_in_web_ui_renderer = |
680 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 685 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
681 controller_->GetBrowserContext(), url); | 686 controller_->GetBrowserContext(), url); |
682 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | 687 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
683 !is_allowed_in_web_ui_renderer) { | 688 !is_allowed_in_web_ui_renderer) { |
684 // Log the URL to help us diagnose any future failures of this CHECK. | 689 // Log the URL to help us diagnose any future failures of this CHECK. |
685 GetContentClient()->SetActiveURL(url); | 690 GetContentClient()->SetActiveURL(url); |
686 CHECK(0); | 691 CHECK(0); |
687 } | 692 } |
688 } | 693 } |
689 | 694 |
690 } // namespace content | 695 } // namespace content |
OLD | NEW |