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