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

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

Issue 135723003: Move DidCommitProvisionalLoad code from RenderView to RenderFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some clean up, ready to start reviewing. Created 6 years, 10 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 | Annotate | Revision Log
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/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" // Temporary 10 #include "base/strings/string_number_conversions.h" // Temporary
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "content/browser/browser_url_handler_impl.h" 14 #include "content/browser/browser_url_handler_impl.h"
15 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" 15 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
16 #include "content/browser/dom_storage/session_storage_namespace_impl.h" 16 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
17 #include "content/browser/frame_host/debug_urls.h" 17 #include "content/browser/frame_host/debug_urls.h"
18 #include "content/browser/frame_host/interstitial_page_impl.h" 18 #include "content/browser/frame_host/interstitial_page_impl.h"
19 #include "content/browser/frame_host/navigation_entry_impl.h" 19 #include "content/browser/frame_host/navigation_entry_impl.h"
20 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 20 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
21 #include "content/browser/renderer_host/render_view_host_impl.h" // Temporary 21 #include "content/browser/renderer_host/render_view_host_impl.h" // Temporary
22 #include "content/browser/site_instance_impl.h" 22 #include "content/browser/site_instance_impl.h"
23 #include "content/common/frame_messages.h"
23 #include "content/common/view_messages.h" 24 #include "content/common/view_messages.h"
24 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/content_browser_client.h" 26 #include "content/public/browser/content_browser_client.h"
26 #include "content/public/browser/invalidate_type.h" 27 #include "content/public/browser/invalidate_type.h"
27 #include "content/public/browser/navigation_details.h" 28 #include "content/public/browser/navigation_details.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_types.h" 30 #include "content/public/browser/notification_types.h"
30 #include "content/public/browser/render_widget_host.h" 31 #include "content/public/browser/render_widget_host.h"
31 #include "content/public/browser/render_widget_host_view.h" 32 #include "content/public/browser/render_widget_host_view.h"
32 #include "content/public/browser/storage_partition.h" 33 #include "content/public/browser/storage_partition.h"
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 default: 728 default:
728 NOTREACHED(); 729 NOTREACHED();
729 break; 730 break;
730 }; 731 };
731 732
732 LoadEntry(entry); 733 LoadEntry(entry);
733 } 734 }
734 735
735 bool NavigationControllerImpl::RendererDidNavigate( 736 bool NavigationControllerImpl::RendererDidNavigate(
736 RenderViewHost* rvh, 737 RenderViewHost* rvh,
737 const ViewHostMsg_FrameNavigate_Params& params, 738 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
738 LoadCommittedDetails* details) { 739 LoadCommittedDetails* details) {
739 is_initial_navigation_ = false; 740 is_initial_navigation_ = false;
740 741
741 // Save the previous state before we clobber it. 742 // Save the previous state before we clobber it.
742 if (GetLastCommittedEntry()) { 743 if (GetLastCommittedEntry()) {
743 details->previous_url = GetLastCommittedEntry()->GetURL(); 744 details->previous_url = GetLastCommittedEntry()->GetURL();
744 details->previous_entry_index = GetLastCommittedEntryIndex(); 745 details->previous_entry_index = GetLastCommittedEntryIndex();
745 } else { 746 } else {
746 details->previous_url = GURL(); 747 details->previous_url = GURL();
747 details->previous_entry_index = -1; 748 details->previous_entry_index = -1;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 PageTransitionIsMainFrame(params.transition); 845 PageTransitionIsMainFrame(params.transition);
845 details->serialized_security_info = params.security_info; 846 details->serialized_security_info = params.security_info;
846 details->http_status_code = params.http_status_code; 847 details->http_status_code = params.http_status_code;
847 NotifyNavigationEntryCommitted(details); 848 NotifyNavigationEntryCommitted(details);
848 849
849 return true; 850 return true;
850 } 851 }
851 852
852 NavigationType NavigationControllerImpl::ClassifyNavigation( 853 NavigationType NavigationControllerImpl::ClassifyNavigation(
853 RenderViewHost* rvh, 854 RenderViewHost* rvh,
854 const ViewHostMsg_FrameNavigate_Params& params) const { 855 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) const {
855 if (params.page_id == -1) { 856 if (params.page_id == -1) {
856 // The renderer generates the page IDs, and so if it gives us the invalid 857 // The renderer generates the page IDs, and so if it gives us the invalid
857 // page ID (-1) we know it didn't actually navigate. This happens in a few 858 // page ID (-1) we know it didn't actually navigate. This happens in a few
858 // cases: 859 // cases:
859 // 860 //
860 // - If a page makes a popup navigated to about blank, and then writes 861 // - If a page makes a popup navigated to about blank, and then writes
861 // stuff like a subframe navigated to a real page. We'll get the commit 862 // stuff like a subframe navigated to a real page. We'll get the commit
862 // for the subframe, but there won't be any commit for the outer page. 863 // for the subframe, but there won't be any commit for the outer page.
863 // 864 //
864 // - We were also getting these for failed loads (for example, bug 21849). 865 // - We were also getting these for failed loads (for example, bug 21849).
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 return NAVIGATION_TYPE_IN_PAGE; 980 return NAVIGATION_TYPE_IN_PAGE;
980 } 981 }
981 982
982 // Since we weeded out "new" navigations above, we know this is an existing 983 // Since we weeded out "new" navigations above, we know this is an existing
983 // (back/forward) navigation. 984 // (back/forward) navigation.
984 return NAVIGATION_TYPE_EXISTING_PAGE; 985 return NAVIGATION_TYPE_EXISTING_PAGE;
985 } 986 }
986 987
987 void NavigationControllerImpl::RendererDidNavigateToNewPage( 988 void NavigationControllerImpl::RendererDidNavigateToNewPage(
988 RenderViewHost* rvh, 989 RenderViewHost* rvh,
989 const ViewHostMsg_FrameNavigate_Params& params, 990 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
990 bool replace_entry) { 991 bool replace_entry) {
991 NavigationEntryImpl* new_entry; 992 NavigationEntryImpl* new_entry;
992 bool update_virtual_url; 993 bool update_virtual_url;
993 // Only make a copy of the pending entry if it is appropriate for the new page 994 // Only make a copy of the pending entry if it is appropriate for the new page
994 // that was just loaded. We verify this at a coarse grain by checking that 995 // that was just loaded. We verify this at a coarse grain by checking that
995 // the SiteInstance hasn't been assigned to something else. 996 // the SiteInstance hasn't been assigned to something else.
996 if (pending_entry_ && 997 if (pending_entry_ &&
997 (!pending_entry_->site_instance() || 998 (!pending_entry_->site_instance() ||
998 pending_entry_->site_instance() == rvh->GetSiteInstance())) { 999 pending_entry_->site_instance() == rvh->GetSiteInstance())) {
999 new_entry = new NavigationEntryImpl(*pending_entry_); 1000 new_entry = new NavigationEntryImpl(*pending_entry_);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 DiscardNonCommittedEntriesInternal(); 1044 DiscardNonCommittedEntriesInternal();
1044 entries_.clear(); 1045 entries_.clear();
1045 last_committed_entry_index_ = -1; 1046 last_committed_entry_index_ = -1;
1046 } 1047 }
1047 1048
1048 InsertOrReplaceEntry(new_entry, replace_entry); 1049 InsertOrReplaceEntry(new_entry, replace_entry);
1049 } 1050 }
1050 1051
1051 void NavigationControllerImpl::RendererDidNavigateToExistingPage( 1052 void NavigationControllerImpl::RendererDidNavigateToExistingPage(
1052 RenderViewHost* rvh, 1053 RenderViewHost* rvh,
1053 const ViewHostMsg_FrameNavigate_Params& params) { 1054 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
1054 // We should only get here for main frame navigations. 1055 // We should only get here for main frame navigations.
1055 DCHECK(PageTransitionIsMainFrame(params.transition)); 1056 DCHECK(PageTransitionIsMainFrame(params.transition));
1056 1057
1057 // This is a back/forward navigation. The existing page for the ID is 1058 // This is a back/forward navigation. The existing page for the ID is
1058 // guaranteed to exist by ClassifyNavigation, and we just need to update it 1059 // guaranteed to exist by ClassifyNavigation, and we just need to update it
1059 // with new information from the renderer. 1060 // with new information from the renderer.
1060 int entry_index = GetEntryIndexWithPageID(rvh->GetSiteInstance(), 1061 int entry_index = GetEntryIndexWithPageID(rvh->GetSiteInstance(),
1061 params.page_id); 1062 params.page_id);
1062 DCHECK(entry_index >= 0 && 1063 DCHECK(entry_index >= 0 &&
1063 entry_index < static_cast<int>(entries_.size())); 1064 entry_index < static_cast<int>(entries_.size()));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 DiscardNonCommittedEntriesInternal(); 1097 DiscardNonCommittedEntriesInternal();
1097 1098
1098 // If a transient entry was removed, the indices might have changed, so we 1099 // If a transient entry was removed, the indices might have changed, so we
1099 // have to query the entry index again. 1100 // have to query the entry index again.
1100 last_committed_entry_index_ = 1101 last_committed_entry_index_ =
1101 GetEntryIndexWithPageID(rvh->GetSiteInstance(), params.page_id); 1102 GetEntryIndexWithPageID(rvh->GetSiteInstance(), params.page_id);
1102 } 1103 }
1103 1104
1104 void NavigationControllerImpl::RendererDidNavigateToSamePage( 1105 void NavigationControllerImpl::RendererDidNavigateToSamePage(
1105 RenderViewHost* rvh, 1106 RenderViewHost* rvh,
1106 const ViewHostMsg_FrameNavigate_Params& params) { 1107 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
1107 // This mode implies we have a pending entry that's the same as an existing 1108 // This mode implies we have a pending entry that's the same as an existing
1108 // entry for this page ID. This entry is guaranteed to exist by 1109 // entry for this page ID. This entry is guaranteed to exist by
1109 // ClassifyNavigation. All we need to do is update the existing entry. 1110 // ClassifyNavigation. All we need to do is update the existing entry.
1110 NavigationEntryImpl* existing_entry = GetEntryWithPageID( 1111 NavigationEntryImpl* existing_entry = GetEntryWithPageID(
1111 rvh->GetSiteInstance(), params.page_id); 1112 rvh->GetSiteInstance(), params.page_id);
1112 1113
1113 // We assign the entry's unique ID to be that of the new one. Since this is 1114 // We assign the entry's unique ID to be that of the new one. Since this is
1114 // always the result of a user action, we want to dismiss infobars, etc. like 1115 // always the result of a user action, we want to dismiss infobars, etc. like
1115 // a regular user-initiated navigation. 1116 // a regular user-initiated navigation.
1116 existing_entry->set_unique_id(pending_entry_->GetUniqueID()); 1117 existing_entry->set_unique_id(pending_entry_->GetUniqueID());
1117 1118
1118 // The URL may have changed due to redirects. 1119 // The URL may have changed due to redirects.
1119 if (existing_entry->update_virtual_url_with_url()) 1120 if (existing_entry->update_virtual_url_with_url())
1120 UpdateVirtualURLToURL(existing_entry, params.url); 1121 UpdateVirtualURLToURL(existing_entry, params.url);
1121 existing_entry->SetURL(params.url); 1122 existing_entry->SetURL(params.url);
1122 existing_entry->SetReferrer(params.referrer); 1123 existing_entry->SetReferrer(params.referrer);
1123 1124
1124 // The page may have been requested with a different HTTP method. 1125 // The page may have been requested with a different HTTP method.
1125 existing_entry->SetHasPostData(params.is_post); 1126 existing_entry->SetHasPostData(params.is_post);
1126 existing_entry->SetPostID(params.post_id); 1127 existing_entry->SetPostID(params.post_id);
1127 1128
1128 DiscardNonCommittedEntries(); 1129 DiscardNonCommittedEntries();
1129 } 1130 }
1130 1131
1131 void NavigationControllerImpl::RendererDidNavigateInPage( 1132 void NavigationControllerImpl::RendererDidNavigateInPage(
1132 RenderViewHost* rvh, 1133 RenderViewHost* rvh,
1133 const ViewHostMsg_FrameNavigate_Params& params, 1134 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
1134 bool* did_replace_entry) { 1135 bool* did_replace_entry) {
1135 DCHECK(PageTransitionIsMainFrame(params.transition)) << 1136 DCHECK(PageTransitionIsMainFrame(params.transition)) <<
1136 "WebKit should only tell us about in-page navs for the main frame."; 1137 "WebKit should only tell us about in-page navs for the main frame.";
1137 // We're guaranteed to have an entry for this one. 1138 // We're guaranteed to have an entry for this one.
1138 NavigationEntryImpl* existing_entry = GetEntryWithPageID( 1139 NavigationEntryImpl* existing_entry = GetEntryWithPageID(
1139 rvh->GetSiteInstance(), params.page_id); 1140 rvh->GetSiteInstance(), params.page_id);
1140 1141
1141 // Reference fragment navigation. We're guaranteed to have the last_committed 1142 // Reference fragment navigation. We're guaranteed to have the last_committed
1142 // entry and it will be the same page as the new navigation (minus the 1143 // entry and it will be the same page as the new navigation (minus the
1143 // reference fragments, of course). We'll update the URL of the existing 1144 // reference fragments, of course). We'll update the URL of the existing
1144 // entry without pruning the forward history. 1145 // entry without pruning the forward history.
1145 existing_entry->SetURL(params.url); 1146 existing_entry->SetURL(params.url);
1146 if (existing_entry->update_virtual_url_with_url()) 1147 if (existing_entry->update_virtual_url_with_url())
1147 UpdateVirtualURLToURL(existing_entry, params.url); 1148 UpdateVirtualURLToURL(existing_entry, params.url);
1148 1149
1149 // This replaces the existing entry since the page ID didn't change. 1150 // This replaces the existing entry since the page ID didn't change.
1150 *did_replace_entry = true; 1151 *did_replace_entry = true;
1151 1152
1152 DiscardNonCommittedEntriesInternal(); 1153 DiscardNonCommittedEntriesInternal();
1153 1154
1154 // If a transient entry was removed, the indices might have changed, so we 1155 // If a transient entry was removed, the indices might have changed, so we
1155 // have to query the entry index again. 1156 // have to query the entry index again.
1156 last_committed_entry_index_ = 1157 last_committed_entry_index_ =
1157 GetEntryIndexWithPageID(rvh->GetSiteInstance(), params.page_id); 1158 GetEntryIndexWithPageID(rvh->GetSiteInstance(), params.page_id);
1158 } 1159 }
1159 1160
1160 void NavigationControllerImpl::RendererDidNavigateNewSubframe( 1161 void NavigationControllerImpl::RendererDidNavigateNewSubframe(
1161 RenderViewHost* rvh, 1162 RenderViewHost* rvh,
1162 const ViewHostMsg_FrameNavigate_Params& params) { 1163 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
1163 if (PageTransitionCoreTypeIs(params.transition, 1164 if (PageTransitionCoreTypeIs(params.transition,
1164 PAGE_TRANSITION_AUTO_SUBFRAME)) { 1165 PAGE_TRANSITION_AUTO_SUBFRAME)) {
1165 // This is not user-initiated. Ignore. 1166 // This is not user-initiated. Ignore.
1166 DiscardNonCommittedEntriesInternal(); 1167 DiscardNonCommittedEntriesInternal();
1167 return; 1168 return;
1168 } 1169 }
1169 1170
1170 // Manual subframe navigations just get the current entry cloned so the user 1171 // Manual subframe navigations just get the current entry cloned so the user
1171 // can go back or forward to it. The actual subframe information will be 1172 // can go back or forward to it. The actual subframe information will be
1172 // stored in the page state for each of those entries. This happens out of 1173 // stored in the page state for each of those entries. This happens out of
1173 // band with the actual navigations. 1174 // band with the actual navigations.
1174 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " 1175 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee "
1175 << "that a last committed entry exists."; 1176 << "that a last committed entry exists.";
1176 NavigationEntryImpl* new_entry = new NavigationEntryImpl( 1177 NavigationEntryImpl* new_entry = new NavigationEntryImpl(
1177 *NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry())); 1178 *NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()));
1178 new_entry->SetPageID(params.page_id); 1179 new_entry->SetPageID(params.page_id);
1179 InsertOrReplaceEntry(new_entry, false); 1180 InsertOrReplaceEntry(new_entry, false);
1180 } 1181 }
1181 1182
1182 bool NavigationControllerImpl::RendererDidNavigateAutoSubframe( 1183 bool NavigationControllerImpl::RendererDidNavigateAutoSubframe(
1183 RenderViewHost* rvh, 1184 RenderViewHost* rvh,
1184 const ViewHostMsg_FrameNavigate_Params& params) { 1185 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
1185 // We're guaranteed to have a previously committed entry, and we now need to 1186 // We're guaranteed to have a previously committed entry, and we now need to
1186 // handle navigation inside of a subframe in it without creating a new entry. 1187 // handle navigation inside of a subframe in it without creating a new entry.
1187 DCHECK(GetLastCommittedEntry()); 1188 DCHECK(GetLastCommittedEntry());
1188 1189
1189 // Handle the case where we're navigating back/forward to a previous subframe 1190 // Handle the case where we're navigating back/forward to a previous subframe
1190 // navigation entry. This is case "2." in NAV_AUTO_SUBFRAME comment in the 1191 // navigation entry. This is case "2." in NAV_AUTO_SUBFRAME comment in the
1191 // header file. In case "1." this will be a NOP. 1192 // header file. In case "1." this will be a NOP.
1192 int entry_index = GetEntryIndexWithPageID( 1193 int entry_index = GetEntryIndexWithPageID(
1193 rvh->GetSiteInstance(), 1194 rvh->GetSiteInstance(),
1194 params.page_id); 1195 params.page_id);
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 } 1723 }
1723 } 1724 }
1724 } 1725 }
1725 1726
1726 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 1727 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
1727 const base::Callback<base::Time()>& get_timestamp_callback) { 1728 const base::Callback<base::Time()>& get_timestamp_callback) {
1728 get_timestamp_callback_ = get_timestamp_callback; 1729 get_timestamp_callback_ = get_timestamp_callback;
1729 } 1730 }
1730 1731
1731 } // namespace content 1732 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698