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

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

Issue 872473003: PlzNavigate: Remove the RequestNavigation IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits + fix compilation error Created 5 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
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | content/renderer/render_view_browsertest.cc » ('j') | 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 return true; 378 return true;
379 379
380 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) 380 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
381 return true; 381 return true;
382 } 382 }
383 return false; 383 return false;
384 } 384 }
385 385
386 WebURLRequest CreateURLRequestForNavigation( 386 WebURLRequest CreateURLRequestForNavigation(
387 const CommonNavigationParams& common_params, 387 const CommonNavigationParams& common_params,
388 const RequestNavigationParams& request_params,
389 scoped_ptr<StreamOverrideParameters> stream_override, 388 scoped_ptr<StreamOverrideParameters> stream_override,
390 bool is_view_source_mode_enabled) { 389 bool is_view_source_mode_enabled) {
391 WebURLRequest request(common_params.url); 390 WebURLRequest request(common_params.url);
392 if (is_view_source_mode_enabled) 391 if (is_view_source_mode_enabled)
393 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); 392 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
394 393
395 if (common_params.referrer.url.is_valid()) { 394 if (common_params.referrer.url.is_valid()) {
396 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( 395 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader(
397 common_params.referrer.policy, 396 common_params.referrer.policy,
398 common_params.url, 397 common_params.url,
399 WebString::fromUTF8(common_params.referrer.url.spec())); 398 WebString::fromUTF8(common_params.referrer.url.spec()));
400 if (!web_referrer.isEmpty()) 399 if (!web_referrer.isEmpty())
401 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); 400 request.setHTTPReferrer(web_referrer, common_params.referrer.policy);
402 } 401 }
403 402
404 if (!request_params.extra_headers.empty()) {
405 for (net::HttpUtil::HeadersIterator i(request_params.extra_headers.begin(),
406 request_params.extra_headers.end(),
407 "\n");
408 i.GetNext();) {
409 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
410 WebString::fromUTF8(i.values()));
411 }
412 }
413
414 if (request_params.is_post) {
415 request.setHTTPMethod(WebString::fromUTF8("POST"));
416
417 // Set post data.
418 WebHTTPBody http_body;
419 http_body.initialize();
420 const char* data = NULL;
421 if (request_params.browser_initiated_post_data.size()) {
422 data = reinterpret_cast<const char*>(
423 &request_params.browser_initiated_post_data.front());
424 }
425 http_body.appendData(
426 WebData(data, request_params.browser_initiated_post_data.size()));
427 request.setHTTPBody(http_body);
428 }
429
430 RequestExtraData* extra_data = new RequestExtraData(); 403 RequestExtraData* extra_data = new RequestExtraData();
431 extra_data->set_stream_override(stream_override.Pass()); 404 extra_data->set_stream_override(stream_override.Pass());
432 request.setExtraData(extra_data); 405 request.setExtraData(extra_data);
433 406
434 // Set the ui timestamp for this navigation. Currently the timestamp here is 407 // Set the ui timestamp for this navigation. Currently the timestamp here is
435 // only non empty when the navigation was triggered by an Android intent. The 408 // only non empty when the navigation was triggered by an Android intent. The
436 // timestamp is converted to a double version supported by blink. It will be 409 // timestamp is converted to a double version supported by blink. It will be
437 // passed back to the browser in the DidCommitProvisionalLoad and the 410 // passed back to the browser in the DidCommitProvisionalLoad and the
438 // DocumentLoadComplete IPCs. 411 // DocumentLoadComplete IPCs.
439 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks(); 412 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks();
(...skipping 22 matching lines...) Expand all
462 double navigation_start_seconds = 435 double navigation_start_seconds =
463 (navigation_start - base::TimeTicks()).InSecondsF(); 436 (navigation_start - base::TimeTicks()).InSecondsF();
464 frame->provisionalDataSource()->setNavigationStartTime( 437 frame->provisionalDataSource()->setNavigationStartTime(
465 navigation_start_seconds); 438 navigation_start_seconds);
466 // TODO(clamy): We need to provide additional timing values for the 439 // TODO(clamy): We need to provide additional timing values for the
467 // Navigation Timing API to work with browser-side navigations. 440 // Navigation Timing API to work with browser-side navigations.
468 } 441 }
469 } 442 }
470 443
471 // PlzNavigate 444 // PlzNavigate
472 FrameHostMsg_BeginNavigation_Params MakeBeginNavigationParams(
473 blink::WebURLRequest* request) {
474 FrameHostMsg_BeginNavigation_Params params;
475 params.method = request->httpMethod().latin1();
476 params.headers = GetWebURLRequestHeaders(*request);
477 params.load_flags = GetLoadFlagsForWebURLRequest(*request);
478 params.request_body = GetRequestBodyForWebURLRequest(*request);
479 params.has_user_gesture = request->hasUserGesture();
480 return params;
481 }
482
483 // PlzNavigate
484 CommonNavigationParams MakeCommonNavigationParams( 445 CommonNavigationParams MakeCommonNavigationParams(
485 blink::WebURLRequest* request) { 446 blink::WebURLRequest* request) {
486 const RequestExtraData kEmptyData; 447 const RequestExtraData kEmptyData;
487 const RequestExtraData* extra_data = 448 const RequestExtraData* extra_data =
488 static_cast<RequestExtraData*>(request->extraData()); 449 static_cast<RequestExtraData*>(request->extraData());
489 if (!extra_data) 450 if (!extra_data)
490 extra_data = &kEmptyData; 451 extra_data = &kEmptyData;
491 CommonNavigationParams params; 452 CommonNavigationParams params;
492 params.url = request->url(); 453 params.url = request->url();
493 params.referrer = Referrer( 454 params.referrer = Referrer(
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 IPC_MESSAGE_HANDLER(FrameMsg_ShowTransitionElements, 1001 IPC_MESSAGE_HANDLER(FrameMsg_ShowTransitionElements,
1041 OnShowTransitionElements) 1002 OnShowTransitionElements)
1042 IPC_MESSAGE_HANDLER(FrameMsg_Reload, OnReload) 1003 IPC_MESSAGE_HANDLER(FrameMsg_Reload, OnReload)
1043 IPC_MESSAGE_HANDLER(FrameMsg_TextSurroundingSelectionRequest, 1004 IPC_MESSAGE_HANDLER(FrameMsg_TextSurroundingSelectionRequest,
1044 OnTextSurroundingSelectionRequest) 1005 OnTextSurroundingSelectionRequest)
1045 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL, 1006 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL,
1046 OnAddStyleSheetByURL) 1007 OnAddStyleSheetByURL)
1047 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode, 1008 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode,
1048 OnSetAccessibilityMode) 1009 OnSetAccessibilityMode)
1049 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener) 1010 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener)
1050 IPC_MESSAGE_HANDLER(FrameMsg_RequestNavigation, OnRequestNavigation)
1051 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation) 1011 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation)
1052 #if defined(OS_ANDROID) 1012 #if defined(OS_ANDROID)
1053 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) 1013 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
1054 #elif defined(OS_MACOSX) 1014 #elif defined(OS_MACOSX)
1055 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) 1015 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1056 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) 1016 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
1057 #endif 1017 #endif
1058 IPC_END_MESSAGE_MAP() 1018 IPC_END_MESSAGE_MAP()
1059 1019
1060 return handled; 1020 return handled;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 params.history_url_for_data_url, 1103 params.history_url_for_data_url,
1144 false); 1104 false);
1145 } else { 1105 } else {
1146 CHECK(false) << "Invalid URL passed: " 1106 CHECK(false) << "Invalid URL passed: "
1147 << params.common_params.url.possibly_invalid_spec(); 1107 << params.common_params.url.possibly_invalid_spec();
1148 } 1108 }
1149 } else { 1109 } else {
1150 // Navigate to the given URL. 1110 // Navigate to the given URL.
1151 WebURLRequest request = 1111 WebURLRequest request =
1152 CreateURLRequestForNavigation(params.common_params, 1112 CreateURLRequestForNavigation(params.common_params,
1153 params.request_params,
1154 scoped_ptr<StreamOverrideParameters>(), 1113 scoped_ptr<StreamOverrideParameters>(),
1155 frame->isViewSourceModeEnabled()); 1114 frame->isViewSourceModeEnabled());
1156 1115
1116 if (!params.extra_headers.empty()) {
1117 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1118 params.extra_headers.end(),
1119 "\n");
1120 i.GetNext();) {
1121 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1122 WebString::fromUTF8(i.values()));
1123 }
1124 }
1125
1126 if (params.is_post) {
1127 request.setHTTPMethod(WebString::fromUTF8("POST"));
1128
1129 // Set post data.
1130 WebHTTPBody http_body;
1131 http_body.initialize();
1132 const char* data = NULL;
1133 if (params.browser_initiated_post_data.size()) {
1134 data = reinterpret_cast<const char*>(
1135 &params.browser_initiated_post_data.front());
1136 }
1137 http_body.appendData(
1138 WebData(data, params.browser_initiated_post_data.size()));
1139 request.setHTTPBody(http_body);
1140 }
1141
1157 // A session history navigation should have been accompanied by state. 1142 // A session history navigation should have been accompanied by state.
1158 CHECK_EQ(params.page_id, -1); 1143 CHECK_EQ(params.page_id, -1);
1159 1144
1160 // Record this before starting the load, we need a lower bound of this time 1145 // Record this before starting the load, we need a lower bound of this time
1161 // to sanitize the navigationStart override set below. 1146 // to sanitize the navigationStart override set below.
1162 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 1147 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
1163 frame->loadRequest(request); 1148 frame->loadRequest(request);
1164 1149
1165 UpdateFrameNavigationTiming( 1150 UpdateFrameNavigationTiming(
1166 frame, params.commit_params.browser_navigation_start, 1151 frame, params.commit_params.browser_navigation_start,
(...skipping 2712 matching lines...) Expand 10 before | Expand all | Expand 10 after
3879 void RenderFrameImpl::FocusedNodeChanged(const WebNode& node) { 3864 void RenderFrameImpl::FocusedNodeChanged(const WebNode& node) {
3880 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FocusedNodeChanged(node)); 3865 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FocusedNodeChanged(node));
3881 } 3866 }
3882 3867
3883 void RenderFrameImpl::FocusedNodeChangedForAccessibility(const WebNode& node) { 3868 void RenderFrameImpl::FocusedNodeChangedForAccessibility(const WebNode& node) {
3884 if (renderer_accessibility()) 3869 if (renderer_accessibility())
3885 renderer_accessibility()->AccessibilityFocusedNodeChanged(node); 3870 renderer_accessibility()->AccessibilityFocusedNodeChanged(node);
3886 } 3871 }
3887 3872
3888 // PlzNavigate 3873 // PlzNavigate
3889 void RenderFrameImpl::OnRequestNavigation(
3890 const CommonNavigationParams& common_params,
3891 const RequestNavigationParams& request_params) {
3892 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
3893 switches::kEnableBrowserSideNavigation));
3894 WebURLRequest request =
3895 CreateURLRequestForNavigation(common_params,
3896 request_params,
3897 scoped_ptr<StreamOverrideParameters>(),
3898 frame_->isViewSourceModeEnabled());
3899 BeginNavigation(&request);
3900 }
3901
3902 // PlzNavigate
3903 void RenderFrameImpl::OnCommitNavigation( 3874 void RenderFrameImpl::OnCommitNavigation(
3904 const ResourceResponseHead& response, 3875 const ResourceResponseHead& response,
3905 const GURL& stream_url, 3876 const GURL& stream_url,
3906 const CommonNavigationParams& common_params, 3877 const CommonNavigationParams& common_params,
3907 const CommitNavigationParams& commit_params) { 3878 const CommitNavigationParams& commit_params) {
3908 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 3879 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
3909 switches::kEnableBrowserSideNavigation)); 3880 switches::kEnableBrowserSideNavigation));
3910 bool is_reload = false; 3881 bool is_reload = false;
3911 bool is_history_navigation = commit_params.page_state.IsValid(); 3882 bool is_history_navigation = commit_params.page_state.IsValid();
3912 WebURLRequest::CachePolicy cache_policy = 3883 WebURLRequest::CachePolicy cache_policy =
(...skipping 11 matching lines...) Expand all
3924 // response through a stream in the browser. Blink will then commit the 3895 // response through a stream in the browser. Blink will then commit the
3925 // navigation. 3896 // navigation.
3926 // TODO(clamy): Have the navigation commit directly, without going through 3897 // TODO(clamy): Have the navigation commit directly, without going through
3927 // loading a WebURLRequest. 3898 // loading a WebURLRequest.
3928 scoped_ptr<StreamOverrideParameters> stream_override( 3899 scoped_ptr<StreamOverrideParameters> stream_override(
3929 new StreamOverrideParameters()); 3900 new StreamOverrideParameters());
3930 stream_override->stream_url = stream_url; 3901 stream_override->stream_url = stream_url;
3931 stream_override->response = response; 3902 stream_override->response = response;
3932 WebURLRequest request = 3903 WebURLRequest request =
3933 CreateURLRequestForNavigation(common_params, 3904 CreateURLRequestForNavigation(common_params,
3934 RequestNavigationParams(),
3935 stream_override.Pass(), 3905 stream_override.Pass(),
3936 frame_->isViewSourceModeEnabled()); 3906 frame_->isViewSourceModeEnabled());
3937 3907
3938 // Make sure that blink loader will not try to use browser side navigation for 3908 // Make sure that blink loader will not try to use browser side navigation for
3939 // this request (since it already went to the browser). 3909 // this request (since it already went to the browser).
3940 request.setCheckForBrowserSideNavigation(false); 3910 request.setCheckForBrowserSideNavigation(false);
3941 3911
3942 // Record this before starting the load. A lower bound of this time is needed 3912 // Record this before starting the load. A lower bound of this time is needed
3943 // to sanitize the navigationStart override set below. 3913 // to sanitize the navigationStart override set below.
3944 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 3914 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
4398 // 4368 //
4399 // TODO(clamy): Apply devtools override. 4369 // TODO(clamy): Apply devtools override.
4400 // TODO(clamy): Make sure that navigation requests are not modified somewhere 4370 // TODO(clamy): Make sure that navigation requests are not modified somewhere
4401 // else in blink. 4371 // else in blink.
4402 willSendRequest(frame_, 0, *request, blink::WebURLResponse()); 4372 willSendRequest(frame_, 0, *request, blink::WebURLResponse());
4403 4373
4404 // TODO(clamy): Same-document navigations should not be sent back to the 4374 // TODO(clamy): Same-document navigations should not be sent back to the
4405 // browser. 4375 // browser.
4406 // TODO(clamy): Data urls should not be sent back to the browser either. 4376 // TODO(clamy): Data urls should not be sent back to the browser either.
4407 Send(new FrameHostMsg_DidStartLoading(routing_id_, true)); 4377 Send(new FrameHostMsg_DidStartLoading(routing_id_, true));
4408 Send(new FrameHostMsg_BeginNavigation(routing_id_, 4378 Send(new FrameHostMsg_BeginNavigation(
4409 MakeBeginNavigationParams(request), 4379 routing_id_, MakeCommonNavigationParams(request),
4410 MakeCommonNavigationParams(request))); 4380 BeginNavigationParams(request->httpMethod().latin1(),
4381 GetWebURLRequestHeaders(*request),
4382 GetLoadFlagsForWebURLRequest(*request),
4383 request->hasUserGesture()),
4384 GetRequestBodyForWebURLRequest(*request)));
4411 } 4385 }
4412 4386
4413 GURL RenderFrameImpl::GetLoadingUrl() const { 4387 GURL RenderFrameImpl::GetLoadingUrl() const {
4414 WebDataSource* ds = frame_->dataSource(); 4388 WebDataSource* ds = frame_->dataSource();
4415 if (ds->hasUnreachableURL()) 4389 if (ds->hasUnreachableURL())
4416 return ds->unreachableURL(); 4390 return ds->unreachableURL();
4417 4391
4418 const WebURLRequest& request = ds->request(); 4392 const WebURLRequest& request = ds->request();
4419 return request.url(); 4393 return request.url();
4420 } 4394 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
4474 4448
4475 #if defined(ENABLE_BROWSER_CDMS) 4449 #if defined(ENABLE_BROWSER_CDMS)
4476 RendererCdmManager* RenderFrameImpl::GetCdmManager() { 4450 RendererCdmManager* RenderFrameImpl::GetCdmManager() {
4477 if (!cdm_manager_) 4451 if (!cdm_manager_)
4478 cdm_manager_ = new RendererCdmManager(this); 4452 cdm_manager_ = new RendererCdmManager(this);
4479 return cdm_manager_; 4453 return cdm_manager_;
4480 } 4454 }
4481 #endif // defined(ENABLE_BROWSER_CDMS) 4455 #endif // defined(ENABLE_BROWSER_CDMS)
4482 4456
4483 } // namespace content 4457 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | content/renderer/render_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698