| 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 3283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3294 internal_data->set_is_overriding_user_agent( | 3294 internal_data->set_is_overriding_user_agent( |
| 3295 old_internal_data->is_overriding_user_agent()); | 3295 old_internal_data->is_overriding_user_agent()); |
| 3296 } | 3296 } |
| 3297 } | 3297 } |
| 3298 | 3298 |
| 3299 // The rest of RenderView assumes that a WebDataSource will always have a | 3299 // The rest of RenderView assumes that a WebDataSource will always have a |
| 3300 // non-null NavigationState. | 3300 // non-null NavigationState. |
| 3301 UpdateNavigationState(document_state, false /* was_within_same_page */, | 3301 UpdateNavigationState(document_state, false /* was_within_same_page */, |
| 3302 content_initiated); | 3302 content_initiated); |
| 3303 | 3303 |
| 3304 if (content_initiated) { | |
| 3305 const WebURLRequest& request = datasource->request(); | |
| 3306 switch (request.getCachePolicy()) { | |
| 3307 case WebCachePolicy::UseProtocolCachePolicy: // normal load. | |
| 3308 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); | |
| 3309 break; | |
| 3310 case WebCachePolicy::ValidatingCacheData: // reload. | |
| 3311 case WebCachePolicy::BypassingCache: // end-to-end reload. | |
| 3312 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); | |
| 3313 break; | |
| 3314 case WebCachePolicy::ReturnCacheDataElseLoad: // allow stale data. | |
| 3315 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_STALE_OK); | |
| 3316 break; | |
| 3317 case WebCachePolicy::ReturnCacheDataDontLoad: // Don't re-post. | |
| 3318 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); | |
| 3319 break; | |
| 3320 case WebCachePolicy::ReturnCacheDataIfValid: | |
| 3321 // This policy is currently only used in subresource loading. | |
| 3322 NOTREACHED(); | |
| 3323 } | |
| 3324 } | |
| 3325 | |
| 3326 NavigationStateImpl* navigation_state = static_cast<NavigationStateImpl*>( | 3304 NavigationStateImpl* navigation_state = static_cast<NavigationStateImpl*>( |
| 3327 document_state->navigation_state()); | 3305 document_state->navigation_state()); |
| 3328 | 3306 |
| 3329 // Set the navigation start time in blink. | 3307 // Set the navigation start time in blink. |
| 3330 datasource->setNavigationStartTime( | 3308 datasource->setNavigationStartTime( |
| 3331 ConvertToBlinkTime(navigation_state->common_params().navigation_start)); | 3309 ConvertToBlinkTime(navigation_state->common_params().navigation_start)); |
| 3332 | 3310 |
| 3333 // PlzNavigate: if an actual navigation took place, inform the datasource of | 3311 // PlzNavigate: if an actual navigation took place, inform the datasource of |
| 3334 // what happened in the browser. | 3312 // what happened in the browser. |
| 3335 if (IsBrowserSideNavigationEnabled() && | 3313 if (IsBrowserSideNavigationEnabled() && |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3361 DocumentState::FromDataSource(datasource))) | 3339 DocumentState::FromDataSource(datasource))) |
| 3362 return; | 3340 return; |
| 3363 | 3341 |
| 3364 ServiceWorkerNetworkProvider::AttachToDocumentState( | 3342 ServiceWorkerNetworkProvider::AttachToDocumentState( |
| 3365 DocumentState::FromDataSource(datasource), | 3343 DocumentState::FromDataSource(datasource), |
| 3366 ServiceWorkerNetworkProvider::CreateForNavigation( | 3344 ServiceWorkerNetworkProvider::CreateForNavigation( |
| 3367 routing_id_, navigation_state->request_params(), frame, | 3345 routing_id_, navigation_state->request_params(), frame, |
| 3368 content_initiated)); | 3346 content_initiated)); |
| 3369 } | 3347 } |
| 3370 | 3348 |
| 3371 void RenderFrameImpl::didStartProvisionalLoad(blink::WebLocalFrame* frame, | 3349 void RenderFrameImpl::didStartProvisionalLoad(blink::WebLocalFrame* frame) { |
| 3372 double triggering_event_time) { | |
| 3373 DCHECK_EQ(frame_, frame); | 3350 DCHECK_EQ(frame_, frame); |
| 3374 WebDataSource* ds = frame->provisionalDataSource(); | 3351 WebDataSource* ds = frame->provisionalDataSource(); |
| 3375 | 3352 |
| 3376 // In fast/loader/stop-provisional-loads.html, we abort the load before this | 3353 // In fast/loader/stop-provisional-loads.html, we abort the load before this |
| 3377 // callback is invoked. | 3354 // callback is invoked. |
| 3378 if (!ds) | 3355 if (!ds) |
| 3379 return; | 3356 return; |
| 3380 | 3357 |
| 3381 TRACE_EVENT2("navigation,benchmark,rail", | 3358 TRACE_EVENT2("navigation,benchmark,rail", |
| 3382 "RenderFrameImpl::didStartProvisionalLoad", "id", routing_id_, | 3359 "RenderFrameImpl::didStartProvisionalLoad", "id", routing_id_, |
| 3383 "url", ds->request().url().string().utf8()); | 3360 "url", ds->request().url().string().utf8()); |
| 3384 DocumentState* document_state = DocumentState::FromDataSource(ds); | 3361 DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3385 | |
| 3386 // Update the request time if WebKit has better knowledge of it. | |
| 3387 if (document_state->request_time().is_null() && | |
| 3388 triggering_event_time != 0.0) { | |
| 3389 document_state->set_request_time(Time::FromDoubleT(triggering_event_time)); | |
| 3390 } | |
| 3391 | |
| 3392 // Start time is only set after request time. | |
| 3393 document_state->set_start_load_time(Time::Now()); | |
| 3394 | |
| 3395 NavigationStateImpl* navigation_state = static_cast<NavigationStateImpl*>( | 3362 NavigationStateImpl* navigation_state = static_cast<NavigationStateImpl*>( |
| 3396 document_state->navigation_state()); | 3363 document_state->navigation_state()); |
| 3397 bool is_top_most = !frame->parent(); | 3364 bool is_top_most = !frame->parent(); |
| 3398 if (is_top_most) { | 3365 if (is_top_most) { |
| 3399 render_view_->set_navigation_gesture( | 3366 render_view_->set_navigation_gesture( |
| 3400 WebUserGestureIndicator::isProcessingUserGesture() ? | 3367 WebUserGestureIndicator::isProcessingUserGesture() ? |
| 3401 NavigationGestureUser : NavigationGestureAuto); | 3368 NavigationGestureUser : NavigationGestureAuto); |
| 3402 } else if (ds->replacesCurrentHistoryItem()) { | 3369 } else if (ds->replacesCurrentHistoryItem()) { |
| 3403 // Subframe navigations that don't add session history items must be | 3370 // Subframe navigations that don't add session history items must be |
| 3404 // marked with AUTO_SUBFRAME. See also didFailProvisionalLoad for how we | 3371 // marked with AUTO_SUBFRAME. See also didFailProvisionalLoad for how we |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3470 // Otherwise, we do a normal load, which simulates a 'go' navigation as far | 3437 // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 3471 // as session history is concerned. | 3438 // as session history is concerned. |
| 3472 bool replace = commit_type != blink::WebStandardCommit; | 3439 bool replace = commit_type != blink::WebStandardCommit; |
| 3473 | 3440 |
| 3474 // If we failed on a browser initiated request, then make sure that our error | 3441 // If we failed on a browser initiated request, then make sure that our error |
| 3475 // page load is regarded as the same browser initiated request. | 3442 // page load is regarded as the same browser initiated request. |
| 3476 if (!navigation_state->IsContentInitiated()) { | 3443 if (!navigation_state->IsContentInitiated()) { |
| 3477 pending_navigation_params_.reset(new NavigationParams( | 3444 pending_navigation_params_.reset(new NavigationParams( |
| 3478 navigation_state->common_params(), navigation_state->start_params(), | 3445 navigation_state->common_params(), navigation_state->start_params(), |
| 3479 navigation_state->request_params())); | 3446 navigation_state->request_params())); |
| 3480 pending_navigation_params_->request_params.request_time = | |
| 3481 document_state->request_time(); | |
| 3482 } | 3447 } |
| 3483 | 3448 |
| 3484 // Load an error page. | 3449 // Load an error page. |
| 3485 LoadNavigationErrorPage(failed_request, error, replace, nullptr); | 3450 LoadNavigationErrorPage(failed_request, error, replace, nullptr); |
| 3486 } | 3451 } |
| 3487 | 3452 |
| 3488 void RenderFrameImpl::didCommitProvisionalLoad( | 3453 void RenderFrameImpl::didCommitProvisionalLoad( |
| 3489 blink::WebLocalFrame* frame, | 3454 blink::WebLocalFrame* frame, |
| 3490 const blink::WebHistoryItem& item, | 3455 const blink::WebHistoryItem& item, |
| 3491 blink::WebHistoryCommitType commit_type) { | 3456 blink::WebHistoryCommitType commit_type) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3609 render_view_->history_controller()->UpdateForCommit( | 3574 render_view_->history_controller()->UpdateForCommit( |
| 3610 this, item, commit_type, navigation_state->WasWithinSamePage()); | 3575 this, item, commit_type, navigation_state->WasWithinSamePage()); |
| 3611 } | 3576 } |
| 3612 // Update the current history item for this frame (both in default Chrome and | 3577 // Update the current history item for this frame (both in default Chrome and |
| 3613 // subframe FrameNavigationEntry modes). | 3578 // subframe FrameNavigationEntry modes). |
| 3614 current_history_item_ = item; | 3579 current_history_item_ = item; |
| 3615 | 3580 |
| 3616 InternalDocumentStateData* internal_data = | 3581 InternalDocumentStateData* internal_data = |
| 3617 InternalDocumentStateData::FromDocumentState(document_state); | 3582 InternalDocumentStateData::FromDocumentState(document_state); |
| 3618 | 3583 |
| 3619 if (document_state->commit_load_time().is_null()) | |
| 3620 document_state->set_commit_load_time(Time::Now()); | |
| 3621 | |
| 3622 if (internal_data->must_reset_scroll_and_scale_state()) { | 3584 if (internal_data->must_reset_scroll_and_scale_state()) { |
| 3623 render_view_->webview()->resetScrollAndScaleState(); | 3585 render_view_->webview()->resetScrollAndScaleState(); |
| 3624 internal_data->set_must_reset_scroll_and_scale_state(false); | 3586 internal_data->set_must_reset_scroll_and_scale_state(false); |
| 3625 } | 3587 } |
| 3626 | 3588 |
| 3627 const RequestNavigationParams& request_params = | 3589 const RequestNavigationParams& request_params = |
| 3628 navigation_state->request_params(); | 3590 navigation_state->request_params(); |
| 3629 bool is_new_navigation = commit_type == blink::WebStandardCommit; | 3591 bool is_new_navigation = commit_type == blink::WebStandardCommit; |
| 3630 if (is_new_navigation) { | 3592 if (is_new_navigation) { |
| 3631 DCHECK(!navigation_state->common_params().should_replace_current_entry || | 3593 DCHECK(!navigation_state->common_params().should_replace_current_entry || |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3788 blink::WebIconURL::Type icon_type) { | 3750 blink::WebIconURL::Type icon_type) { |
| 3789 DCHECK_EQ(frame_, frame); | 3751 DCHECK_EQ(frame_, frame); |
| 3790 // TODO(nasko): Investigate wheather implementation should move here. | 3752 // TODO(nasko): Investigate wheather implementation should move here. |
| 3791 render_view_->didChangeIcon(frame, icon_type); | 3753 render_view_->didChangeIcon(frame, icon_type); |
| 3792 } | 3754 } |
| 3793 | 3755 |
| 3794 void RenderFrameImpl::didFinishDocumentLoad(blink::WebLocalFrame* frame) { | 3756 void RenderFrameImpl::didFinishDocumentLoad(blink::WebLocalFrame* frame) { |
| 3795 TRACE_EVENT1("navigation,benchmark,rail", | 3757 TRACE_EVENT1("navigation,benchmark,rail", |
| 3796 "RenderFrameImpl::didFinishDocumentLoad", "id", routing_id_); | 3758 "RenderFrameImpl::didFinishDocumentLoad", "id", routing_id_); |
| 3797 DCHECK_EQ(frame_, frame); | 3759 DCHECK_EQ(frame_, frame); |
| 3798 WebDataSource* ds = frame->dataSource(); | |
| 3799 DocumentState* document_state = DocumentState::FromDataSource(ds); | |
| 3800 document_state->set_finish_document_load_time(Time::Now()); | |
| 3801 | 3760 |
| 3802 Send(new FrameHostMsg_DidFinishDocumentLoad(routing_id_)); | 3761 Send(new FrameHostMsg_DidFinishDocumentLoad(routing_id_)); |
| 3803 | 3762 |
| 3804 for (auto& observer : render_view_->observers()) | 3763 for (auto& observer : render_view_->observers()) |
| 3805 observer.DidFinishDocumentLoad(frame); | 3764 observer.DidFinishDocumentLoad(frame); |
| 3806 for (auto& observer : observers_) | 3765 for (auto& observer : observers_) |
| 3807 observer.DidFinishDocumentLoad(); | 3766 observer.DidFinishDocumentLoad(); |
| 3808 | 3767 |
| 3809 // Check whether we have new encoding name. | 3768 // Check whether we have new encoding name. |
| 3810 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); | 3769 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3903 failed_request.url(), | 3862 failed_request.url(), |
| 3904 error.reason, | 3863 error.reason, |
| 3905 error_description, | 3864 error_description, |
| 3906 error.wasIgnoredByHandler)); | 3865 error.wasIgnoredByHandler)); |
| 3907 } | 3866 } |
| 3908 | 3867 |
| 3909 void RenderFrameImpl::didFinishLoad(blink::WebLocalFrame* frame) { | 3868 void RenderFrameImpl::didFinishLoad(blink::WebLocalFrame* frame) { |
| 3910 TRACE_EVENT1("navigation,benchmark,rail", | 3869 TRACE_EVENT1("navigation,benchmark,rail", |
| 3911 "RenderFrameImpl::didFinishLoad", "id", routing_id_); | 3870 "RenderFrameImpl::didFinishLoad", "id", routing_id_); |
| 3912 DCHECK_EQ(frame_, frame); | 3871 DCHECK_EQ(frame_, frame); |
| 3913 WebDataSource* ds = frame->dataSource(); | 3872 if (!frame->parent()) { |
| 3914 DocumentState* document_state = DocumentState::FromDataSource(ds); | 3873 TRACE_EVENT_INSTANT0("WebCore,benchmark,rail", "LoadFinished", |
| 3915 if (document_state->finish_load_time().is_null()) { | 3874 TRACE_EVENT_SCOPE_PROCESS); |
| 3916 if (!frame->parent()) { | |
| 3917 TRACE_EVENT_INSTANT0("WebCore,benchmark,rail", "LoadFinished", | |
| 3918 TRACE_EVENT_SCOPE_PROCESS); | |
| 3919 } | |
| 3920 document_state->set_finish_load_time(Time::Now()); | |
| 3921 } | 3875 } |
| 3922 | 3876 |
| 3923 for (auto& observer : render_view_->observers()) | 3877 for (auto& observer : render_view_->observers()) |
| 3924 observer.DidFinishLoad(frame); | 3878 observer.DidFinishLoad(frame); |
| 3925 for (auto& observer : observers_) | 3879 for (auto& observer : observers_) |
| 3926 observer.DidFinishLoad(); | 3880 observer.DidFinishLoad(); |
| 3927 | 3881 |
| 3882 WebDataSource* ds = frame->dataSource(); |
| 3928 Send(new FrameHostMsg_DidFinishLoad(routing_id_, | 3883 Send(new FrameHostMsg_DidFinishLoad(routing_id_, |
| 3929 ds->request().url())); | 3884 ds->request().url())); |
| 3930 } | 3885 } |
| 3931 | 3886 |
| 3932 void RenderFrameImpl::didNavigateWithinPage( | 3887 void RenderFrameImpl::didNavigateWithinPage( |
| 3933 blink::WebLocalFrame* frame, | 3888 blink::WebLocalFrame* frame, |
| 3934 const blink::WebHistoryItem& item, | 3889 const blink::WebHistoryItem& item, |
| 3935 blink::WebHistoryCommitType commit_type, | 3890 blink::WebHistoryCommitType commit_type, |
| 3936 bool content_initiated) { | 3891 bool content_initiated) { |
| 3937 TRACE_EVENT1("navigation,rail", "RenderFrameImpl::didNavigateWithinPage", | 3892 TRACE_EVENT1("navigation,rail", "RenderFrameImpl::didNavigateWithinPage", |
| (...skipping 2321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6259 GURL overriden_url; | 6214 GURL overriden_url; |
| 6260 if (MaybeGetOverriddenURL(ds, &overriden_url)) | 6215 if (MaybeGetOverriddenURL(ds, &overriden_url)) |
| 6261 return overriden_url; | 6216 return overriden_url; |
| 6262 | 6217 |
| 6263 const WebURLRequest& request = ds->request(); | 6218 const WebURLRequest& request = ds->request(); |
| 6264 return request.url(); | 6219 return request.url(); |
| 6265 } | 6220 } |
| 6266 | 6221 |
| 6267 void RenderFrameImpl::PopulateDocumentStateFromPending( | 6222 void RenderFrameImpl::PopulateDocumentStateFromPending( |
| 6268 DocumentState* document_state) { | 6223 DocumentState* document_state) { |
| 6269 document_state->set_request_time( | |
| 6270 pending_navigation_params_->request_params.request_time); | |
| 6271 | |
| 6272 InternalDocumentStateData* internal_data = | 6224 InternalDocumentStateData* internal_data = |
| 6273 InternalDocumentStateData::FromDocumentState(document_state); | 6225 InternalDocumentStateData::FromDocumentState(document_state); |
| 6274 | 6226 |
| 6275 if (!pending_navigation_params_->common_params.url.SchemeIs( | 6227 if (!pending_navigation_params_->common_params.url.SchemeIs( |
| 6276 url::kJavaScriptScheme) && | 6228 url::kJavaScriptScheme) && |
| 6277 pending_navigation_params_->common_params.navigation_type == | 6229 pending_navigation_params_->common_params.navigation_type == |
| 6278 FrameMsg_Navigate_Type::RESTORE) { | 6230 FrameMsg_Navigate_Type::RESTORE) { |
| 6279 // We're doing a load of a page that was restored from the last session. | 6231 // We're doing a load of a page that was restored from the last session. |
| 6280 // By default this prefers the cache over loading | 6232 // By default this prefers the cache over loading |
| 6281 // (LOAD_SKIP_CACHE_VALIDATION) which can result in stale data for pages | 6233 // (LOAD_SKIP_CACHE_VALIDATION) which can result in stale data for pages |
| 6282 // that are set to expire. We explicitly override that by setting the | 6234 // that are set to expire. We explicitly override that by setting the |
| 6283 // policy here so that as necessary we load from the network. | 6235 // policy here so that as necessary we load from the network. |
| 6284 // | 6236 // |
| 6285 // TODO(davidben): Remove this in favor of passing a cache policy to the | 6237 // TODO(davidben): Remove this in favor of passing a cache policy to the |
| 6286 // loadHistoryItem call in OnNavigate. That requires not overloading | 6238 // loadHistoryItem call in OnNavigate. That requires not overloading |
| 6287 // UseProtocolCachePolicy to mean both "normal load" and "determine cache | 6239 // UseProtocolCachePolicy to mean both "normal load" and "determine cache |
| 6288 // policy based on load type, etc". | 6240 // policy based on load type, etc". |
| 6289 internal_data->set_cache_policy_override( | 6241 internal_data->set_cache_policy_override( |
| 6290 WebCachePolicy::UseProtocolCachePolicy); | 6242 WebCachePolicy::UseProtocolCachePolicy); |
| 6291 } | 6243 } |
| 6292 | 6244 |
| 6293 if (IsReload(pending_navigation_params_->common_params.navigation_type)) | |
| 6294 document_state->set_load_type(DocumentState::RELOAD); | |
| 6295 else if (pending_navigation_params_->request_params.page_state.IsValid()) | |
| 6296 document_state->set_load_type(DocumentState::HISTORY_LOAD); | |
| 6297 else | |
| 6298 document_state->set_load_type(DocumentState::NORMAL_LOAD); | |
| 6299 | |
| 6300 internal_data->set_is_overriding_user_agent( | 6245 internal_data->set_is_overriding_user_agent( |
| 6301 pending_navigation_params_->request_params.is_overriding_user_agent); | 6246 pending_navigation_params_->request_params.is_overriding_user_agent); |
| 6302 internal_data->set_must_reset_scroll_and_scale_state( | 6247 internal_data->set_must_reset_scroll_and_scale_state( |
| 6303 pending_navigation_params_->common_params.navigation_type == | 6248 pending_navigation_params_->common_params.navigation_type == |
| 6304 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); | 6249 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
| 6305 document_state->set_can_load_local_resources( | 6250 document_state->set_can_load_local_resources( |
| 6306 pending_navigation_params_->request_params.can_load_local_resources); | 6251 pending_navigation_params_->request_params.can_load_local_resources); |
| 6307 } | 6252 } |
| 6308 | 6253 |
| 6309 NavigationState* RenderFrameImpl::CreateNavigationStateFromPending() { | 6254 NavigationState* RenderFrameImpl::CreateNavigationStateFromPending() { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6629 // event target. Potentially a Pepper plugin will receive the event. | 6574 // event target. Potentially a Pepper plugin will receive the event. |
| 6630 // In order to tell whether a plugin gets the last mouse event and which it | 6575 // In order to tell whether a plugin gets the last mouse event and which it |
| 6631 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets | 6576 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets |
| 6632 // the event, it will notify us via DidReceiveMouseEvent() and set itself as | 6577 // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 6633 // |pepper_last_mouse_event_target_|. | 6578 // |pepper_last_mouse_event_target_|. |
| 6634 pepper_last_mouse_event_target_ = nullptr; | 6579 pepper_last_mouse_event_target_ = nullptr; |
| 6635 #endif | 6580 #endif |
| 6636 } | 6581 } |
| 6637 | 6582 |
| 6638 } // namespace content | 6583 } // namespace content |
| OLD | NEW |