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" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 } | 64 } |
65 | 65 |
66 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { | 66 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { |
67 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 67 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
68 switches::kSitePerProcess)) | 68 switches::kSitePerProcess)) |
69 return rfh->frame_tree_node()->render_manager(); | 69 return rfh->frame_tree_node()->render_manager(); |
70 | 70 |
71 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); | 71 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
72 } | 72 } |
73 | 73 |
74 } // namespace | 74 void InitializeCoreNavigationParams( |
75 | 75 const NavigationEntryImpl& entry, |
76 | 76 NavigationControllerImpl* controller, |
77 NavigatorImpl::NavigatorImpl( | 77 NavigationController::ReloadType reload_type, |
78 NavigationControllerImpl* navigation_controller, | 78 CoreNavigationParams* params) { |
79 NavigatorDelegate* delegate) | 79 params->url = entry.GetURL(); |
80 : controller_(navigation_controller), | 80 params->referrer = entry.GetReferrer(); |
81 delegate_(delegate) { | 81 params->transition = entry.GetTransitionType(); |
82 params->navigation_type = | |
83 GetNavigationType(controller->GetBrowserContext(), entry, reload_type); | |
84 params->allow_download = !entry.IsViewSourceMode(); | |
82 } | 85 } |
83 | 86 |
84 // static. | 87 void InitializeRequestNavigationParams(const NavigationEntryImpl& entry, |
85 void NavigatorImpl::MakeNavigateParams( | 88 RequestNavigationParams* params) { |
89 params->is_post = entry.GetHasPostData(); | |
90 // Avoid downloading when in view-source mode. | |
Charlie Reis
2014/09/19 23:12:31
This comment sounds like it belongs above line 84.
clamy
2014/09/23 21:13:25
Moved to the description of the parameter in CoreN
| |
91 params->extra_headers = entry.extra_headers(); | |
92 if (entry.GetBrowserInitiatedPostData()) { | |
93 params->browser_initiated_post_data.assign( | |
94 entry.GetBrowserInitiatedPostData()->front(), | |
95 entry.GetBrowserInitiatedPostData()->front() + | |
96 entry.GetBrowserInitiatedPostData()->size()); | |
97 } | |
98 } | |
99 | |
100 void InitializeCommitNavigationParams( | |
86 const NavigationEntryImpl& entry, | 101 const NavigationEntryImpl& entry, |
87 const NavigationControllerImpl& controller, | 102 NavigationControllerImpl* controller, |
88 NavigationController::ReloadType reload_type, | |
89 base::TimeTicks navigation_start, | 103 base::TimeTicks navigation_start, |
90 FrameMsg_Navigate_Params* params) { | 104 CommitNavigationParams* params) { |
91 params->page_id = entry.GetPageID(); | 105 params->page_id = entry.GetPageID(); |
92 params->should_clear_history_list = entry.should_clear_history_list(); | 106 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()) { | 107 if (entry.should_clear_history_list()) { |
95 // Set the history list related parameters to the same values a | 108 // Set the history list related parameters to the same values a |
96 // NavigationController would return before its first navigation. This will | 109 // NavigationController would return before its first navigation. This will |
97 // fully clear the RenderView's view of the session history. | 110 // fully clear the RenderView's view of the session history. |
98 params->pending_history_list_offset = -1; | 111 params->pending_history_list_offset = -1; |
99 params->current_history_list_offset = -1; | 112 params->current_history_list_offset = -1; |
100 params->current_history_list_length = 0; | 113 params->current_history_list_length = 0; |
101 } else { | 114 } else { |
102 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); | 115 params->pending_history_list_offset = controller->GetIndexOfEntry(&entry); |
103 params->current_history_list_offset = | 116 params->current_history_list_offset = |
104 controller.GetLastCommittedEntryIndex(); | 117 controller->GetLastCommittedEntryIndex(); |
105 params->current_history_list_length = controller.GetEntryCount(); | 118 params->current_history_list_length = controller->GetEntryCount(); |
106 } | 119 } |
107 params->url = entry.GetURL(); | 120 params->page_state = entry.GetPageState(); |
121 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent(); | |
122 params->browser_navigation_start = navigation_start; | |
123 } | |
124 | |
125 void MakeNavigateParams(const NavigationEntryImpl& entry, | |
126 NavigationControllerImpl* controller, | |
127 NavigationController::ReloadType reload_type, | |
128 base::TimeTicks navigation_start, | |
129 FrameMsg_Navigate_Params* params) { | |
130 InitializeCoreNavigationParams( | |
131 entry, controller, reload_type, ¶ms->core_params); | |
132 InitializeRequestNavigationParams(entry, ¶ms->request_params); | |
133 InitializeCommitNavigationParams( | |
134 entry, controller, navigation_start, ¶ms->commit_params); | |
108 if (!entry.GetBaseURLForDataURL().is_empty()) { | 135 if (!entry.GetBaseURLForDataURL().is_empty()) { |
109 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); | 136 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); |
110 params->history_url_for_data_url = entry.GetVirtualURL(); | 137 params->history_url_for_data_url = entry.GetVirtualURL(); |
111 } | 138 } |
112 params->referrer = entry.GetReferrer(); | 139 params->should_replace_current_entry = entry.should_replace_entry(); |
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 | 140 // This is used by the old performance infrastructure to set up DocumentState |
118 // associated with the RenderView. | 141 // associated with the RenderView. |
119 // TODO(ppi): make it go away. | 142 // TODO(ppi): make it go away. |
120 params->request_time = base::Time::Now(); | 143 params->request_time = base::Time::Now(); |
121 params->extra_headers = entry.extra_headers(); | |
122 params->transferred_request_child_id = | 144 params->transferred_request_child_id = |
123 entry.transferred_global_request_id().child_id; | 145 entry.transferred_global_request_id().child_id; |
124 params->transferred_request_request_id = | 146 params->transferred_request_request_id = |
125 entry.transferred_global_request_id().request_id; | 147 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 | 148 |
137 // Set the redirect chain to the navigation's redirects, unless we are | 149 // Set the redirect chain to the navigation's redirects, unless we are |
138 // returning to a completed navigation (whose previous redirects don't apply). | 150 // returning to a completed navigation (whose previous redirects don't apply). |
139 if (PageTransitionIsNewNavigation(params->transition)) { | 151 if (PageTransitionIsNewNavigation(params->core_params.transition)) { |
140 params->redirects = entry.GetRedirectChain(); | 152 params->redirects = entry.GetRedirectChain(); |
141 } else { | 153 } else { |
142 params->redirects.clear(); | 154 params->redirects.clear(); |
143 } | 155 } |
144 | 156 |
145 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | 157 params->can_load_local_resources = entry.GetCanLoadLocalResources(); |
146 params->frame_to_navigate = entry.GetFrameToNavigate(); | 158 params->frame_to_navigate = entry.GetFrameToNavigate(); |
147 params->browser_navigation_start = navigation_start; | 159 } |
160 | |
161 } // namespace | |
162 | |
163 | |
164 NavigatorImpl::NavigatorImpl( | |
165 NavigationControllerImpl* navigation_controller, | |
166 NavigatorDelegate* delegate) | |
167 : controller_(navigation_controller), | |
168 delegate_(delegate) { | |
148 } | 169 } |
149 | 170 |
150 NavigationController* NavigatorImpl::GetController() { | 171 NavigationController* NavigatorImpl::GetController() { |
151 return controller_; | 172 return controller_; |
152 } | 173 } |
153 | 174 |
154 void NavigatorImpl::DidStartProvisionalLoad( | 175 void NavigatorImpl::DidStartProvisionalLoad( |
155 RenderFrameHostImpl* render_frame_host, | 176 RenderFrameHostImpl* render_frame_host, |
156 const GURL& url, | 177 const GURL& url, |
157 bool is_transition_navigation) { | 178 bool is_transition_navigation) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 << " characters."; | 356 << " characters."; |
336 return false; | 357 return false; |
337 } | 358 } |
338 | 359 |
339 // This will be used to set the Navigation Timing API navigationStart | 360 // This will be used to set the Navigation Timing API navigationStart |
340 // parameter for browser navigations in new tabs (intents, tabs opened through | 361 // 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 | 362 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to |
342 // capture the time needed for the RenderFrameHost initialization. | 363 // capture the time needed for the RenderFrameHost initialization. |
343 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 364 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
344 | 365 |
345 FrameMsg_Navigate_Params navigate_params; | |
346 RenderFrameHostManager* manager = | 366 RenderFrameHostManager* manager = |
347 render_frame_host->frame_tree_node()->render_manager(); | 367 render_frame_host->frame_tree_node()->render_manager(); |
348 | 368 |
349 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead | 369 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead |
350 // the RenderFrameHostManager handles the navigation requests for that frame | 370 // the RenderFrameHostManager handles the navigation requests for that frame |
351 // node. | 371 // node. |
352 if (CommandLine::ForCurrentProcess()->HasSwitch( | 372 if (CommandLine::ForCurrentProcess()->HasSwitch( |
353 switches::kEnableBrowserSideNavigation)) { | 373 switches::kEnableBrowserSideNavigation)) { |
354 // Create the navigation parameters. | 374 scoped_ptr<CoreNavigationParams> core_params(new CoreNavigationParams()); |
355 MakeNavigateParams( | 375 scoped_ptr<CommitNavigationParams> commit_params( |
356 entry, *controller_, reload_type, navigation_start, &navigate_params); | 376 new CommitNavigationParams()); |
357 return manager->RequestNavigation(entry, navigate_params); | 377 RequestNavigationParams request_params; |
Charlie Reis
2014/09/19 23:12:31
Why are the first two scoped_ptrs and this one isn
clamy
2014/09/23 21:13:25
Following changes in ownership of the *Params, the
| |
378 InitializeCoreNavigationParams( | |
379 entry, controller_, reload_type, core_params.get()); | |
380 InitializeCommitNavigationParams( | |
381 entry, controller_, navigation_start, commit_params.get()); | |
382 InitializeRequestNavigationParams(entry, &request_params); | |
383 return manager->RequestNavigation( | |
384 core_params.Pass(), request_params, commit_params.Pass()); | |
358 } | 385 } |
359 | 386 |
360 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 387 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
361 if (!dest_render_frame_host) | 388 if (!dest_render_frame_host) |
362 return false; // Unable to create the desired RenderFrameHost. | 389 return false; // Unable to create the desired RenderFrameHost. |
363 | 390 |
364 // Make sure no code called via RFHM::Navigate clears the pending entry. | 391 // Make sure no code called via RFHM::Navigate clears the pending entry. |
365 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 392 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
366 | 393 |
367 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 394 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
368 // Double check that here. | 395 // Double check that here. |
369 CheckWebUIRendererDoesNotDisplayNormalURL( | 396 CheckWebUIRendererDoesNotDisplayNormalURL( |
370 dest_render_frame_host, entry.GetURL()); | 397 dest_render_frame_host, entry.GetURL()); |
371 | 398 |
372 // Notify observers that we will navigate in this RenderFrame. | 399 // Notify observers that we will navigate in this RenderFrame. |
373 if (delegate_) | 400 if (delegate_) |
374 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); | 401 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); |
375 | 402 |
376 // Create the navigation parameters. | 403 // Create the navigation parameters. |
377 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once | 404 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once |
378 // http://crbug.com/408684 is fixed. | 405 // http://crbug.com/408684 is fixed. |
406 FrameMsg_Navigate_Params navigate_params; | |
379 MakeNavigateParams( | 407 MakeNavigateParams( |
380 entry, *controller_, reload_type, navigation_start, &navigate_params); | 408 entry, controller_, reload_type, navigation_start, &navigate_params); |
381 | 409 |
382 // Navigate in the desired RenderFrameHost. | 410 // Navigate in the desired RenderFrameHost. |
383 // We can skip this step in the rare case that this is a transfer navigation | 411 // 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 | 412 // which began in the chosen RenderFrameHost, since the request has already |
385 // been issued. In that case, simply resume the response. | 413 // been issued. In that case, simply resume the response. |
386 bool is_transfer_to_same = | 414 bool is_transfer_to_same = |
387 navigate_params.transferred_request_child_id != -1 && | 415 navigate_params.transferred_request_child_id != -1 && |
388 navigate_params.transferred_request_child_id == | 416 navigate_params.transferred_request_child_id == |
389 dest_render_frame_host->GetProcess()->GetID(); | 417 dest_render_frame_host->GetProcess()->GetID(); |
390 if (!is_transfer_to_same) { | 418 if (!is_transfer_to_same) { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 // Navigations in Web UI pages count as browser-initiated navigations. | 680 // Navigations in Web UI pages count as browser-initiated navigations. |
653 params.is_renderer_initiated = false; | 681 params.is_renderer_initiated = false; |
654 } | 682 } |
655 | 683 |
656 if (delegate_) | 684 if (delegate_) |
657 delegate_->RequestOpenURL(render_frame_host, params); | 685 delegate_->RequestOpenURL(render_frame_host, params); |
658 } | 686 } |
659 | 687 |
660 void NavigatorImpl::CommitNavigation( | 688 void NavigatorImpl::CommitNavigation( |
661 RenderFrameHostImpl* render_frame_host, | 689 RenderFrameHostImpl* render_frame_host, |
662 const NavigationBeforeCommitInfo& info) { | 690 const GURL& stream_url, |
663 CheckWebUIRendererDoesNotDisplayNormalURL( | 691 const CoreNavigationParams& core_params, |
664 render_frame_host, info.navigation_url); | 692 const CommitNavigationParams& commit_params) { |
665 // TODO(clamy): the render_frame_host should now send a commit IPC to the | 693 CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, core_params.url); |
666 // renderer. | 694 render_frame_host->CommitNavigation(stream_url, core_params, commit_params); |
695 } | |
696 | |
697 void NavigatorImpl::MakeNavigationParamsForTest( | |
698 const NavigationEntryImpl& entry, | |
699 NavigationController::ReloadType reload_type, | |
700 CoreNavigationParams* core_params, | |
701 RequestNavigationParams* request_params, | |
702 CommitNavigationParams* commit_params) { | |
703 InitializeCoreNavigationParams(entry, controller_, reload_type, core_params); | |
704 InitializeRequestNavigationParams(entry, request_params); | |
705 InitializeCommitNavigationParams( | |
706 entry, controller_, base::TimeTicks::Now(), commit_params); | |
667 } | 707 } |
668 | 708 |
669 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( | 709 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
670 RenderFrameHostImpl* render_frame_host, | 710 RenderFrameHostImpl* render_frame_host, |
671 const GURL& url) { | 711 const GURL& url) { |
672 int enabled_bindings = | 712 int enabled_bindings = |
673 render_frame_host->render_view_host()->GetEnabledBindings(); | 713 render_frame_host->render_view_host()->GetEnabledBindings(); |
674 bool is_allowed_in_web_ui_renderer = | 714 bool is_allowed_in_web_ui_renderer = |
675 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 715 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
676 controller_->GetBrowserContext(), url); | 716 controller_->GetBrowserContext(), url); |
677 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | 717 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
678 !is_allowed_in_web_ui_renderer) { | 718 !is_allowed_in_web_ui_renderer) { |
679 // Log the URL to help us diagnose any future failures of this CHECK. | 719 // Log the URL to help us diagnose any future failures of this CHECK. |
680 GetContentClient()->SetActiveURL(url); | 720 GetContentClient()->SetActiveURL(url); |
681 CHECK(0); | 721 CHECK(0); |
682 } | 722 } |
683 } | 723 } |
684 | 724 |
685 } // namespace content | 725 } // namespace content |
OLD | NEW |