| 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 #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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 #endif // ADDRESS_SANITIZER || SYZYASAN | 554 #endif // ADDRESS_SANITIZER || SYZYASAN |
| 555 } | 555 } |
| 556 | 556 |
| 557 // Returns false unless this is a top-level navigation. | 557 // Returns false unless this is a top-level navigation. |
| 558 bool IsTopLevelNavigation(WebFrame* frame) { | 558 bool IsTopLevelNavigation(WebFrame* frame) { |
| 559 return frame->parent() == NULL; | 559 return frame->parent() == NULL; |
| 560 } | 560 } |
| 561 | 561 |
| 562 WebURLRequest CreateURLRequestForNavigation( | 562 WebURLRequest CreateURLRequestForNavigation( |
| 563 const CommonNavigationParams& common_params, | 563 const CommonNavigationParams& common_params, |
| 564 const RequestNavigationParams& request_params, |
| 564 std::unique_ptr<StreamOverrideParameters> stream_override, | 565 std::unique_ptr<StreamOverrideParameters> stream_override, |
| 565 bool is_view_source_mode_enabled, | 566 bool is_view_source_mode_enabled, |
| 566 bool is_same_document_navigation, | 567 bool is_same_document_navigation) { |
| 567 int nav_entry_id) { | 568 // PlzNavigate: use the original navigation url to construct the |
| 568 WebURLRequest request(common_params.url); | 569 // WebURLRequest. The WebURLloaderImpl will replay the redirects afterwards |
| 570 // and will eventually commit the final url. |
| 571 const GURL navigation_url = IsBrowserSideNavigationEnabled() && |
| 572 !request_params.original_url.is_empty() |
| 573 ? request_params.original_url |
| 574 : common_params.url; |
| 575 const std::string navigation_method = |
| 576 IsBrowserSideNavigationEnabled() && |
| 577 !request_params.original_method.empty() |
| 578 ? request_params.original_method |
| 579 : common_params.method; |
| 580 WebURLRequest request(navigation_url); |
| 581 request.setHTTPMethod(WebString::fromUTF8(navigation_method)); |
| 582 |
| 569 if (is_view_source_mode_enabled) | 583 if (is_view_source_mode_enabled) |
| 570 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad); | 584 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad); |
| 571 | 585 |
| 572 request.setHTTPMethod(WebString::fromUTF8(common_params.method)); | |
| 573 if (common_params.referrer.url.is_valid()) { | 586 if (common_params.referrer.url.is_valid()) { |
| 574 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( | 587 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( |
| 575 common_params.referrer.policy, common_params.url, | 588 common_params.referrer.policy, common_params.url, |
| 576 WebString::fromUTF8(common_params.referrer.url.spec())); | 589 WebString::fromUTF8(common_params.referrer.url.spec())); |
| 577 if (!web_referrer.isEmpty()) { | 590 if (!web_referrer.isEmpty()) { |
| 578 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); | 591 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); |
| 579 request.addHTTPOriginIfNeeded( | 592 request.addHTTPOriginIfNeeded( |
| 580 WebSecurityOrigin(url::Origin(common_params.referrer.url))); | 593 WebSecurityOrigin(url::Origin(common_params.referrer.url))); |
| 581 } | 594 } |
| 582 } | 595 } |
| 583 | 596 |
| 584 request.setIsSameDocumentNavigation(is_same_document_navigation); | 597 request.setIsSameDocumentNavigation(is_same_document_navigation); |
| 585 request.setPreviewsState( | 598 request.setPreviewsState( |
| 586 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state)); | 599 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state)); |
| 587 | 600 |
| 588 RequestExtraData* extra_data = new RequestExtraData(); | 601 RequestExtraData* extra_data = new RequestExtraData(); |
| 589 extra_data->set_stream_override(std::move(stream_override)); | 602 extra_data->set_stream_override(std::move(stream_override)); |
| 590 extra_data->set_navigation_initiated_by_renderer(nav_entry_id == 0); | 603 extra_data->set_navigation_initiated_by_renderer( |
| 604 request_params.nav_entry_id == 0); |
| 591 request.setExtraData(extra_data); | 605 request.setExtraData(extra_data); |
| 592 | 606 |
| 593 // Set the ui timestamp for this navigation. Currently the timestamp here is | 607 // Set the ui timestamp for this navigation. Currently the timestamp here is |
| 594 // only non empty when the navigation was triggered by an Android intent. The | 608 // only non empty when the navigation was triggered by an Android intent. The |
| 595 // timestamp is converted to a double version supported by blink. It will be | 609 // timestamp is converted to a double version supported by blink. It will be |
| 596 // passed back to the browser in the DidCommitProvisionalLoad and the | 610 // passed back to the browser in the DidCommitProvisionalLoad and the |
| 597 // DocumentLoadComplete IPCs. | 611 // DocumentLoadComplete IPCs. |
| 598 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks(); | 612 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks(); |
| 599 request.setUiStartTime(ui_timestamp.InSecondsF()); | 613 request.setUiStartTime(ui_timestamp.InSecondsF()); |
| 600 request.setInputPerfMetricReportPolicy( | 614 request.setInputPerfMetricReportPolicy( |
| (...skipping 2739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3340 observer.WillSubmitForm(form); | 3354 observer.WillSubmitForm(form); |
| 3341 } | 3355 } |
| 3342 | 3356 |
| 3343 void RenderFrameImpl::didCreateDataSource(blink::WebLocalFrame* frame, | 3357 void RenderFrameImpl::didCreateDataSource(blink::WebLocalFrame* frame, |
| 3344 blink::WebDataSource* datasource) { | 3358 blink::WebDataSource* datasource) { |
| 3345 DCHECK(!frame_ || frame_ == frame); | 3359 DCHECK(!frame_ || frame_ == frame); |
| 3346 | 3360 |
| 3347 bool content_initiated = !pending_navigation_params_.get(); | 3361 bool content_initiated = !pending_navigation_params_.get(); |
| 3348 | 3362 |
| 3349 // Make sure any previous redirect URLs end up in our new data source. | 3363 // Make sure any previous redirect URLs end up in our new data source. |
| 3350 if (pending_navigation_params_.get()) { | 3364 if (pending_navigation_params_.get() && !IsBrowserSideNavigationEnabled()) { |
| 3351 for (const auto& i : | 3365 for (const auto& i : |
| 3352 pending_navigation_params_->request_params.redirects) { | 3366 pending_navigation_params_->request_params.redirects) { |
| 3353 datasource->appendRedirect(i); | 3367 datasource->appendRedirect(i); |
| 3354 } | 3368 } |
| 3355 } | 3369 } |
| 3356 | 3370 |
| 3357 DocumentState* document_state = DocumentState::FromDataSource(datasource); | 3371 DocumentState* document_state = DocumentState::FromDataSource(datasource); |
| 3358 if (!document_state) { | 3372 if (!document_state) { |
| 3359 document_state = new DocumentState; | 3373 document_state = new DocumentState; |
| 3360 datasource->setExtraData(document_state); | 3374 datasource->setExtraData(document_state); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3397 !navigation_state->request_params() | 3411 !navigation_state->request_params() |
| 3398 .navigation_timing.fetch_start.is_null()) { | 3412 .navigation_timing.fetch_start.is_null()) { |
| 3399 // Set timing of several events that happened during navigation. | 3413 // Set timing of several events that happened during navigation. |
| 3400 // They will be used in blink for the Navigation Timing API. | 3414 // They will be used in blink for the Navigation Timing API. |
| 3401 double redirect_start = ConvertToBlinkTime( | 3415 double redirect_start = ConvertToBlinkTime( |
| 3402 navigation_state->request_params().navigation_timing.redirect_start); | 3416 navigation_state->request_params().navigation_timing.redirect_start); |
| 3403 double redirect_end = ConvertToBlinkTime( | 3417 double redirect_end = ConvertToBlinkTime( |
| 3404 navigation_state->request_params().navigation_timing.redirect_end); | 3418 navigation_state->request_params().navigation_timing.redirect_end); |
| 3405 double fetch_start = ConvertToBlinkTime( | 3419 double fetch_start = ConvertToBlinkTime( |
| 3406 navigation_state->request_params().navigation_timing.fetch_start); | 3420 navigation_state->request_params().navigation_timing.fetch_start); |
| 3407 std::vector<GURL> redirectChain = | |
| 3408 navigation_state->request_params().redirects; | |
| 3409 redirectChain.push_back(navigation_state->common_params().url); | |
| 3410 | 3421 |
| 3411 datasource->updateNavigation(redirect_start, redirect_end, fetch_start, | 3422 datasource->updateNavigation( |
| 3412 redirectChain); | 3423 redirect_start, redirect_end, fetch_start, |
| 3424 !navigation_state->request_params().redirects.empty()); |
| 3413 // TODO(clamy) We need to provide additional timing values for the | 3425 // TODO(clamy) We need to provide additional timing values for the |
| 3414 // Navigation Timing API to work with browser-side navigations. | 3426 // Navigation Timing API to work with browser-side navigations. |
| 3415 // UnloadEventStart and UnloadEventEnd are still missing. | 3427 // UnloadEventStart and UnloadEventEnd are still missing. |
| 3416 } | 3428 } |
| 3417 | 3429 |
| 3418 // Create the serviceworker's per-document network observing object if it | 3430 // Create the serviceworker's per-document network observing object if it |
| 3419 // does not exist (When navigation happens within a page, the provider already | 3431 // does not exist (When navigation happens within a page, the provider already |
| 3420 // exists). | 3432 // exists). |
| 3421 if (ServiceWorkerNetworkProvider::FromDocumentState( | 3433 if (ServiceWorkerNetworkProvider::FromDocumentState( |
| 3422 DocumentState::FromDataSource(datasource))) | 3434 DocumentState::FromDataSource(datasource))) |
| (...skipping 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5133 const RequestNavigationParams& request_params) { | 5145 const RequestNavigationParams& request_params) { |
| 5134 CHECK(IsBrowserSideNavigationEnabled()); | 5146 CHECK(IsBrowserSideNavigationEnabled()); |
| 5135 // This will override the url requested by the WebURLLoader, as well as | 5147 // This will override the url requested by the WebURLLoader, as well as |
| 5136 // provide it with the response to the request. | 5148 // provide it with the response to the request. |
| 5137 std::unique_ptr<StreamOverrideParameters> stream_override( | 5149 std::unique_ptr<StreamOverrideParameters> stream_override( |
| 5138 new StreamOverrideParameters()); | 5150 new StreamOverrideParameters()); |
| 5139 stream_override->stream_url = stream_url; | 5151 stream_override->stream_url = stream_url; |
| 5140 stream_override->response = response; | 5152 stream_override->response = response; |
| 5141 stream_override->redirects = request_params.redirects; | 5153 stream_override->redirects = request_params.redirects; |
| 5142 stream_override->redirect_responses = request_params.redirect_response; | 5154 stream_override->redirect_responses = request_params.redirect_response; |
| 5155 stream_override->redirect_infos = request_params.redirect_infos; |
| 5143 | 5156 |
| 5144 // If the request was initiated in the context of a user gesture then make | 5157 // If the request was initiated in the context of a user gesture then make |
| 5145 // sure that the navigation also executes in the context of a user gesture. | 5158 // sure that the navigation also executes in the context of a user gesture. |
| 5146 std::unique_ptr<blink::WebScopedUserGesture> gesture( | 5159 std::unique_ptr<blink::WebScopedUserGesture> gesture( |
| 5147 request_params.has_user_gesture ? new blink::WebScopedUserGesture(frame_) | 5160 request_params.has_user_gesture ? new blink::WebScopedUserGesture(frame_) |
| 5148 : nullptr); | 5161 : nullptr); |
| 5149 | 5162 |
| 5150 browser_side_navigation_pending_ = false; | 5163 browser_side_navigation_pending_ = false; |
| 5151 | 5164 |
| 5152 NavigateInternal(common_params, StartNavigationParams(), request_params, | 5165 NavigateInternal(common_params, StartNavigationParams(), request_params, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5176 // already committed other loads. | 5189 // already committed other loads. |
| 5177 if (request_params.has_committed_real_load && frame_->parent()) | 5190 if (request_params.has_committed_real_load && frame_->parent()) |
| 5178 frame_->setCommittedFirstRealLoad(); | 5191 frame_->setCommittedFirstRealLoad(); |
| 5179 | 5192 |
| 5180 pending_navigation_params_.reset(new NavigationParams( | 5193 pending_navigation_params_.reset(new NavigationParams( |
| 5181 common_params, StartNavigationParams(), request_params)); | 5194 common_params, StartNavigationParams(), request_params)); |
| 5182 | 5195 |
| 5183 // Send the provisional load failure. | 5196 // Send the provisional load failure. |
| 5184 blink::WebURLError error = | 5197 blink::WebURLError error = |
| 5185 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code); | 5198 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code); |
| 5186 WebURLRequest failed_request = CreateURLRequestForNavigation( | 5199 WebURLRequest failed_request = |
| 5187 common_params, std::unique_ptr<StreamOverrideParameters>(), | 5200 CreateURLRequestForNavigation(common_params, request_params, |
| 5188 frame_->isViewSourceModeEnabled(), | 5201 std::unique_ptr<StreamOverrideParameters>(), |
| 5189 false, // is_same_document_navigation | 5202 frame_->isViewSourceModeEnabled(), |
| 5190 request_params.nav_entry_id); | 5203 false); // is_same_document_navigation |
| 5191 | 5204 |
| 5192 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) { | 5205 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) { |
| 5193 // The browser expects this frame to be loading an error page. Inform it | 5206 // The browser expects this frame to be loading an error page. Inform it |
| 5194 // that the load stopped. | 5207 // that the load stopped. |
| 5195 Send(new FrameHostMsg_DidStopLoading(routing_id_)); | 5208 Send(new FrameHostMsg_DidStopLoading(routing_id_)); |
| 5196 browser_side_navigation_pending_ = false; | 5209 browser_side_navigation_pending_ = false; |
| 5197 return; | 5210 return; |
| 5198 } | 5211 } |
| 5199 | 5212 |
| 5200 // On load failure, a frame can ask its owner to render fallback content. | 5213 // On load failure, a frame can ask its owner to render fallback content. |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5883 bool should_load_request = false; | 5896 bool should_load_request = false; |
| 5884 WebHistoryItem item_for_history_navigation; | 5897 WebHistoryItem item_for_history_navigation; |
| 5885 | 5898 |
| 5886 // Enforce same-document navigation from the browser only if | 5899 // Enforce same-document navigation from the browser only if |
| 5887 // browser-side-navigation is enabled. | 5900 // browser-side-navigation is enabled. |
| 5888 bool is_same_document = | 5901 bool is_same_document = |
| 5889 IsBrowserSideNavigationEnabled() && | 5902 IsBrowserSideNavigationEnabled() && |
| 5890 FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type); | 5903 FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type); |
| 5891 | 5904 |
| 5892 WebURLRequest request = CreateURLRequestForNavigation( | 5905 WebURLRequest request = CreateURLRequestForNavigation( |
| 5893 common_params, std::move(stream_params), | 5906 common_params, request_params, std::move(stream_params), |
| 5894 frame_->isViewSourceModeEnabled(), is_same_document, | 5907 frame_->isViewSourceModeEnabled(), is_same_document); |
| 5895 request_params.nav_entry_id); | |
| 5896 request.setFrameType(IsTopLevelNavigation(frame_) | 5908 request.setFrameType(IsTopLevelNavigation(frame_) |
| 5897 ? blink::WebURLRequest::FrameTypeTopLevel | 5909 ? blink::WebURLRequest::FrameTypeTopLevel |
| 5898 : blink::WebURLRequest::FrameTypeNested); | 5910 : blink::WebURLRequest::FrameTypeNested); |
| 5899 | 5911 |
| 5900 if (IsBrowserSideNavigationEnabled() && common_params.post_data) | 5912 if (IsBrowserSideNavigationEnabled() && common_params.post_data) |
| 5901 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data)); | 5913 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data)); |
| 5902 | 5914 |
| 5903 // Used to determine whether this frame is actually loading a request as part | 5915 // Used to determine whether this frame is actually loading a request as part |
| 5904 // of a history navigation. | 5916 // of a history navigation. |
| 5905 bool has_history_navigation_in_frame = false; | 5917 bool has_history_navigation_in_frame = false; |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6851 // event target. Potentially a Pepper plugin will receive the event. | 6863 // event target. Potentially a Pepper plugin will receive the event. |
| 6852 // In order to tell whether a plugin gets the last mouse event and which it | 6864 // In order to tell whether a plugin gets the last mouse event and which it |
| 6853 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets | 6865 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets |
| 6854 // the event, it will notify us via DidReceiveMouseEvent() and set itself as | 6866 // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 6855 // |pepper_last_mouse_event_target_|. | 6867 // |pepper_last_mouse_event_target_|. |
| 6856 pepper_last_mouse_event_target_ = nullptr; | 6868 pepper_last_mouse_event_target_ = nullptr; |
| 6857 #endif | 6869 #endif |
| 6858 } | 6870 } |
| 6859 | 6871 |
| 6860 } // namespace content | 6872 } // namespace content |
| OLD | NEW |