Commit 34ab40ca authored by Makoto Shimazu's avatar Makoto Shimazu Committed by Commit Bot

Use network::mojom::kURLLoadOptionSniffMimeType everywhere

This CL is to reflect kURLLoadOptionSniffMimeType when making
ResourceHandlers. If there is no option to request mime sniffing, it won't
create MimeSniffingResourceHandler. ServiceWorkerNewScriptLoader removes the
mime sniffing option, so requests for service worker scripts can skip mime
sniffing in RDHI.

Context of this CL:
Before NetS13nServiceWorker, network requests for service worker scripts is handled
by ServiceWorkerWriteToCacheJob, and it rejects responses without mime type. It
results in network error and none of ResourceHandlers handle the response.
After NetS13nServiceWorker, network requests coming from the renderer reach
ServiceWorkerNewScriptLoader first, and eventually they are routed to
ResourceDispatcherHostImpl. It means that ResourceDispatcherHostImpl works as
usual and MimeSniffingResourceHandler in RDHI handles the response.
This CL helps to avoid the script response is handled by
MimeSniffingResourceHandler.


Bug: 871654
Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: Ia7c7885157029be16a3a4669cf204ac85232f1b6
Reviewed-on: https://chromium-review.googlesource.com/1179482Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585398}
parent b9501577
...@@ -380,6 +380,10 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -380,6 +380,10 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
static uint32_t GetURLLoaderOptions(bool is_main_frame) { static uint32_t GetURLLoaderOptions(bool is_main_frame) {
uint32_t options = network::mojom::kURLLoadOptionNone; uint32_t options = network::mojom::kURLLoadOptionNone;
// Ensure that Mime sniffing works.
options |= network::mojom::kURLLoadOptionSniffMimeType;
if (is_main_frame) { if (is_main_frame) {
// SSLInfo is not needed on subframe responses because users can inspect // SSLInfo is not needed on subframe responses because users can inspect
// only the certificate for the main frame when using the info bubble. // only the certificate for the main frame when using the info bubble.
...@@ -387,9 +391,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -387,9 +391,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
options |= network::mojom::kURLLoadOptionSendSSLInfoForCertificateError; options |= network::mojom::kURLLoadOptionSendSSLInfoForCertificateError;
} }
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) { if (!base::FeatureList::IsEnabled(network::features::kNetworkService)) {
options |= network::mojom::kURLLoadOptionSniffMimeType;
} else {
// TODO(arthursonzogni): This is a temporary option. Remove this as soon // TODO(arthursonzogni): This is a temporary option. Remove this as soon
// as the InterceptingResourceHandler is removed. // as the InterceptingResourceHandler is removed.
// See https://crbug.com/791049. // See https://crbug.com/791049.
......
...@@ -1079,8 +1079,8 @@ ResourceDispatcherHostImpl::CreateResourceHandler( ...@@ -1079,8 +1079,8 @@ ResourceDispatcherHostImpl::CreateResourceHandler(
request, static_cast<ResourceType>(request_data.resource_type), request, static_cast<ResourceType>(request_data.resource_type),
resource_context, request_data.fetch_request_mode, resource_context, request_data.fetch_request_mode,
static_cast<RequestContextType>(request_data.fetch_request_context_type), static_cast<RequestContextType>(request_data.fetch_request_context_type),
requester_info->appcache_service(), child_id, route_id, url_loader_options, requester_info->appcache_service(), child_id,
std::move(handler)); route_id, std::move(handler));
} }
std::unique_ptr<ResourceHandler> std::unique_ptr<ResourceHandler>
...@@ -1090,6 +1090,7 @@ ResourceDispatcherHostImpl::AddStandardHandlers( ...@@ -1090,6 +1090,7 @@ ResourceDispatcherHostImpl::AddStandardHandlers(
ResourceContext* resource_context, ResourceContext* resource_context,
network::mojom::FetchRequestMode fetch_request_mode, network::mojom::FetchRequestMode fetch_request_mode,
RequestContextType fetch_request_context_type, RequestContextType fetch_request_context_type,
uint32_t url_loader_options,
AppCacheService* appcache_service, AppCacheService* appcache_service,
int child_id, int child_id,
int route_id, int route_id,
...@@ -1158,9 +1159,11 @@ ResourceDispatcherHostImpl::AddStandardHandlers( ...@@ -1158,9 +1159,11 @@ ResourceDispatcherHostImpl::AddStandardHandlers(
// Note: all ResourceHandler following the MimeSniffingResourceHandler // Note: all ResourceHandler following the MimeSniffingResourceHandler
// should expect OnWillRead to be called *before* OnResponseStarted as // should expect OnWillRead to be called *before* OnResponseStarted as
// part of the mime sniffing process. // part of the mime sniffing process.
handler.reset(new MimeSniffingResourceHandler( if (url_loader_options & network::mojom::kURLLoadOptionSniffMimeType) {
std::move(handler), this, plugin_service, intercepting_handler, request, handler.reset(new MimeSniffingResourceHandler(
fetch_request_context_type)); std::move(handler), this, plugin_service, intercepting_handler, request,
fetch_request_context_type));
}
// Add the pre mime sniffing throttles. // Add the pre mime sniffing throttles.
handler.reset(new ThrottlingResourceHandler( handler.reset(new ThrottlingResourceHandler(
...@@ -1612,7 +1615,7 @@ void ResourceDispatcherHostImpl::BeginNavigationRequest( ...@@ -1612,7 +1615,7 @@ void ResourceDispatcherHostImpl::BeginNavigationRequest(
handler = AddStandardHandlers( handler = AddStandardHandlers(
new_request.get(), resource_type, resource_context, new_request.get(), resource_type, resource_context,
network::mojom::FetchRequestMode::kNoCORS, network::mojom::FetchRequestMode::kNoCORS,
info.begin_params->request_context_type, info.begin_params->request_context_type, url_loader_options,
appcache_handle_core ? appcache_handle_core->GetAppCacheService() appcache_handle_core ? appcache_handle_core->GetAppCacheService()
: nullptr, : nullptr,
-1, // child_id -1, // child_id
......
...@@ -597,6 +597,7 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl ...@@ -597,6 +597,7 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl
ResourceContext* resource_context, ResourceContext* resource_context,
network::mojom::FetchRequestMode fetch_request_mode, network::mojom::FetchRequestMode fetch_request_mode,
RequestContextType fetch_request_context_type, RequestContextType fetch_request_context_type,
uint32_t url_loader_options,
AppCacheService* appcache_service, AppCacheService* appcache_service,
int child_id, int child_id,
int route_id, int route_id,
......
...@@ -899,7 +899,7 @@ void ResourceDispatcherHostTest::MakeTestRequestWithRenderFrame( ...@@ -899,7 +899,7 @@ void ResourceDispatcherHostTest::MakeTestRequestWithRenderFrame(
request.render_frame_id = render_frame_id; request.render_frame_id = render_frame_id;
filter_->CreateLoaderAndStart( filter_->CreateLoaderAndStart(
std::move(loader_request), render_view_id, request_id, std::move(loader_request), render_view_id, request_id,
network::mojom::kURLLoadOptionNone, request, std::move(client), network::mojom::kURLLoadOptionSniffMimeType, request, std::move(client),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
} }
...@@ -914,7 +914,7 @@ void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( ...@@ -914,7 +914,7 @@ void ResourceDispatcherHostTest::MakeTestRequestWithResourceType(
network::ResourceRequest request = CreateResourceRequest("GET", type, url); network::ResourceRequest request = CreateResourceRequest("GET", type, url);
filter->CreateLoaderAndStart( filter->CreateLoaderAndStart(
std::move(loader_request), render_view_id, request_id, std::move(loader_request), render_view_id, request_id,
network::mojom::kURLLoadOptionNone, request, std::move(client), network::mojom::kURLLoadOptionSniffMimeType, request, std::move(client),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
} }
......
...@@ -149,7 +149,8 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) { ...@@ -149,7 +149,8 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) {
request.request_initiator = url::Origin::Create(request.url); request.request_initiator = url::Origin::Create(request.url);
factory_->CreateLoaderAndStart( factory_->CreateLoaderAndStart(
mojo::MakeRequest(&loader), kRoutingId, kRequestId, mojo::MakeRequest(&loader), kRoutingId, kRequestId,
network::mojom::kURLLoadOptionNone, request, client.CreateInterfacePtr(), network::mojom::kURLLoadOptionSniffMimeType, request,
client.CreateInterfacePtr(),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
ASSERT_FALSE(client.has_received_response()); ASSERT_FALSE(client.has_received_response());
...@@ -224,8 +225,9 @@ TEST_P(URLLoaderFactoryImplTest, GetFailedResponse) { ...@@ -224,8 +225,9 @@ TEST_P(URLLoaderFactoryImplTest, GetFailedResponse) {
// Need to set same-site |request_initiator| for non main frame type request. // Need to set same-site |request_initiator| for non main frame type request.
request.request_initiator = url::Origin::Create(request.url); request.request_initiator = url::Origin::Create(request.url);
factory_->CreateLoaderAndStart( factory_->CreateLoaderAndStart(
mojo::MakeRequest(&loader), 2, 1, network::mojom::kURLLoadOptionNone, mojo::MakeRequest(&loader), 2, 1,
request, client.CreateInterfacePtr(), network::mojom::kURLLoadOptionSniffMimeType, request,
client.CreateInterfacePtr(),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
client.RunUntilComplete(); client.RunUntilComplete();
...@@ -253,8 +255,9 @@ TEST_P(URLLoaderFactoryImplTest, GetFailedResponse2) { ...@@ -253,8 +255,9 @@ TEST_P(URLLoaderFactoryImplTest, GetFailedResponse2) {
// Need to set same-site |request_initiator| for non main frame type request. // Need to set same-site |request_initiator| for non main frame type request.
request.request_initiator = url::Origin::Create(request.url); request.request_initiator = url::Origin::Create(request.url);
factory_->CreateLoaderAndStart( factory_->CreateLoaderAndStart(
mojo::MakeRequest(&loader), 2, 1, network::mojom::kURLLoadOptionNone, mojo::MakeRequest(&loader), 2, 1,
request, client.CreateInterfacePtr(), network::mojom::kURLLoadOptionSniffMimeType, request,
client.CreateInterfacePtr(),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
client.RunUntilComplete(); client.RunUntilComplete();
...@@ -281,8 +284,9 @@ TEST_P(URLLoaderFactoryImplTest, InvalidURL) { ...@@ -281,8 +284,9 @@ TEST_P(URLLoaderFactoryImplTest, InvalidURL) {
request.request_initiator = url::Origin::Create(request.url); request.request_initiator = url::Origin::Create(request.url);
ASSERT_FALSE(request.url.is_valid()); ASSERT_FALSE(request.url.is_valid());
factory_->CreateLoaderAndStart( factory_->CreateLoaderAndStart(
mojo::MakeRequest(&loader), 2, 1, network::mojom::kURLLoadOptionNone, mojo::MakeRequest(&loader), 2, 1,
request, client.CreateInterfacePtr(), network::mojom::kURLLoadOptionSniffMimeType, request,
client.CreateInterfacePtr(),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
client.RunUntilComplete(); client.RunUntilComplete();
...@@ -310,8 +314,9 @@ TEST_P(URLLoaderFactoryImplTest, ShouldNotRequestURL) { ...@@ -310,8 +314,9 @@ TEST_P(URLLoaderFactoryImplTest, ShouldNotRequestURL) {
// Need to set same-site |request_initiator| for non main frame type request. // Need to set same-site |request_initiator| for non main frame type request.
request.request_initiator = url::Origin::Create(request.url); request.request_initiator = url::Origin::Create(request.url);
factory_->CreateLoaderAndStart( factory_->CreateLoaderAndStart(
mojo::MakeRequest(&loader), 2, 1, network::mojom::kURLLoadOptionNone, mojo::MakeRequest(&loader), 2, 1,
request, client.CreateInterfacePtr(), network::mojom::kURLLoadOptionSniffMimeType, request,
client.CreateInterfacePtr(),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
client.RunUntilComplete(); client.RunUntilComplete();
...@@ -343,7 +348,8 @@ TEST_P(URLLoaderFactoryImplTest, OnTransferSizeUpdated) { ...@@ -343,7 +348,8 @@ TEST_P(URLLoaderFactoryImplTest, OnTransferSizeUpdated) {
request.report_raw_headers = true; request.report_raw_headers = true;
factory_->CreateLoaderAndStart( factory_->CreateLoaderAndStart(
mojo::MakeRequest(&loader), kRoutingId, kRequestId, mojo::MakeRequest(&loader), kRoutingId, kRequestId,
network::mojom::kURLLoadOptionNone, request, client.CreateInterfacePtr(), network::mojom::kURLLoadOptionSniffMimeType, request,
client.CreateInterfacePtr(),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
client.RunUntilComplete(); client.RunUntilComplete();
...@@ -403,7 +409,8 @@ TEST_P(URLLoaderFactoryImplTest, CancelFromRenderer) { ...@@ -403,7 +409,8 @@ TEST_P(URLLoaderFactoryImplTest, CancelFromRenderer) {
request.request_initiator = url::Origin::Create(request.url); request.request_initiator = url::Origin::Create(request.url);
factory_->CreateLoaderAndStart( factory_->CreateLoaderAndStart(
mojo::MakeRequest(&loader), kRoutingId, kRequestId, mojo::MakeRequest(&loader), kRoutingId, kRequestId,
network::mojom::kURLLoadOptionNone, request, client.CreateInterfacePtr(), network::mojom::kURLLoadOptionSniffMimeType, request,
client.CreateInterfacePtr(),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
...@@ -752,11 +752,11 @@ int ResourceDispatcher::StartAsync( ...@@ -752,11 +752,11 @@ int ResourceDispatcher::StartAsync(
uint32_t options = network::mojom::kURLLoadOptionNone; uint32_t options = network::mojom::kURLLoadOptionNone;
// TODO(jam): use this flag for ResourceDispatcherHost code path once // TODO(jam): use this flag for ResourceDispatcherHost code path once
// MojoLoading is the only IPC code path. // MojoLoading is the only IPC code path.
if (blink::ServiceWorkerUtils::IsServicificationEnabled() && if (request->fetch_request_context_type != REQUEST_CONTEXT_TYPE_FETCH) {
request->fetch_request_context_type != REQUEST_CONTEXT_TYPE_FETCH) {
// MIME sniffing should be disabled for a request initiated by fetch(). // MIME sniffing should be disabled for a request initiated by fetch().
options |= network::mojom::kURLLoadOptionSniffMimeType; options |= network::mojom::kURLLoadOptionSniffMimeType;
throttles.push_back(std::make_unique<MimeSniffingThrottle>()); if (blink::ServiceWorkerUtils::IsServicificationEnabled())
throttles.push_back(std::make_unique<MimeSniffingThrottle>());
} }
if (is_sync) { if (is_sync) {
options |= network::mojom::kURLLoadOptionSynchronous; options |= network::mojom::kURLLoadOptionSynchronous;
......
...@@ -10,7 +10,7 @@ import "services/network/public/mojom/url_loader.mojom"; ...@@ -10,7 +10,7 @@ import "services/network/public/mojom/url_loader.mojom";
const uint32 kURLLoadOptionNone = 0; const uint32 kURLLoadOptionNone = 0;
// Sends the net::SSLInfo struct in OnReceiveResponse. // Sends the net::SSLInfo struct in OnReceiveResponse.
const uint32 kURLLoadOptionSendSSLInfoWithResponse = 1; const uint32 kURLLoadOptionSendSSLInfoWithResponse = 1;
// Enables mime sniffing. NOTE: this is only used with the network service. // Enables mime sniffing.
const uint32 kURLLoadOptionSniffMimeType = 2; const uint32 kURLLoadOptionSniffMimeType = 2;
// Indicates that execution is blocking on the completion of the request. // Indicates that execution is blocking on the completion of the request.
const uint32 kURLLoadOptionSynchronous = 4; const uint32 kURLLoadOptionSynchronous = 4;
......
This is a testharness.js-based test.
PASS Registering same scope as the script directory without the last slash
PASS Registration scope outside the script directory
PASS Registration scope outside domain
PASS Registering script outside domain
PASS Registering non-existent script
PASS Registering invalid chunked encoding script
FAIL Registering script with no MIME type assert_equals: expected "Failed to register a ServiceWorker: The script does not have a MIME type." but got "Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/plain')."
PASS Registering script with bad MIME type
PASS Registering redirected script
PASS Registering script including parse error
PASS Registering script including undefined error
PASS Registering script including uncaught exception
PASS Registering script importing malformed script
PASS Registering script importing non-existent script
PASS Script URL including URL-encoded slash
Harness: the test ran to completion.
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