Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl.cc

Issue 1110943003: Revert of Classify navigations without page id in parallel to the existing classifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 // pending parameters that were saved. 812 // pending parameters that were saved.
813 if (params.url_is_unreachable && failed_pending_entry_id_ != 0) { 813 if (params.url_is_unreachable && failed_pending_entry_id_ != 0) {
814 details->did_replace_entry = failed_pending_entry_should_replace_; 814 details->did_replace_entry = failed_pending_entry_should_replace_;
815 } else { 815 } else {
816 details->did_replace_entry = pending_entry_ && 816 details->did_replace_entry = pending_entry_ &&
817 pending_entry_->should_replace_entry(); 817 pending_entry_->should_replace_entry();
818 } 818 }
819 819
820 // Do navigation-type specific actions. These will make and commit an entry. 820 // Do navigation-type specific actions. These will make and commit an entry.
821 details->type = ClassifyNavigation(rfh, params); 821 details->type = ClassifyNavigation(rfh, params);
822 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
823 switches::kSitePerProcess)) {
824 // For site-per-process, both ClassifyNavigation methods get it wrong (see
825 // http://crbug.com/464014) so don't worry about a mismatch if that's the
826 // case.
827 DCHECK_EQ(details->type, ClassifyNavigationWithoutPageID(rfh, params));
828 }
829 822
830 // is_in_page must be computed before the entry gets committed. 823 // is_in_page must be computed before the entry gets committed.
831 details->is_in_page = AreURLsInPageNavigation(rfh->GetLastCommittedURL(), 824 details->is_in_page = AreURLsInPageNavigation(rfh->GetLastCommittedURL(),
832 params.url, params.was_within_same_page, rfh); 825 params.url, params.was_within_same_page, rfh);
833 826
834 switch (details->type) { 827 switch (details->type) {
835 case NAVIGATION_TYPE_NEW_PAGE: 828 case NAVIGATION_TYPE_NEW_PAGE:
836 RendererDidNavigateToNewPage(rfh, params, details->did_replace_entry); 829 RendererDidNavigateToNewPage(rfh, params, details->did_replace_entry);
837 break; 830 break;
838 case NAVIGATION_TYPE_EXISTING_PAGE: 831 case NAVIGATION_TYPE_EXISTING_PAGE:
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 if (AreURLsInPageNavigation(existing_entry->GetURL(), params.url, 1056 if (AreURLsInPageNavigation(existing_entry->GetURL(), params.url,
1064 params.was_within_same_page, rfh)) { 1057 params.was_within_same_page, rfh)) {
1065 return NAVIGATION_TYPE_IN_PAGE; 1058 return NAVIGATION_TYPE_IN_PAGE;
1066 } 1059 }
1067 1060
1068 // Since we weeded out "new" navigations above, we know this is an existing 1061 // Since we weeded out "new" navigations above, we know this is an existing
1069 // (back/forward) navigation. 1062 // (back/forward) navigation.
1070 return NAVIGATION_TYPE_EXISTING_PAGE; 1063 return NAVIGATION_TYPE_EXISTING_PAGE;
1071 } 1064 }
1072 1065
1073 NavigationType NavigationControllerImpl::ClassifyNavigationWithoutPageID(
1074 RenderFrameHostImpl* rfh,
1075 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) const {
1076 if (params.did_create_new_entry) {
1077 // A new entry. We may or may not have a pending entry for the page, and
1078 // this may or may not be the main frame.
1079 if (ui::PageTransitionIsMainFrame(params.transition)) {
1080 // TODO(avi): I want to use |if (!rfh->GetParent())| here but lots of unit
1081 // tests fake auto subframe commits by sending the main frame a
1082 // PAGE_TRANSITION_AUTO_SUBFRAME transition. Fix those, and adjust here.
1083 return NAVIGATION_TYPE_NEW_PAGE;
1084 }
1085
1086 // When this is a new subframe navigation, we should have a committed page
1087 // in which it's a subframe. This may not be the case when an iframe is
1088 // navigated on a popup navigated to about:blank (the iframe would be
1089 // written into the popup by script on the main page). For these cases,
1090 // there isn't any navigation stuff we can do, so just ignore it.
1091 if (!GetLastCommittedEntry())
1092 return NAVIGATION_TYPE_NAV_IGNORE;
1093
1094 // Valid subframe navigation.
1095 return NAVIGATION_TYPE_NEW_SUBFRAME;
1096 }
1097
1098 // We only clear the session history when navigating to a new page.
1099 DCHECK(!params.history_list_was_cleared);
1100
1101 if (!ui::PageTransitionIsMainFrame(params.transition)) {
1102 // All manual subframes would be did_create_new_entry and handled above, so
1103 // we know this is auto.
1104 if (GetLastCommittedEntry()) {
1105 return NAVIGATION_TYPE_AUTO_SUBFRAME;
1106 } else {
1107 // We ignore subframes created in non-committed pages; we'd appreciate if
1108 // people stopped doing that.
1109 return NAVIGATION_TYPE_NAV_IGNORE;
1110 }
1111 }
1112
1113 if (params.nav_entry_id == 0) {
1114 // This is a renderer-initiated navigation (nav_entry_id == 0), but didn't
1115 // create a new page.
1116
1117 // Just like above in the did_create_new_entry case, it's possible to
1118 // scribble onto an uncommitted page. Again, there isn't any navigation
1119 // stuff that we can do, so ignore it here as well.
1120 if (!GetLastCommittedEntry())
1121 return NAVIGATION_TYPE_NAV_IGNORE;
1122
1123 if (params.was_within_same_page) {
1124 // This is history.replaceState(), which is renderer-initiated yet within
1125 // the same page.
1126 return NAVIGATION_TYPE_IN_PAGE;
1127 } else {
1128 // This is history.reload() or a client-side redirect.
1129 return NAVIGATION_TYPE_EXISTING_PAGE;
1130 }
1131 }
1132
1133 if (pending_entry_ && pending_entry_index_ == -1 &&
1134 pending_entry_->GetUniqueID() == params.nav_entry_id) {
1135 // In this case, we have a pending entry for a load of a new URL but Blink
1136 // didn't do a new navigation (params.did_create_new_entry). This happens
1137 // when you press enter in the URL bar to reload. We will create a pending
1138 // entry, but Blink will convert it to a reload since it's the same page and
1139 // not create a new entry for it (the user doesn't want to have a new
1140 // back/forward entry when they do this). Therefore we want to just ignore
1141 // the pending entry and go back to where we were (the "existing entry").
1142 return NAVIGATION_TYPE_SAME_PAGE;
1143 }
1144
1145 if (params.intended_as_new_entry) {
1146 // This was intended to be a navigation to a new entry but the pending entry
1147 // got cleared in the meanwhile. Classify as EXISTING_PAGE because we may or
1148 // may not have a pending entry.
1149 return NAVIGATION_TYPE_EXISTING_PAGE;
1150 }
1151
1152 if (params.url_is_unreachable && failed_pending_entry_id_ != 0 &&
1153 params.nav_entry_id == failed_pending_entry_id_) {
1154 // If the renderer was going to a new pending entry that got cleared because
1155 // of an error, this is the case of the user trying to retry a failed load
1156 // by pressing return. Classify as EXISTING_PAGE because we probably don't
1157 // have a pending entry.
1158 return NAVIGATION_TYPE_EXISTING_PAGE;
1159 }
1160
1161 // Now we know that the notification is for an existing page. Find that entry.
1162 int existing_entry_index = GetEntryIndexWithUniqueID(params.nav_entry_id);
1163 if (existing_entry_index == -1) {
1164 // The page was not found. It could have been pruned because of the limit on
1165 // back/forward entries (not likely since we'll usually tell it to navigate
1166 // to such entries). It could also mean that the renderer is smoking crack.
1167 // TODO(avi): Crash the renderer like we do in the old ClassifyNavigation?
1168 NOTREACHED() << "Could not find nav entry with id " << params.nav_entry_id;
1169 return NAVIGATION_TYPE_NAV_IGNORE;
1170 }
1171
1172 // Any top-level navigations with the same base (minus the reference fragment)
1173 // are in-page navigations. (We weeded out subframe navigations above.) Most
1174 // of the time this doesn't matter since Blink doesn't tell us about subframe
1175 // navigations that don't actually navigate, but it can happen when there is
1176 // an encoding override (it always sends a navigation request).
1177 NavigationEntryImpl* existing_entry = entries_[existing_entry_index].get();
1178 if (AreURLsInPageNavigation(existing_entry->GetURL(), params.url,
1179 params.was_within_same_page, rfh)) {
1180 return NAVIGATION_TYPE_IN_PAGE;
1181 }
1182
1183 // Since we weeded out "new" navigations above, we know this is an existing
1184 // (back/forward) navigation.
1185 return NAVIGATION_TYPE_EXISTING_PAGE;
1186 }
1187
1188 void NavigationControllerImpl::RendererDidNavigateToNewPage( 1066 void NavigationControllerImpl::RendererDidNavigateToNewPage(
1189 RenderFrameHostImpl* rfh, 1067 RenderFrameHostImpl* rfh,
1190 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, 1068 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
1191 bool replace_entry) { 1069 bool replace_entry) {
1192 NavigationEntryImpl* new_entry; 1070 NavigationEntryImpl* new_entry;
1193 bool update_virtual_url; 1071 bool update_virtual_url;
1194 // Only make a copy of the pending entry if it is appropriate for the new page 1072 // Only make a copy of the pending entry if it is appropriate for the new page
1195 // that was just loaded. We verify this at a coarse grain by checking that 1073 // that was just loaded. We verify this at a coarse grain by checking that
1196 // the SiteInstance hasn't been assigned to something else. 1074 // the SiteInstance hasn't been assigned to something else.
1197 if (pending_entry_ && 1075 if (pending_entry_ &&
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 int NavigationControllerImpl::GetEntryIndexWithPageID( 1817 int NavigationControllerImpl::GetEntryIndexWithPageID(
1940 SiteInstance* instance, int32 page_id) const { 1818 SiteInstance* instance, int32 page_id) const {
1941 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) { 1819 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) {
1942 if ((entries_[i]->site_instance() == instance) && 1820 if ((entries_[i]->site_instance() == instance) &&
1943 (entries_[i]->GetPageID() == page_id)) 1821 (entries_[i]->GetPageID() == page_id))
1944 return i; 1822 return i;
1945 } 1823 }
1946 return -1; 1824 return -1;
1947 } 1825 }
1948 1826
1949 int NavigationControllerImpl::GetEntryIndexWithUniqueID(
1950 int nav_entry_id) const {
1951 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) {
1952 if (entries_[i]->GetUniqueID() == nav_entry_id)
1953 return i;
1954 }
1955 return -1;
1956 }
1957
1958 NavigationEntryImpl* NavigationControllerImpl::GetTransientEntry() const { 1827 NavigationEntryImpl* NavigationControllerImpl::GetTransientEntry() const {
1959 if (transient_entry_index_ == -1) 1828 if (transient_entry_index_ == -1)
1960 return NULL; 1829 return NULL;
1961 return entries_[transient_entry_index_].get(); 1830 return entries_[transient_entry_index_].get();
1962 } 1831 }
1963 1832
1964 void NavigationControllerImpl::SetTransientEntry(NavigationEntry* entry) { 1833 void NavigationControllerImpl::SetTransientEntry(NavigationEntry* entry) {
1965 // Discard any current transient entry, we can only have one at a time. 1834 // Discard any current transient entry, we can only have one at a time.
1966 int index = 0; 1835 int index = 0;
1967 if (last_committed_entry_index_ != -1) 1836 if (last_committed_entry_index_ != -1)
(...skipping 23 matching lines...) Expand all
1991 } 1860 }
1992 } 1861 }
1993 } 1862 }
1994 1863
1995 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 1864 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
1996 const base::Callback<base::Time()>& get_timestamp_callback) { 1865 const base::Callback<base::Time()>& get_timestamp_callback) {
1997 get_timestamp_callback_ = get_timestamp_callback; 1866 get_timestamp_callback_ = get_timestamp_callback;
1998 } 1867 }
1999 1868
2000 } // namespace content 1869 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698