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

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 1112513002: PlzNavigate: unify OnCommitNavigation with OnNavigate in RenderFrameImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-browsertests
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
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 } 1070 }
1071 1071
1072 void RenderFrameImpl::OnNavigate( 1072 void RenderFrameImpl::OnNavigate(
1073 const CommonNavigationParams& common_params, 1073 const CommonNavigationParams& common_params,
1074 const StartNavigationParams& start_params, 1074 const StartNavigationParams& start_params,
1075 const RequestNavigationParams& request_params) { 1075 const RequestNavigationParams& request_params) {
1076 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( 1076 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
1077 switches::kEnableBrowserSideNavigation)); 1077 switches::kEnableBrowserSideNavigation));
1078 TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate", "id", routing_id_, 1078 TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate", "id", routing_id_,
1079 "url", common_params.url.possibly_invalid_spec()); 1079 "url", common_params.url.possibly_invalid_spec());
1080 1080 NavigateInternal(common_params, start_params, request_params,
1081 bool is_reload = IsReload(common_params.navigation_type); 1081 scoped_ptr<StreamOverrideParameters>());
1082 bool is_history_navigation = request_params.page_state.IsValid();
1083 WebURLRequest::CachePolicy cache_policy =
1084 WebURLRequest::UseProtocolCachePolicy;
1085 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
1086 common_params.url, is_history_navigation, request_params, &is_reload,
1087 &cache_policy)) {
1088 Send(new FrameHostMsg_DidDropNavigation(routing_id_));
1089 return;
1090 }
1091
1092 GetContentClient()->SetActiveURL(common_params.url);
1093
1094 // If this frame isn't in the same process as its parent, it will naively
1095 // assume that this is the first navigation in the iframe, but this may not
1096 // actually be the case. The PageTransition differentiates between the first
1097 // navigation in a subframe and subsequent navigations, so if this is a
1098 // subsequent navigation, force the frame's state machine forward.
1099 if (ui::PageTransitionCoreTypeIs(common_params.transition,
1100 ui::PAGE_TRANSITION_MANUAL_SUBFRAME)) {
1101 CHECK(frame_->parent());
1102 if (frame_->parent()->isWebRemoteFrame()) {
1103 frame_->setCommittedFirstRealLoad();
1104 }
1105 }
Avi (use Gerrit) 2015/04/28 15:39:07 Note that this block is in conflict with your patc
clamy 2015/04/29 09:36:57 Acknowledged.
1106
1107 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) {
1108 // We cannot reload if we do not have any history state. This happens, for
1109 // example, when recovering from a crash.
1110 is_reload = false;
1111 cache_policy = WebURLRequest::ReloadIgnoringCacheData;
1112 }
1113
1114 pending_navigation_params_.reset(
1115 new NavigationParams(common_params, start_params, request_params));
1116
1117 // If we are reloading, then WebKit will use the history state of the current
1118 // page, so we should just ignore any given history state. Otherwise, if we
1119 // have history state, then we need to navigate to it, which corresponds to a
1120 // back/forward navigation event.
1121 if (is_reload) {
1122 bool reload_original_url =
1123 (common_params.navigation_type ==
1124 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
1125 bool ignore_cache = (common_params.navigation_type ==
1126 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
1127
1128 if (reload_original_url)
1129 frame_->reloadWithOverrideURL(common_params.url, true);
1130 else
1131 frame_->reload(ignore_cache);
1132 } else if (is_history_navigation) {
1133 // We must know the page ID of the page we are navigating back to.
1134 DCHECK_NE(request_params.page_id, -1);
1135 scoped_ptr<HistoryEntry> entry =
1136 PageStateToHistoryEntry(request_params.page_state);
1137 if (entry) {
1138 // Ensure we didn't save the swapped out URL in UpdateState, since the
1139 // browser should never be telling us to navigate to swappedout://.
1140 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL));
1141 scoped_ptr<NavigationParams> navigation_params(
1142 new NavigationParams(*pending_navigation_params_.get()));
1143 render_view_->history_controller()->GoToEntry(
1144 entry.Pass(), navigation_params.Pass(), cache_policy);
1145 }
1146 } else if (!common_params.base_url_for_data_url.is_empty()) {
1147 LoadDataURL(common_params, frame_);
1148 } else {
1149 // Navigate to the given URL.
1150 WebURLRequest request = CreateURLRequestForNavigation(
1151 common_params, scoped_ptr<StreamOverrideParameters>(),
1152 frame_->isViewSourceModeEnabled());
1153
1154 if (!start_params.extra_headers.empty()) {
1155 for (net::HttpUtil::HeadersIterator i(start_params.extra_headers.begin(),
1156 start_params.extra_headers.end(),
1157 "\n");
1158 i.GetNext();) {
1159 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1160 WebString::fromUTF8(i.values()));
1161 }
1162 }
1163
1164 if (start_params.is_post) {
1165 request.setHTTPMethod(WebString::fromUTF8("POST"));
1166
1167 // Set post data.
1168 WebHTTPBody http_body;
1169 http_body.initialize();
1170 const char* data = NULL;
1171 if (start_params.browser_initiated_post_data.size()) {
1172 data = reinterpret_cast<const char*>(
1173 &start_params.browser_initiated_post_data.front());
1174 }
1175 http_body.appendData(
1176 WebData(data, start_params.browser_initiated_post_data.size()));
1177 request.setHTTPBody(http_body);
1178 }
1179
1180 // A session history navigation should have been accompanied by state.
1181 CHECK_EQ(request_params.page_id, -1);
1182
1183 // Record this before starting the load, we need a lower bound of this time
1184 // to sanitize the navigationStart override set below.
1185 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
1186 frame_->loadRequest(request);
1187
1188 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start,
1189 renderer_navigation_start);
1190 }
1191
1192 // In case LoadRequest failed before didCreateDataSource was called.
1193 pending_navigation_params_.reset();
1194 } 1082 }
1195 1083
1196 void RenderFrameImpl::NavigateToSwappedOutURL() { 1084 void RenderFrameImpl::NavigateToSwappedOutURL() {
1197 // We use loadRequest instead of loadHTMLString because the former commits 1085 // We use loadRequest instead of loadHTMLString because the former commits
1198 // synchronously. Otherwise a new navigation can interrupt the navigation 1086 // synchronously. Otherwise a new navigation can interrupt the navigation
1199 // to kSwappedOutURL. If that happens to be to the page we had been 1087 // to kSwappedOutURL. If that happens to be to the page we had been
1200 // showing, then WebKit will never send a commit and we'll be left spinning. 1088 // showing, then WebKit will never send a commit and we'll be left spinning.
1201 // Set the is_swapped_out_ bit to true, so IPC filtering is in effect and 1089 // Set the is_swapped_out_ bit to true, so IPC filtering is in effect and
1202 // the navigation to swappedout:// is not announced to the browser side. 1090 // the navigation to swappedout:// is not announced to the browser side.
1203 is_swapped_out_ = true; 1091 is_swapped_out_ = true;
(...skipping 2885 matching lines...) Expand 10 before | Expand all | Expand 10 after
4089 } 3977 }
4090 3978
4091 // PlzNavigate 3979 // PlzNavigate
4092 void RenderFrameImpl::OnCommitNavigation( 3980 void RenderFrameImpl::OnCommitNavigation(
4093 const ResourceResponseHead& response, 3981 const ResourceResponseHead& response,
4094 const GURL& stream_url, 3982 const GURL& stream_url,
4095 const CommonNavigationParams& common_params, 3983 const CommonNavigationParams& common_params,
4096 const RequestNavigationParams& request_params) { 3984 const RequestNavigationParams& request_params) {
4097 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 3985 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
4098 switches::kEnableBrowserSideNavigation)); 3986 switches::kEnableBrowserSideNavigation));
4099 bool is_reload = false; 3987 // This will override the url requested by the WebURLLoader, as well as
4100 bool is_history_navigation = request_params.page_state.IsValid(); 3988 // provide it with the response to the request.
4101 WebURLRequest::CachePolicy cache_policy =
4102 WebURLRequest::UseProtocolCachePolicy;
4103 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
4104 common_params.url, is_history_navigation, request_params, &is_reload,
4105 &cache_policy)) {
4106 Send(new FrameHostMsg_DidDropNavigation(routing_id_));
4107 return;
4108 }
4109
4110 GetContentClient()->SetActiveURL(common_params.url);
4111
4112 pending_navigation_params_.reset(new NavigationParams(
4113 common_params, StartNavigationParams(), request_params));
4114
4115 if (!common_params.base_url_for_data_url.is_empty() ||
4116 common_params.url.SchemeIs(url::kDataScheme)) {
4117 LoadDataURL(common_params, frame_);
4118 return;
4119 }
4120
4121 // Create a WebURLRequest that blink can use to get access to the body of the
4122 // response through a stream in the browser. Blink will then commit the
4123 // navigation.
4124 // TODO(clamy): Have the navigation commit directly, without going through
4125 // loading a WebURLRequest.
4126 scoped_ptr<StreamOverrideParameters> stream_override( 3989 scoped_ptr<StreamOverrideParameters> stream_override(
4127 new StreamOverrideParameters()); 3990 new StreamOverrideParameters());
4128 stream_override->stream_url = stream_url; 3991 stream_override->stream_url = stream_url;
4129 stream_override->response = response; 3992 stream_override->response = response;
4130 WebURLRequest request =
4131 CreateURLRequestForNavigation(common_params,
4132 stream_override.Pass(),
4133 frame_->isViewSourceModeEnabled());
4134 3993
4135 // Make sure that blink loader will not try to use browser side navigation for 3994 NavigateInternal(common_params, StartNavigationParams(), request_params,
4136 // this request (since it already went to the browser). 3995 stream_override.Pass());
4137 request.setCheckForBrowserSideNavigation(false);
4138
4139 // Record this before starting the load. A lower bound of this time is needed
4140 // to sanitize the navigationStart override set below.
4141 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
4142 frame_->loadRequest(request);
4143 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start,
4144 renderer_navigation_start);
4145 } 3996 }
4146 3997
4147 void RenderFrameImpl::OnFailedNavigation( 3998 void RenderFrameImpl::OnFailedNavigation(
4148 const CommonNavigationParams& common_params, 3999 const CommonNavigationParams& common_params,
4149 const RequestNavigationParams& request_params, 4000 const RequestNavigationParams& request_params,
4150 bool has_stale_copy_in_cache, 4001 bool has_stale_copy_in_cache,
4151 int error_code) { 4002 int error_code) {
4152 bool is_reload = IsReload(common_params.navigation_type); 4003 bool is_reload = IsReload(common_params.navigation_type);
4153 bool is_history_navigation = request_params.page_state.IsValid(); 4004 bool is_history_navigation = request_params.page_state.IsValid();
4154 WebURLRequest::CachePolicy cache_policy = 4005 WebURLRequest::CachePolicy cache_policy =
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
4467 if (policy == blink::WebNavigationPolicyNewBackgroundTab || 4318 if (policy == blink::WebNavigationPolicyNewBackgroundTab ||
4468 policy == blink::WebNavigationPolicyNewForegroundTab || 4319 policy == blink::WebNavigationPolicyNewForegroundTab ||
4469 policy == blink::WebNavigationPolicyNewWindow || 4320 policy == blink::WebNavigationPolicyNewWindow ||
4470 policy == blink::WebNavigationPolicyNewPopup) { 4321 policy == blink::WebNavigationPolicyNewPopup) {
4471 WebUserGestureIndicator::consumeUserGesture(); 4322 WebUserGestureIndicator::consumeUserGesture();
4472 } 4323 }
4473 4324
4474 Send(new FrameHostMsg_OpenURL(routing_id_, params)); 4325 Send(new FrameHostMsg_OpenURL(routing_id_, params));
4475 } 4326 }
4476 4327
4328 void RenderFrameImpl::NavigateInternal(
4329 const CommonNavigationParams& common_params,
4330 const StartNavigationParams& start_params,
4331 const RequestNavigationParams& request_params,
4332 scoped_ptr<StreamOverrideParameters> stream_params) {
4333 bool browser_side_navigation =
4334 base::CommandLine::ForCurrentProcess()->HasSwitch(
4335 switches::kEnableBrowserSideNavigation);
4336 bool is_reload = IsReload(common_params.navigation_type);
4337 bool is_history_navigation = request_params.page_state.IsValid();
4338 WebURLRequest::CachePolicy cache_policy =
4339 WebURLRequest::UseProtocolCachePolicy;
4340 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
4341 common_params.url, is_history_navigation, request_params, &is_reload,
4342 &cache_policy)) {
4343 Send(new FrameHostMsg_DidDropNavigation(routing_id_));
4344 return;
4345 }
4346
4347 GetContentClient()->SetActiveURL(common_params.url);
4348
4349 // If this frame isn't in the same process as its parent, it will naively
4350 // assume that this is the first navigation in the iframe, but this may not
4351 // actually be the case. The PageTransition differentiates between the first
4352 // navigation in a subframe and subsequent navigations, so if this is a
4353 // subsequent navigation, force the frame's state machine forward.
4354 if (ui::PageTransitionCoreTypeIs(common_params.transition,
4355 ui::PAGE_TRANSITION_MANUAL_SUBFRAME)) {
Avi (use Gerrit) 2015/04/28 15:39:08 See above about this block.
clamy 2015/04/29 09:36:57 Done. It was removed following a rebase on https:/
4356 CHECK(frame_->parent());
4357 if (frame_->parent()->isWebRemoteFrame()) {
4358 frame_->setCommittedFirstRealLoad();
4359 }
4360 }
4361
4362 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) {
4363 // We cannot reload if we do not have any history state. This happens, for
4364 // example, when recovering from a crash.
4365 is_reload = false;
4366 cache_policy = WebURLRequest::ReloadIgnoringCacheData;
4367 }
4368
4369 pending_navigation_params_.reset(
4370 new NavigationParams(common_params, start_params, request_params));
4371
4372 // If we are reloading, then Blink will use the history state of the current
4373 // page, so we should just ignore any given history state. Otherwise, if we
4374 // have history state, then we need to navigate to it, which corresponds to a
4375 // back/forward navigation event.
4376 if (is_reload && !browser_side_navigation) {
clamy 2015/04/28 10:26:40 Currently reloads are not properly supported by Pl
Charlie Reis 2015/04/28 23:01:03 Acknowledged.
4377 // TODO(clamy): adapt this code for PlzNavigate. In particular the stream
4378 // override should be given to the generated request,
nasko 2015/04/28 17:23:43 nit: period/full stop instead of comma after "requ
clamy 2015/04/29 09:36:57 Done.
4379 bool reload_original_url =
4380 (common_params.navigation_type ==
4381 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
4382 bool ignore_cache = (common_params.navigation_type ==
4383 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
4384
4385 if (reload_original_url)
4386 frame_->reloadWithOverrideURL(common_params.url, true);
4387 else
4388 frame_->reload(ignore_cache);
4389 } else if (is_history_navigation && !browser_side_navigation) {
clamy 2015/04/28 10:26:40 Same for history navigations.
Charlie Reis 2015/04/28 23:01:03 Acknowledged.
4390 // TODO(clamy): adapt this code for PlzNavigate. In particular the stream
4391 // override should be given to the generated request,
nasko 2015/04/28 17:23:43 nit: Another ',' -> '.'
clamy 2015/04/29 09:36:57 Done.
4392
4393 // We must know the page ID of the page we are navigating back to.
4394 DCHECK_NE(request_params.page_id, -1);
4395 scoped_ptr<HistoryEntry> entry =
4396 PageStateToHistoryEntry(request_params.page_state);
4397 if (entry) {
4398 // Ensure we didn't save the swapped out URL in UpdateState, since the
4399 // browser should never be telling us to navigate to swappedout://.
4400 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL));
4401 scoped_ptr<NavigationParams> navigation_params(
4402 new NavigationParams(*pending_navigation_params_.get()));
4403 render_view_->history_controller()->GoToEntry(
4404 entry.Pass(), navigation_params.Pass(), cache_policy);
4405 }
4406 } else if (!common_params.base_url_for_data_url.is_empty() ||
4407 (browser_side_navigation &&
4408 common_params.url.SchemeIs(url::kDataScheme))) {
4409 LoadDataURL(common_params, frame_);
4410 } else {
4411 // Navigate to the given URL.
4412 WebURLRequest request = CreateURLRequestForNavigation(
4413 common_params, stream_params.Pass(), frame_->isViewSourceModeEnabled());
4414
4415 if (!start_params.extra_headers.empty() && !browser_side_navigation) {
clamy 2015/04/28 10:26:41 This could maybe be extracted to a helper function
Avi (use Gerrit) 2015/04/28 15:39:07 Merged with what other code?
Charlie Reis 2015/04/28 23:01:03 Just a AddExtraHeaders(start_params.extra_headers,
clamy 2015/04/29 09:36:57 Acknowledged.
4416 for (net::HttpUtil::HeadersIterator i(start_params.extra_headers.begin(),
4417 start_params.extra_headers.end(),
4418 "\n");
4419 i.GetNext();) {
4420 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
4421 WebString::fromUTF8(i.values()));
4422 }
4423 }
4424
4425 if (start_params.is_post && !browser_side_navigation) {
4426 request.setHTTPMethod(WebString::fromUTF8("POST"));
4427
4428 // Set post data.
4429 WebHTTPBody http_body;
4430 http_body.initialize();
4431 const char* data = NULL;
Charlie Reis 2015/04/28 23:01:03 nullptr (while we're here and tweaking small thing
clamy 2015/04/29 09:36:57 Done.
4432 if (start_params.browser_initiated_post_data.size()) {
4433 data = reinterpret_cast<const char*>(
4434 &start_params.browser_initiated_post_data.front());
4435 }
4436 http_body.appendData(
4437 WebData(data, start_params.browser_initiated_post_data.size()));
4438 request.setHTTPBody(http_body);
4439 }
4440
4441 // A session history navigation should have been accompanied by state.
4442 CHECK_EQ(request_params.page_id, -1);
4443
4444 // PlzNavigate: Make sure that blink loader will not try to use browser side
Charlie Reis 2015/04/28 23:01:03 s/blink/Blink's/
clamy 2015/04/29 09:36:57 Done.
4445 // navigation for this request (since it already went to the browser).
4446 if (browser_side_navigation)
4447 request.setCheckForBrowserSideNavigation(false);
4448
4449 // Record this before starting the load, we need a lower bound of this time
Charlie Reis 2015/04/28 23:01:03 nit: Period rather than comma (or "since we").
clamy 2015/04/29 09:36:57 Done.
4450 // to sanitize the navigationStart override set below.
4451 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
4452 frame_->loadRequest(request);
4453
4454 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start,
4455 renderer_navigation_start);
4456 }
4457
4458 // In case LoadRequest failed before didCreateDataSource was called.
4459 pending_navigation_params_.reset();
4460 }
4461
4477 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, 4462 void RenderFrameImpl::UpdateEncoding(WebFrame* frame,
4478 const std::string& encoding_name) { 4463 const std::string& encoding_name) {
4479 // Only update main frame's encoding_name. 4464 // Only update main frame's encoding_name.
4480 if (!frame->parent()) 4465 if (!frame->parent())
4481 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); 4466 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name));
4482 } 4467 }
4483 4468
4484 void RenderFrameImpl::SyncSelectionIfRequired() { 4469 void RenderFrameImpl::SyncSelectionIfRequired() {
4485 base::string16 text; 4470 base::string16 text;
4486 size_t offset; 4471 size_t offset;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
4871 #elif defined(ENABLE_BROWSER_CDMS) 4856 #elif defined(ENABLE_BROWSER_CDMS)
4872 cdm_manager_, 4857 cdm_manager_,
4873 #endif 4858 #endif
4874 this); 4859 this);
4875 } 4860 }
4876 4861
4877 return cdm_factory_; 4862 return cdm_factory_;
4878 } 4863 }
4879 4864
4880 } // namespace content 4865 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698