Chromium Code Reviews| 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 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 853 | 853 |
| 854 // is_in_page must be computed before the entry gets committed. | 854 // is_in_page must be computed before the entry gets committed. |
| 855 details->is_in_page = IsURLInPageNavigation( | 855 details->is_in_page = IsURLInPageNavigation( |
| 856 params.url, params.was_within_same_page, rfh); | 856 params.url, params.was_within_same_page, rfh); |
| 857 | 857 |
| 858 switch (details->type) { | 858 switch (details->type) { |
| 859 case NAVIGATION_TYPE_NEW_PAGE: | 859 case NAVIGATION_TYPE_NEW_PAGE: |
| 860 RendererDidNavigateToNewPage(rfh, params, details->did_replace_entry); | 860 RendererDidNavigateToNewPage(rfh, params, details->did_replace_entry); |
| 861 break; | 861 break; |
| 862 case NAVIGATION_TYPE_EXISTING_PAGE: | 862 case NAVIGATION_TYPE_EXISTING_PAGE: |
| 863 details->did_replace_entry = details->is_in_page; | |
| 863 RendererDidNavigateToExistingPage(rfh, params); | 864 RendererDidNavigateToExistingPage(rfh, params); |
| 864 break; | 865 break; |
| 865 case NAVIGATION_TYPE_SAME_PAGE: | 866 case NAVIGATION_TYPE_SAME_PAGE: |
| 866 RendererDidNavigateToSamePage(rfh, params); | 867 RendererDidNavigateToSamePage(rfh, params); |
| 867 break; | 868 break; |
| 868 case NAVIGATION_TYPE_IN_PAGE: | |
| 869 RendererDidNavigateInPage(rfh, params, &details->did_replace_entry); | |
| 870 break; | |
| 871 case NAVIGATION_TYPE_NEW_SUBFRAME: | 869 case NAVIGATION_TYPE_NEW_SUBFRAME: |
| 872 RendererDidNavigateNewSubframe(rfh, params); | 870 RendererDidNavigateNewSubframe(rfh, params); |
| 873 break; | 871 break; |
| 874 case NAVIGATION_TYPE_AUTO_SUBFRAME: | 872 case NAVIGATION_TYPE_AUTO_SUBFRAME: |
| 875 if (!RendererDidNavigateAutoSubframe(rfh, params)) | 873 if (!RendererDidNavigateAutoSubframe(rfh, params)) |
| 876 return false; | 874 return false; |
| 877 break; | 875 break; |
| 878 case NAVIGATION_TYPE_NAV_IGNORE: | 876 case NAVIGATION_TYPE_NAV_IGNORE: |
| 879 // If a pending navigation was in progress, this canceled it. We should | 877 // If a pending navigation was in progress, this canceled it. We should |
| 880 // discard it and make sure it is removed from the URL bar. After that, | 878 // discard it and make sure it is removed from the URL bar. After that, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 // This is a renderer-initiated navigation (nav_entry_id == 0), but didn't | 991 // This is a renderer-initiated navigation (nav_entry_id == 0), but didn't |
| 994 // create a new page. | 992 // create a new page. |
| 995 | 993 |
| 996 // Just like above in the did_create_new_entry case, it's possible to | 994 // Just like above in the did_create_new_entry case, it's possible to |
| 997 // scribble onto an uncommitted page. Again, there isn't any navigation | 995 // scribble onto an uncommitted page. Again, there isn't any navigation |
| 998 // stuff that we can do, so ignore it here as well. | 996 // stuff that we can do, so ignore it here as well. |
| 999 NavigationEntry* last_committed = GetLastCommittedEntry(); | 997 NavigationEntry* last_committed = GetLastCommittedEntry(); |
| 1000 if (!last_committed) | 998 if (!last_committed) |
| 1001 return NAVIGATION_TYPE_NAV_IGNORE; | 999 return NAVIGATION_TYPE_NAV_IGNORE; |
| 1002 | 1000 |
| 1003 if (IsURLInPageNavigation(params.url, params.was_within_same_page, rfh)) { | 1001 // This is history.replaceState(), history.reload(), or a client-side |
| 1004 // This is history.replaceState(), which is renderer-initiated yet within | 1002 // redirect. |
| 1005 // the same page. | 1003 return NAVIGATION_TYPE_EXISTING_PAGE; |
| 1006 return NAVIGATION_TYPE_IN_PAGE; | |
| 1007 } else { | |
| 1008 // This is history.reload() or a client-side redirect. | |
| 1009 return NAVIGATION_TYPE_EXISTING_PAGE; | |
| 1010 } | |
| 1011 } | 1004 } |
| 1012 | 1005 |
| 1013 if (pending_entry_ && pending_entry_index_ == -1 && | 1006 if (pending_entry_ && pending_entry_index_ == -1 && |
| 1014 pending_entry_->GetUniqueID() == params.nav_entry_id) { | 1007 pending_entry_->GetUniqueID() == params.nav_entry_id) { |
| 1015 // In this case, we have a pending entry for a load of a new URL but Blink | 1008 // In this case, we have a pending entry for a load of a new URL but Blink |
| 1016 // didn't do a new navigation (params.did_create_new_entry). This happens | 1009 // didn't do a new navigation (params.did_create_new_entry). This happens |
| 1017 // when you press enter in the URL bar to reload. We will create a pending | 1010 // when you press enter in the URL bar to reload. We will create a pending |
| 1018 // entry, but Blink will convert it to a reload since it's the same page and | 1011 // entry, but Blink will convert it to a reload since it's the same page and |
| 1019 // not create a new entry for it (the user doesn't want to have a new | 1012 // not create a new entry for it (the user doesn't want to have a new |
| 1020 // back/forward entry when they do this). Therefore we want to just ignore | 1013 // back/forward entry when they do this). Therefore we want to just ignore |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1039 } | 1032 } |
| 1040 | 1033 |
| 1041 // Now we know that the notification is for an existing page. Find that entry. | 1034 // Now we know that the notification is for an existing page. Find that entry. |
| 1042 int existing_entry_index = GetEntryIndexWithUniqueID(params.nav_entry_id); | 1035 int existing_entry_index = GetEntryIndexWithUniqueID(params.nav_entry_id); |
| 1043 if (existing_entry_index == -1) { | 1036 if (existing_entry_index == -1) { |
| 1044 // The renderer has committed a navigation to an entry that no longer | 1037 // The renderer has committed a navigation to an entry that no longer |
| 1045 // exists. Because the renderer is showing that page, resurrect that entry. | 1038 // exists. Because the renderer is showing that page, resurrect that entry. |
| 1046 return NAVIGATION_TYPE_NEW_PAGE; | 1039 return NAVIGATION_TYPE_NEW_PAGE; |
| 1047 } | 1040 } |
| 1048 | 1041 |
| 1049 // Any top-level navigations with the same base (minus the reference fragment) | |
| 1050 // are in-page navigations. (We weeded out subframe navigations above.) Most | |
| 1051 // of the time this doesn't matter since Blink doesn't tell us about subframe | |
| 1052 // navigations that don't actually navigate, but it can happen when there is | |
| 1053 // an encoding override (it always sends a navigation request). | |
| 1054 if (IsURLInPageNavigation(params.url, params.was_within_same_page, rfh)) | |
| 1055 return NAVIGATION_TYPE_IN_PAGE; | |
| 1056 | |
| 1057 // Since we weeded out "new" navigations above, we know this is an existing | 1042 // Since we weeded out "new" navigations above, we know this is an existing |
| 1058 // (back/forward) navigation. | 1043 // (back/forward) navigation. |
| 1059 return NAVIGATION_TYPE_EXISTING_PAGE; | 1044 return NAVIGATION_TYPE_EXISTING_PAGE; |
| 1060 } | 1045 } |
| 1061 | 1046 |
| 1062 void NavigationControllerImpl::RendererDidNavigateToNewPage( | 1047 void NavigationControllerImpl::RendererDidNavigateToNewPage( |
| 1063 RenderFrameHostImpl* rfh, | 1048 RenderFrameHostImpl* rfh, |
| 1064 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 1049 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 1065 bool replace_entry) { | 1050 bool replace_entry) { |
| 1066 scoped_ptr<NavigationEntryImpl> new_entry; | 1051 scoped_ptr<NavigationEntryImpl> new_entry; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1224 existing_entry->SetURL(params.url); | 1209 existing_entry->SetURL(params.url); |
| 1225 existing_entry->SetReferrer(params.referrer); | 1210 existing_entry->SetReferrer(params.referrer); |
| 1226 | 1211 |
| 1227 // The page may have been requested with a different HTTP method. | 1212 // The page may have been requested with a different HTTP method. |
| 1228 existing_entry->SetHasPostData(params.is_post); | 1213 existing_entry->SetHasPostData(params.is_post); |
| 1229 existing_entry->SetPostID(params.post_id); | 1214 existing_entry->SetPostID(params.post_id); |
| 1230 | 1215 |
| 1231 DiscardNonCommittedEntries(); | 1216 DiscardNonCommittedEntries(); |
| 1232 } | 1217 } |
| 1233 | 1218 |
| 1234 void NavigationControllerImpl::RendererDidNavigateInPage( | |
|
Charlie Reis
2015/07/07 00:07:15
Wow, this is all handled by RendererDidNavigateToE
Avi (use Gerrit)
2015/07/07 04:38:16
Yes. The only real difference is setting the did_r
| |
| 1235 RenderFrameHostImpl* rfh, | |
| 1236 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | |
| 1237 bool* did_replace_entry) { | |
| 1238 DCHECK(!rfh->GetParent()) << | |
| 1239 "Blink should only tell us about in-page navs for the main frame."; | |
| 1240 | |
| 1241 NavigationEntryImpl* existing_entry; | |
| 1242 if (params.nav_entry_id) { | |
| 1243 // This is a browser-initiated history navigation across an existing | |
| 1244 // fragment navigation or pushState-created entry. | |
| 1245 existing_entry = GetEntryWithUniqueID(params.nav_entry_id); | |
| 1246 } else { | |
| 1247 // This is renderer-initiated. The only kinds of renderer-initated | |
| 1248 // navigations that are IN_PAGE are history.replaceState, which lands us at | |
| 1249 // the last committed entry. | |
| 1250 existing_entry = GetLastCommittedEntry(); | |
| 1251 } | |
| 1252 DCHECK(existing_entry); | |
| 1253 | |
| 1254 // Reference fragment navigation. We're guaranteed to have the last_committed | |
| 1255 // entry and it will be the same page as the new navigation (minus the | |
| 1256 // reference fragments, of course). We'll update the URL of the existing | |
| 1257 // entry without pruning the forward history. | |
| 1258 existing_entry->set_page_type(params.url_is_unreachable ? PAGE_TYPE_ERROR | |
| 1259 : PAGE_TYPE_NORMAL); | |
| 1260 existing_entry->SetURL(params.url); | |
| 1261 if (existing_entry->update_virtual_url_with_url()) | |
| 1262 UpdateVirtualURLToURL(existing_entry, params.url); | |
| 1263 | |
| 1264 existing_entry->SetHasPostData(params.is_post); | |
| 1265 existing_entry->SetPostID(params.post_id); | |
| 1266 | |
| 1267 // This replaces the existing entry since the page ID didn't change. | |
| 1268 *did_replace_entry = true; | |
| 1269 | |
| 1270 DiscardNonCommittedEntriesInternal(); | |
| 1271 | |
| 1272 // If a transient entry was removed, the indices might have changed, so we | |
| 1273 // have to query the entry index again. | |
| 1274 last_committed_entry_index_ = GetIndexOfEntry(existing_entry); | |
| 1275 } | |
| 1276 | |
| 1277 void NavigationControllerImpl::RendererDidNavigateNewSubframe( | 1219 void NavigationControllerImpl::RendererDidNavigateNewSubframe( |
| 1278 RenderFrameHostImpl* rfh, | 1220 RenderFrameHostImpl* rfh, |
| 1279 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { | 1221 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 1280 if (!ui::PageTransitionCoreTypeIs(params.transition, | 1222 if (!ui::PageTransitionCoreTypeIs(params.transition, |
| 1281 ui::PAGE_TRANSITION_MANUAL_SUBFRAME)) { | 1223 ui::PAGE_TRANSITION_MANUAL_SUBFRAME)) { |
| 1282 // There was a comment here that said, "This is not user-initiated. Ignore." | 1224 // There was a comment here that said, "This is not user-initiated. Ignore." |
| 1283 // But this makes no sense; non-user-initiated navigations should be | 1225 // But this makes no sense; non-user-initiated navigations should be |
| 1284 // determined to be of type NAVIGATION_TYPE_AUTO_SUBFRAME and sent to | 1226 // determined to be of type NAVIGATION_TYPE_AUTO_SUBFRAME and sent to |
| 1285 // RendererDidNavigateAutoSubframe below. | 1227 // RendererDidNavigateAutoSubframe below. |
| 1286 // | 1228 // |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2055 } | 1997 } |
| 2056 } | 1998 } |
| 2057 } | 1999 } |
| 2058 | 2000 |
| 2059 void NavigationControllerImpl::SetGetTimestampCallbackForTest( | 2001 void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
| 2060 const base::Callback<base::Time()>& get_timestamp_callback) { | 2002 const base::Callback<base::Time()>& get_timestamp_callback) { |
| 2061 get_timestamp_callback_ = get_timestamp_callback; | 2003 get_timestamp_callback_ = get_timestamp_callback; |
| 2062 } | 2004 } |
| 2063 | 2005 |
| 2064 } // namespace content | 2006 } // namespace content |
| OLD | NEW |