Commit 7ebaa8cd authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

AppCache: Create ApplicationCacheHostForSharedWorker in WebSharedWorkerImpl

Before this CL, ApplicationCacheHostForSharedWorker was created via
WorkerShadowPage and DocumentLoader. That was blocking WorkerShadowPage removal.

This CL removes the dependency by creating the host for shared workers in
WebSharedWorkerImpl instead.

Bug: 538751, 982996
Change-Id: I64e4a0cbba835d126c5144072e369f8bad3dc477
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724641Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682952}
parent 9c1c6fd1
......@@ -882,12 +882,6 @@ class BLINK_EXPORT WebLocalFrameClient {
virtual WebLocalFrameClient::AppCacheType GetAppCacheType() {
return WebLocalFrameClient::AppCacheType::kAppCacheForNone;
}
// TODO(https://crbug.com/982996): This is a stopgap implementation for
// removing DocumentLoader dependencies from shared workers. Remove this once
// it's done.
virtual base::UnguessableToken GetAppCacheHostIDForSharedWorker() {
return base::UnguessableToken();
}
};
} // namespace blink
......
......@@ -1270,12 +1270,6 @@ WebLocalFrameClient::AppCacheType LocalFrameClientImpl::GetAppCacheType() {
return web_frame_->Client()->GetAppCacheType();
}
base::UnguessableToken
LocalFrameClientImpl::GetAppCacheHostIDForSharedWorker() {
DCHECK(web_frame_->Client());
return web_frame_->Client()->GetAppCacheHostIDForSharedWorker();
}
STATIC_ASSERT_ENUM(DownloadCrossOriginRedirects::kFollow,
WebLocalFrameClient::CrossOriginRedirects::kFollow);
STATIC_ASSERT_ENUM(DownloadCrossOriginRedirects::kNavigate,
......
......@@ -331,7 +331,6 @@ class LocalFrameClientImpl final : public LocalFrameClient {
void UpdateSubresourceFactory(
std::unique_ptr<blink::URLLoaderFactoryBundleInfo> info) override;
WebLocalFrameClient::AppCacheType GetAppCacheType() override;
base::UnguessableToken GetAppCacheHostIDForSharedWorker() override;
private:
struct DocumentInterfaceBrokerForwarderTraits {
......
......@@ -48,7 +48,6 @@
#include "third_party/blink/renderer/core/events/message_event.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/loader/appcache/application_cache_host.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/frame_load_request.h"
#include "third_party/blink/renderer/core/loader/frame_loader.h"
......@@ -81,7 +80,9 @@ WebSharedWorkerImpl::WebSharedWorkerImpl(
creation_address_space_(mojom::IPAddressSpace::kPublic),
parent_execution_context_task_runners_(
ParentExecutionContextTaskRunners::Create()),
appcache_host_id_(appcache_host_id) {
appcache_host_(MakeGarbageCollected<ApplicationCacheHostForSharedWorker>(
appcache_host_id,
Thread::Current()->GetTaskRunner())) {
DCHECK(IsMainThread());
}
......@@ -94,6 +95,7 @@ void WebSharedWorkerImpl::TerminateWorkerThread() {
if (asked_to_terminate_)
return;
asked_to_terminate_ = true;
appcache_host_->Detach();
if (shadow_page_ && !shadow_page_->WasInitialized()) {
client_->WorkerScriptLoadFailed();
// The worker thread hasn't been started yet. Immediately notify the client
......@@ -125,7 +127,7 @@ void WebSharedWorkerImpl::ResumeStartup() {
is_paused_on_start_ = false;
if (is_paused_on_start) {
// We'll continue in OnShadowPageInitialized().
shadow_page_->Initialize(script_request_url_, appcache_host_id_);
shadow_page_->Initialize(script_request_url_);
}
}
......@@ -140,15 +142,10 @@ void WebSharedWorkerImpl::CountFeature(WebFeature feature) {
void WebSharedWorkerImpl::DidFetchScript(int64_t app_cache_id) {
DCHECK(IsMainThread());
Document* document = shadow_page_->GetDocument();
ApplicationCacheHost* host = document->Loader()->GetApplicationCacheHost();
if (host) {
host->SelectCacheForSharedWorker(
DCHECK(appcache_host_);
appcache_host_->SelectCacheForSharedWorker(
app_cache_id, WTF::Bind(&WebSharedWorkerImpl::OnAppCacheSelected,
weak_ptr_factory_.GetWeakPtr()));
} else {
OnAppCacheSelected();
}
}
void WebSharedWorkerImpl::DidFailToFetchClassicScript() {
......@@ -224,8 +221,6 @@ void WebSharedWorkerImpl::StartWorkerContext(
// token.
shadow_page_ = std::make_unique<WorkerShadowPage>(
this, std::move(loader_factory), std::move(privacy_preferences));
// TODO(https://crbug.com/982996): Create ApplicationCacheHostForSharedWorker
// here without depending on WorkerShadowPage and DocumentLoader.
// If we were asked to pause worker context on start and wait for debugger
// then now is a good time to do that.
......@@ -236,7 +231,7 @@ void WebSharedWorkerImpl::StartWorkerContext(
}
// We'll continue in OnShadowPageInitialized().
shadow_page_->Initialize(script_request_url_, appcache_host_id_);
shadow_page_->Initialize(script_request_url_);
}
void WebSharedWorkerImpl::OnAppCacheSelected() {
......@@ -271,7 +266,7 @@ void WebSharedWorkerImpl::ContinueStartWorkerContext() {
client_->CreateWorkerFetchContext();
DCHECK(web_worker_fetch_context);
web_worker_fetch_context->SetApplicationCacheHostID(
document->Loader()->GetApplicationCacheHost()->GetHostID());
appcache_host_->GetHostID());
// TODO(nhiroki); Set |script_type| to mojom::ScriptType::kModule for module
// fetch (https://crbug.com/824646).
......
......@@ -45,6 +45,7 @@
#include "third_party/blink/public/web/web_shared_worker_client.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/exported/worker_shadow_page.h"
#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.h"
#include "third_party/blink/renderer/core/workers/shared_worker_reporting_proxy.h"
#include "third_party/blink/renderer/core/workers/worker_clients.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h"
......@@ -163,7 +164,8 @@ class CORE_EXPORT WebSharedWorkerImpl final : public WebSharedWorker,
// document.
Persistent<ParentExecutionContextTaskRunners>
parent_execution_context_task_runners_;
const base::UnguessableToken appcache_host_id_;
Persistent<ApplicationCacheHostForSharedWorker> appcache_host_;
base::WeakPtrFactory<WebSharedWorkerImpl> weak_ptr_factory_{this};
};
......
......@@ -34,12 +34,9 @@ WorkerShadowPage::WorkerShadowPage(
/*compositing_enabled=*/false,
nullptr)),
loader_factory_(std::move(loader_factory)),
appcache_host_id_(base::UnguessableToken()),
preferences_(std::move(preferences)) {
DCHECK(IsMainThread());
// This should be called after |appcache_host_id_| is initialized because this
// initiates document loading and accesses it.
main_frame_ = WebLocalFrameImpl::CreateMainFrame(
web_view_, this, nullptr /* interface_registry */,
CreateStubDocumentInterfaceBrokerHandle(), nullptr /* opener */,
......@@ -56,17 +53,10 @@ WorkerShadowPage::~WorkerShadowPage() {
main_frame_->Close();
}
void WorkerShadowPage::Initialize(
const KURL& script_url,
const base::UnguessableToken& appcache_host_id) {
void WorkerShadowPage::Initialize(const KURL& script_url) {
DCHECK(IsMainThread());
AdvanceState(State::kInitializing);
// Lazily set the |appcache_host_id_| in order to avoid the initial document
// loading via WebLocalFrameImpl::CreateMainFrame() on the constructor from
// consuming the |appcache_host_id_|.
appcache_host_id_ = appcache_host_id;
// Construct substitute data source. We only need it to have same origin as
// the worker so the loading checks work correctly.
std::string content("");
......
......@@ -58,8 +58,7 @@ class CORE_EXPORT WorkerShadowPage : public WebLocalFrameClient {
// Initializes this instance and calls Client::OnShadowPageInitialized() when
// complete.
void Initialize(const KURL& script_url,
const base::UnguessableToken& appcache_host_id);
void Initialize(const KURL& script_url);
// WebLocalFrameClient overrides.
// Note: usually WebLocalFrameClient implementations override
......@@ -75,9 +74,6 @@ class CORE_EXPORT WorkerShadowPage : public WebLocalFrameClient {
WebLocalFrameClient::AppCacheType GetAppCacheType() override {
return client_->GetAppCacheType();
}
base::UnguessableToken GetAppCacheHostIDForSharedWorker() override {
return appcache_host_id_;
}
Document* GetDocument() { return main_frame_->GetFrame()->GetDocument(); }
WebSettings* GetSettings() { return web_view_->GetSettings(); }
......@@ -96,7 +92,6 @@ class CORE_EXPORT WorkerShadowPage : public WebLocalFrameClient {
WebView* web_view_;
Persistent<WebLocalFrameImpl> main_frame_;
scoped_refptr<network::SharedURLLoaderFactory> loader_factory_;
base::UnguessableToken appcache_host_id_;
// TODO(crbug.com/862854): Update the values when the browser process changes
// the preferences.
......
......@@ -535,12 +535,6 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
virtual WebLocalFrameClient::AppCacheType GetAppCacheType() {
return WebLocalFrameClient::AppCacheType::kAppCacheForNone;
}
// TODO(https://crbug.com/982996): This is a stopgap implementation for
// removing DocumentLoader dependencies from shared workers. Remove this once
// it's done.
virtual base::UnguessableToken GetAppCacheHostIDForSharedWorker() {
return base::UnguessableToken();
}
};
} // namespace blink
......
......@@ -69,9 +69,9 @@ mojom::blink::DocumentInterfaceBroker* GetDocumentInterfaceBroker(
} // namespace
// TODO(https://crbug.com/982996): Remove this creation function, and instead
// directly create an appcache host for frame in DocumentLoader, and for shared
// workers in WebSharedWorkerImpl.
// TODO(https://crbug.com/538751): Remove this creation function, and instead
// directly create an appcache host for frame in DocumentLoader after
// WorkerShadowPage is removed.
ApplicationCacheHost* ApplicationCacheHost::Create(
DocumentLoader* document_loader) {
DCHECK(document_loader);
......@@ -87,10 +87,10 @@ ApplicationCacheHost* ApplicationCacheHost::Create(
document_loader, GetDocumentInterfaceBroker(local_frame),
local_frame->GetTaskRunner(TaskType::kNetworking));
case WebLocalFrameClient::AppCacheType::kAppCacheForSharedWorker:
return MakeGarbageCollected<ApplicationCacheHostForSharedWorker>(
local_frame->Client()->GetAppCacheHostIDForSharedWorker(),
Thread::Current()->GetTaskRunner());
default:
// This creation function is being called for WorkerShadowPage. Return a
// null application cache host. A real host is constructed in
// WebSharedWorkerImpl.
case WebLocalFrameClient::AppCacheType::kAppCacheForNone:
return MakeGarbageCollected<ApplicationCacheHost>(
/*interface_broker=*/nullptr, /*task_runner=*/nullptr);
}
......
......@@ -193,8 +193,7 @@ void WebEmbeddedWorkerImpl::StartWorkerContext(
return;
}
shadow_page_->Initialize(worker_start_data_.script_url,
base::UnguessableToken());
shadow_page_->Initialize(worker_start_data_.script_url);
}
void WebEmbeddedWorkerImpl::TerminateWorkerContext() {
......@@ -327,10 +326,8 @@ void WebEmbeddedWorkerImpl::OnShadowPageInitialized() {
void WebEmbeddedWorkerImpl::ResumeStartup() {
bool was_waiting = (waiting_for_debugger_state_ == kWaitingForDebugger);
waiting_for_debugger_state_ = kNotWaitingForDebugger;
if (was_waiting) {
shadow_page_->Initialize(worker_start_data_.script_url,
base::UnguessableToken());
}
if (was_waiting)
shadow_page_->Initialize(worker_start_data_.script_url);
}
const base::UnguessableToken& WebEmbeddedWorkerImpl::GetDevToolsWorkerToken() {
......
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