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/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 | 71 |
72 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { | 72 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { |
73 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 73 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
74 switches::kSitePerProcess)) | 74 switches::kSitePerProcess)) |
75 return rfh->frame_tree_node()->render_manager(); | 75 return rfh->frame_tree_node()->render_manager(); |
76 | 76 |
77 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); | 77 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
78 } | 78 } |
79 | 79 |
| 80 HistoryNavigationParams MakeHistoryParams( |
| 81 const NavigationEntryImpl& entry, |
| 82 NavigationControllerImpl* controller) { |
| 83 int pending_history_list_offset = controller->GetIndexOfEntry(&entry); |
| 84 int current_history_list_offset = controller->GetLastCommittedEntryIndex(); |
| 85 int current_history_list_length = controller->GetEntryCount(); |
| 86 if (entry.should_clear_history_list()) { |
| 87 // Set the history list related parameters to the same values a |
| 88 // NavigationController would return before its first navigation. This will |
| 89 // fully clear the RenderView's view of the session history. |
| 90 pending_history_list_offset = -1; |
| 91 current_history_list_offset = -1; |
| 92 current_history_list_length = 0; |
| 93 } |
| 94 return HistoryNavigationParams( |
| 95 entry.GetPageState(), entry.GetPageID(), pending_history_list_offset, |
| 96 current_history_list_offset, current_history_list_length, |
| 97 entry.should_clear_history_list()); |
| 98 } |
| 99 |
80 void MakeNavigateParams(const NavigationEntryImpl& entry, | 100 void MakeNavigateParams(const NavigationEntryImpl& entry, |
81 NavigationControllerImpl* controller, | 101 NavigationControllerImpl* controller, |
82 NavigationController::ReloadType reload_type, | 102 NavigationController::ReloadType reload_type, |
83 base::TimeTicks navigation_start, | 103 base::TimeTicks navigation_start, |
84 FrameMsg_Navigate_Params* params) { | 104 FrameMsg_Navigate_Params* params) { |
85 FrameMsg_UILoadMetricsReportType::Value report_type = | 105 FrameMsg_UILoadMetricsReportType::Value report_type = |
86 FrameMsg_UILoadMetricsReportType::NO_REPORT; | 106 FrameMsg_UILoadMetricsReportType::NO_REPORT; |
87 base::TimeTicks ui_timestamp = base::TimeTicks(); | 107 base::TimeTicks ui_timestamp = base::TimeTicks(); |
88 #if defined(OS_ANDROID) | 108 #if defined(OS_ANDROID) |
89 if (!entry.intent_received_timestamp().is_null()) | 109 if (!entry.intent_received_timestamp().is_null()) |
90 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; | 110 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; |
91 ui_timestamp = entry.intent_received_timestamp(); | 111 ui_timestamp = entry.intent_received_timestamp(); |
92 #endif | 112 #endif |
93 | 113 |
94 params->common_params = CommonNavigationParams( | 114 params->common_params = CommonNavigationParams( |
95 entry.GetURL(), entry.GetReferrer(), entry.GetTransitionType(), | 115 entry.GetURL(), entry.GetReferrer(), entry.GetTransitionType(), |
96 GetNavigationType(controller->GetBrowserContext(), entry, reload_type), | 116 GetNavigationType(controller->GetBrowserContext(), entry, reload_type), |
97 !entry.IsViewSourceMode(), ui_timestamp, report_type, | 117 !entry.IsViewSourceMode(), ui_timestamp, report_type, |
98 entry.GetBaseURLForDataURL(), entry.GetHistoryURLForDataURL()); | 118 entry.GetBaseURLForDataURL(), entry.GetHistoryURLForDataURL()); |
99 params->commit_params = CommitNavigationParams( | 119 params->commit_params = CommitNavigationParams( |
100 entry.GetPageState(), entry.GetIsOverridingUserAgent(), navigation_start); | 120 entry.GetIsOverridingUserAgent(), navigation_start); |
| 121 params->history_params = MakeHistoryParams(entry, controller); |
| 122 |
101 params->is_post = entry.GetHasPostData(); | 123 params->is_post = entry.GetHasPostData(); |
102 params->extra_headers = entry.extra_headers(); | 124 params->extra_headers = entry.extra_headers(); |
103 if (entry.GetBrowserInitiatedPostData()) { | 125 if (entry.GetBrowserInitiatedPostData()) { |
104 params->browser_initiated_post_data.assign( | 126 params->browser_initiated_post_data.assign( |
105 entry.GetBrowserInitiatedPostData()->front(), | 127 entry.GetBrowserInitiatedPostData()->front(), |
106 entry.GetBrowserInitiatedPostData()->front() + | 128 entry.GetBrowserInitiatedPostData()->front() + |
107 entry.GetBrowserInitiatedPostData()->size()); | 129 entry.GetBrowserInitiatedPostData()->size()); |
108 } | 130 } |
109 | 131 |
110 params->should_replace_current_entry = entry.should_replace_entry(); | 132 params->should_replace_current_entry = entry.should_replace_entry(); |
111 // This is used by the old performance infrastructure to set up DocumentState | 133 // This is used by the old performance infrastructure to set up DocumentState |
112 // associated with the RenderView. | 134 // associated with the RenderView. |
113 // TODO(ppi): make it go away. | 135 // TODO(ppi): make it go away. |
114 params->request_time = base::Time::Now(); | 136 params->request_time = base::Time::Now(); |
115 params->transferred_request_child_id = | 137 params->transferred_request_child_id = |
116 entry.transferred_global_request_id().child_id; | 138 entry.transferred_global_request_id().child_id; |
117 params->transferred_request_request_id = | 139 params->transferred_request_request_id = |
118 entry.transferred_global_request_id().request_id; | 140 entry.transferred_global_request_id().request_id; |
119 | 141 |
120 params->page_id = entry.GetPageID(); | |
121 params->should_clear_history_list = entry.should_clear_history_list(); | |
122 if (entry.should_clear_history_list()) { | |
123 // Set the history list related parameters to the same values a | |
124 // NavigationController would return before its first navigation. This will | |
125 // fully clear the RenderView's view of the session history. | |
126 params->pending_history_list_offset = -1; | |
127 params->current_history_list_offset = -1; | |
128 params->current_history_list_length = 0; | |
129 } else { | |
130 params->pending_history_list_offset = controller->GetIndexOfEntry(&entry); | |
131 params->current_history_list_offset = | |
132 controller->GetLastCommittedEntryIndex(); | |
133 params->current_history_list_length = controller->GetEntryCount(); | |
134 } | |
135 // Set the redirect chain to the navigation's redirects, unless we are | 142 // Set the redirect chain to the navigation's redirects, unless we are |
136 // returning to a completed navigation (whose previous redirects don't apply). | 143 // returning to a completed navigation (whose previous redirects don't apply). |
137 if (ui::PageTransitionIsNewNavigation(params->common_params.transition)) { | 144 if (ui::PageTransitionIsNewNavigation(params->common_params.transition)) { |
138 params->redirects = entry.GetRedirectChain(); | 145 params->redirects = entry.GetRedirectChain(); |
139 } else { | 146 } else { |
140 params->redirects.clear(); | 147 params->redirects.clear(); |
141 } | 148 } |
142 | 149 |
143 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | 150 params->can_load_local_resources = entry.GetCanLoadLocalResources(); |
144 params->frame_to_navigate = entry.GetFrameToNavigate(); | 151 params->frame_to_navigate = entry.GetFrameToNavigate(); |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 ongoing_navigation_request->begin_params().has_user_gesture) && | 713 ongoing_navigation_request->begin_params().has_user_gesture) && |
707 !begin_params.has_user_gesture) { | 714 !begin_params.has_user_gesture) { |
708 return; | 715 return; |
709 } | 716 } |
710 | 717 |
711 // In all other cases the current navigation, if any, is canceled and a new | 718 // In all other cases the current navigation, if any, is canceled and a new |
712 // NavigationRequest is created and stored in the map. Actual cancellation | 719 // NavigationRequest is created and stored in the map. Actual cancellation |
713 // happens when the existing request map entry is replaced and destroyed. | 720 // happens when the existing request map entry is replaced and destroyed. |
714 scoped_ptr<NavigationRequest> navigation_request = | 721 scoped_ptr<NavigationRequest> navigation_request = |
715 NavigationRequest::CreateRendererInitiated( | 722 NavigationRequest::CreateRendererInitiated( |
716 frame_tree_node, common_params, begin_params, body); | 723 frame_tree_node, common_params, begin_params, body, |
| 724 controller_->GetLastCommittedEntryIndex(), |
| 725 controller_->GetEntryCount()); |
717 navigation_request_map_.set( | 726 navigation_request_map_.set( |
718 frame_tree_node->frame_tree_node_id(), navigation_request.Pass()); | 727 frame_tree_node->frame_tree_node_id(), navigation_request.Pass()); |
719 | 728 |
720 if (frame_tree_node->IsMainFrame()) | 729 if (frame_tree_node->IsMainFrame()) |
721 navigation_data_.reset(); | 730 navigation_data_.reset(); |
722 | 731 |
723 BeginNavigation(frame_tree_node); | 732 BeginNavigation(frame_tree_node); |
724 } | 733 } |
725 | 734 |
726 // PlzNavigate | 735 // PlzNavigate |
(...skipping 21 matching lines...) Expand all Loading... |
748 | 757 |
749 // Select an appropriate renderer to commit the navigation. | 758 // Select an appropriate renderer to commit the navigation. |
750 RenderFrameHostImpl* render_frame_host = | 759 RenderFrameHostImpl* render_frame_host = |
751 frame_tree_node->render_manager()->GetFrameHostForNavigation( | 760 frame_tree_node->render_manager()->GetFrameHostForNavigation( |
752 *navigation_request); | 761 *navigation_request); |
753 CheckWebUIRendererDoesNotDisplayNormalURL( | 762 CheckWebUIRendererDoesNotDisplayNormalURL( |
754 render_frame_host, navigation_request->common_params().url); | 763 render_frame_host, navigation_request->common_params().url); |
755 | 764 |
756 render_frame_host->CommitNavigation(response, body.Pass(), | 765 render_frame_host->CommitNavigation(response, body.Pass(), |
757 navigation_request->common_params(), | 766 navigation_request->common_params(), |
758 navigation_request->commit_params()); | 767 navigation_request->commit_params(), |
| 768 navigation_request->history_params()); |
759 } | 769 } |
760 | 770 |
761 // PlzNavigate | 771 // PlzNavigate |
762 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { | 772 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { |
763 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 773 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
764 switches::kEnableBrowserSideNavigation)); | 774 switches::kEnableBrowserSideNavigation)); |
765 navigation_request_map_.erase(frame_tree_node->frame_tree_node_id()); | 775 navigation_request_map_.erase(frame_tree_node->frame_tree_node_id()); |
766 if (frame_tree_node->IsMainFrame()) | 776 if (frame_tree_node->IsMainFrame()) |
767 navigation_data_.reset(); | 777 navigation_data_.reset(); |
768 // TODO(carlosk): move this cleanup into the NavigationRequest destructor once | 778 // TODO(carlosk): move this cleanup into the NavigationRequest destructor once |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 NavigationController::ReloadType reload_type, | 842 NavigationController::ReloadType reload_type, |
833 base::TimeTicks navigation_start) { | 843 base::TimeTicks navigation_start) { |
834 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 844 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
835 switches::kEnableBrowserSideNavigation)); | 845 switches::kEnableBrowserSideNavigation)); |
836 DCHECK(frame_tree_node); | 846 DCHECK(frame_tree_node); |
837 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); | 847 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); |
838 FrameMsg_Navigate_Type::Value navigation_type = | 848 FrameMsg_Navigate_Type::Value navigation_type = |
839 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); | 849 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
840 scoped_ptr<NavigationRequest> navigation_request = | 850 scoped_ptr<NavigationRequest> navigation_request = |
841 NavigationRequest::CreateBrowserInitiated( | 851 NavigationRequest::CreateBrowserInitiated( |
842 frame_tree_node, entry, navigation_type, navigation_start); | 852 frame_tree_node, entry, navigation_type, navigation_start, |
| 853 MakeHistoryParams(entry, controller_)); |
843 // TODO(clamy): Check if navigations are blocked and if so store the | 854 // TODO(clamy): Check if navigations are blocked and if so store the |
844 // parameters. | 855 // parameters. |
845 | 856 |
846 // If there is an ongoing request, replace it. | 857 // If there is an ongoing request, replace it. |
847 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); | 858 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); |
848 | 859 |
849 // Have the current renderer execute its beforeUnload event if needed. If it | 860 // Have the current renderer execute its beforeUnload event if needed. If it |
850 // is not needed (eg. the renderer is not live), BeginNavigation should get | 861 // is not needed (eg. the renderer is not live), BeginNavigation should get |
851 // called. | 862 // called. |
852 NavigationRequest* request_to_send = | 863 NavigationRequest* request_to_send = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", | 932 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", |
922 time_to_commit); | 933 time_to_commit); |
923 UMA_HISTOGRAM_TIMES( | 934 UMA_HISTOGRAM_TIMES( |
924 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", | 935 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", |
925 time_to_network); | 936 time_to_network); |
926 } | 937 } |
927 navigation_data_.reset(); | 938 navigation_data_.reset(); |
928 } | 939 } |
929 | 940 |
930 } // namespace content | 941 } // namespace content |
OLD | NEW |