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