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