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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 << " characters."; | 329 << " characters."; |
336 return false; | 330 return false; |
337 } | 331 } |
338 | 332 |
339 // This will be used to set the Navigation Timing API navigationStart | 333 // This will be used to set the Navigation Timing API navigationStart |
340 // parameter for browser navigations in new tabs (intents, tabs opened through | 334 // parameter for browser navigations in new tabs (intents, tabs opened through |
341 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to | 335 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to |
342 // capture the time needed for the RenderFrameHost initialization. | 336 // capture the time needed for the RenderFrameHost initialization. |
343 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 337 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
344 | 338 |
345 FrameMsg_Navigate_Params navigate_params; | |
346 RenderFrameHostManager* manager = | 339 RenderFrameHostManager* manager = |
347 render_frame_host->frame_tree_node()->render_manager(); | 340 render_frame_host->frame_tree_node()->render_manager(); |
348 | 341 |
349 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead | 342 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead |
350 // the RenderFrameHostManager handles the navigation requests for that frame | 343 // the RenderFrameHostManager handles the navigation requests for that frame |
351 // node. | 344 // node. |
352 if (CommandLine::ForCurrentProcess()->HasSwitch( | 345 if (CommandLine::ForCurrentProcess()->HasSwitch( |
353 switches::kEnableBrowserSideNavigation)) { | 346 switches::kEnableBrowserSideNavigation)) { |
354 // Create the navigation parameters. | 347 FrameMsg_Navigate_Type::Value navigation_type = |
355 MakeNavigateParams( | 348 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
356 entry, *controller_, reload_type, navigation_start, &navigate_params); | 349 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
357 return manager->RequestNavigation(entry, navigate_params); | 350 render_frame_host->frame_tree_node()->frame_tree_node_id(), |
| 351 CoreNavigationParams(entry.GetURL(), entry.GetReferrer(), |
| 352 entry.GetTransitionType(), navigation_type, |
| 353 !entry.IsViewSourceMode()), |
| 354 CommitNavigationParams(entry.GetPageState(), |
| 355 entry.GetIsOverridingUserAgent(), |
| 356 navigation_start))); |
| 357 RequestNavigationParams request_params(entry.GetHasPostData(), |
| 358 entry.extra_headers(), |
| 359 entry.GetBrowserInitiatedPostData()); |
| 360 return manager->RequestNavigation(navigation_request.Pass(), |
| 361 request_params); |
358 } | 362 } |
359 | 363 |
360 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 364 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
361 if (!dest_render_frame_host) | 365 if (!dest_render_frame_host) |
362 return false; // Unable to create the desired RenderFrameHost. | 366 return false; // Unable to create the desired RenderFrameHost. |
363 | 367 |
364 // Make sure no code called via RFHM::Navigate clears the pending entry. | 368 // Make sure no code called via RFHM::Navigate clears the pending entry. |
365 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 369 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
366 | 370 |
367 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 371 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
368 // Double check that here. | 372 // Double check that here. |
369 CheckWebUIRendererDoesNotDisplayNormalURL( | 373 CheckWebUIRendererDoesNotDisplayNormalURL( |
370 dest_render_frame_host, entry.GetURL()); | 374 dest_render_frame_host, entry.GetURL()); |
371 | 375 |
372 // Notify observers that we will navigate in this RenderFrame. | 376 // Notify observers that we will navigate in this RenderFrame. |
373 if (delegate_) | 377 if (delegate_) |
374 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); | 378 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); |
375 | 379 |
376 // Create the navigation parameters. | 380 // Create the navigation parameters. |
377 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once | 381 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once |
378 // http://crbug.com/408684 is fixed. | 382 // http://crbug.com/408684 is fixed. |
| 383 FrameMsg_Navigate_Params navigate_params; |
379 MakeNavigateParams( | 384 MakeNavigateParams( |
380 entry, *controller_, reload_type, navigation_start, &navigate_params); | 385 entry, controller_, reload_type, navigation_start, &navigate_params); |
381 | 386 |
382 // Navigate in the desired RenderFrameHost. | 387 // Navigate in the desired RenderFrameHost. |
383 // We can skip this step in the rare case that this is a transfer navigation | 388 // 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 | 389 // which began in the chosen RenderFrameHost, since the request has already |
385 // been issued. In that case, simply resume the response. | 390 // been issued. In that case, simply resume the response. |
386 bool is_transfer_to_same = | 391 bool is_transfer_to_same = |
387 navigate_params.transferred_request_child_id != -1 && | 392 navigate_params.transferred_request_child_id != -1 && |
388 navigate_params.transferred_request_child_id == | 393 navigate_params.transferred_request_child_id == |
389 dest_render_frame_host->GetProcess()->GetID(); | 394 dest_render_frame_host->GetProcess()->GetID(); |
390 if (!is_transfer_to_same) { | 395 if (!is_transfer_to_same) { |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 // Navigations in Web UI pages count as browser-initiated navigations. | 663 // Navigations in Web UI pages count as browser-initiated navigations. |
659 params.is_renderer_initiated = false; | 664 params.is_renderer_initiated = false; |
660 } | 665 } |
661 | 666 |
662 if (delegate_) | 667 if (delegate_) |
663 delegate_->RequestOpenURL(render_frame_host, params); | 668 delegate_->RequestOpenURL(render_frame_host, params); |
664 } | 669 } |
665 | 670 |
666 void NavigatorImpl::CommitNavigation( | 671 void NavigatorImpl::CommitNavigation( |
667 RenderFrameHostImpl* render_frame_host, | 672 RenderFrameHostImpl* render_frame_host, |
668 const NavigationBeforeCommitInfo& info) { | 673 const GURL& stream_url, |
669 CheckWebUIRendererDoesNotDisplayNormalURL( | 674 const CoreNavigationParams& core_params, |
670 render_frame_host, info.navigation_url); | 675 const CommitNavigationParams& commit_params) { |
671 // TODO(clamy): the render_frame_host should now send a commit IPC to the | 676 CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, core_params.url); |
672 // renderer. | 677 render_frame_host->CommitNavigation(stream_url, core_params, commit_params); |
673 } | 678 } |
674 | 679 |
675 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( | 680 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
676 RenderFrameHostImpl* render_frame_host, | 681 RenderFrameHostImpl* render_frame_host, |
677 const GURL& url) { | 682 const GURL& url) { |
678 int enabled_bindings = | 683 int enabled_bindings = |
679 render_frame_host->render_view_host()->GetEnabledBindings(); | 684 render_frame_host->render_view_host()->GetEnabledBindings(); |
680 bool is_allowed_in_web_ui_renderer = | 685 bool is_allowed_in_web_ui_renderer = |
681 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 686 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
682 controller_->GetBrowserContext(), url); | 687 controller_->GetBrowserContext(), url); |
683 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | 688 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
684 !is_allowed_in_web_ui_renderer) { | 689 !is_allowed_in_web_ui_renderer) { |
685 // Log the URL to help us diagnose any future failures of this CHECK. | 690 // Log the URL to help us diagnose any future failures of this CHECK. |
686 GetContentClient()->SetActiveURL(url); | 691 GetContentClient()->SetActiveURL(url); |
687 CHECK(0); | 692 CHECK(0); |
688 } | 693 } |
689 } | 694 } |
690 | 695 |
691 } // namespace content | 696 } // namespace content |
OLD | NEW |