| 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 /* | 5 /* |
| 6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
| 9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
| 10 * | 10 * |
| (...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 // Since we weeded out "new" navigations above, we know this is an existing | 1094 // Since we weeded out "new" navigations above, we know this is an existing |
| 1095 // (back/forward) navigation. | 1095 // (back/forward) navigation. |
| 1096 return NAVIGATION_TYPE_EXISTING_PAGE; | 1096 return NAVIGATION_TYPE_EXISTING_PAGE; |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 void NavigationControllerImpl::RendererDidNavigateToNewPage( | 1099 void NavigationControllerImpl::RendererDidNavigateToNewPage( |
| 1100 RenderFrameHostImpl* rfh, | 1100 RenderFrameHostImpl* rfh, |
| 1101 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 1101 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 1102 bool is_in_page, | 1102 bool is_same_document, |
| 1103 bool replace_entry, | 1103 bool replace_entry, |
| 1104 NavigationHandleImpl* handle) { | 1104 NavigationHandleImpl* handle) { |
| 1105 std::unique_ptr<NavigationEntryImpl> new_entry; | 1105 std::unique_ptr<NavigationEntryImpl> new_entry; |
| 1106 bool update_virtual_url = false; | 1106 bool update_virtual_url = false; |
| 1107 | 1107 |
| 1108 // First check if this is an in-page navigation. If so, clone the current | 1108 // First check if this is an in-page navigation. If so, clone the current |
| 1109 // entry instead of looking at the pending entry, because the pending entry | 1109 // entry instead of looking at the pending entry, because the pending entry |
| 1110 // does not have any subframe history items. | 1110 // does not have any subframe history items. |
| 1111 if (is_in_page && GetLastCommittedEntry()) { | 1111 if (is_same_document && GetLastCommittedEntry()) { |
| 1112 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( | 1112 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( |
| 1113 params.frame_unique_name, params.item_sequence_number, | 1113 params.frame_unique_name, params.item_sequence_number, |
| 1114 params.document_sequence_number, rfh->GetSiteInstance(), nullptr, | 1114 params.document_sequence_number, rfh->GetSiteInstance(), nullptr, |
| 1115 params.url, params.referrer, params.method, params.post_id); | 1115 params.url, params.referrer, params.method, params.post_id); |
| 1116 new_entry = GetLastCommittedEntry()->CloneAndReplace( | 1116 new_entry = GetLastCommittedEntry()->CloneAndReplace( |
| 1117 frame_entry, true, rfh->frame_tree_node(), | 1117 frame_entry, true, rfh->frame_tree_node(), |
| 1118 delegate_->GetFrameTree()->root()); | 1118 delegate_->GetFrameTree()->root()); |
| 1119 if (new_entry->GetURL().GetOrigin() != params.url.GetOrigin()) { | 1119 if (new_entry->GetURL().GetOrigin() != params.url.GetOrigin()) { |
| 1120 // TODO(jam): we had one report of this with a URL that was redirecting to | 1120 // TODO(jam): we had one report of this with a URL that was redirecting to |
| 1121 // only tildes. Until we understand that better, don't copy the cert in | 1121 // only tildes. Until we understand that better, don't copy the cert in |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 | 1187 |
| 1188 // Update the FrameNavigationEntry for new main frame commits. | 1188 // Update the FrameNavigationEntry for new main frame commits. |
| 1189 FrameNavigationEntry* frame_entry = | 1189 FrameNavigationEntry* frame_entry = |
| 1190 new_entry->GetFrameEntry(rfh->frame_tree_node()); | 1190 new_entry->GetFrameEntry(rfh->frame_tree_node()); |
| 1191 frame_entry->set_frame_unique_name(params.frame_unique_name); | 1191 frame_entry->set_frame_unique_name(params.frame_unique_name); |
| 1192 frame_entry->set_item_sequence_number(params.item_sequence_number); | 1192 frame_entry->set_item_sequence_number(params.item_sequence_number); |
| 1193 frame_entry->set_document_sequence_number(params.document_sequence_number); | 1193 frame_entry->set_document_sequence_number(params.document_sequence_number); |
| 1194 frame_entry->set_method(params.method); | 1194 frame_entry->set_method(params.method); |
| 1195 frame_entry->set_post_id(params.post_id); | 1195 frame_entry->set_post_id(params.post_id); |
| 1196 | 1196 |
| 1197 // history.pushState() is classified as a navigation to a new page, but | 1197 // history.pushState() is classified as a navigation to a new page, but sets |
| 1198 // sets is_in_page to true. In this case, we already have the title and | 1198 // is_same_document to true. In this case, we already have the title and |
| 1199 // favicon available, so set them immediately. | 1199 // favicon available, so set them immediately. |
| 1200 if (is_in_page && GetLastCommittedEntry()) { | 1200 if (is_same_document && GetLastCommittedEntry()) { |
| 1201 new_entry->SetTitle(GetLastCommittedEntry()->GetTitle()); | 1201 new_entry->SetTitle(GetLastCommittedEntry()->GetTitle()); |
| 1202 new_entry->GetFavicon() = GetLastCommittedEntry()->GetFavicon(); | 1202 new_entry->GetFavicon() = GetLastCommittedEntry()->GetFavicon(); |
| 1203 } | 1203 } |
| 1204 | 1204 |
| 1205 DCHECK(!params.history_list_was_cleared || !replace_entry); | 1205 DCHECK(!params.history_list_was_cleared || !replace_entry); |
| 1206 // The browser requested to clear the session history when it initiated the | 1206 // The browser requested to clear the session history when it initiated the |
| 1207 // navigation. Now we know that the renderer has updated its state accordingly | 1207 // navigation. Now we know that the renderer has updated its state accordingly |
| 1208 // and it is safe to also clear the browser side history. | 1208 // and it is safe to also clear the browser side history. |
| 1209 if (params.history_list_was_cleared) { | 1209 if (params.history_list_was_cleared) { |
| 1210 DiscardNonCommittedEntriesInternal(); | 1210 DiscardNonCommittedEntriesInternal(); |
| 1211 entries_.clear(); | 1211 entries_.clear(); |
| 1212 last_committed_entry_index_ = -1; | 1212 last_committed_entry_index_ = -1; |
| 1213 } | 1213 } |
| 1214 | 1214 |
| 1215 InsertOrReplaceEntry(std::move(new_entry), replace_entry); | 1215 InsertOrReplaceEntry(std::move(new_entry), replace_entry); |
| 1216 } | 1216 } |
| 1217 | 1217 |
| 1218 void NavigationControllerImpl::RendererDidNavigateToExistingPage( | 1218 void NavigationControllerImpl::RendererDidNavigateToExistingPage( |
| 1219 RenderFrameHostImpl* rfh, | 1219 RenderFrameHostImpl* rfh, |
| 1220 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 1220 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 1221 bool is_in_page, | 1221 bool is_same_document, |
| 1222 bool was_restored, | 1222 bool was_restored, |
| 1223 NavigationHandleImpl* handle) { | 1223 NavigationHandleImpl* handle) { |
| 1224 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " | 1224 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " |
| 1225 << "that a last committed entry exists."; | 1225 << "that a last committed entry exists."; |
| 1226 | 1226 |
| 1227 // We should only get here for main frame navigations. | 1227 // We should only get here for main frame navigations. |
| 1228 DCHECK(!rfh->GetParent()); | 1228 DCHECK(!rfh->GetParent()); |
| 1229 | 1229 |
| 1230 // TODO(creis): Classify location.replace as NEW_PAGE instead of EXISTING_PAGE | 1230 // TODO(creis): Classify location.replace as NEW_PAGE instead of EXISTING_PAGE |
| 1231 // in https://crbug.com/596707. | 1231 // in https://crbug.com/596707. |
| 1232 | 1232 |
| 1233 NavigationEntryImpl* entry; | 1233 NavigationEntryImpl* entry; |
| 1234 if (params.intended_as_new_entry) { | 1234 if (params.intended_as_new_entry) { |
| 1235 // This was intended as a new entry but the pending entry was lost in the | 1235 // This was intended as a new entry but the pending entry was lost in the |
| 1236 // meanwhile and no new page was created. We are stuck at the last committed | 1236 // meanwhile and no new page was created. We are stuck at the last committed |
| 1237 // entry. | 1237 // entry. |
| 1238 entry = GetLastCommittedEntry(); | 1238 entry = GetLastCommittedEntry(); |
| 1239 // If this is an in-page navigation, then there's no SSLStatus in the | 1239 // If this is a same document navigation, then there's no SSLStatus in the |
| 1240 // NavigationHandle so don't overwrite the existing entry's SSLStatus. | 1240 // NavigationHandle so don't overwrite the existing entry's SSLStatus. |
| 1241 if (!is_in_page) | 1241 if (!is_same_document) |
| 1242 entry->GetSSL() = handle->ssl_status(); | 1242 entry->GetSSL() = handle->ssl_status(); |
| 1243 } else if (params.nav_entry_id) { | 1243 } else if (params.nav_entry_id) { |
| 1244 // This is a browser-initiated navigation (back/forward/reload). | 1244 // This is a browser-initiated navigation (back/forward/reload). |
| 1245 entry = GetEntryWithUniqueID(params.nav_entry_id); | 1245 entry = GetEntryWithUniqueID(params.nav_entry_id); |
| 1246 | 1246 |
| 1247 if (is_in_page) { | 1247 if (is_same_document) { |
| 1248 // There's no SSLStatus in the NavigationHandle for in-page navigations, | 1248 // There's no SSLStatus in the NavigationHandle for same document |
| 1249 // so normally we leave |entry|'s SSLStatus as is. However if this was a | 1249 // navigations, so normally we leave |entry|'s SSLStatus as is. However if |
| 1250 // restored in-page navigation entry, then it won't have an SSLStatus. So | 1250 // this was a restored same document navigation entry, then it won't have |
| 1251 // we need to copy over the SSLStatus from the entry that navigated it. | 1251 // an SSLStatus. So we need to copy over the SSLStatus from the entry that |
| 1252 // navigated it. |
| 1252 NavigationEntryImpl* last_entry = GetLastCommittedEntry(); | 1253 NavigationEntryImpl* last_entry = GetLastCommittedEntry(); |
| 1253 if (entry->GetURL().GetOrigin() == last_entry->GetURL().GetOrigin() && | 1254 if (entry->GetURL().GetOrigin() == last_entry->GetURL().GetOrigin() && |
| 1254 last_entry->GetSSL().initialized && !entry->GetSSL().initialized && | 1255 last_entry->GetSSL().initialized && !entry->GetSSL().initialized && |
| 1255 was_restored) { | 1256 was_restored) { |
| 1256 entry->GetSSL() = last_entry->GetSSL(); | 1257 entry->GetSSL() = last_entry->GetSSL(); |
| 1257 } | 1258 } |
| 1258 } else { | 1259 } else { |
| 1259 // When restoring a tab, the serialized NavigationEntry doesn't have the | 1260 // When restoring a tab, the serialized NavigationEntry doesn't have the |
| 1260 // SSL state. | 1261 // SSL state. |
| 1261 entry->GetSSL() = handle->ssl_status(); | 1262 entry->GetSSL() = handle->ssl_status(); |
| 1262 } | 1263 } |
| 1263 } else { | 1264 } else { |
| 1264 // This is renderer-initiated. The only kinds of renderer-initated | 1265 // This is renderer-initiated. The only kinds of renderer-initated |
| 1265 // navigations that are EXISTING_PAGE are reloads and location.replace, | 1266 // navigations that are EXISTING_PAGE are reloads and location.replace, |
| 1266 // which land us at the last committed entry. | 1267 // which land us at the last committed entry. |
| 1267 entry = GetLastCommittedEntry(); | 1268 entry = GetLastCommittedEntry(); |
| 1268 | 1269 |
| 1269 // If this is an in-page navigation, then there's no SSLStatus in the | 1270 // If this is a same document navigation, then there's no SSLStatus in the |
| 1270 // NavigationHandle so don't overwrite the existing entry's SSLStatus. | 1271 // NavigationHandle so don't overwrite the existing entry's SSLStatus. |
| 1271 if (!is_in_page) | 1272 if (!is_same_document) |
| 1272 entry->GetSSL() = handle->ssl_status(); | 1273 entry->GetSSL() = handle->ssl_status(); |
| 1273 } | 1274 } |
| 1274 DCHECK(entry); | 1275 DCHECK(entry); |
| 1275 | 1276 |
| 1276 // The URL may have changed due to redirects. | 1277 // The URL may have changed due to redirects. |
| 1277 entry->set_page_type(params.url_is_unreachable ? PAGE_TYPE_ERROR | 1278 entry->set_page_type(params.url_is_unreachable ? PAGE_TYPE_ERROR |
| 1278 : PAGE_TYPE_NORMAL); | 1279 : PAGE_TYPE_NORMAL); |
| 1279 entry->SetURL(params.url); | 1280 entry->SetURL(params.url); |
| 1280 entry->SetReferrer(params.referrer); | 1281 entry->SetReferrer(params.referrer); |
| 1281 if (entry->update_virtual_url_with_url()) | 1282 if (entry->update_virtual_url_with_url()) |
| 1282 UpdateVirtualURLToURL(entry, params.url); | 1283 UpdateVirtualURLToURL(entry, params.url); |
| 1283 | 1284 |
| 1284 // The site instance will normally be the same except | 1285 // The site instance will normally be the same except |
| 1285 // 1) session restore, when no site instance will be assigned or | 1286 // 1) session restore, when no site instance will be assigned or |
| 1286 // 2) redirect, when the site instance is reset. | 1287 // 2) redirect, when the site instance is reset. |
| 1287 DCHECK(entry->site_instance() == nullptr || | 1288 DCHECK(entry->site_instance() == nullptr || |
| 1288 !entry->GetRedirectChain().empty() || | 1289 !entry->GetRedirectChain().empty() || |
| 1289 entry->site_instance() == rfh->GetSiteInstance()); | 1290 entry->site_instance() == rfh->GetSiteInstance()); |
| 1290 | 1291 |
| 1291 // Update the existing FrameNavigationEntry to ensure all of its members | 1292 // Update the existing FrameNavigationEntry to ensure all of its members |
| 1292 // reflect the parameters coming from the renderer process. | 1293 // reflect the parameters coming from the renderer process. |
| 1293 entry->AddOrUpdateFrameEntry( | 1294 entry->AddOrUpdateFrameEntry( |
| 1294 rfh->frame_tree_node(), params.item_sequence_number, | 1295 rfh->frame_tree_node(), params.item_sequence_number, |
| 1295 params.document_sequence_number, rfh->GetSiteInstance(), nullptr, | 1296 params.document_sequence_number, rfh->GetSiteInstance(), nullptr, |
| 1296 params.url, params.referrer, params.redirects, params.page_state, | 1297 params.url, params.referrer, params.redirects, params.page_state, |
| 1297 params.method, params.post_id); | 1298 params.method, params.post_id); |
| 1298 | 1299 |
| 1299 // The redirected to page should not inherit the favicon from the previous | 1300 // The redirected to page should not inherit the favicon from the previous |
| 1300 // page. | 1301 // page. |
| 1301 if (ui::PageTransitionIsRedirect(params.transition) && !is_in_page) | 1302 if (ui::PageTransitionIsRedirect(params.transition) && !is_same_document) |
| 1302 entry->GetFavicon() = FaviconStatus(); | 1303 entry->GetFavicon() = FaviconStatus(); |
| 1303 | 1304 |
| 1304 // The entry we found in the list might be pending if the user hit | 1305 // The entry we found in the list might be pending if the user hit |
| 1305 // back/forward/reload. This load should commit it (since it's already in the | 1306 // back/forward/reload. This load should commit it (since it's already in the |
| 1306 // list, we can just discard the pending pointer). We should also discard the | 1307 // list, we can just discard the pending pointer). We should also discard the |
| 1307 // pending entry if it corresponds to a different navigation, since that one | 1308 // pending entry if it corresponds to a different navigation, since that one |
| 1308 // is now likely canceled. If it is not canceled, we will treat it as a new | 1309 // is now likely canceled. If it is not canceled, we will treat it as a new |
| 1309 // navigation when it arrives, which is also ok. | 1310 // navigation when it arrives, which is also ok. |
| 1310 // | 1311 // |
| 1311 // Note that we need to use the "internal" version since we don't want to | 1312 // Note that we need to use the "internal" version since we don't want to |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 params.document_sequence_number, rfh->GetSiteInstance(), nullptr, | 1358 params.document_sequence_number, rfh->GetSiteInstance(), nullptr, |
| 1358 params.url, params.referrer, params.redirects, params.page_state, | 1359 params.url, params.referrer, params.redirects, params.page_state, |
| 1359 params.method, params.post_id); | 1360 params.method, params.post_id); |
| 1360 | 1361 |
| 1361 DiscardNonCommittedEntries(); | 1362 DiscardNonCommittedEntries(); |
| 1362 } | 1363 } |
| 1363 | 1364 |
| 1364 void NavigationControllerImpl::RendererDidNavigateNewSubframe( | 1365 void NavigationControllerImpl::RendererDidNavigateNewSubframe( |
| 1365 RenderFrameHostImpl* rfh, | 1366 RenderFrameHostImpl* rfh, |
| 1366 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 1367 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 1367 bool is_in_page, | 1368 bool is_same_document, |
| 1368 bool replace_entry) { | 1369 bool replace_entry) { |
| 1369 DCHECK(ui::PageTransitionCoreTypeIs(params.transition, | 1370 DCHECK(ui::PageTransitionCoreTypeIs(params.transition, |
| 1370 ui::PAGE_TRANSITION_MANUAL_SUBFRAME)); | 1371 ui::PAGE_TRANSITION_MANUAL_SUBFRAME)); |
| 1371 | 1372 |
| 1372 // Manual subframe navigations just get the current entry cloned so the user | 1373 // Manual subframe navigations just get the current entry cloned so the user |
| 1373 // can go back or forward to it. The actual subframe information will be | 1374 // can go back or forward to it. The actual subframe information will be |
| 1374 // stored in the page state for each of those entries. This happens out of | 1375 // stored in the page state for each of those entries. This happens out of |
| 1375 // band with the actual navigations. | 1376 // band with the actual navigations. |
| 1376 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " | 1377 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " |
| 1377 << "that a last committed entry exists."; | 1378 << "that a last committed entry exists."; |
| 1378 | 1379 |
| 1379 // Make sure we don't leak frame_entry if new_entry doesn't take ownership. | 1380 // Make sure we don't leak frame_entry if new_entry doesn't take ownership. |
| 1380 scoped_refptr<FrameNavigationEntry> frame_entry(new FrameNavigationEntry( | 1381 scoped_refptr<FrameNavigationEntry> frame_entry(new FrameNavigationEntry( |
| 1381 params.frame_unique_name, params.item_sequence_number, | 1382 params.frame_unique_name, params.item_sequence_number, |
| 1382 params.document_sequence_number, rfh->GetSiteInstance(), nullptr, | 1383 params.document_sequence_number, rfh->GetSiteInstance(), nullptr, |
| 1383 params.url, params.referrer, params.method, params.post_id)); | 1384 params.url, params.referrer, params.method, params.post_id)); |
| 1384 std::unique_ptr<NavigationEntryImpl> new_entry = | 1385 std::unique_ptr<NavigationEntryImpl> new_entry = |
| 1385 GetLastCommittedEntry()->CloneAndReplace( | 1386 GetLastCommittedEntry()->CloneAndReplace( |
| 1386 frame_entry.get(), is_in_page, rfh->frame_tree_node(), | 1387 frame_entry.get(), is_same_document, rfh->frame_tree_node(), |
| 1387 delegate_->GetFrameTree()->root()); | 1388 delegate_->GetFrameTree()->root()); |
| 1388 | 1389 |
| 1389 // TODO(creis): Update this to add the frame_entry if we can't find the one | 1390 // TODO(creis): Update this to add the frame_entry if we can't find the one |
| 1390 // to replace, which can happen due to a unique name change. See | 1391 // to replace, which can happen due to a unique name change. See |
| 1391 // https://crbug.com/607205. For now, frame_entry will be deleted when it | 1392 // https://crbug.com/607205. For now, frame_entry will be deleted when it |
| 1392 // goes out of scope if it doesn't get used. | 1393 // goes out of scope if it doesn't get used. |
| 1393 | 1394 |
| 1394 InsertOrReplaceEntry(std::move(new_entry), replace_entry); | 1395 InsertOrReplaceEntry(std::move(new_entry), replace_entry); |
| 1395 } | 1396 } |
| 1396 | 1397 |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2192 DCHECK(pending_entry_index_ == -1 || | 2193 DCHECK(pending_entry_index_ == -1 || |
| 2193 pending_entry_ == GetEntryAtIndex(pending_entry_index_)); | 2194 pending_entry_ == GetEntryAtIndex(pending_entry_index_)); |
| 2194 } | 2195 } |
| 2195 | 2196 |
| 2196 void NavigationControllerImpl::SetGetTimestampCallbackForTest( | 2197 void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
| 2197 const base::Callback<base::Time()>& get_timestamp_callback) { | 2198 const base::Callback<base::Time()>& get_timestamp_callback) { |
| 2198 get_timestamp_callback_ = get_timestamp_callback; | 2199 get_timestamp_callback_ = get_timestamp_callback; |
| 2199 } | 2200 } |
| 2200 | 2201 |
| 2201 } // namespace content | 2202 } // namespace content |
| OLD | NEW |