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_before_commit_info.h" |
12 #include "content/browser/frame_host/navigation_controller_impl.h" | 12 #include "content/browser/frame_host/navigation_controller_impl.h" |
13 #include "content/browser/frame_host/navigation_entry_impl.h" | 13 #include "content/browser/frame_host/navigation_entry_impl.h" |
14 #include "content/browser/frame_host/navigation_parameters.h" | |
14 #include "content/browser/frame_host/navigator_delegate.h" | 15 #include "content/browser/frame_host/navigator_delegate.h" |
15 #include "content/browser/frame_host/render_frame_host_impl.h" | 16 #include "content/browser/frame_host/render_frame_host_impl.h" |
16 #include "content/browser/renderer_host/render_view_host_impl.h" | 17 #include "content/browser/renderer_host/render_view_host_impl.h" |
17 #include "content/browser/site_instance_impl.h" | 18 #include "content/browser/site_instance_impl.h" |
18 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 19 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
19 #include "content/browser/webui/web_ui_impl.h" | 20 #include "content/browser/webui/web_ui_impl.h" |
20 #include "content/common/frame_messages.h" | 21 #include "content/common/frame_messages.h" |
21 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
22 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
23 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 } | 65 } |
65 | 66 |
66 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { | 67 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { |
67 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 68 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
68 switches::kSitePerProcess)) | 69 switches::kSitePerProcess)) |
69 return rfh->frame_tree_node()->render_manager(); | 70 return rfh->frame_tree_node()->render_manager(); |
70 | 71 |
71 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); | 72 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
72 } | 73 } |
73 | 74 |
74 } // namespace | 75 void MakeNavigateParams( |
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, | 76 const NavigationEntryImpl& entry, |
87 const NavigationControllerImpl& controller, | 77 NavigationControllerImpl* controller, |
88 NavigationController::ReloadType reload_type, | 78 NavigationController::ReloadType reload_type, |
89 base::TimeTicks navigation_start, | 79 base::TimeTicks navigation_start, |
90 FrameMsg_Navigate_Params* params) { | 80 FrameMsg_Navigate_Params* params) { |
91 params->page_id = entry.GetPageID(); | 81 params->page_id = entry.GetPageID(); |
92 params->should_clear_history_list = entry.should_clear_history_list(); | 82 params->should_clear_history_list = entry.should_clear_history_list(); |
93 params->should_replace_current_entry = entry.should_replace_entry(); | 83 params->should_replace_current_entry = entry.should_replace_entry(); |
94 if (entry.should_clear_history_list()) { | |
95 // Set the history list related parameters to the same values a | |
96 // NavigationController would return before its first navigation. This will | |
97 // fully clear the RenderView's view of the session history. | |
98 params->pending_history_list_offset = -1; | |
99 params->current_history_list_offset = -1; | |
100 params->current_history_list_length = 0; | |
101 } else { | |
102 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); | |
103 params->current_history_list_offset = | |
104 controller.GetLastCommittedEntryIndex(); | |
105 params->current_history_list_length = controller.GetEntryCount(); | |
106 } | |
107 params->url = entry.GetURL(); | 84 params->url = entry.GetURL(); |
85 controller->FillHistoryParametersForNavigationEntry( | |
86 entry, | |
87 ¶ms->pending_history_list_offset, | |
88 ¶ms->current_history_list_offset, | |
89 ¶ms->current_history_list_length); | |
108 if (!entry.GetBaseURLForDataURL().is_empty()) { | 90 if (!entry.GetBaseURLForDataURL().is_empty()) { |
109 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); | 91 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); |
110 params->history_url_for_data_url = entry.GetVirtualURL(); | 92 params->history_url_for_data_url = entry.GetVirtualURL(); |
111 } | 93 } |
112 params->referrer = entry.GetReferrer(); | 94 params->referrer = entry.GetReferrer(); |
113 params->transition = entry.GetTransitionType(); | 95 params->transition = entry.GetTransitionType(); |
114 params->page_state = entry.GetPageState(); | 96 params->page_state = entry.GetPageState(); |
115 params->navigation_type = | 97 params->navigation_type = GetNavigationType( |
116 GetNavigationType(controller.GetBrowserContext(), entry, reload_type); | 98 controller->GetBrowserContext(), entry, reload_type); |
117 // This is used by the old performance infrastructure to set up DocumentState | 99 // This is used by the old performance infrastructure to set up DocumentState |
118 // associated with the RenderView. | 100 // associated with the RenderView. |
119 // TODO(ppi): make it go away. | 101 // TODO(ppi): make it go away. |
120 params->request_time = base::Time::Now(); | 102 params->request_time = base::Time::Now(); |
121 params->extra_headers = entry.extra_headers(); | 103 params->extra_headers = entry.extra_headers(); |
122 params->transferred_request_child_id = | 104 params->transferred_request_child_id = |
123 entry.transferred_global_request_id().child_id; | 105 entry.transferred_global_request_id().child_id; |
124 params->transferred_request_request_id = | 106 params->transferred_request_request_id = |
125 entry.transferred_global_request_id().request_id; | 107 entry.transferred_global_request_id().request_id; |
126 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent(); | 108 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent(); |
(...skipping 13 matching lines...) Expand all Loading... | |
140 params->redirects = entry.GetRedirectChain(); | 122 params->redirects = entry.GetRedirectChain(); |
141 } else { | 123 } else { |
142 params->redirects.clear(); | 124 params->redirects.clear(); |
143 } | 125 } |
144 | 126 |
145 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | 127 params->can_load_local_resources = entry.GetCanLoadLocalResources(); |
146 params->frame_to_navigate = entry.GetFrameToNavigate(); | 128 params->frame_to_navigate = entry.GetFrameToNavigate(); |
147 params->browser_navigation_start = navigation_start; | 129 params->browser_navigation_start = navigation_start; |
148 } | 130 } |
149 | 131 |
132 } // namespace | |
133 | |
134 | |
135 NavigatorImpl::NavigatorImpl( | |
136 NavigationControllerImpl* navigation_controller, | |
137 NavigatorDelegate* delegate) | |
138 : controller_(navigation_controller), | |
139 delegate_(delegate) { | |
140 } | |
141 | |
150 NavigationController* NavigatorImpl::GetController() { | 142 NavigationController* NavigatorImpl::GetController() { |
151 return controller_; | 143 return controller_; |
152 } | 144 } |
153 | 145 |
154 void NavigatorImpl::DidStartProvisionalLoad( | 146 void NavigatorImpl::DidStartProvisionalLoad( |
155 RenderFrameHostImpl* render_frame_host, | 147 RenderFrameHostImpl* render_frame_host, |
156 const GURL& url, | 148 const GURL& url, |
157 bool is_transition_navigation) { | 149 bool is_transition_navigation) { |
158 bool is_error_page = (url.spec() == kUnreachableWebDataURL); | 150 bool is_error_page = (url.spec() == kUnreachableWebDataURL); |
159 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); | 151 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to | 333 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to |
342 // capture the time needed for the RenderFrameHost initialization. | 334 // capture the time needed for the RenderFrameHost initialization. |
343 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 335 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
344 | 336 |
345 // WebContents uses this to fill LoadNotificationDetails when the load | 337 // WebContents uses this to fill LoadNotificationDetails when the load |
346 // completes, so that PerformanceMonitor that listens to the notification can | 338 // completes, so that PerformanceMonitor that listens to the notification can |
347 // record the load time. PerformanceMonitor is no longer maintained. | 339 // record the load time. PerformanceMonitor is no longer maintained. |
348 // TODO(ppi): make this go away. | 340 // TODO(ppi): make this go away. |
349 current_load_start_ = base::TimeTicks::Now(); | 341 current_load_start_ = base::TimeTicks::Now(); |
350 | 342 |
351 // Create the navigation parameters. | |
352 FrameMsg_Navigate_Params navigate_params; | |
353 MakeNavigateParams( | |
354 entry, *controller_, reload_type, navigation_start, &navigate_params); | |
355 | |
356 RenderFrameHostManager* manager = | 343 RenderFrameHostManager* manager = |
357 render_frame_host->frame_tree_node()->render_manager(); | 344 render_frame_host->frame_tree_node()->render_manager(); |
358 | 345 |
359 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead | 346 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead |
360 // the RenderFrameHostManager handles the navigation requests for that frame | 347 // the RenderFrameHostManager handles the navigation requests for that frame |
361 // node. | 348 // node. |
362 if (CommandLine::ForCurrentProcess()->HasSwitch( | 349 if (CommandLine::ForCurrentProcess()->HasSwitch( |
363 switches::kEnableBrowserSideNavigation)) { | 350 switches::kEnableBrowserSideNavigation)) { |
364 return manager->RequestNavigation(entry, navigate_params); | 351 scoped_ptr<NavigationParameters> navigation_parameters( |
352 new NavigationParameters( | |
353 entry, | |
354 controller_, | |
355 current_load_start_, | |
356 GetNavigationType( | |
357 controller_->GetBrowserContext(), entry, reload_type))); | |
358 return manager->RequestNavigation(navigation_parameters.Pass()); | |
365 } | 359 } |
366 | 360 |
367 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 361 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
368 if (!dest_render_frame_host) | 362 if (!dest_render_frame_host) |
369 return false; // Unable to create the desired RenderFrameHost. | 363 return false; // Unable to create the desired RenderFrameHost. |
370 | 364 |
371 // Make sure no code called via RFHM::Navigate clears the pending entry. | 365 // Make sure no code called via RFHM::Navigate clears the pending entry. |
372 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 366 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
373 | 367 |
374 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 368 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
375 // Double check that here. | 369 // Double check that here. |
376 CheckWebUIRendererDoesNotDisplayNormalURL( | 370 CheckWebUIRendererDoesNotDisplayNormalURL( |
377 dest_render_frame_host, entry.GetURL()); | 371 dest_render_frame_host, entry.GetURL()); |
378 | 372 |
379 // Notify observers that we will navigate in this RenderFrame. | 373 // Notify observers that we will navigate in this RenderFrame. |
380 if (delegate_) | 374 if (delegate_) |
381 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); | 375 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); |
382 | 376 |
377 // Create the navigation parameters. | |
378 FrameMsg_Navigate_Params navigate_params; | |
379 MakeNavigateParams( | |
380 entry, controller_, reload_type, navigation_start, &navigate_params); | |
381 | |
383 // Navigate in the desired RenderFrameHost. | 382 // Navigate in the desired RenderFrameHost. |
384 // We can skip this step in the rare case that this is a transfer navigation | 383 // We can skip this step in the rare case that this is a transfer navigation |
385 // which began in the chosen RenderFrameHost, since the request has already | 384 // which began in the chosen RenderFrameHost, since the request has already |
386 // been issued. In that case, simply resume the response. | 385 // been issued. In that case, simply resume the response. |
387 bool is_transfer_to_same = | 386 bool is_transfer_to_same = |
388 navigate_params.transferred_request_child_id != -1 && | 387 navigate_params.transferred_request_child_id != -1 && |
389 navigate_params.transferred_request_child_id == | 388 navigate_params.transferred_request_child_id == |
390 dest_render_frame_host->GetProcess()->GetID(); | 389 dest_render_frame_host->GetProcess()->GetID(); |
391 if (!is_transfer_to_same) { | 390 if (!is_transfer_to_same) { |
392 dest_render_frame_host->Navigate(navigate_params); | 391 dest_render_frame_host->Navigate(navigate_params); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 // Navigations in Web UI pages count as browser-initiated navigations. | 656 // Navigations in Web UI pages count as browser-initiated navigations. |
658 params.is_renderer_initiated = false; | 657 params.is_renderer_initiated = false; |
659 } | 658 } |
660 | 659 |
661 if (delegate_) | 660 if (delegate_) |
662 delegate_->RequestOpenURL(render_frame_host, params); | 661 delegate_->RequestOpenURL(render_frame_host, params); |
663 } | 662 } |
664 | 663 |
665 void NavigatorImpl::CommitNavigation( | 664 void NavigatorImpl::CommitNavigation( |
666 RenderFrameHostImpl* render_frame_host, | 665 RenderFrameHostImpl* render_frame_host, |
667 const NavigationBeforeCommitInfo& info) { | 666 const FrameMsg_CommitNavigation_Params& commit_navigation_params) { |
668 CheckWebUIRendererDoesNotDisplayNormalURL( | 667 CheckWebUIRendererDoesNotDisplayNormalURL( |
669 render_frame_host, info.navigation_url); | 668 render_frame_host, commit_navigation_params.url); |
670 // TODO(clamy): the render_frame_host should now send a commit IPC to the | 669 render_frame_host->CommitNavigation(commit_navigation_params); |
671 // renderer. | 670 } |
671 | |
672 NavigationParameters* NavigatorImpl::MakeNavigationParametersForTest( | |
(Do not use) nasko
2014/09/05 17:04:48
I know this is for testing, but it seems that it w
clamy
2014/09/08 18:37:12
Done.
| |
673 const NavigationEntryImpl& entry, | |
674 NavigationController::ReloadType reload_type) { | |
675 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType( | |
676 controller_->GetBrowserContext(), | |
677 entry, | |
678 reload_type); | |
679 return new NavigationParameters( | |
680 entry, controller_, base::TimeTicks::Now(), navigation_type); | |
672 } | 681 } |
673 | 682 |
674 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( | 683 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
675 RenderFrameHostImpl* render_frame_host, | 684 RenderFrameHostImpl* render_frame_host, |
676 const GURL& url) { | 685 const GURL& url) { |
677 int enabled_bindings = | 686 int enabled_bindings = |
678 render_frame_host->render_view_host()->GetEnabledBindings(); | 687 render_frame_host->render_view_host()->GetEnabledBindings(); |
679 bool is_allowed_in_web_ui_renderer = | 688 bool is_allowed_in_web_ui_renderer = |
680 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 689 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
681 controller_->GetBrowserContext(), url); | 690 controller_->GetBrowserContext(), url); |
682 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | 691 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
683 !is_allowed_in_web_ui_renderer) { | 692 !is_allowed_in_web_ui_renderer) { |
684 // Log the URL to help us diagnose any future failures of this CHECK. | 693 // Log the URL to help us diagnose any future failures of this CHECK. |
685 GetContentClient()->SetActiveURL(url); | 694 GetContentClient()->SetActiveURL(url); |
686 CHECK(0); | 695 CHECK(0); |
687 } | 696 } |
688 } | 697 } |
689 | 698 |
690 } // namespace content | 699 } // namespace content |
OLD | NEW |