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 (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) |
67 NavigationController::ReloadType reload_type, | 68 return rfh->frame_tree_node()->render_manager(); |
68 base::TimeTicks navigation_start, | 69 |
69 FrameMsg_Navigate_Params* params) { | 70 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
71 } | |
72 | |
73 } // namespace | |
74 | |
75 | |
76 NavigatorImpl::NavigatorImpl( | |
77 NavigationControllerImpl* navigation_controller, | |
78 NavigatorDelegate* delegate) | |
79 : controller_(navigation_controller), | |
80 delegate_(delegate) { | |
81 } | |
82 | |
83 // static. | |
84 void NavigatorImpl::MakeNavigateParams( | |
85 const NavigationEntryImpl& entry, | |
86 const NavigationControllerImpl& controller, | |
87 NavigationController::ReloadType reload_type, | |
88 base::TimeTicks navigation_start, | |
89 FrameMsg_Navigate_Params* params) { | |
70 params->page_id = entry.GetPageID(); | 90 params->page_id = entry.GetPageID(); |
71 params->should_clear_history_list = entry.should_clear_history_list(); | 91 params->should_clear_history_list = entry.should_clear_history_list(); |
72 params->should_replace_current_entry = entry.should_replace_entry(); | 92 params->should_replace_current_entry = entry.should_replace_entry(); |
73 if (entry.should_clear_history_list()) { | 93 if (entry.should_clear_history_list()) { |
74 // Set the history list related parameters to the same values a | 94 // Set the history list related parameters to the same values a |
75 // NavigationController would return before its first navigation. This will | 95 // NavigationController would return before its first navigation. This will |
76 // fully clear the RenderView's view of the session history. | 96 // fully clear the RenderView's view of the session history. |
77 params->pending_history_list_offset = -1; | 97 params->pending_history_list_offset = -1; |
78 params->current_history_list_offset = -1; | 98 params->current_history_list_offset = -1; |
79 params->current_history_list_length = 0; | 99 params->current_history_list_length = 0; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 params->redirects = entry.GetRedirectChain(); | 139 params->redirects = entry.GetRedirectChain(); |
120 } else { | 140 } else { |
121 params->redirects.clear(); | 141 params->redirects.clear(); |
122 } | 142 } |
123 | 143 |
124 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | 144 params->can_load_local_resources = entry.GetCanLoadLocalResources(); |
125 params->frame_to_navigate = entry.GetFrameToNavigate(); | 145 params->frame_to_navigate = entry.GetFrameToNavigate(); |
126 params->browser_navigation_start = navigation_start; | 146 params->browser_navigation_start = navigation_start; |
127 } | 147 } |
128 | 148 |
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() { | 149 NavigationController* NavigatorImpl::GetController() { |
147 return controller_; | 150 return controller_; |
148 } | 151 } |
149 | 152 |
150 void NavigatorImpl::DidStartProvisionalLoad( | 153 void NavigatorImpl::DidStartProvisionalLoad( |
151 RenderFrameHostImpl* render_frame_host, | 154 RenderFrameHostImpl* render_frame_host, |
152 const GURL& url, | 155 const GURL& url, |
153 bool is_transition_navigation) { | 156 bool is_transition_navigation) { |
154 bool is_error_page = (url.spec() == kUnreachableWebDataURL); | 157 bool is_error_page = (url.spec() == kUnreachableWebDataURL); |
155 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); | 158 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 << " characters."; | 334 << " characters."; |
332 return false; | 335 return false; |
333 } | 336 } |
334 | 337 |
335 // This will be used to set the Navigation Timing API navigationStart | 338 // This will be used to set the Navigation Timing API navigationStart |
336 // parameter for browser navigations in new tabs (intents, tabs opened through | 339 // 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 | 340 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to |
338 // capture the time needed for the RenderFrameHost initialization. | 341 // capture the time needed for the RenderFrameHost initialization. |
339 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 342 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
340 | 343 |
344 // WebContents uses this to fill LoadNotificationDetails when the load | |
345 // completes, so that PerformanceMonitor that listens to the notification can | |
346 // record the load time. PerformanceMonitor is no longer maintained. | |
347 // TODO(ppi): make this go away. | |
348 current_load_start_ = base::TimeTicks::Now(); | |
349 | |
350 // Create the navigation parameters. | |
351 FrameMsg_Navigate_Params navigate_params; | |
352 MakeNavigateParams( | |
353 entry, *controller_, reload_type, navigation_start, &navigate_params); | |
354 | |
341 RenderFrameHostManager* manager = | 355 RenderFrameHostManager* manager = |
342 render_frame_host->frame_tree_node()->render_manager(); | 356 render_frame_host->frame_tree_node()->render_manager(); |
357 | |
358 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead | |
359 // the RenderFrameHostManager handles the navigation requests for that frame | |
360 // node. | |
361 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
362 switches::kEnableBrowserSideNavigation)) { | |
363 return manager->RequestNavigation(entry, navigate_params); | |
364 } | |
365 | |
343 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 366 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
344 if (!dest_render_frame_host) | 367 if (!dest_render_frame_host) |
345 return false; // Unable to create the desired RenderFrameHost. | 368 return false; // Unable to create the desired RenderFrameHost. |
346 | 369 |
347 // Make sure no code called via RFHM::Navigate clears the pending entry. | 370 // Make sure no code called via RFHM::Navigate clears the pending entry. |
348 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 371 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
349 | 372 |
350 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 373 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
351 // Double check that here. | 374 // Double check that here. |
352 int enabled_bindings = | 375 CheckWebUIRendererDoesNotDisplayNormalURL( |
353 dest_render_frame_host->render_view_host()->GetEnabledBindings(); | 376 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 | 377 |
364 // Notify observers that we will navigate in this RenderFrame. | 378 // Notify observers that we will navigate in this RenderFrame. |
365 if (delegate_) | 379 if (delegate_) |
366 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); | 380 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); |
367 | 381 |
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. | 382 // 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); | 383 dest_render_frame_host->Navigate(navigate_params); |
379 | 384 |
380 // Make sure no code called via RFH::Navigate clears the pending entry. | 385 // Make sure no code called via RFH::Navigate clears the pending entry. |
381 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 386 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
382 | 387 |
383 if (entry.GetPageID() == -1) { | 388 if (entry.GetPageID() == -1) { |
384 // HACK!! This code suppresses javascript: URLs from being added to | 389 // HACK!! This code suppresses javascript: URLs from being added to |
385 // session history, which is what we want to do for javascript: URLs that | 390 // 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 | 391 // 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 | 392 // 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(); | 639 params.referrer = Referrer(); |
635 | 640 |
636 // Navigations in Web UI pages count as browser-initiated navigations. | 641 // Navigations in Web UI pages count as browser-initiated navigations. |
637 params.is_renderer_initiated = false; | 642 params.is_renderer_initiated = false; |
638 } | 643 } |
639 | 644 |
640 if (delegate_) | 645 if (delegate_) |
641 delegate_->RequestOpenURL(render_frame_host, params); | 646 delegate_->RequestOpenURL(render_frame_host, params); |
642 } | 647 } |
643 | 648 |
649 void NavigatorImpl::OnBeginNavigation( | |
650 RenderFrameHostImpl* render_frame_host, | |
651 const FrameHostMsg_BeginNavigation_Params& params) { | |
652 // TODO(clamy): If a NavigationEntryImpl has already been passed to the | |
653 // RenderFrameHostManager in RenderFrameHostManager::RequestNavigation, then | |
654 // it should be updated instead of creating a new one (except if the | |
655 // navigation is renderer-originated). | |
656 scoped_ptr<NavigationEntryImpl> entry( | |
Charlie Reis
2014/08/08 20:25:28
I don't think this flow is quite right yet. In th
clamy
2014/08/12 12:13:15
We are still going through LoadURL for browser ini
| |
657 NavigationEntryImpl::FromNavigationEntry( | |
658 NavigationController::CreateNavigationEntry( | |
659 params.url, | |
660 params.referrer, | |
661 params.transition_type, | |
662 true, | |
663 params.headers, | |
664 controller_->GetBrowserContext()))); | |
665 render_frame_host->frame_tree_node()->render_manager()->OnBeginNavigation( | |
666 params, *entry.get()); | |
667 } | |
668 | |
669 void NavigatorImpl::CommitNavigation( | |
670 RenderFrameHostImpl* render_frame_host, | |
671 const NavigationBeforeCommitInfo& info) { | |
672 CheckWebUIRendererDoesNotDisplayNormalURL( | |
673 render_frame_host, info.navigation_url); | |
674 // TODO(clamy): the render_frame_host should now send a commit IPC to the | |
675 // renderer. | |
676 // TODO(clamy): investigate if the NavigationController should be made aware | |
Charlie Reis
2014/08/08 20:25:28
Sorry-- if I suggested this, I was confused by the
clamy
2014/08/12 12:13:15
Done.
| |
677 // of commit here. | |
678 } | |
679 | |
680 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( | |
681 RenderFrameHostImpl* render_frame_host, | |
682 const GURL& url) { | |
683 int enabled_bindings = | |
684 render_frame_host->render_view_host()->GetEnabledBindings(); | |
685 bool is_allowed_in_web_ui_renderer = | |
686 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | |
687 controller_->GetBrowserContext(), url); | |
688 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | |
689 !is_allowed_in_web_ui_renderer) { | |
690 // Log the URL to help us diagnose any future failures of this CHECK. | |
691 GetContentClient()->SetActiveURL(url); | |
692 CHECK(0); | |
693 } | |
694 } | |
695 | |
644 } // namespace content | 696 } // namespace content |
OLD | NEW |