| 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_controller_impl.h" | 12 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 12 #include "content/browser/frame_host/navigation_entry_impl.h" | 13 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 13 #include "content/browser/frame_host/navigator_delegate.h" | 14 #include "content/browser/frame_host/navigator_delegate.h" |
| 14 #include "content/browser/frame_host/render_frame_host_impl.h" | 15 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 15 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 16 #include "content/browser/site_instance_impl.h" | 17 #include "content/browser/site_instance_impl.h" |
| 17 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 18 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 18 #include "content/browser/webui/web_ui_impl.h" | 19 #include "content/browser/webui/web_ui_impl.h" |
| 19 #include "content/common/frame_messages.h" | 20 #include "content/common/frame_messages.h" |
| 20 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 if (entry.restore_type() == | 56 if (entry.restore_type() == |
| 56 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) { | 57 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) { |
| 57 if (entry.GetHasPostData()) | 58 if (entry.GetHasPostData()) |
| 58 return FrameMsg_Navigate_Type::RESTORE_WITH_POST; | 59 return FrameMsg_Navigate_Type::RESTORE_WITH_POST; |
| 59 return FrameMsg_Navigate_Type::RESTORE; | 60 return FrameMsg_Navigate_Type::RESTORE; |
| 60 } | 61 } |
| 61 | 62 |
| 62 return FrameMsg_Navigate_Type::NORMAL; | 63 return FrameMsg_Navigate_Type::NORMAL; |
| 63 } | 64 } |
| 64 | 65 |
| 65 void MakeNavigateParams(const NavigationEntryImpl& entry, | 66 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { |
| 66 const NavigationControllerImpl& controller, | 67 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 67 NavigationController::ReloadType reload_type, | 68 switches::kSitePerProcess)) |
| 68 base::TimeTicks navigation_start, | 69 return rfh->frame_tree_node()->render_manager(); |
| 69 FrameMsg_Navigate_Params* params) { | 70 |
| 71 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
| 72 } |
| 73 |
| 74 } // namespace |
| 75 |
| 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) { |
| 70 params->page_id = entry.GetPageID(); | 91 params->page_id = entry.GetPageID(); |
| 71 params->should_clear_history_list = entry.should_clear_history_list(); | 92 params->should_clear_history_list = entry.should_clear_history_list(); |
| 72 params->should_replace_current_entry = entry.should_replace_entry(); | 93 params->should_replace_current_entry = entry.should_replace_entry(); |
| 73 if (entry.should_clear_history_list()) { | 94 if (entry.should_clear_history_list()) { |
| 74 // Set the history list related parameters to the same values a | 95 // Set the history list related parameters to the same values a |
| 75 // NavigationController would return before its first navigation. This will | 96 // NavigationController would return before its first navigation. This will |
| 76 // fully clear the RenderView's view of the session history. | 97 // fully clear the RenderView's view of the session history. |
| 77 params->pending_history_list_offset = -1; | 98 params->pending_history_list_offset = -1; |
| 78 params->current_history_list_offset = -1; | 99 params->current_history_list_offset = -1; |
| 79 params->current_history_list_length = 0; | 100 params->current_history_list_length = 0; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 params->redirects = entry.GetRedirectChain(); | 140 params->redirects = entry.GetRedirectChain(); |
| 120 } else { | 141 } else { |
| 121 params->redirects.clear(); | 142 params->redirects.clear(); |
| 122 } | 143 } |
| 123 | 144 |
| 124 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | 145 params->can_load_local_resources = entry.GetCanLoadLocalResources(); |
| 125 params->frame_to_navigate = entry.GetFrameToNavigate(); | 146 params->frame_to_navigate = entry.GetFrameToNavigate(); |
| 126 params->browser_navigation_start = navigation_start; | 147 params->browser_navigation_start = navigation_start; |
| 127 } | 148 } |
| 128 | 149 |
| 129 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { | |
| 130 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 131 switches::kSitePerProcess)) | |
| 132 return rfh->frame_tree_node()->render_manager(); | |
| 133 | |
| 134 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); | |
| 135 } | |
| 136 | |
| 137 } // namespace | |
| 138 | |
| 139 | |
| 140 NavigatorImpl::NavigatorImpl( | |
| 141 NavigationControllerImpl* navigation_controller, | |
| 142 NavigatorDelegate* delegate) | |
| 143 : controller_(navigation_controller), | |
| 144 delegate_(delegate) { | |
| 145 } | |
| 146 | |
| 147 NavigationController* NavigatorImpl::GetController() { | 150 NavigationController* NavigatorImpl::GetController() { |
| 148 return controller_; | 151 return controller_; |
| 149 } | 152 } |
| 150 | 153 |
| 151 void NavigatorImpl::DidStartProvisionalLoad( | 154 void NavigatorImpl::DidStartProvisionalLoad( |
| 152 RenderFrameHostImpl* render_frame_host, | 155 RenderFrameHostImpl* render_frame_host, |
| 153 const GURL& url, | 156 const GURL& url, |
| 154 bool is_transition_navigation) { | 157 bool is_transition_navigation) { |
| 155 bool is_error_page = (url.spec() == kUnreachableWebDataURL); | 158 bool is_error_page = (url.spec() == kUnreachableWebDataURL); |
| 156 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); | 159 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 << " characters."; | 335 << " characters."; |
| 333 return false; | 336 return false; |
| 334 } | 337 } |
| 335 | 338 |
| 336 // This will be used to set the Navigation Timing API navigationStart | 339 // This will be used to set the Navigation Timing API navigationStart |
| 337 // parameter for browser navigations in new tabs (intents, tabs opened through | 340 // parameter for browser navigations in new tabs (intents, tabs opened through |
| 338 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to | 341 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to |
| 339 // capture the time needed for the RenderFrameHost initialization. | 342 // capture the time needed for the RenderFrameHost initialization. |
| 340 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 343 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
| 341 | 344 |
| 345 // WebContents uses this to fill LoadNotificationDetails when the load |
| 346 // completes, so that PerformanceMonitor that listens to the notification can |
| 347 // record the load time. PerformanceMonitor is no longer maintained. |
| 348 // TODO(ppi): make this go away. |
| 349 current_load_start_ = base::TimeTicks::Now(); |
| 350 |
| 351 // Create the navigation parameters. |
| 352 FrameMsg_Navigate_Params navigate_params; |
| 353 MakeNavigateParams( |
| 354 entry, *controller_, reload_type, navigation_start, &navigate_params); |
| 355 |
| 342 RenderFrameHostManager* manager = | 356 RenderFrameHostManager* manager = |
| 343 render_frame_host->frame_tree_node()->render_manager(); | 357 render_frame_host->frame_tree_node()->render_manager(); |
| 358 |
| 359 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead |
| 360 // the RenderFrameHostManager handles the navigation requests for that frame |
| 361 // node. |
| 362 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 363 switches::kEnableBrowserSideNavigation)) { |
| 364 return manager->RequestNavigation(entry, navigate_params); |
| 365 } |
| 366 |
| 344 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 367 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
| 345 if (!dest_render_frame_host) | 368 if (!dest_render_frame_host) |
| 346 return false; // Unable to create the desired RenderFrameHost. | 369 return false; // Unable to create the desired RenderFrameHost. |
| 347 | 370 |
| 348 // Make sure no code called via RFHM::Navigate clears the pending entry. | 371 // Make sure no code called via RFHM::Navigate clears the pending entry. |
| 349 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 372 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
| 350 | 373 |
| 351 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 374 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
| 352 // Double check that here. | 375 // Double check that here. |
| 353 int enabled_bindings = | 376 CheckWebUIRendererDoesNotDisplayNormalURL( |
| 354 dest_render_frame_host->render_view_host()->GetEnabledBindings(); | 377 dest_render_frame_host, entry.GetURL()); |
| 355 bool is_allowed_in_web_ui_renderer = | |
| 356 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | |
| 357 controller_->GetBrowserContext(), entry.GetURL()); | |
| 358 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | |
| 359 !is_allowed_in_web_ui_renderer) { | |
| 360 // Log the URL to help us diagnose any future failures of this CHECK. | |
| 361 GetContentClient()->SetActiveURL(entry.GetURL()); | |
| 362 CHECK(0); | |
| 363 } | |
| 364 | 378 |
| 365 // Notify observers that we will navigate in this RenderFrame. | 379 // Notify observers that we will navigate in this RenderFrame. |
| 366 if (delegate_) | 380 if (delegate_) |
| 367 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); | 381 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); |
| 368 | 382 |
| 369 // WebContents uses this to fill LoadNotificationDetails when the load | |
| 370 // completes, so that PerformanceMonitor that listens to the notification can | |
| 371 // record the load time. PerformanceMonitor is no longer maintained. | |
| 372 // TODO(ppi): make this go away. | |
| 373 current_load_start_ = base::TimeTicks::Now(); | |
| 374 | |
| 375 // Navigate in the desired RenderFrameHost. | 383 // Navigate in the desired RenderFrameHost. |
| 376 FrameMsg_Navigate_Params navigate_params; | |
| 377 MakeNavigateParams(entry, *controller_, reload_type, navigation_start, | |
| 378 &navigate_params); | |
| 379 dest_render_frame_host->Navigate(navigate_params); | 384 dest_render_frame_host->Navigate(navigate_params); |
| 380 | 385 |
| 381 // Make sure no code called via RFH::Navigate clears the pending entry. | 386 // Make sure no code called via RFH::Navigate clears the pending entry. |
| 382 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 387 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
| 383 | 388 |
| 384 if (entry.GetPageID() == -1) { | 389 if (entry.GetPageID() == -1) { |
| 385 // HACK!! This code suppresses javascript: URLs from being added to | 390 // HACK!! This code suppresses javascript: URLs from being added to |
| 386 // session history, which is what we want to do for javascript: URLs that | 391 // session history, which is what we want to do for javascript: URLs that |
| 387 // do not generate content. What we really need is a message from the | 392 // do not generate content. What we really need is a message from the |
| 388 // renderer telling us that a new page was not created. The same message | 393 // renderer telling us that a new page was not created. The same message |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 params.referrer = Referrer(); | 641 params.referrer = Referrer(); |
| 637 | 642 |
| 638 // Navigations in Web UI pages count as browser-initiated navigations. | 643 // Navigations in Web UI pages count as browser-initiated navigations. |
| 639 params.is_renderer_initiated = false; | 644 params.is_renderer_initiated = false; |
| 640 } | 645 } |
| 641 | 646 |
| 642 if (delegate_) | 647 if (delegate_) |
| 643 delegate_->RequestOpenURL(render_frame_host, params); | 648 delegate_->RequestOpenURL(render_frame_host, params); |
| 644 } | 649 } |
| 645 | 650 |
| 651 void NavigatorImpl::CommitNavigation( |
| 652 RenderFrameHostImpl* render_frame_host, |
| 653 const NavigationBeforeCommitInfo& info) { |
| 654 CheckWebUIRendererDoesNotDisplayNormalURL( |
| 655 render_frame_host, info.navigation_url); |
| 656 // TODO(clamy): the render_frame_host should now send a commit IPC to the |
| 657 // renderer. |
| 658 } |
| 659 |
| 660 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
| 661 RenderFrameHostImpl* render_frame_host, |
| 662 const GURL& url) { |
| 663 int enabled_bindings = |
| 664 render_frame_host->render_view_host()->GetEnabledBindings(); |
| 665 bool is_allowed_in_web_ui_renderer = |
| 666 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
| 667 controller_->GetBrowserContext(), url); |
| 668 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
| 669 !is_allowed_in_web_ui_renderer) { |
| 670 // Log the URL to help us diagnose any future failures of this CHECK. |
| 671 GetContentClient()->SetActiveURL(url); |
| 672 CHECK(0); |
| 673 } |
| 674 } |
| 675 |
| 646 } // namespace content | 676 } // namespace content |
| OLD | NEW |