Commit 70454663 authored by Tsuyoshi Horo's avatar Tsuyoshi Horo Committed by Commit Bot

Refactor NavigationURLLoaderImpl::URLLoaderRequestController

This CL moves the location where SignedExchangeRequestHandler is created when
NetworkService is disabled from CreateNonNetworkServiceURLLoader() to
StartWithoutNetworkService() where ServiceWorkerRequestHandler is created.

Bug: 898733
Change-Id: If122c3ae296dca7382417f204754ac3ba8f78206
Reviewed-on: https://chromium-review.googlesource.com/c/1298094
Commit-Queue: Tsuyoshi Horo <horo@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605229}
parent d21cc3cd
...@@ -446,8 +446,6 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -446,8 +446,6 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
storage::FileSystemContext* upload_file_system_context, storage::FileSystemContext* upload_file_system_context,
ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core, ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core,
AppCacheNavigationHandleCore* appcache_handle_core, AppCacheNavigationHandleCore* appcache_handle_core,
scoped_refptr<SignedExchangePrefetchMetricRecorder>
signed_exchange_prefetch_metric_recorder,
bool was_request_intercepted) const { bool was_request_intercepted) const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!base::FeatureList::IsEnabled(network::features::kNetworkService)); DCHECK(!base::FeatureList::IsEnabled(network::features::kNetworkService));
...@@ -470,8 +468,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -470,8 +468,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
? nullptr ? nullptr
: service_worker_navigation_handle_core), : service_worker_navigation_handle_core),
base::Unretained(was_request_intercepted ? nullptr base::Unretained(was_request_intercepted ? nullptr
: appcache_handle_core), : appcache_handle_core));
std::move(signed_exchange_prefetch_metric_recorder));
} }
void CreateNonNetworkServiceURLLoader( void CreateNonNetworkServiceURLLoader(
...@@ -480,8 +477,6 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -480,8 +477,6 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
std::unique_ptr<NavigationRequestInfo> request_info, std::unique_ptr<NavigationRequestInfo> request_info,
ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core, ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core,
AppCacheNavigationHandleCore* appcache_handle_core, AppCacheNavigationHandleCore* appcache_handle_core,
scoped_refptr<SignedExchangePrefetchMetricRecorder>
signed_exchange_prefetch_metric_recorder,
const network::ResourceRequest& /* resource_request */, const network::ResourceRequest& /* resource_request */,
network::mojom::URLLoaderRequest url_loader, network::mojom::URLLoaderRequest url_loader,
network::mojom::URLLoaderClientPtr url_loader_client) { network::mojom::URLLoaderClientPtr url_loader_client) {
...@@ -495,30 +490,6 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -495,30 +490,6 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
DCHECK(started_); DCHECK(started_);
default_loader_used_ = true; default_loader_used_ = true;
if (signed_exchange_utils::IsSignedExchangeHandlingEnabled()) {
// TODO(falken): Understand and add a comment about why
// SignedExchangeRequestHandler is the only interceptor being added here.
DCHECK(!network_loader_factory_);
// It is safe to pass the callback of CreateURLLoaderThrottles with the
// unretained |this|, because the passed callback will be used by a
// SignedExchangeHandler which is indirectly owned by |this| until its
// header is verified and parsed, that's where the getter is used.
interceptors_.push_back(std::make_unique<SignedExchangeRequestHandler>(
url::Origin::Create(request_info->common_params.url),
GetURLLoaderOptions(request_info->is_main_frame),
request_info->frame_tree_node_id,
request_info->devtools_navigation_token,
request_info->devtools_frame_token, request_info->report_raw_headers,
request_info->begin_params->load_flags,
base::MakeRefCounted<
SignedExchangeURLLoaderFactoryForNonNetworkService>(
resource_context_, url_request_context_getter),
base::BindRepeating(
&URLLoaderRequestController::CreateURLLoaderThrottles,
base::Unretained(this)),
std::move(signed_exchange_prefetch_metric_recorder)));
}
uint32_t options = GetURLLoaderOptions(request_info->is_main_frame); uint32_t options = GetURLLoaderOptions(request_info->is_main_frame);
bool intercepted = false; bool intercepted = false;
...@@ -580,8 +551,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -580,8 +551,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
base::Unretained(this), base::Unretained(url_request_context_getter), base::Unretained(this), base::Unretained(url_request_context_getter),
base::Unretained(upload_file_system_context), base::Unretained(upload_file_system_context),
base::Unretained(service_worker_navigation_handle_core), base::Unretained(service_worker_navigation_handle_core),
base::Unretained(appcache_handle_core), base::Unretained(appcache_handle_core));
base::RetainedRef(signed_exchange_prefetch_metric_recorder));
// Requests to Blob scheme won't get redirected to/from other schemes // Requests to Blob scheme won't get redirected to/from other schemes
// or be intercepted, so we just let it go here. // or be intercepted, so we just let it go here.
...@@ -597,33 +567,30 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -597,33 +567,30 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
return; return;
} }
// If S13nServiceWorker is disabled, just use if (blink::ServiceWorkerUtils::IsServicificationEnabled() &&
// |default_request_handler_factory_| and return. The non network service service_worker_navigation_handle_core) {
// request handling goes through ResourceDispatcherHost which has legacy std::unique_ptr<NavigationLoaderInterceptor> service_worker_interceptor =
// hooks for service worker (ServiceWorkerRequestInterceptor), so no service CreateServiceWorkerInterceptor(*request_info_,
// worker interception is needed here. service_worker_navigation_handle_core);
if (!blink::ServiceWorkerUtils::IsServicificationEnabled() || // The interceptor for service worker may not be created for some reasons
!service_worker_navigation_handle_core) { // (e.g. the origin is not secure).
url_loader_ = ThrottlingURLLoader::CreateLoaderAndStart( if (service_worker_interceptor)
base::MakeRefCounted<SingleRequestURLLoaderFactory>( interceptors_.push_back(std::move(service_worker_interceptor));
default_request_handler_factory_.Run( }
false /* was_request_intercepted */)),
CreateURLLoaderThrottles(), -1 /* routing_id */, 0 /* request_id */, if (signed_exchange_utils::IsSignedExchangeHandlingEnabled()) {
network::mojom::kURLLoadOptionNone, resource_request_.get(), DCHECK(!network_loader_factory_);
this /* client */, kNavigationUrlLoaderTrafficAnnotation, interceptors_.push_back(CreateSignedExchangeRequestHandler(
base::ThreadTaskRunnerHandle::Get()); *request_info_,
return; base::MakeRefCounted<
SignedExchangeURLLoaderFactoryForNonNetworkService>(
resource_context_, url_request_context_getter),
std::move(signed_exchange_prefetch_metric_recorder)));
} }
// Otherwise, if S13nServiceWorker is enabled, create an interceptor so // If an interceptor is not created, we no longer have to go through the
// S13nServiceWorker has a chance to intercept the request. // rest of the network service code.
std::unique_ptr<NavigationLoaderInterceptor> service_worker_interceptor = if (interceptors_.empty()) {
CreateServiceWorkerInterceptor(*request_info_,
service_worker_navigation_handle_core);
// If an interceptor is not created for some reasons (e.g. the origin is not
// secure), we no longer have to go through the rest of the network service
// code.
if (!service_worker_interceptor) {
url_loader_ = ThrottlingURLLoader::CreateLoaderAndStart( url_loader_ = ThrottlingURLLoader::CreateLoaderAndStart(
base::MakeRefCounted<SingleRequestURLLoaderFactory>( base::MakeRefCounted<SingleRequestURLLoaderFactory>(
default_request_handler_factory_.Run( default_request_handler_factory_.Run(
...@@ -635,8 +602,6 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -635,8 +602,6 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
return; return;
} }
interceptors_.push_back(std::move(service_worker_interceptor));
Restart(); Restart();
} }
...@@ -721,21 +686,9 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -721,21 +686,9 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
} }
if (signed_exchange_utils::IsSignedExchangeHandlingEnabled()) { if (signed_exchange_utils::IsSignedExchangeHandlingEnabled()) {
// It is safe to pass the callback of CreateURLLoaderThrottles with the interceptors_.push_back(CreateSignedExchangeRequestHandler(
// unretained |this|, because the passed callback will be used by a *request_info, network_loader_factory_,
// SignedExchangeHandler which is indirectly owned by |this| until its std::move(signed_exchange_prefetch_metric_recorder)));
// header is verified and parsed, that's where the getter is used.
interceptors_.push_back(std::make_unique<SignedExchangeRequestHandler>(
url::Origin::Create(request_info->common_params.url),
GetURLLoaderOptions(request_info->is_main_frame),
request_info->frame_tree_node_id,
request_info->devtools_navigation_token,
request_info->devtools_frame_token, request_info->report_raw_headers,
request_info->begin_params->load_flags, network_loader_factory_,
base::BindRepeating(
&URLLoaderRequestController::CreateURLLoaderThrottles,
base::Unretained(this)),
signed_exchange_prefetch_metric_recorder));
} }
std::vector<std::unique_ptr<URLLoaderRequestInterceptor>> std::vector<std::unique_ptr<URLLoaderRequestInterceptor>>
...@@ -1435,6 +1388,28 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -1435,6 +1388,28 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
web_contents_getter_); web_contents_getter_);
} }
std::unique_ptr<SignedExchangeRequestHandler>
CreateSignedExchangeRequestHandler(
const NavigationRequestInfo& request_info,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
scoped_refptr<SignedExchangePrefetchMetricRecorder>
signed_exchange_prefetch_metric_recorder) {
// It is safe to pass the callback of CreateURLLoaderThrottles with the
// unretained |this|, because the passed callback will be used by a
// SignedExchangeHandler which is indirectly owned by |this| until its
// header is verified and parsed, that's where the getter is used.
return std::make_unique<SignedExchangeRequestHandler>(
url::Origin::Create(request_info.common_params.url),
GetURLLoaderOptions(request_info.is_main_frame),
request_info.frame_tree_node_id, request_info.devtools_navigation_token,
request_info.devtools_frame_token, request_info.report_raw_headers,
request_info.begin_params->load_flags, std::move(url_loader_factory),
base::BindRepeating(
&URLLoaderRequestController::CreateURLLoaderThrottles,
base::Unretained(this)),
std::move(signed_exchange_prefetch_metric_recorder));
}
void RecordSCTHistogramIfNeeded( void RecordSCTHistogramIfNeeded(
const base::Optional<net::SSLInfo>& ssl_info) { const base::Optional<net::SSLInfo>& ssl_info) {
if (is_main_frame_ && url_.SchemeIsCryptographic() && if (is_main_frame_ && url_.SchemeIsCryptographic() &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment