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