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

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

Issue 2653953005: PlzNavigate: transmit redirect info to the renderer side (Closed)
Patch Set: PlzNavigate: transmit redirect info to the renderer side Created 3 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
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 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 #endif // ADDRESS_SANITIZER || SYZYASAN 552 #endif // ADDRESS_SANITIZER || SYZYASAN
553 } 553 }
554 554
555 // Returns false unless this is a top-level navigation. 555 // Returns false unless this is a top-level navigation.
556 bool IsTopLevelNavigation(WebFrame* frame) { 556 bool IsTopLevelNavigation(WebFrame* frame) {
557 return frame->parent() == NULL; 557 return frame->parent() == NULL;
558 } 558 }
559 559
560 WebURLRequest CreateURLRequestForNavigation( 560 WebURLRequest CreateURLRequestForNavigation(
561 const CommonNavigationParams& common_params, 561 const CommonNavigationParams& common_params,
562 const RequestNavigationParams& request_params,
562 std::unique_ptr<StreamOverrideParameters> stream_override, 563 std::unique_ptr<StreamOverrideParameters> stream_override,
563 bool is_view_source_mode_enabled, 564 bool is_view_source_mode_enabled,
564 bool is_same_document_navigation, 565 bool is_same_document_navigation) {
565 int nav_entry_id) { 566 // PlzNavigate: use the original navigation url to construct the
566 WebURLRequest request(common_params.url); 567 // WebURLRequest. The WebURLloaderImpl will replay the redirects afterwards
568 // and will eventually commit the final url.
569 const GURL navigation_url = IsBrowserSideNavigationEnabled() &&
570 !request_params.original_url.is_empty()
571 ? request_params.original_url
572 : common_params.url;
573 const std::string navigation_method =
574 IsBrowserSideNavigationEnabled() &&
575 !request_params.original_method.empty()
576 ? request_params.original_method
577 : common_params.method;
578 WebURLRequest request(navigation_url);
579 request.setHTTPMethod(WebString::fromUTF8(navigation_method));
580
567 if (is_view_source_mode_enabled) 581 if (is_view_source_mode_enabled)
568 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad); 582 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad);
569 583
570 request.setHTTPMethod(WebString::fromUTF8(common_params.method));
571 if (common_params.referrer.url.is_valid()) { 584 if (common_params.referrer.url.is_valid()) {
572 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( 585 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader(
573 common_params.referrer.policy, common_params.url, 586 common_params.referrer.policy, common_params.url,
574 WebString::fromUTF8(common_params.referrer.url.spec())); 587 WebString::fromUTF8(common_params.referrer.url.spec()));
575 if (!web_referrer.isEmpty()) { 588 if (!web_referrer.isEmpty()) {
576 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); 589 request.setHTTPReferrer(web_referrer, common_params.referrer.policy);
577 request.addHTTPOriginIfNeeded( 590 request.addHTTPOriginIfNeeded(
578 WebSecurityOrigin(url::Origin(common_params.referrer.url))); 591 WebSecurityOrigin(url::Origin(common_params.referrer.url)));
579 } 592 }
580 } 593 }
581 594
582 request.setIsSameDocumentNavigation(is_same_document_navigation); 595 request.setIsSameDocumentNavigation(is_same_document_navigation);
583 request.setPreviewsState( 596 request.setPreviewsState(
584 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state)); 597 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state));
585 598
586 RequestExtraData* extra_data = new RequestExtraData(); 599 RequestExtraData* extra_data = new RequestExtraData();
587 extra_data->set_stream_override(std::move(stream_override)); 600 extra_data->set_stream_override(std::move(stream_override));
588 extra_data->set_navigation_initiated_by_renderer(nav_entry_id == 0); 601 extra_data->set_navigation_initiated_by_renderer(
602 request_params.nav_entry_id == 0);
589 request.setExtraData(extra_data); 603 request.setExtraData(extra_data);
590 604
591 // Set the ui timestamp for this navigation. Currently the timestamp here is 605 // Set the ui timestamp for this navigation. Currently the timestamp here is
592 // only non empty when the navigation was triggered by an Android intent. The 606 // only non empty when the navigation was triggered by an Android intent. The
593 // timestamp is converted to a double version supported by blink. It will be 607 // timestamp is converted to a double version supported by blink. It will be
594 // passed back to the browser in the DidCommitProvisionalLoad and the 608 // passed back to the browser in the DidCommitProvisionalLoad and the
595 // DocumentLoadComplete IPCs. 609 // DocumentLoadComplete IPCs.
596 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks(); 610 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks();
597 request.setUiStartTime(ui_timestamp.InSecondsF()); 611 request.setUiStartTime(ui_timestamp.InSecondsF());
598 request.setInputPerfMetricReportPolicy( 612 request.setInputPerfMetricReportPolicy(
(...skipping 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after
3357 observer.WillSubmitForm(form); 3371 observer.WillSubmitForm(form);
3358 } 3372 }
3359 3373
3360 void RenderFrameImpl::didCreateDataSource(blink::WebLocalFrame* frame, 3374 void RenderFrameImpl::didCreateDataSource(blink::WebLocalFrame* frame,
3361 blink::WebDataSource* datasource) { 3375 blink::WebDataSource* datasource) {
3362 DCHECK(!frame_ || frame_ == frame); 3376 DCHECK(!frame_ || frame_ == frame);
3363 3377
3364 bool content_initiated = !pending_navigation_params_.get(); 3378 bool content_initiated = !pending_navigation_params_.get();
3365 3379
3366 // Make sure any previous redirect URLs end up in our new data source. 3380 // Make sure any previous redirect URLs end up in our new data source.
3367 if (pending_navigation_params_.get()) { 3381 if (pending_navigation_params_.get() && !IsBrowserSideNavigationEnabled()) {
3368 for (const auto& i : 3382 for (const auto& i :
3369 pending_navigation_params_->request_params.redirects) { 3383 pending_navigation_params_->request_params.redirects) {
3370 datasource->appendRedirect(i); 3384 datasource->appendRedirect(i);
3371 } 3385 }
3372 } 3386 }
3373 3387
3374 DocumentState* document_state = DocumentState::FromDataSource(datasource); 3388 DocumentState* document_state = DocumentState::FromDataSource(datasource);
3375 if (!document_state) { 3389 if (!document_state) {
3376 document_state = new DocumentState; 3390 document_state = new DocumentState;
3377 datasource->setExtraData(document_state); 3391 datasource->setExtraData(document_state);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3414 !navigation_state->request_params() 3428 !navigation_state->request_params()
3415 .navigation_timing.fetch_start.is_null()) { 3429 .navigation_timing.fetch_start.is_null()) {
3416 // Set timing of several events that happened during navigation. 3430 // Set timing of several events that happened during navigation.
3417 // They will be used in blink for the Navigation Timing API. 3431 // They will be used in blink for the Navigation Timing API.
3418 double redirect_start = ConvertToBlinkTime( 3432 double redirect_start = ConvertToBlinkTime(
3419 navigation_state->request_params().navigation_timing.redirect_start); 3433 navigation_state->request_params().navigation_timing.redirect_start);
3420 double redirect_end = ConvertToBlinkTime( 3434 double redirect_end = ConvertToBlinkTime(
3421 navigation_state->request_params().navigation_timing.redirect_end); 3435 navigation_state->request_params().navigation_timing.redirect_end);
3422 double fetch_start = ConvertToBlinkTime( 3436 double fetch_start = ConvertToBlinkTime(
3423 navigation_state->request_params().navigation_timing.fetch_start); 3437 navigation_state->request_params().navigation_timing.fetch_start);
3424 std::vector<GURL> redirectChain =
3425 navigation_state->request_params().redirects;
3426 redirectChain.push_back(navigation_state->common_params().url);
3427 3438
3428 datasource->updateNavigation(redirect_start, redirect_end, fetch_start, 3439 datasource->updateNavigation(
3429 redirectChain); 3440 redirect_start, redirect_end, fetch_start,
3441 !navigation_state->request_params().redirects.empty());
3430 // TODO(clamy) We need to provide additional timing values for the 3442 // TODO(clamy) We need to provide additional timing values for the
3431 // Navigation Timing API to work with browser-side navigations. 3443 // Navigation Timing API to work with browser-side navigations.
3432 // UnloadEventStart and UnloadEventEnd are still missing. 3444 // UnloadEventStart and UnloadEventEnd are still missing.
3433 } 3445 }
3434 3446
3435 // Create the serviceworker's per-document network observing object if it 3447 // Create the serviceworker's per-document network observing object if it
3436 // does not exist (When navigation happens within a page, the provider already 3448 // does not exist (When navigation happens within a page, the provider already
3437 // exists). 3449 // exists).
3438 if (ServiceWorkerNetworkProvider::FromDocumentState( 3450 if (ServiceWorkerNetworkProvider::FromDocumentState(
3439 DocumentState::FromDataSource(datasource))) 3451 DocumentState::FromDataSource(datasource)))
(...skipping 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after
5139 const RequestNavigationParams& request_params) { 5151 const RequestNavigationParams& request_params) {
5140 CHECK(IsBrowserSideNavigationEnabled()); 5152 CHECK(IsBrowserSideNavigationEnabled());
5141 // This will override the url requested by the WebURLLoader, as well as 5153 // This will override the url requested by the WebURLLoader, as well as
5142 // provide it with the response to the request. 5154 // provide it with the response to the request.
5143 std::unique_ptr<StreamOverrideParameters> stream_override( 5155 std::unique_ptr<StreamOverrideParameters> stream_override(
5144 new StreamOverrideParameters()); 5156 new StreamOverrideParameters());
5145 stream_override->stream_url = stream_url; 5157 stream_override->stream_url = stream_url;
5146 stream_override->response = response; 5158 stream_override->response = response;
5147 stream_override->redirects = request_params.redirects; 5159 stream_override->redirects = request_params.redirects;
5148 stream_override->redirect_responses = request_params.redirect_response; 5160 stream_override->redirect_responses = request_params.redirect_response;
5161 stream_override->redirect_infos = request_params.redirect_infos;
5149 5162
5150 // If the request was initiated in the context of a user gesture then make 5163 // If the request was initiated in the context of a user gesture then make
5151 // sure that the navigation also executes in the context of a user gesture. 5164 // sure that the navigation also executes in the context of a user gesture.
5152 std::unique_ptr<blink::WebScopedUserGesture> gesture( 5165 std::unique_ptr<blink::WebScopedUserGesture> gesture(
5153 request_params.has_user_gesture ? new blink::WebScopedUserGesture(frame_) 5166 request_params.has_user_gesture ? new blink::WebScopedUserGesture(frame_)
5154 : nullptr); 5167 : nullptr);
5155 5168
5156 browser_side_navigation_pending_ = false; 5169 browser_side_navigation_pending_ = false;
5157 5170
5158 NavigateInternal(common_params, StartNavigationParams(), request_params, 5171 NavigateInternal(common_params, StartNavigationParams(), request_params,
(...skipping 23 matching lines...) Expand all
5182 // already committed other loads. 5195 // already committed other loads.
5183 if (request_params.has_committed_real_load && frame_->parent()) 5196 if (request_params.has_committed_real_load && frame_->parent())
5184 frame_->setCommittedFirstRealLoad(); 5197 frame_->setCommittedFirstRealLoad();
5185 5198
5186 pending_navigation_params_.reset(new NavigationParams( 5199 pending_navigation_params_.reset(new NavigationParams(
5187 common_params, StartNavigationParams(), request_params)); 5200 common_params, StartNavigationParams(), request_params));
5188 5201
5189 // Send the provisional load failure. 5202 // Send the provisional load failure.
5190 blink::WebURLError error = 5203 blink::WebURLError error =
5191 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code); 5204 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code);
5192 WebURLRequest failed_request = CreateURLRequestForNavigation( 5205 WebURLRequest failed_request =
5193 common_params, std::unique_ptr<StreamOverrideParameters>(), 5206 CreateURLRequestForNavigation(common_params, request_params,
5194 frame_->isViewSourceModeEnabled(), 5207 std::unique_ptr<StreamOverrideParameters>(),
5195 false, // is_same_document_navigation 5208 frame_->isViewSourceModeEnabled(),
5196 request_params.nav_entry_id); 5209 false); // is_same_document_navigation
5197 5210
5198 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) { 5211 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) {
5199 // The browser expects this frame to be loading an error page. Inform it 5212 // The browser expects this frame to be loading an error page. Inform it
5200 // that the load stopped. 5213 // that the load stopped.
5201 Send(new FrameHostMsg_DidStopLoading(routing_id_)); 5214 Send(new FrameHostMsg_DidStopLoading(routing_id_));
5202 browser_side_navigation_pending_ = false; 5215 browser_side_navigation_pending_ = false;
5203 return; 5216 return;
5204 } 5217 }
5205 5218
5206 // On load failure, a frame can ask its owner to render fallback content. 5219 // On load failure, a frame can ask its owner to render fallback content.
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
5868 bool should_load_request = false; 5881 bool should_load_request = false;
5869 WebHistoryItem item_for_history_navigation; 5882 WebHistoryItem item_for_history_navigation;
5870 5883
5871 // Enforce same-document navigation from the browser only if 5884 // Enforce same-document navigation from the browser only if
5872 // browser-side-navigation is enabled. 5885 // browser-side-navigation is enabled.
5873 bool is_same_document = 5886 bool is_same_document =
5874 IsBrowserSideNavigationEnabled() && 5887 IsBrowserSideNavigationEnabled() &&
5875 FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type); 5888 FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type);
5876 5889
5877 WebURLRequest request = CreateURLRequestForNavigation( 5890 WebURLRequest request = CreateURLRequestForNavigation(
5878 common_params, std::move(stream_params), 5891 common_params, request_params, std::move(stream_params),
5879 frame_->isViewSourceModeEnabled(), is_same_document, 5892 frame_->isViewSourceModeEnabled(), is_same_document);
5880 request_params.nav_entry_id);
5881 request.setFrameType(IsTopLevelNavigation(frame_) 5893 request.setFrameType(IsTopLevelNavigation(frame_)
5882 ? blink::WebURLRequest::FrameTypeTopLevel 5894 ? blink::WebURLRequest::FrameTypeTopLevel
5883 : blink::WebURLRequest::FrameTypeNested); 5895 : blink::WebURLRequest::FrameTypeNested);
5884 5896
5885 if (IsBrowserSideNavigationEnabled() && common_params.post_data) 5897 if (IsBrowserSideNavigationEnabled() && common_params.post_data)
5886 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data)); 5898 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data));
5887 5899
5888 // Used to determine whether this frame is actually loading a request as part 5900 // Used to determine whether this frame is actually loading a request as part
5889 // of a history navigation. 5901 // of a history navigation.
5890 bool has_history_navigation_in_frame = false; 5902 bool has_history_navigation_in_frame = false;
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
6838 // event target. Potentially a Pepper plugin will receive the event. 6850 // event target. Potentially a Pepper plugin will receive the event.
6839 // In order to tell whether a plugin gets the last mouse event and which it 6851 // In order to tell whether a plugin gets the last mouse event and which it
6840 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6852 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6841 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6853 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6842 // |pepper_last_mouse_event_target_|. 6854 // |pepper_last_mouse_event_target_|.
6843 pepper_last_mouse_event_target_ = nullptr; 6855 pepper_last_mouse_event_target_ = nullptr;
6844 #endif 6856 #endif
6845 } 6857 }
6846 6858
6847 } // namespace content 6859 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698