Commit e28d67b6 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worker: Use nearest ancestor frame's AppCacheHost for PlzDedicatedWorker

This CL supports AppCache with PlzDedicatedWorker. Dedicated workers use their
ancestor frame's AppCacheHost, while shared workers have their own AppCacheHost.

The most tricky part of this CL is that dedicated workers are handled as
subresources of the nearest ancestor frame's AppCacheHost, but they also behave
as independent execution contexts. That is, dedicated workers have their own
subresource loaders. See comments in DedicatedWorkerHost and
AppCacheRequestHandler for details.

Change-Id: I0f24c57e94bf6fa71b8f15a22214ed91a96fbb17
Bug: 945673
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768485
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692392}
parent 8bba431f
......@@ -229,16 +229,16 @@ AppCacheRequestHandler::InitializeForMainResourceNetworkService(
std::make_unique<AppCacheURLLoaderRequest>(request),
static_cast<ResourceType>(request.resource_type),
request.should_reset_appcache);
handler->appcache_host_ = std::move(appcache_host);
if (handler)
handler->appcache_host_ = std::move(appcache_host);
return handler;
}
// static
bool AppCacheRequestHandler::IsMainResourceType(ResourceType type) {
// When PlzDedicatedWorker is enabled, a dedicated worker script is considered
// to be a main resource.
if (type == ResourceType::kWorker)
return base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker);
// This returns false for kWorker, which is typically considered a main
// resource. In appcache, dedicated workers are treated as subresources of
// their nearest ancestor frame's appcache host unlike shared workers.
return IsResourceTypeFrame(type) || type == ResourceType::kSharedWorker;
}
......@@ -571,8 +571,16 @@ bool AppCacheRequestHandler::MaybeCreateLoaderForResponse(
return false;
}
DCHECK(was_called);
if (IsMainResourceType(resource_type_))
// Create a subresource loader if needed (it's a main resource or a dedicated
// worker).
// In appcache, dedicated workers are treated as subresources of their nearest
// ancestor frame's appcache host. On the other hand, dedicated workers need
// their own subresource loader.
if (IsMainResourceType(resource_type_) ||
resource_type_ == ResourceType::kWorker) {
should_create_subresource_loader_ = true;
}
return true;
}
......
......@@ -1056,6 +1056,10 @@ class CONTENT_EXPORT RenderFrameHostImpl
std::unique_ptr<blink::URLLoaderFactoryBundleInfo>
CreateCrossOriginPrefetchLoaderFactoryBundle();
const AppCacheNavigationHandle* GetAppCacheNavigationHandle() const {
return appcache_handle_.get();
}
protected:
friend class RenderFrameHostFactory;
......
......@@ -191,8 +191,14 @@ void DedicatedWorkerHost::StartScriptLoad(
}
}
appcache_handle_ = std::make_unique<AppCacheNavigationHandle>(
storage_partition_impl->GetAppCacheService(), worker_process_id_);
// A dedicated worker depends on its nearest ancestor's appcache host.
AppCacheHost* appcache_host = nullptr;
const AppCacheNavigationHandle* appcache_handle =
nearest_ancestor_render_frame_host->GetAppCacheNavigationHandle();
if (appcache_handle) {
appcache_host = storage_partition_impl->GetAppCacheService()->GetHost(
appcache_handle->appcache_host_id());
}
service_worker_handle_ = std::make_unique<ServiceWorkerNavigationHandle>(
storage_partition_impl->GetServiceWorkerContext());
......@@ -202,7 +208,8 @@ void DedicatedWorkerHost::StartScriptLoad(
request_initiator_origin, network_isolation_key_, credentials_mode,
std::move(outside_fetch_client_settings_object), ResourceType::kWorker,
storage_partition_impl->GetServiceWorkerContext(),
service_worker_handle_.get(), appcache_handle_->host()->GetWeakPtr(),
service_worker_handle_.get(),
appcache_host ? appcache_host->GetWeakPtr() : nullptr,
std::move(blob_url_loader_factory), nullptr, storage_partition_impl,
storage_domain,
base::BindOnce(&DedicatedWorkerHost::DidStartScriptLoad,
......
......@@ -26,7 +26,6 @@ class Origin;
namespace content {
class AppCacheNavigationHandle;
class ServiceWorkerNavigationHandle;
class ServiceWorkerObjectHost;
......@@ -164,7 +163,6 @@ class DedicatedWorkerHost final
// starting or running.
mojo::Remote<blink::mojom::DedicatedWorkerHostFactoryClient> client_;
std::unique_ptr<AppCacheNavigationHandle> appcache_handle_;
std::unique_ptr<ServiceWorkerNavigationHandle> service_worker_handle_;
service_manager::BinderRegistry registry_;
......
This is a testharness.js-based test.
FAIL Dedicated worker of the cached script assert_equals: expected "Done: cached" but got "Error: Importing a non-cached script must fail."
FAIL Dedicated worker of the fallbacked script assert_equals: expected "Done: fallbacked" but got "Error: Importing a non-cached script must fail."
FAIL Dedicated worker of the not-in-cache script promise_test: Unhandled rejection with value: "The worker not in the AppCache must not be executed."
PASS Shared worker of the cached script
PASS Shared worker of the fallbacked script
PASS Shared worker of the not-in-cache script
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