OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 350 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
351 RenderFrameHostImpl* host = | 351 RenderFrameHostImpl* host = |
352 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 352 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
353 if (host != nullptr) { | 353 if (host != nullptr) { |
354 DCHECK(host->frame_tree_node()->IsMainFrame()); | 354 DCHECK(host->frame_tree_node()->IsMainFrame()); |
355 host->frame_tree_node()->navigator()->LogResourceRequestTime( | 355 host->frame_tree_node()->navigator()->LogResourceRequestTime( |
356 timestamp, url); | 356 timestamp, url); |
357 } | 357 } |
358 } | 358 } |
359 | 359 |
360 bool IsUsingLoFi(LoFiState lofi_state, | 360 int GetPreviewsState(int previews_state, |
361 ResourceDispatcherHostDelegate* delegate, | 361 ResourceDispatcherHostDelegate* delegate, |
362 const net::URLRequest& request, | 362 const net::URLRequest& request, |
363 ResourceContext* resource_context, | 363 ResourceContext* resource_context, |
364 bool is_main_frame) { | 364 bool is_main_frame) { |
365 if (lofi_state == LOFI_UNSPECIFIED && delegate && is_main_frame) | 365 // previews_state is set to PREVIEWS_OFF when reloading with Lo-Fi disabled. |
366 return delegate->ShouldEnableLoFiMode(request, resource_context); | 366 if (previews_state == 0 && delegate && is_main_frame) |
367 return lofi_state == LOFI_ON; | 367 return delegate->GetPreviewsState(request, resource_context); |
| 368 return previews_state; |
368 } | 369 } |
369 | 370 |
370 // The following functions simplify code paths where the UI thread notifies the | 371 // The following functions simplify code paths where the UI thread notifies the |
371 // ResourceDispatcherHostImpl of information pertaining to loading behavior of | 372 // ResourceDispatcherHostImpl of information pertaining to loading behavior of |
372 // frame hosts. | 373 // frame hosts. |
373 void NotifyForRouteOnIO( | 374 void NotifyForRouteOnIO( |
374 base::Callback<void(ResourceDispatcherHostImpl*, | 375 base::Callback<void(ResourceDispatcherHostImpl*, |
375 const GlobalFrameRoutingId&)> frame_callback, | 376 const GlobalFrameRoutingId&)> frame_callback, |
376 const GlobalFrameRoutingId& global_routing_id) { | 377 const GlobalFrameRoutingId& global_routing_id) { |
377 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 378 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 request_data.is_main_frame, request_data.parent_is_main_frame, | 1542 request_data.is_main_frame, request_data.parent_is_main_frame, |
1542 request_data.resource_type, request_data.transition_type, | 1543 request_data.resource_type, request_data.transition_type, |
1543 request_data.should_replace_current_entry, | 1544 request_data.should_replace_current_entry, |
1544 false, // is download | 1545 false, // is download |
1545 false, // is stream | 1546 false, // is stream |
1546 allow_download, request_data.has_user_gesture, | 1547 allow_download, request_data.has_user_gesture, |
1547 request_data.enable_load_timing, request_data.enable_upload_progress, | 1548 request_data.enable_load_timing, request_data.enable_upload_progress, |
1548 do_not_prompt_for_login, request_data.referrer_policy, | 1549 do_not_prompt_for_login, request_data.referrer_policy, |
1549 request_data.visibility_state, resource_context, report_raw_headers, | 1550 request_data.visibility_state, resource_context, report_raw_headers, |
1550 !is_sync_load, | 1551 !is_sync_load, |
1551 IsUsingLoFi(request_data.lofi_state, delegate_, *new_request, | 1552 GetPreviewsState(request_data.previews_state, delegate_, *new_request, |
1552 resource_context, | 1553 resource_context, |
1553 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME), | 1554 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME), |
1554 support_async_revalidation ? request_data.headers : std::string(), | 1555 support_async_revalidation ? request_data.headers : std::string(), |
1555 request_data.request_body, request_data.initiated_in_secure_context); | 1556 request_data.request_body, request_data.initiated_in_secure_context); |
1556 // Request takes ownership. | 1557 // Request takes ownership. |
1557 extra_info->AssociateWithRequest(new_request.get()); | 1558 extra_info->AssociateWithRequest(new_request.get()); |
1558 | 1559 |
1559 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 1560 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
1560 // Hang on to a reference to ensure the blob is not released prior | 1561 // Hang on to a reference to ensure the blob is not released prior |
1561 // to the job being started. | 1562 // to the job being started. |
1562 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 1563 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
1563 new_request.get(), requester_info->blob_storage_context() | 1564 new_request.get(), requester_info->blob_storage_context() |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 ResourceRequesterInfo* requester_info, | 1833 ResourceRequesterInfo* requester_info, |
1833 int request_id) { | 1834 int request_id) { |
1834 CancelRequestFromRenderer( | 1835 CancelRequestFromRenderer( |
1835 GlobalRequestID(requester_info->child_id(), request_id)); | 1836 GlobalRequestID(requester_info->child_id(), request_id)); |
1836 } | 1837 } |
1837 | 1838 |
1838 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( | 1839 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( |
1839 int child_id, | 1840 int child_id, |
1840 int render_view_route_id, | 1841 int render_view_route_id, |
1841 int render_frame_route_id, | 1842 int render_frame_route_id, |
| 1843 int previews_state, |
1842 bool download, | 1844 bool download, |
1843 ResourceContext* context) { | 1845 ResourceContext* context) { |
1844 return new ResourceRequestInfoImpl( | 1846 return new ResourceRequestInfoImpl( |
1845 ResourceRequesterInfo::CreateForDownloadOrPageSave(child_id), | 1847 ResourceRequesterInfo::CreateForDownloadOrPageSave(child_id), |
1846 render_view_route_id, | 1848 render_view_route_id, |
1847 -1, // frame_tree_node_id | 1849 -1, // frame_tree_node_id |
1848 0, MakeRequestID(), render_frame_route_id, | 1850 0, MakeRequestID(), render_frame_route_id, |
1849 false, // is_main_frame | 1851 false, // is_main_frame |
1850 false, // parent_is_main_frame | 1852 false, // parent_is_main_frame |
1851 RESOURCE_TYPE_SUB_RESOURCE, ui::PAGE_TRANSITION_LINK, | 1853 RESOURCE_TYPE_SUB_RESOURCE, ui::PAGE_TRANSITION_LINK, |
1852 false, // should_replace_current_entry | 1854 false, // should_replace_current_entry |
1853 download, // is_download | 1855 download, // is_download |
1854 false, // is_stream | 1856 false, // is_stream |
1855 download, // allow_download | 1857 download, // allow_download |
1856 false, // has_user_gesture | 1858 false, // has_user_gesture |
1857 false, // enable_load_timing | 1859 false, // enable_load_timing |
1858 false, // enable_upload_progress | 1860 false, // enable_upload_progress |
1859 false, // do_not_prompt_for_login | 1861 false, // do_not_prompt_for_login |
1860 blink::WebReferrerPolicyDefault, blink::WebPageVisibilityStateVisible, | 1862 blink::WebReferrerPolicyDefault, blink::WebPageVisibilityStateVisible, |
1861 context, | 1863 context, |
1862 false, // report_raw_headers | 1864 false, // report_raw_headers |
1863 true, // is_async | 1865 true, // is_async |
1864 false, // is_using_lofi | 1866 previews_state, // previews_state |
1865 std::string(), // original_headers | 1867 std::string(), // original_headers |
1866 nullptr, // body | 1868 nullptr, // body |
1867 false); // initiated_in_secure_context | 1869 false); // initiated_in_secure_context |
1868 } | 1870 } |
1869 | 1871 |
1870 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, | 1872 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, |
1871 int route_id) { | 1873 int route_id) { |
1872 scheduler_->OnClientCreated(child_id, route_id); | 1874 scheduler_->OnClientCreated(child_id, route_id); |
1873 } | 1875 } |
1874 | 1876 |
1875 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, | 1877 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, |
1876 int route_id) { | 1878 int route_id) { |
1877 scheduler_->OnClientDeleted(child_id, route_id); | 1879 scheduler_->OnClientDeleted(child_id, route_id); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 info.common_params.gesture == NavigationGestureUser, | 2226 info.common_params.gesture == NavigationGestureUser, |
2225 true, // enable_load_timing | 2227 true, // enable_load_timing |
2226 false, // enable_upload_progress | 2228 false, // enable_upload_progress |
2227 false, // do_not_prompt_for_login | 2229 false, // do_not_prompt_for_login |
2228 info.common_params.referrer.policy, | 2230 info.common_params.referrer.policy, |
2229 // TODO(davidben): This is only used for prerenders. Replace | 2231 // TODO(davidben): This is only used for prerenders. Replace |
2230 // is_showing with something for that. Or maybe it just comes from the | 2232 // is_showing with something for that. Or maybe it just comes from the |
2231 // same mechanism as the cookie one. | 2233 // same mechanism as the cookie one. |
2232 blink::WebPageVisibilityStateVisible, resource_context, | 2234 blink::WebPageVisibilityStateVisible, resource_context, |
2233 info.report_raw_headers, | 2235 info.report_raw_headers, |
2234 true, // is_async | 2236 true, // is_async |
2235 IsUsingLoFi(info.common_params.lofi_state, delegate_, *new_request, | 2237 GetPreviewsState(info.common_params.previews_state, delegate_, |
2236 resource_context, info.is_main_frame), | 2238 *new_request, resource_context, info.is_main_frame), |
2237 // The original_headers field is for stale-while-revalidate but the | 2239 // The original_headers field is for stale-while-revalidate but the |
2238 // feature doesn't work with PlzNavigate, so it's just a placeholder | 2240 // feature doesn't work with PlzNavigate, so it's just a placeholder |
2239 // here. | 2241 // here. |
2240 // TODO(ricea): Make the feature work with stale-while-revalidate | 2242 // TODO(ricea): Make the feature work with stale-while-revalidate |
2241 // and clean this up. | 2243 // and clean this up. |
2242 std::string(), // original_headers | 2244 std::string(), // original_headers |
2243 info.common_params.post_data, | 2245 info.common_params.post_data, |
2244 // TODO(mek): Currently initiated_in_secure_context is only used for | 2246 // TODO(mek): Currently initiated_in_secure_context is only used for |
2245 // subresource requests, so it doesn't matter what value it gets here. | 2247 // subresource requests, so it doesn't matter what value it gets here. |
2246 // If in the future this changes this should be updated to somehow get a | 2248 // If in the future this changes this should be updated to somehow get a |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2395 StartLoading(info, std::move(loader)); | 2397 StartLoading(info, std::move(loader)); |
2396 } | 2398 } |
2397 | 2399 |
2398 void ResourceDispatcherHostImpl::InitializeURLRequest( | 2400 void ResourceDispatcherHostImpl::InitializeURLRequest( |
2399 net::URLRequest* request, | 2401 net::URLRequest* request, |
2400 const Referrer& referrer, | 2402 const Referrer& referrer, |
2401 bool is_download, | 2403 bool is_download, |
2402 int render_process_host_id, | 2404 int render_process_host_id, |
2403 int render_view_routing_id, | 2405 int render_view_routing_id, |
2404 int render_frame_routing_id, | 2406 int render_frame_routing_id, |
| 2407 int previews_state, |
2405 ResourceContext* context) { | 2408 ResourceContext* context) { |
2406 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2409 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
2407 DCHECK(!request->is_pending()); | 2410 DCHECK(!request->is_pending()); |
2408 | 2411 |
2409 SetReferrerForRequest(request, referrer); | 2412 SetReferrerForRequest(request, referrer); |
2410 | 2413 |
2411 ResourceRequestInfoImpl* info = | 2414 ResourceRequestInfoImpl* info = CreateRequestInfo( |
2412 CreateRequestInfo(render_process_host_id, render_view_routing_id, | 2415 render_process_host_id, render_view_routing_id, render_frame_routing_id, |
2413 render_frame_routing_id, is_download, context); | 2416 previews_state, is_download, context); |
2414 // Request takes ownership. | 2417 // Request takes ownership. |
2415 info->AssociateWithRequest(request); | 2418 info->AssociateWithRequest(request); |
2416 } | 2419 } |
2417 | 2420 |
2418 void ResourceDispatcherHostImpl::BeginURLRequest( | 2421 void ResourceDispatcherHostImpl::BeginURLRequest( |
2419 std::unique_ptr<net::URLRequest> request, | 2422 std::unique_ptr<net::URLRequest> request, |
2420 std::unique_ptr<ResourceHandler> handler, | 2423 std::unique_ptr<ResourceHandler> handler, |
2421 bool is_download, | 2424 bool is_download, |
2422 bool is_content_initiated, | 2425 bool is_content_initiated, |
2423 bool do_not_prompt_for_login, | 2426 bool do_not_prompt_for_login, |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2814 &throttles); | 2817 &throttles); |
2815 if (!throttles.empty()) { | 2818 if (!throttles.empty()) { |
2816 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2819 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
2817 std::move(throttles))); | 2820 std::move(throttles))); |
2818 } | 2821 } |
2819 } | 2822 } |
2820 return handler; | 2823 return handler; |
2821 } | 2824 } |
2822 | 2825 |
2823 } // namespace content | 2826 } // namespace content |
OLD | NEW |