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_transition_navigation) { | 155 bool is_transition_navigation) { |
154 bool is_error_page = (url.spec() == kUnreachableWebDataURL); | 156 bool is_error_page = (url.spec() == kUnreachableWebDataURL); |
155 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); | 157 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 << " characters."; | 333 << " characters."; |
332 return false; | 334 return false; |
333 } | 335 } |
334 | 336 |
335 // This will be used to set the Navigation Timing API navigationStart | 337 // This will be used to set the Navigation Timing API navigationStart |
336 // parameter for browser navigations in new tabs (intents, tabs opened through | 338 // parameter for browser navigations in new tabs (intents, tabs opened through |
337 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to | 339 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to |
338 // capture the time needed for the RenderFrameHost initialization. | 340 // capture the time needed for the RenderFrameHost initialization. |
339 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 341 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
340 | 342 |
| 343 // WebContents uses this to fill LoadNotificationDetails when the load |
| 344 // completes, so that PerformanceMonitor that listens to the notification can |
| 345 // record the load time. PerformanceMonitor is no longer maintained. |
| 346 // TODO(ppi): make this go away. |
| 347 current_load_start_ = base::TimeTicks::Now(); |
| 348 |
| 349 // Create the navigation parameters. |
| 350 FrameMsg_Navigate_Params navigate_params; |
| 351 MakeNavigateParams( |
| 352 entry, *controller_, reload_type, navigation_start, &navigate_params); |
| 353 |
341 RenderFrameHostManager* manager = | 354 RenderFrameHostManager* manager = |
342 render_frame_host->frame_tree_node()->render_manager(); | 355 render_frame_host->frame_tree_node()->render_manager(); |
| 356 |
| 357 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead |
| 358 // the RenderFrameHostManager handles the navigation requests for that frame |
| 359 // node. |
| 360 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 361 switches::kEnableBrowserSideNavigation)) { |
| 362 return manager->RequestNavigation(entry, navigate_params); |
| 363 } |
| 364 |
343 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 365 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
344 if (!dest_render_frame_host) | 366 if (!dest_render_frame_host) |
345 return false; // Unable to create the desired RenderFrameHost. | 367 return false; // Unable to create the desired RenderFrameHost. |
346 | 368 |
347 // Make sure no code called via RFHM::Navigate clears the pending entry. | 369 // Make sure no code called via RFHM::Navigate clears the pending entry. |
348 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 370 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
349 | 371 |
350 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 372 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
351 // Double check that here. | 373 // Double check that here. |
352 int enabled_bindings = | 374 CheckWebUIRendererDoesNotDisplayNormalURL( |
353 dest_render_frame_host->render_view_host()->GetEnabledBindings(); | 375 dest_render_frame_host, entry.GetURL()); |
354 bool is_allowed_in_web_ui_renderer = | |
355 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | |
356 controller_->GetBrowserContext(), entry.GetURL()); | |
357 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | |
358 !is_allowed_in_web_ui_renderer) { | |
359 // Log the URL to help us diagnose any future failures of this CHECK. | |
360 GetContentClient()->SetActiveURL(entry.GetURL()); | |
361 CHECK(0); | |
362 } | |
363 | 376 |
364 // Notify observers that we will navigate in this RenderFrame. | 377 // Notify observers that we will navigate in this RenderFrame. |
365 if (delegate_) | 378 if (delegate_) |
366 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); | 379 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); |
367 | 380 |
368 // WebContents uses this to fill LoadNotificationDetails when the load | |
369 // completes, so that PerformanceMonitor that listens to the notification can | |
370 // record the load time. PerformanceMonitor is no longer maintained. | |
371 // TODO(ppi): make this go away. | |
372 current_load_start_ = base::TimeTicks::Now(); | |
373 | |
374 // Navigate in the desired RenderFrameHost. | 381 // Navigate in the desired RenderFrameHost. |
375 FrameMsg_Navigate_Params navigate_params; | |
376 MakeNavigateParams(entry, *controller_, reload_type, navigation_start, | |
377 &navigate_params); | |
378 dest_render_frame_host->Navigate(navigate_params); | 382 dest_render_frame_host->Navigate(navigate_params); |
379 | 383 |
380 // Make sure no code called via RFH::Navigate clears the pending entry. | 384 // Make sure no code called via RFH::Navigate clears the pending entry. |
381 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 385 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
382 | 386 |
383 if (entry.GetPageID() == -1) { | 387 if (entry.GetPageID() == -1) { |
384 // HACK!! This code suppresses javascript: URLs from being added to | 388 // HACK!! This code suppresses javascript: URLs from being added to |
385 // session history, which is what we want to do for javascript: URLs that | 389 // session history, which is what we want to do for javascript: URLs that |
386 // do not generate content. What we really need is a message from the | 390 // do not generate content. What we really need is a message from the |
387 // renderer telling us that a new page was not created. The same message | 391 // renderer telling us that a new page was not created. The same message |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 params.referrer = Referrer(); | 638 params.referrer = Referrer(); |
635 | 639 |
636 // Navigations in Web UI pages count as browser-initiated navigations. | 640 // Navigations in Web UI pages count as browser-initiated navigations. |
637 params.is_renderer_initiated = false; | 641 params.is_renderer_initiated = false; |
638 } | 642 } |
639 | 643 |
640 if (delegate_) | 644 if (delegate_) |
641 delegate_->RequestOpenURL(render_frame_host, params); | 645 delegate_->RequestOpenURL(render_frame_host, params); |
642 } | 646 } |
643 | 647 |
| 648 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
| 649 RenderFrameHostImpl* render_frame_host, |
| 650 const GURL& url) { |
| 651 int enabled_bindings = |
| 652 render_frame_host->render_view_host()->GetEnabledBindings(); |
| 653 bool is_allowed_in_web_ui_renderer = |
| 654 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
| 655 controller_->GetBrowserContext(), url); |
| 656 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
| 657 !is_allowed_in_web_ui_renderer) { |
| 658 // Log the URL to help us diagnose any future failures of this CHECK. |
| 659 GetContentClient()->SetActiveURL(url); |
| 660 CHECK(0); |
| 661 } |
| 662 } |
| 663 |
644 } // namespace content | 664 } // namespace content |
OLD | NEW |