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