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 18 matching lines...) Expand all Loading... | |
29 #include "content/public/common/bindings_policy.h" | 29 #include "content/public/common/bindings_policy.h" |
30 #include "content/public/common/content_client.h" | 30 #include "content/public/common/content_client.h" |
31 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
32 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
33 #include "content/public/common/url_utils.h" | 33 #include "content/public/common/url_utils.h" |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 FrameMsg_Navigate_Type::Value GetNavigationType( | |
40 BrowserContext* browser_context, const NavigationEntryImpl& entry, | |
41 NavigationController::ReloadType reload_type) { | |
42 switch (reload_type) { | |
43 case NavigationControllerImpl::RELOAD: | |
44 return FrameMsg_Navigate_Type::RELOAD; | |
45 case NavigationControllerImpl::RELOAD_IGNORING_CACHE: | |
46 return FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE; | |
47 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL: | |
48 return FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; | |
49 case NavigationControllerImpl::NO_RELOAD: | |
50 break; // Fall through to rest of function. | |
51 } | |
52 | |
53 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates | |
54 // between |RESTORE_WITH_POST| and |RESTORE|. | |
55 if (entry.restore_type() == | |
56 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) { | |
57 if (entry.GetHasPostData()) | |
58 return FrameMsg_Navigate_Type::RESTORE_WITH_POST; | |
59 return FrameMsg_Navigate_Type::RESTORE; | |
60 } | |
61 | |
62 return FrameMsg_Navigate_Type::NORMAL; | |
63 } | |
64 | |
65 void MakeNavigateParams(const NavigationEntryImpl& entry, | |
66 const NavigationControllerImpl& controller, | |
67 NavigationController::ReloadType reload_type, | |
68 base::TimeTicks navigation_start, | |
69 FrameMsg_Navigate_Params* params) { | |
70 params->page_id = entry.GetPageID(); | |
71 params->should_clear_history_list = entry.should_clear_history_list(); | |
72 params->should_replace_current_entry = entry.should_replace_entry(); | |
73 if (entry.should_clear_history_list()) { | |
74 // Set the history list related parameters to the same values a | |
75 // NavigationController would return before its first navigation. This will | |
76 // fully clear the RenderView's view of the session history. | |
77 params->pending_history_list_offset = -1; | |
78 params->current_history_list_offset = -1; | |
79 params->current_history_list_length = 0; | |
80 } else { | |
81 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); | |
82 params->current_history_list_offset = | |
83 controller.GetLastCommittedEntryIndex(); | |
84 params->current_history_list_length = controller.GetEntryCount(); | |
85 } | |
86 params->url = entry.GetURL(); | |
87 if (!entry.GetBaseURLForDataURL().is_empty()) { | |
88 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); | |
89 params->history_url_for_data_url = entry.GetVirtualURL(); | |
90 } | |
91 params->referrer = entry.GetReferrer(); | |
92 params->transition = entry.GetTransitionType(); | |
93 params->page_state = entry.GetPageState(); | |
94 params->navigation_type = | |
95 GetNavigationType(controller.GetBrowserContext(), entry, reload_type); | |
96 // This is used by the old performance infrastructure to set up DocumentState | |
97 // associated with the RenderView. | |
98 // TODO(ppi): make it go away. | |
99 params->request_time = base::Time::Now(); | |
100 params->extra_headers = entry.extra_headers(); | |
101 params->transferred_request_child_id = | |
102 entry.transferred_global_request_id().child_id; | |
103 params->transferred_request_request_id = | |
104 entry.transferred_global_request_id().request_id; | |
105 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent(); | |
106 // Avoid downloading when in view-source mode. | |
107 params->allow_download = !entry.IsViewSourceMode(); | |
108 params->is_post = entry.GetHasPostData(); | |
109 if (entry.GetBrowserInitiatedPostData()) { | |
110 params->browser_initiated_post_data.assign( | |
111 entry.GetBrowserInitiatedPostData()->front(), | |
112 entry.GetBrowserInitiatedPostData()->front() + | |
113 entry.GetBrowserInitiatedPostData()->size()); | |
114 } | |
115 | |
116 // Set the redirect chain to the navigation's redirects, unless we are | |
117 // returning to a completed navigation (whose previous redirects don't apply). | |
118 if (PageTransitionIsNewNavigation(params->transition)) { | |
119 params->redirects = entry.GetRedirectChain(); | |
120 } else { | |
121 params->redirects.clear(); | |
122 } | |
123 | |
124 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | |
125 params->frame_to_navigate = entry.GetFrameToNavigate(); | |
126 params->browser_navigation_start = navigation_start; | |
127 } | |
128 | |
129 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { | 39 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { |
130 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) | 40 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) |
131 return rfh->frame_tree_node()->render_manager(); | 41 return rfh->frame_tree_node()->render_manager(); |
132 | 42 |
133 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); | 43 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
134 } | 44 } |
135 | 45 |
136 } // namespace | 46 } // namespace |
137 | 47 |
138 | |
139 NavigatorImpl::NavigatorImpl( | 48 NavigatorImpl::NavigatorImpl( |
140 NavigationControllerImpl* navigation_controller, | 49 NavigationControllerImpl* navigation_controller, |
141 NavigatorDelegate* delegate) | 50 NavigatorDelegate* delegate) |
142 : controller_(navigation_controller), | 51 : controller_(navigation_controller), |
143 delegate_(delegate) { | 52 delegate_(delegate) { |
144 } | 53 } |
145 | 54 |
146 NavigationController* NavigatorImpl::GetController() { | 55 NavigationController* NavigatorImpl::GetController() { |
147 return controller_; | 56 return controller_; |
148 } | 57 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 << " characters."; | 236 << " characters."; |
328 return false; | 237 return false; |
329 } | 238 } |
330 | 239 |
331 // This will be used to set the Navigation Timing API navigationStart | 240 // This will be used to set the Navigation Timing API navigationStart |
332 // parameter for browser navigations in new tabs (intents, tabs opened through | 241 // 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 | 242 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to |
334 // capture the time needed for the RenderFrameHost initialization. | 243 // capture the time needed for the RenderFrameHost initialization. |
335 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 244 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
336 | 245 |
246 // WebContents uses this to fill LoadNotificationDetails when the load | |
247 // completes, so that PerformanceMonitor that listens to the notification can | |
248 // record the load time. PerformanceMonitor is no longer maintained. | |
249 // TODO(ppi): make this go away. | |
250 current_load_start_ = base::TimeTicks::Now(); | |
251 | |
252 // Create the navigation parameters that may be used directly by the | |
253 // RenderFrameHostManager in browser initiated navigation (part of project | |
254 // PlzNavigate navigation refactoring). | |
255 FrameMsg_Navigate_Params navigate_params; | |
256 entry.MakeNavigateParams( | |
257 *controller_, reload_type, navigation_start, &navigate_params); | |
258 | |
337 RenderFrameHostManager* manager = | 259 RenderFrameHostManager* manager = |
338 render_frame_host->frame_tree_node()->render_manager(); | 260 render_frame_host->frame_tree_node()->render_manager(); |
261 | |
262 // As part of the PlzNavigate project, the RenderFrameHosts are no longer | |
263 // asked to navigate. Instead the RenderFrameHostManager handles the | |
264 // navigation requests for that frame node. | |
265 #if defined(USE_PLZ_NAVIGATE) | |
clamy
2014/07/16 12:13:49
Do you think it is better to use a runtime flag in
ppi
2014/07/16 14:28:09
I'm curious to hear Nasko's opinion, personally I
| |
266 return manager->RequestNavigation(entry, navigaet_params); | |
267 #endif | |
268 | |
339 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 269 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
340 if (!dest_render_frame_host) | 270 if (!dest_render_frame_host) |
341 return false; // Unable to create the desired RenderFrameHost. | 271 return false; // Unable to create the desired RenderFrameHost. |
342 | 272 |
343 // Make sure no code called via RFHM::Navigate clears the pending entry. | 273 // Make sure no code called via RFHM::Navigate clears the pending entry. |
344 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 274 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
345 | 275 |
346 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 276 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
347 // Double check that here. | 277 // Double check that here. |
348 int enabled_bindings = | 278 int enabled_bindings = |
349 dest_render_frame_host->render_view_host()->GetEnabledBindings(); | 279 dest_render_frame_host->render_view_host()->GetEnabledBindings(); |
350 bool is_allowed_in_web_ui_renderer = | 280 bool is_allowed_in_web_ui_renderer = |
351 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 281 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
352 controller_->GetBrowserContext(), entry.GetURL()); | 282 controller_->GetBrowserContext(), entry.GetURL()); |
353 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | 283 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
354 !is_allowed_in_web_ui_renderer) { | 284 !is_allowed_in_web_ui_renderer) { |
355 // Log the URL to help us diagnose any future failures of this CHECK. | 285 // Log the URL to help us diagnose any future failures of this CHECK. |
356 GetContentClient()->SetActiveURL(entry.GetURL()); | 286 GetContentClient()->SetActiveURL(entry.GetURL()); |
357 CHECK(0); | 287 CHECK(0); |
358 } | 288 } |
359 | 289 |
360 // Notify observers that we will navigate in this RenderFrame. | 290 // Notify observers that we will navigate in this RenderFrame. |
361 if (delegate_) | 291 if (delegate_) |
362 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); | 292 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); |
363 | 293 |
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. | 294 // 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); | 295 dest_render_frame_host->Navigate(navigate_params); |
375 | 296 |
376 // Make sure no code called via RFH::Navigate clears the pending entry. | 297 // Make sure no code called via RFH::Navigate clears the pending entry. |
377 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 298 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
378 | 299 |
379 if (entry.GetPageID() == -1) { | 300 if (entry.GetPageID() == -1) { |
380 // HACK!! This code suppresses javascript: URLs from being added to | 301 // HACK!! This code suppresses javascript: URLs from being added to |
381 // session history, which is what we want to do for javascript: URLs that | 302 // 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 | 303 // 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 | 304 // renderer telling us that a new page was not created. The same message |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 | 563 |
643 // Navigations in Web UI pages count as browser-initiated navigations. | 564 // Navigations in Web UI pages count as browser-initiated navigations. |
644 params.is_renderer_initiated = false; | 565 params.is_renderer_initiated = false; |
645 } | 566 } |
646 | 567 |
647 if (delegate_) | 568 if (delegate_) |
648 delegate_->RequestOpenURL(render_frame_host, params); | 569 delegate_->RequestOpenURL(render_frame_host, params); |
649 } | 570 } |
650 | 571 |
651 } // namespace content | 572 } // namespace content |
OLD | NEW |