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 "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
9 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | 11 #include "content/browser/frame_host/navigation_controller_impl.h" |
11 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
12 #include "content/browser/frame_host/navigator_delegate.h" | 13 #include "content/browser/frame_host/navigator_delegate.h" |
13 #include "content/browser/frame_host/render_frame_host_impl.h" | 14 #include "content/browser/frame_host/render_frame_host_impl.h" |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/browser/site_instance_impl.h" | 16 #include "content/browser/site_instance_impl.h" |
16 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 17 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
17 #include "content/browser/webui/web_ui_impl.h" | 18 #include "content/browser/webui/web_ui_impl.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return FrameMsg_Navigate_Type::RESTORE_WITH_POST; | 58 return FrameMsg_Navigate_Type::RESTORE_WITH_POST; |
58 return FrameMsg_Navigate_Type::RESTORE; | 59 return FrameMsg_Navigate_Type::RESTORE; |
59 } | 60 } |
60 | 61 |
61 return FrameMsg_Navigate_Type::NORMAL; | 62 return FrameMsg_Navigate_Type::NORMAL; |
62 } | 63 } |
63 | 64 |
64 void MakeNavigateParams(const NavigationEntryImpl& entry, | 65 void MakeNavigateParams(const NavigationEntryImpl& entry, |
65 const NavigationControllerImpl& controller, | 66 const NavigationControllerImpl& controller, |
66 NavigationController::ReloadType reload_type, | 67 NavigationController::ReloadType reload_type, |
| 68 base::TimeTicks navigation_start, |
67 FrameMsg_Navigate_Params* params) { | 69 FrameMsg_Navigate_Params* params) { |
68 params->page_id = entry.GetPageID(); | 70 params->page_id = entry.GetPageID(); |
69 params->should_clear_history_list = entry.should_clear_history_list(); | 71 params->should_clear_history_list = entry.should_clear_history_list(); |
70 params->should_replace_current_entry = entry.should_replace_entry(); | 72 params->should_replace_current_entry = entry.should_replace_entry(); |
71 if (entry.should_clear_history_list()) { | 73 if (entry.should_clear_history_list()) { |
72 // Set the history list related parameters to the same values a | 74 // Set the history list related parameters to the same values a |
73 // NavigationController would return before its first navigation. This will | 75 // NavigationController would return before its first navigation. This will |
74 // fully clear the RenderView's view of the session history. | 76 // fully clear the RenderView's view of the session history. |
75 params->pending_history_list_offset = -1; | 77 params->pending_history_list_offset = -1; |
76 params->current_history_list_offset = -1; | 78 params->current_history_list_offset = -1; |
77 params->current_history_list_length = 0; | 79 params->current_history_list_length = 0; |
78 } else { | 80 } else { |
79 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); | 81 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); |
80 params->current_history_list_offset = | 82 params->current_history_list_offset = |
81 controller.GetLastCommittedEntryIndex(); | 83 controller.GetLastCommittedEntryIndex(); |
82 params->current_history_list_length = controller.GetEntryCount(); | 84 params->current_history_list_length = controller.GetEntryCount(); |
83 } | 85 } |
84 params->url = entry.GetURL(); | 86 params->url = entry.GetURL(); |
85 if (!entry.GetBaseURLForDataURL().is_empty()) { | 87 if (!entry.GetBaseURLForDataURL().is_empty()) { |
86 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); | 88 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); |
87 params->history_url_for_data_url = entry.GetVirtualURL(); | 89 params->history_url_for_data_url = entry.GetVirtualURL(); |
88 } | 90 } |
89 params->referrer = entry.GetReferrer(); | 91 params->referrer = entry.GetReferrer(); |
90 params->transition = entry.GetTransitionType(); | 92 params->transition = entry.GetTransitionType(); |
91 params->page_state = entry.GetPageState(); | 93 params->page_state = entry.GetPageState(); |
92 params->navigation_type = | 94 params->navigation_type = |
93 GetNavigationType(controller.GetBrowserContext(), entry, reload_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. |
94 params->request_time = base::Time::Now(); | 99 params->request_time = base::Time::Now(); |
95 params->extra_headers = entry.extra_headers(); | 100 params->extra_headers = entry.extra_headers(); |
96 params->transferred_request_child_id = | 101 params->transferred_request_child_id = |
97 entry.transferred_global_request_id().child_id; | 102 entry.transferred_global_request_id().child_id; |
98 params->transferred_request_request_id = | 103 params->transferred_request_request_id = |
99 entry.transferred_global_request_id().request_id; | 104 entry.transferred_global_request_id().request_id; |
100 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent(); | 105 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent(); |
101 // Avoid downloading when in view-source mode. | 106 // Avoid downloading when in view-source mode. |
102 params->allow_download = !entry.IsViewSourceMode(); | 107 params->allow_download = !entry.IsViewSourceMode(); |
103 params->is_post = entry.GetHasPostData(); | 108 params->is_post = entry.GetHasPostData(); |
104 if (entry.GetBrowserInitiatedPostData()) { | 109 if (entry.GetBrowserInitiatedPostData()) { |
105 params->browser_initiated_post_data.assign( | 110 params->browser_initiated_post_data.assign( |
106 entry.GetBrowserInitiatedPostData()->front(), | 111 entry.GetBrowserInitiatedPostData()->front(), |
107 entry.GetBrowserInitiatedPostData()->front() + | 112 entry.GetBrowserInitiatedPostData()->front() + |
108 entry.GetBrowserInitiatedPostData()->size()); | 113 entry.GetBrowserInitiatedPostData()->size()); |
109 } | 114 } |
110 | 115 |
111 // Set the redirect chain to the navigation's redirects, unless we are | 116 // Set the redirect chain to the navigation's redirects, unless we are |
112 // returning to a completed navigation (whose previous redirects don't apply). | 117 // returning to a completed navigation (whose previous redirects don't apply). |
113 if (PageTransitionIsNewNavigation(params->transition)) { | 118 if (PageTransitionIsNewNavigation(params->transition)) { |
114 params->redirects = entry.GetRedirectChain(); | 119 params->redirects = entry.GetRedirectChain(); |
115 } else { | 120 } else { |
116 params->redirects.clear(); | 121 params->redirects.clear(); |
117 } | 122 } |
118 | 123 |
119 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | 124 params->can_load_local_resources = entry.GetCanLoadLocalResources(); |
120 params->frame_to_navigate = entry.GetFrameToNavigate(); | 125 params->frame_to_navigate = entry.GetFrameToNavigate(); |
| 126 params->browser_navigation_start = navigation_start; |
121 } | 127 } |
122 | 128 |
123 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { | 129 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { |
124 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) | 130 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) |
125 return rfh->frame_tree_node()->render_manager(); | 131 return rfh->frame_tree_node()->render_manager(); |
126 | 132 |
127 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); | 133 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
128 } | 134 } |
129 | 135 |
130 } // namespace | 136 } // namespace |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 TRACE_EVENT0("browser", "NavigatorImpl::NavigateToEntry"); | 321 TRACE_EVENT0("browser", "NavigatorImpl::NavigateToEntry"); |
316 | 322 |
317 // The renderer will reject IPC messages with URLs longer than | 323 // The renderer will reject IPC messages with URLs longer than |
318 // this limit, so don't attempt to navigate with a longer URL. | 324 // this limit, so don't attempt to navigate with a longer URL. |
319 if (entry.GetURL().spec().size() > GetMaxURLChars()) { | 325 if (entry.GetURL().spec().size() > GetMaxURLChars()) { |
320 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars() | 326 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars() |
321 << " characters."; | 327 << " characters."; |
322 return false; | 328 return false; |
323 } | 329 } |
324 | 330 |
| 331 // This will be used to set the Navigation Timing API navigationStart |
| 332 // 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 |
| 334 // capture the time needed for the RenderFrameHost initialization. |
| 335 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
| 336 |
325 RenderFrameHostManager* manager = | 337 RenderFrameHostManager* manager = |
326 render_frame_host->frame_tree_node()->render_manager(); | 338 render_frame_host->frame_tree_node()->render_manager(); |
327 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 339 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
328 if (!dest_render_frame_host) | 340 if (!dest_render_frame_host) |
329 return false; // Unable to create the desired RenderFrameHost. | 341 return false; // Unable to create the desired RenderFrameHost. |
330 | 342 |
331 // Make sure no code called via RFHM::Navigate clears the pending entry. | 343 // Make sure no code called via RFHM::Navigate clears the pending entry. |
332 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 344 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
333 | 345 |
334 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 346 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
335 // Double check that here. | 347 // Double check that here. |
336 int enabled_bindings = | 348 int enabled_bindings = |
337 dest_render_frame_host->render_view_host()->GetEnabledBindings(); | 349 dest_render_frame_host->render_view_host()->GetEnabledBindings(); |
338 bool is_allowed_in_web_ui_renderer = | 350 bool is_allowed_in_web_ui_renderer = |
339 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 351 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
340 controller_->GetBrowserContext(), entry.GetURL()); | 352 controller_->GetBrowserContext(), entry.GetURL()); |
341 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | 353 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
342 !is_allowed_in_web_ui_renderer) { | 354 !is_allowed_in_web_ui_renderer) { |
343 // Log the URL to help us diagnose any future failures of this CHECK. | 355 // Log the URL to help us diagnose any future failures of this CHECK. |
344 GetContentClient()->SetActiveURL(entry.GetURL()); | 356 GetContentClient()->SetActiveURL(entry.GetURL()); |
345 CHECK(0); | 357 CHECK(0); |
346 } | 358 } |
347 | 359 |
348 // Notify observers that we will navigate in this RenderFrame. | 360 // Notify observers that we will navigate in this RenderFrame. |
349 if (delegate_) | 361 if (delegate_) |
350 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); | 362 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); |
351 | 363 |
352 // Used for page load time metrics. | 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. |
353 current_load_start_ = base::TimeTicks::Now(); | 368 current_load_start_ = base::TimeTicks::Now(); |
354 | 369 |
355 // Navigate in the desired RenderFrameHost. | 370 // Navigate in the desired RenderFrameHost. |
356 FrameMsg_Navigate_Params navigate_params; | 371 FrameMsg_Navigate_Params navigate_params; |
357 MakeNavigateParams(entry, *controller_, reload_type, &navigate_params); | 372 MakeNavigateParams(entry, *controller_, reload_type, navigation_start, |
| 373 &navigate_params); |
358 dest_render_frame_host->Navigate(navigate_params); | 374 dest_render_frame_host->Navigate(navigate_params); |
359 | 375 |
360 // Make sure no code called via RFH::Navigate clears the pending entry. | 376 // Make sure no code called via RFH::Navigate clears the pending entry. |
361 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 377 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
362 | 378 |
363 if (entry.GetPageID() == -1) { | 379 if (entry.GetPageID() == -1) { |
364 // HACK!! This code suppresses javascript: URLs from being added to | 380 // HACK!! This code suppresses javascript: URLs from being added to |
365 // session history, which is what we want to do for javascript: URLs that | 381 // session history, which is what we want to do for javascript: URLs that |
366 // do not generate content. What we really need is a message from the | 382 // do not generate content. What we really need is a message from the |
367 // renderer telling us that a new page was not created. The same message | 383 // 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... |
626 | 642 |
627 // Navigations in Web UI pages count as browser-initiated navigations. | 643 // Navigations in Web UI pages count as browser-initiated navigations. |
628 params.is_renderer_initiated = false; | 644 params.is_renderer_initiated = false; |
629 } | 645 } |
630 | 646 |
631 if (delegate_) | 647 if (delegate_) |
632 delegate_->RequestOpenURL(render_frame_host, params); | 648 delegate_->RequestOpenURL(render_frame_host, params); |
633 } | 649 } |
634 | 650 |
635 } // namespace content | 651 } // namespace content |
OLD | NEW |