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