diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/content/browser/worker_host | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/content/browser/worker_host')
21 files changed, 474 insertions, 395 deletions
diff --git a/chromium/content/browser/worker_host/dedicated_worker_host.cc b/chromium/content/browser/worker_host/dedicated_worker_host.cc index e253fb829ec..6b151083a6b 100644 --- a/chromium/content/browser/worker_host/dedicated_worker_host.cc +++ b/chromium/content/browser/worker_host/dedicated_worker_host.cc @@ -2,30 +2,26 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "content/browser/worker_host/dedicated_worker_host.h" + #include <string> #include <utility> -#include "content/browser/worker_host/dedicated_worker_host.h" - #include "base/bind.h" #include "content/browser/appcache/appcache_navigation_handle.h" #include "content/browser/blob_storage/chrome_blob_storage_context.h" -#include "content/browser/frame_host/frame_tree.h" #include "content/browser/frame_host/render_frame_host_impl.h" -#include "content/browser/interface_provider_filtering.h" -#include "content/browser/net/cross_origin_embedder_policy_reporter.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h" #include "content/browser/service_worker/service_worker_object_host.h" #include "content/browser/storage_partition_impl.h" #include "content/browser/url_loader_factory_params_helper.h" #include "content/browser/websockets/websocket_connector_impl.h" #include "content/browser/webtransport/quic_transport_connector_impl.h" +#include "content/browser/worker_host/dedicated_worker_host_factory_impl.h" #include "content/browser/worker_host/dedicated_worker_service_impl.h" #include "content/browser/worker_host/worker_script_fetch_initiator.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/idle_manager.h" -#include "content/public/browser/render_frame_host.h" -#include "content/public/browser/render_view_host.h" #include "content/public/browser/service_worker_context.h" #include "content/public/common/content_client.h" #include "content/public/common/network_service_util.h" @@ -35,8 +31,6 @@ #include "net/base/isolation_info.h" #include "third_party/blink/public/common/features.h" #include "third_party/blink/public/mojom/loader/fetch_client_settings_object.mojom.h" -#include "third_party/blink/public/mojom/usb/web_usb_service.mojom.h" -#include "url/origin.h" namespace content { @@ -49,8 +43,7 @@ DedicatedWorkerHost::DedicatedWorkerHost( const url::Origin& creator_origin, const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy, mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> - coep_reporter, - mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host) + coep_reporter) : service_(service), id_(id), worker_process_host_(worker_process_host), @@ -62,7 +55,6 @@ DedicatedWorkerHost::DedicatedWorkerHost( // the worker script URL. worker_origin_(creator_origin), cross_origin_embedder_policy_(cross_origin_embedder_policy), - host_receiver_(this, std::move(host)), coep_reporter_(std::move(coep_reporter)) { DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK(worker_process_host_); @@ -71,12 +63,12 @@ DedicatedWorkerHost::DedicatedWorkerHost( scoped_process_host_observer_.Add(worker_process_host_); - service_->NotifyWorkerStarted(id_, worker_process_host_->GetID(), + service_->NotifyWorkerCreated(id_, worker_process_host_->GetID(), ancestor_render_frame_host_id_); } DedicatedWorkerHost::~DedicatedWorkerHost() { - service_->NotifyWorkerTerminating(id_, ancestor_render_frame_host_id_); + service_->NotifyBeforeWorkerDestroyed(id_, ancestor_render_frame_host_id_); } void DedicatedWorkerHost::BindBrowserInterfaceBrokerReceiver( @@ -92,24 +84,6 @@ void DedicatedWorkerHost::OnMojoDisconnect() { delete this; } -void DedicatedWorkerHost::LifecycleStateChanged( - blink::mojom::FrameLifecycleState state) { - switch (state) { - case blink::mojom::FrameLifecycleState::kFrozen: - case blink::mojom::FrameLifecycleState::kFrozenAutoResumeMedia: - is_frozen_ = true; - break; - case blink::mojom::FrameLifecycleState::kRunning: - is_frozen_ = false; - break; - case blink::mojom::FrameLifecycleState::kPaused: - // This shouldn't be reached, the render process does not send this - // state. - NOTREACHED(); - break; - } -} - void DedicatedWorkerHost::RenderProcessExited( RenderProcessHost* render_process_host, const ChildProcessTerminationInfo& info) { @@ -147,16 +121,10 @@ void DedicatedWorkerHost::StartScriptLoad( // Get a storage domain. SiteInstance* site_instance = nearest_ancestor_render_frame_host->GetSiteInstance(); - if (!site_instance) { - client_->OnScriptLoadStartFailed(); - return; - } - std::string storage_domain; - std::string partition_name; - bool in_memory; - GetContentClient()->browser()->GetStoragePartitionConfigForSite( - storage_partition_impl->browser_context(), site_instance->GetSiteURL(), - /*can_be_default=*/true, &storage_domain, &partition_name, &in_memory); + auto storage_partition_config = + GetContentClient()->browser()->GetStoragePartitionConfigForSite( + storage_partition_impl->browser_context(), + site_instance->GetSiteURL()); scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory; if (script_url.SchemeIsBlob()) { @@ -216,7 +184,7 @@ void DedicatedWorkerHost::StartScriptLoad( service_worker_handle_.get(), appcache_host ? appcache_host->GetWeakPtr() : nullptr, std::move(blob_url_loader_factory), nullptr, storage_partition_impl, - storage_domain, + storage_partition_config.partition_domain(), base::BindOnce(&DedicatedWorkerHost::DidStartScriptLoad, weak_factory_.GetWeakPtr())); } @@ -282,7 +250,7 @@ void DedicatedWorkerHost::DidStartScriptLoad( } client_->OnScriptLoadStarted( - service_worker_handle_->TakeProviderInfo(), + service_worker_handle_->TakeContainerInfo(), std::move(main_script_load_params), std::move(subresource_loader_factories), subresource_loader_updater_.BindNewPipeAndPassReceiver(), @@ -323,7 +291,11 @@ DedicatedWorkerHost::CreateNetworkFactoryForSubresources( ancestor_render_frame_host, worker_origin_, mojo::Clone(ancestor_render_frame_host ->last_committed_client_security_state()), - std::move(coep_reporter), worker_process_host_); + std::move(coep_reporter), worker_process_host_, + ancestor_render_frame_host->IsFeatureEnabled( + blink::mojom::FeaturePolicyFeature::kTrustTokenRedemption) + ? network::mojom::TrustTokenRedemptionPolicy::kPotentiallyPermit + : network::mojom::TrustTokenRedemptionPolicy::kForbid); GetContentClient()->browser()->WillCreateURLLoaderFactory( worker_process_host_->GetBrowserContext(), /*frame=*/nullptr, worker_process_host_->GetID(), @@ -421,11 +393,13 @@ void DedicatedWorkerHost::CreateNestedDedicatedWorker( coep_reporter; coep_reporter_->Clone(coep_reporter.InitWithNewPipeAndPassReceiver()); // There is no creator frame when the worker is nested. - CreateDedicatedWorkerHostFactory( - worker_process_host_->GetID(), - /*creator_render_frame_host_id_=*/base::nullopt, - ancestor_render_frame_host_id_, worker_origin_, - cross_origin_embedder_policy_, std::move(coep_reporter), + + mojo::MakeSelfOwnedReceiver( + std::make_unique<DedicatedWorkerHostFactoryImpl>( + worker_process_host_->GetID(), + /*creator_render_frame_host_id_=*/base::nullopt, + ancestor_render_frame_host_id_, worker_origin_, + cross_origin_embedder_policy_, std::move(coep_reporter)), std::move(receiver)); } @@ -510,16 +484,12 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() { return; SiteInstance* site_instance = ancestor_render_frame_host->GetSiteInstance(); - if (!site_instance) - return; // Get a storage domain. - std::string storage_domain; - std::string partition_name; - bool in_memory; - GetContentClient()->browser()->GetStoragePartitionConfigForSite( - storage_partition_impl->browser_context(), site_instance->GetSiteURL(), - /*can_be_default=*/true, &storage_domain, &partition_name, &in_memory); + auto storage_partition_config = + GetContentClient()->browser()->GetStoragePartitionConfigForSite( + storage_partition_impl->browser_context(), + site_instance->GetSiteURL()); // Start observing Network Service crash again. ObserveNetworkServiceCrash(storage_partition_impl); @@ -531,7 +501,7 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() { WorkerScriptFetchInitiator::CreateFactoryBundle( WorkerScriptFetchInitiator::LoaderType::kSubResource, worker_process_host_->GetID(), storage_partition_impl, - storage_domain, file_url_support_, + storage_partition_config.partition_domain(), file_url_support_, /*filesystem_url_support=*/true); bool bypass_redirect_checks = false; @@ -545,162 +515,4 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() { std::move(subresource_loader_factories)); } -namespace { -// A factory for creating DedicatedWorkerHosts. Its lifetime is managed by the -// renderer over mojo via SelfOwnedReceiver. It lives on the UI thread. -class DedicatedWorkerHostFactoryImpl final - : public blink::mojom::DedicatedWorkerHostFactory { - public: - DedicatedWorkerHostFactoryImpl( - int worker_process_id, - base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id, - GlobalFrameRoutingId ancestor_render_frame_host_id, - const url::Origin& creator_origin, - const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy, - mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> - coep_reporter) - : worker_process_id_(worker_process_id), - creator_render_frame_host_id_(creator_render_frame_host_id), - ancestor_render_frame_host_id_(ancestor_render_frame_host_id), - creator_origin_(creator_origin), - cross_origin_embedder_policy_(cross_origin_embedder_policy), - coep_reporter_(std::move(coep_reporter)) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - } - - // blink::mojom::DedicatedWorkerHostFactory: - void CreateWorkerHost( - mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker> - broker_receiver, - mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host_receiver, - base::OnceCallback<void(const network::CrossOriginEmbedderPolicy&)> - callback) override { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - if (base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker)) { - mojo::ReportBadMessage("DWH_INVALID_WORKER_CREATION"); - return; - } - - std::move(callback).Run(cross_origin_embedder_policy_); - - auto* worker_process_host = RenderProcessHost::FromID(worker_process_id_); - if (!worker_process_host || - !worker_process_host->IsInitializedAndNotDead()) { - // Abort if the worker's process host is gone. This means that the calling - // frame or worker is also either destroyed or in the process of being - // destroyed. - return; - } - - auto* storage_partition = static_cast<StoragePartitionImpl*>( - worker_process_host->GetStoragePartition()); - - // Get the dedicated worker service. - DedicatedWorkerServiceImpl* service = - storage_partition->GetDedicatedWorkerService(); - - mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> - coep_reporter; - coep_reporter_->Clone(coep_reporter.InitWithNewPipeAndPassReceiver()); - - auto* host = new DedicatedWorkerHost( - service, service->GenerateNextDedicatedWorkerId(), worker_process_host, - creator_render_frame_host_id_, ancestor_render_frame_host_id_, - creator_origin_, cross_origin_embedder_policy_, - std::move(coep_reporter), std::move(host_receiver)); - host->BindBrowserInterfaceBrokerReceiver(std::move(broker_receiver)); - } - - // PlzDedicatedWorker: - void CreateWorkerHostAndStartScriptLoad( - const GURL& script_url, - network::mojom::CredentialsMode credentials_mode, - blink::mojom::FetchClientSettingsObjectPtr - outside_fetch_client_settings_object, - mojo::PendingRemote<blink::mojom::BlobURLToken> blob_url_token, - mojo::PendingRemote<blink::mojom::DedicatedWorkerHostFactoryClient> - client, - mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host_receiver) - override { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - if (!base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker)) { - mojo::ReportBadMessage("DWH_BROWSER_SCRIPT_FETCH_DISABLED"); - return; - } - - // TODO(https://crbug.com/1058759): Compare |creator_origin_| to - // |script_url|, and report as bad message if that fails. - - auto* worker_process_host = RenderProcessHost::FromID(worker_process_id_); - if (!worker_process_host || - !worker_process_host->IsInitializedAndNotDead()) { - // Abort if the worker's process host is gone. This means that the calling - // frame or worker is also either destroyed or in the process of being - // destroyed. - return; - } - - auto* storage_partition = static_cast<StoragePartitionImpl*>( - worker_process_host->GetStoragePartition()); - - // Get the dedicated worker service. - DedicatedWorkerServiceImpl* service = - storage_partition->GetDedicatedWorkerService(); - - mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> - coep_reporter; - coep_reporter_->Clone(coep_reporter.InitWithNewPipeAndPassReceiver()); - - auto* host = new DedicatedWorkerHost( - service, service->GenerateNextDedicatedWorkerId(), worker_process_host, - creator_render_frame_host_id_, ancestor_render_frame_host_id_, - creator_origin_, cross_origin_embedder_policy_, - std::move(coep_reporter), std::move(host_receiver)); - mojo::PendingRemote<blink::mojom::BrowserInterfaceBroker> broker; - host->BindBrowserInterfaceBrokerReceiver( - broker.InitWithNewPipeAndPassReceiver()); - mojo::Remote<blink::mojom::DedicatedWorkerHostFactoryClient> remote_client( - std::move(client)); - remote_client->OnWorkerHostCreated(std::move(broker)); - host->StartScriptLoad(script_url, credentials_mode, - std::move(outside_fetch_client_settings_object), - std::move(blob_url_token), std::move(remote_client)); - } - - private: - // The ID of the RenderProcessHost where the worker will live. - const int worker_process_id_; - - // See comments on the corresponding members of DedicatedWorkerHost. - const base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id_; - const GlobalFrameRoutingId ancestor_render_frame_host_id_; - - const url::Origin creator_origin_; - const network::CrossOriginEmbedderPolicy cross_origin_embedder_policy_; - mojo::Remote<network::mojom::CrossOriginEmbedderPolicyReporter> - coep_reporter_; - - DISALLOW_COPY_AND_ASSIGN(DedicatedWorkerHostFactoryImpl); -}; - -} // namespace - -void CreateDedicatedWorkerHostFactory( - int worker_process_id, - base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id, - GlobalFrameRoutingId ancestor_render_frame_host_id, - const url::Origin& creator_origin, - const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy, - mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> - coep_reporter, - mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - mojo::MakeSelfOwnedReceiver( - std::make_unique<DedicatedWorkerHostFactoryImpl>( - worker_process_id, creator_render_frame_host_id, - ancestor_render_frame_host_id, creator_origin, - cross_origin_embedder_policy, std::move(coep_reporter)), - std::move(receiver)); -} - } // namespace content diff --git a/chromium/content/browser/worker_host/dedicated_worker_host.h b/chromium/content/browser/worker_host/dedicated_worker_host.h index 2e9e168b0b1..00f8c2a1df7 100644 --- a/chromium/content/browser/worker_host/dedicated_worker_host.h +++ b/chromium/content/browser/worker_host/dedicated_worker_host.h @@ -15,32 +15,25 @@ #include "content/public/browser/global_routing_id.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host_observer.h" -#include "media/mojo/mojom/video_decode_perf_history.mojom.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/remote.h" #include "services/network/public/cpp/cross_origin_embedder_policy.h" -#include "third_party/blink/public/mojom/filesystem/file_system.mojom-forward.h" #include "third_party/blink/public/mojom/idle/idle_manager.mojom-forward.h" -#include "third_party/blink/public/mojom/payments/payment_app.mojom-forward.h" #include "third_party/blink/public/mojom/sms/sms_receiver.mojom-forward.h" #include "third_party/blink/public/mojom/usb/web_usb_service.mojom-forward.h" #include "third_party/blink/public/mojom/wake_lock/wake_lock.mojom-forward.h" #include "third_party/blink/public/mojom/websockets/websocket_connector.mojom-forward.h" #include "third_party/blink/public/mojom/webtransport/quic_transport_connector.mojom-forward.h" -#include "third_party/blink/public/mojom/worker/dedicated_worker_host.mojom.h" #include "third_party/blink/public/mojom/worker/dedicated_worker_host_factory.mojom.h" #include "third_party/blink/public/mojom/worker/subresource_loader_updater.mojom.h" +#include "url/origin.h" #if !defined(OS_ANDROID) #include "third_party/blink/public/mojom/serial/serial.mojom-forward.h" #endif -namespace url { -class Origin; -} - namespace content { class CrossOriginEmbedderPolicyReporter; @@ -49,23 +42,10 @@ class ServiceWorkerMainResourceHandle; class ServiceWorkerObjectHost; class StoragePartitionImpl; -// Creates a host factory for a dedicated worker. This must be called on the UI -// thread. -CONTENT_EXPORT void CreateDedicatedWorkerHostFactory( - int worker_process_id, - base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id, - GlobalFrameRoutingId ancestor_render_frame_host_id, - const url::Origin& creator_origin, - const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy, - mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> - coep_reporter, - mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver); - // A host for a single dedicated worker. It deletes itself upon Mojo // disconnection from the worker in the renderer or when the RenderProcessHost // of the worker is destroyed. This lives on the UI thread. -class DedicatedWorkerHost final : public blink::mojom::DedicatedWorkerHost, - public RenderProcessHostObserver { +class DedicatedWorkerHost final : public RenderProcessHostObserver { public: DedicatedWorkerHost( DedicatedWorkerServiceImpl* service, @@ -76,8 +56,7 @@ class DedicatedWorkerHost final : public blink::mojom::DedicatedWorkerHost, const url::Origin& creator_origin, const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy, mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> - coep_reporter, - mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host); + coep_reporter); ~DedicatedWorkerHost() final; void BindBrowserInterfaceBrokerReceiver( @@ -108,14 +87,6 @@ class DedicatedWorkerHost final : public blink::mojom::DedicatedWorkerHost, mojo::PendingReceiver<blink::mojom::SerialService> receiver); #endif - // blink::mojom::DedicatedWorkerHost: - void LifecycleStateChanged(blink::mojom::FrameLifecycleState state) override; - - // TODO(dtapuska): This state needs to be hooked up to the - // ServiceWorkerProviderHost so the correct state is queried when looking - // for frozen dedicated workers. crbug.com/968417 - bool is_frozen() const { return is_frozen_; } - // PlzDedicatedWorker: void StartScriptLoad( const GURL& script_url, @@ -223,14 +194,10 @@ class DedicatedWorkerHost final : public blink::mojom::DedicatedWorkerHost, this}; mojo::Receiver<blink::mojom::BrowserInterfaceBroker> broker_receiver_{ &broker_}; - mojo::Receiver<blink::mojom::DedicatedWorkerHost> host_receiver_; // Indicates if subresource loaders of this worker support file URLs. bool file_url_support_ = false; - // The liveness state of the dedicated worker in the renderer. - bool is_frozen_ = false; - // For observing Network Service connection errors only. mojo::Remote<network::mojom::URLLoaderFactory> network_service_connection_error_handler_holder_; diff --git a/chromium/content/browser/worker_host/dedicated_worker_host_factory_impl.cc b/chromium/content/browser/worker_host/dedicated_worker_host_factory_impl.cc new file mode 100644 index 00000000000..4094b5192e2 --- /dev/null +++ b/chromium/content/browser/worker_host/dedicated_worker_host_factory_impl.cc @@ -0,0 +1,129 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/worker_host/dedicated_worker_host_factory_impl.h" + +#include <memory> +#include <utility> + +#include "base/feature_list.h" +#include "content/browser/storage_partition_impl.h" +#include "content/browser/worker_host/dedicated_worker_host.h" +#include "content/browser/worker_host/dedicated_worker_service_impl.h" +#include "content/public/browser/render_process_host.h" +#include "mojo/public/cpp/bindings/message.h" +#include "third_party/blink/public/common/features.h" + +namespace content { + +DedicatedWorkerHostFactoryImpl::DedicatedWorkerHostFactoryImpl( + int worker_process_id, + base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id, + GlobalFrameRoutingId ancestor_render_frame_host_id, + const url::Origin& creator_origin, + const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy, + mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> + coep_reporter) + : worker_process_id_(worker_process_id), + creator_render_frame_host_id_(creator_render_frame_host_id), + ancestor_render_frame_host_id_(ancestor_render_frame_host_id), + creator_origin_(creator_origin), + cross_origin_embedder_policy_(cross_origin_embedder_policy), + coep_reporter_(std::move(coep_reporter)) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +} + +DedicatedWorkerHostFactoryImpl::~DedicatedWorkerHostFactoryImpl() = default; + +void DedicatedWorkerHostFactoryImpl::CreateWorkerHost( + mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker> broker_receiver, + base::OnceCallback<void(const network::CrossOriginEmbedderPolicy&)> + callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + if (base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker)) { + mojo::ReportBadMessage("DWH_INVALID_WORKER_CREATION"); + return; + } + + std::move(callback).Run(cross_origin_embedder_policy_); + + auto* worker_process_host = RenderProcessHost::FromID(worker_process_id_); + if (!worker_process_host || !worker_process_host->IsInitializedAndNotDead()) { + // Abort if the worker's process host is gone. This means that the calling + // frame or worker is also either destroyed or in the process of being + // destroyed. + return; + } + + auto* storage_partition = static_cast<StoragePartitionImpl*>( + worker_process_host->GetStoragePartition()); + + // Get the dedicated worker service. + DedicatedWorkerServiceImpl* service = + storage_partition->GetDedicatedWorkerService(); + + mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> + coep_reporter; + coep_reporter_->Clone(coep_reporter.InitWithNewPipeAndPassReceiver()); + + auto* host = new DedicatedWorkerHost( + service, service->GenerateNextDedicatedWorkerId(), worker_process_host, + creator_render_frame_host_id_, ancestor_render_frame_host_id_, + creator_origin_, cross_origin_embedder_policy_, std::move(coep_reporter)); + host->BindBrowserInterfaceBrokerReceiver(std::move(broker_receiver)); +} + +// PlzDedicatedWorker: +void DedicatedWorkerHostFactoryImpl::CreateWorkerHostAndStartScriptLoad( + const GURL& script_url, + network::mojom::CredentialsMode credentials_mode, + blink::mojom::FetchClientSettingsObjectPtr + outside_fetch_client_settings_object, + mojo::PendingRemote<blink::mojom::BlobURLToken> blob_url_token, + mojo::PendingRemote<blink::mojom::DedicatedWorkerHostFactoryClient> + client) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + if (!base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker)) { + mojo::ReportBadMessage("DWH_BROWSER_SCRIPT_FETCH_DISABLED"); + return; + } + + // TODO(https://crbug.com/1058759): Compare |creator_origin_| to + // |script_url|, and report as bad message if that fails. + + auto* worker_process_host = RenderProcessHost::FromID(worker_process_id_); + if (!worker_process_host || !worker_process_host->IsInitializedAndNotDead()) { + // Abort if the worker's process host is gone. This means that the calling + // frame or worker is also either destroyed or in the process of being + // destroyed. + return; + } + + auto* storage_partition = static_cast<StoragePartitionImpl*>( + worker_process_host->GetStoragePartition()); + + // Get the dedicated worker service. + DedicatedWorkerServiceImpl* service = + storage_partition->GetDedicatedWorkerService(); + + mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> + coep_reporter; + coep_reporter_->Clone(coep_reporter.InitWithNewPipeAndPassReceiver()); + + auto* host = new DedicatedWorkerHost( + service, service->GenerateNextDedicatedWorkerId(), worker_process_host, + creator_render_frame_host_id_, ancestor_render_frame_host_id_, + creator_origin_, cross_origin_embedder_policy_, std::move(coep_reporter)); + mojo::PendingRemote<blink::mojom::BrowserInterfaceBroker> broker; + host->BindBrowserInterfaceBrokerReceiver( + broker.InitWithNewPipeAndPassReceiver()); + mojo::Remote<blink::mojom::DedicatedWorkerHostFactoryClient> remote_client( + std::move(client)); + remote_client->OnWorkerHostCreated(std::move(broker)); + host->StartScriptLoad(script_url, credentials_mode, + std::move(outside_fetch_client_settings_object), + std::move(blob_url_token), std::move(remote_client)); +} + +} // namespace content diff --git a/chromium/content/browser/worker_host/dedicated_worker_host_factory_impl.h b/chromium/content/browser/worker_host/dedicated_worker_host_factory_impl.h new file mode 100644 index 00000000000..f1583c18689 --- /dev/null +++ b/chromium/content/browser/worker_host/dedicated_worker_host_factory_impl.h @@ -0,0 +1,70 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_WORKER_HOST_DEDICATED_WORKER_HOST_FACTORY_IMPL_H_ +#define CONTENT_BROWSER_WORKER_HOST_DEDICATED_WORKER_HOST_FACTORY_IMPL_H_ + +#include "base/optional.h" +#include "content/common/content_export.h" +#include "content/public/browser/global_routing_id.h" +#include "mojo/public/cpp/bindings/pending_remote.h" +#include "mojo/public/cpp/bindings/remote.h" +#include "services/network/public/cpp/cross_origin_embedder_policy.h" +#include "services/network/public/mojom/cross_origin_embedder_policy.mojom.h" +#include "third_party/blink/public/mojom/worker/dedicated_worker_host_factory.mojom.h" +#include "url/origin.h" + +namespace content { + +// A factory for creating DedicatedWorkerHosts. Its lifetime is managed by the +// renderer over mojo via SelfOwnedReceiver. It lives on the UI thread. +class CONTENT_EXPORT DedicatedWorkerHostFactoryImpl + : public blink::mojom::DedicatedWorkerHostFactory { + public: + DedicatedWorkerHostFactoryImpl( + int worker_process_id, + base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id, + GlobalFrameRoutingId ancestor_render_frame_host_id, + const url::Origin& creator_origin, + const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy, + mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> + coep_reporter); + ~DedicatedWorkerHostFactoryImpl() override; + + // blink::mojom::DedicatedWorkerHostFactory: + void CreateWorkerHost( + mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker> + broker_receiver, + base::OnceCallback<void(const network::CrossOriginEmbedderPolicy&)> + callback) override; + + // PlzDedicatedWorker: + void CreateWorkerHostAndStartScriptLoad( + const GURL& script_url, + network::mojom::CredentialsMode credentials_mode, + blink::mojom::FetchClientSettingsObjectPtr + outside_fetch_client_settings_object, + mojo::PendingRemote<blink::mojom::BlobURLToken> blob_url_token, + mojo::PendingRemote<blink::mojom::DedicatedWorkerHostFactoryClient> + client) override; + + private: + // The ID of the RenderProcessHost where the worker will live. + const int worker_process_id_; + + // See comments on the corresponding members of DedicatedWorkerHost. + const base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id_; + const GlobalFrameRoutingId ancestor_render_frame_host_id_; + + const url::Origin creator_origin_; + const network::CrossOriginEmbedderPolicy cross_origin_embedder_policy_; + mojo::Remote<network::mojom::CrossOriginEmbedderPolicyReporter> + coep_reporter_; + + DISALLOW_COPY_AND_ASSIGN(DedicatedWorkerHostFactoryImpl); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_WORKER_HOST_DEDICATED_WORKER_HOST_FACTORY_IMPL_H_ diff --git a/chromium/content/browser/worker_host/dedicated_worker_service_impl.cc b/chromium/content/browser/worker_host/dedicated_worker_service_impl.cc index 37d54844ea3..b2d4c4808d6 100644 --- a/chromium/content/browser/worker_host/dedicated_worker_service_impl.cc +++ b/chromium/content/browser/worker_host/dedicated_worker_service_impl.cc @@ -8,6 +8,21 @@ namespace content { +DedicatedWorkerServiceImpl::DedicatedWorkerInfo::DedicatedWorkerInfo( + int worker_process_id, + GlobalFrameRoutingId ancestor_render_frame_host_id) + : worker_process_id(worker_process_id), + ancestor_render_frame_host_id(ancestor_render_frame_host_id) {} + +DedicatedWorkerServiceImpl::DedicatedWorkerInfo::DedicatedWorkerInfo( + const DedicatedWorkerInfo& info) = default; +DedicatedWorkerServiceImpl::DedicatedWorkerInfo& +DedicatedWorkerServiceImpl::DedicatedWorkerInfo::operator=( + const DedicatedWorkerInfo& info) = default; + +DedicatedWorkerServiceImpl::DedicatedWorkerInfo::~DedicatedWorkerInfo() = + default; + DedicatedWorkerServiceImpl::DedicatedWorkerServiceImpl() = default; DedicatedWorkerServiceImpl::~DedicatedWorkerServiceImpl() = default; @@ -25,9 +40,13 @@ void DedicatedWorkerServiceImpl::EnumerateDedicatedWorkers(Observer* observer) { DedicatedWorkerId dedicated_worker_id = kv.first; const DedicatedWorkerInfo& dedicated_worker_info = kv.second; - observer->OnWorkerStarted( + observer->OnWorkerCreated( dedicated_worker_id, dedicated_worker_info.worker_process_id, dedicated_worker_info.ancestor_render_frame_host_id); + if (dedicated_worker_info.final_response_url) { + observer->OnFinalResponseURLDetermined( + dedicated_worker_id, *dedicated_worker_info.final_response_url); + } } } @@ -35,40 +54,43 @@ DedicatedWorkerId DedicatedWorkerServiceImpl::GenerateNextDedicatedWorkerId() { return dedicated_worker_id_generator_.GenerateNextId(); } -void DedicatedWorkerServiceImpl::NotifyWorkerStarted( +void DedicatedWorkerServiceImpl::NotifyWorkerCreated( DedicatedWorkerId dedicated_worker_id, int worker_process_id, GlobalFrameRoutingId ancestor_render_frame_host_id) { bool inserted = dedicated_worker_infos_ .emplace(dedicated_worker_id, - DedicatedWorkerInfo{worker_process_id, - ancestor_render_frame_host_id}) + DedicatedWorkerInfo(worker_process_id, + ancestor_render_frame_host_id)) .second; DCHECK(inserted); for (Observer& observer : observers_) { - observer.OnWorkerStarted(dedicated_worker_id, worker_process_id, + observer.OnWorkerCreated(dedicated_worker_id, worker_process_id, ancestor_render_frame_host_id); } } -void DedicatedWorkerServiceImpl::NotifyWorkerTerminating( +void DedicatedWorkerServiceImpl::NotifyBeforeWorkerDestroyed( DedicatedWorkerId dedicated_worker_id, GlobalFrameRoutingId ancestor_render_frame_host_id) { size_t removed = dedicated_worker_infos_.erase(dedicated_worker_id); DCHECK_EQ(removed, 1u); for (Observer& observer : observers_) { - observer.OnBeforeWorkerTerminated(dedicated_worker_id, - ancestor_render_frame_host_id); + observer.OnBeforeWorkerDestroyed(dedicated_worker_id, + ancestor_render_frame_host_id); } } void DedicatedWorkerServiceImpl::NotifyWorkerFinalResponseURLDetermined( DedicatedWorkerId dedicated_worker_id, const GURL& url) { - DCHECK(base::Contains(dedicated_worker_infos_, dedicated_worker_id)); + auto it = dedicated_worker_infos_.find(dedicated_worker_id); + DCHECK(it != dedicated_worker_infos_.end()); + + it->second.final_response_url = url; for (Observer& observer : observers_) observer.OnFinalResponseURLDetermined(dedicated_worker_id, url); diff --git a/chromium/content/browser/worker_host/dedicated_worker_service_impl.h b/chromium/content/browser/worker_host/dedicated_worker_service_impl.h index 4fb3a35cf75..095c369b978 100644 --- a/chromium/content/browser/worker_host/dedicated_worker_service_impl.h +++ b/chromium/content/browser/worker_host/dedicated_worker_service_impl.h @@ -7,6 +7,7 @@ #include "base/observer_list.h" #include "content/public/browser/dedicated_worker_service.h" +#include "url/gurl.h" namespace content { @@ -25,13 +26,13 @@ class CONTENT_EXPORT DedicatedWorkerServiceImpl DedicatedWorkerId GenerateNextDedicatedWorkerId(); - // Notifies all observers about a starting worker. - void NotifyWorkerStarted(DedicatedWorkerId dedicated_worker_id, + // Notifies all observers about a new worker. + void NotifyWorkerCreated(DedicatedWorkerId dedicated_worker_id, int worker_process_id, GlobalFrameRoutingId ancestor_render_frame_host_id); - // Notifies all observers about a terminating worker. - void NotifyWorkerTerminating( + // Notifies all observers about a worker being destroyed. + void NotifyBeforeWorkerDestroyed( DedicatedWorkerId dedicated_worker_id, GlobalFrameRoutingId ancestor_render_frame_host_id); @@ -47,8 +48,16 @@ class CONTENT_EXPORT DedicatedWorkerServiceImpl base::ObserverList<Observer> observers_; struct DedicatedWorkerInfo { + DedicatedWorkerInfo(int worker_process_id, + GlobalFrameRoutingId ancestor_render_frame_host_id); + ~DedicatedWorkerInfo(); + + DedicatedWorkerInfo(const DedicatedWorkerInfo& info); + DedicatedWorkerInfo& operator=(const DedicatedWorkerInfo& info); + int worker_process_id; GlobalFrameRoutingId ancestor_render_frame_host_id; + base::Optional<GURL> final_response_url; }; base::flat_map<DedicatedWorkerId, DedicatedWorkerInfo> dedicated_worker_infos_; diff --git a/chromium/content/browser/worker_host/dedicated_worker_service_impl_unittest.cc b/chromium/content/browser/worker_host/dedicated_worker_service_impl_unittest.cc index 9694ee00129..d9e4832e74a 100644 --- a/chromium/content/browser/worker_host/dedicated_worker_service_impl_unittest.cc +++ b/chromium/content/browser/worker_host/dedicated_worker_service_impl_unittest.cc @@ -12,11 +12,13 @@ #include "base/test/scoped_feature_list.h" #include "content/browser/site_instance_impl.h" #include "content/browser/worker_host/dedicated_worker_host.h" +#include "content/browser/worker_host/dedicated_worker_host_factory_impl.h" #include "content/public/browser/storage_partition.h" #include "content/public/test/test_browser_context.h" #include "content/test/test_render_view_host.h" #include "content/test/test_web_contents.h" #include "mojo/public/cpp/bindings/remote.h" +#include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "third_party/blink/public/common/features.h" #include "third_party/blink/public/mojom/worker/dedicated_worker_host_factory.mojom.h" #include "third_party/blink/public/mojom/worker/worker_main_script_load_params.mojom.h" @@ -35,22 +37,22 @@ class MockDedicatedWorker auto dummy_coep_reporter = coep_reporter_remote.InitWithNewPipeAndPassReceiver(); - CreateDedicatedWorkerHostFactory( - worker_process_id, render_frame_host_id, render_frame_host_id, - url::Origin(), network::CrossOriginEmbedderPolicy(), - std::move(coep_reporter_remote), factory_.BindNewPipeAndPassReceiver()); + mojo::MakeSelfOwnedReceiver( + std::make_unique<DedicatedWorkerHostFactoryImpl>( + worker_process_id, render_frame_host_id, render_frame_host_id, + url::Origin(), network::CrossOriginEmbedderPolicy(), + std::move(coep_reporter_remote)), + factory_.BindNewPipeAndPassReceiver()); if (base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker)) { factory_->CreateWorkerHostAndStartScriptLoad( /*script_url=*/GURL(), network::mojom::CredentialsMode::kSameOrigin, blink::mojom::FetchClientSettingsObject::New(), mojo::PendingRemote<blink::mojom::BlobURLToken>(), - receiver_.BindNewPipeAndPassRemote(), - remote_host_.BindNewPipeAndPassReceiver()); + receiver_.BindNewPipeAndPassRemote()); } else { factory_->CreateWorkerHost( browser_interface_broker_.BindNewPipeAndPassReceiver(), - remote_host_.BindNewPipeAndPassReceiver(), base::BindOnce([](const network::CrossOriginEmbedderPolicy&) {})); } } @@ -68,8 +70,8 @@ class MockDedicatedWorker } void OnScriptLoadStarted( - blink::mojom::ServiceWorkerProviderInfoForClientPtr - service_worker_provider_info, + blink::mojom::ServiceWorkerContainerInfoForClientPtr + service_worker_container_info, blink::mojom::WorkerMainScriptLoadParamsPtr main_script_load_params, std::unique_ptr<blink::PendingURLLoaderFactoryBundle> pending_subresource_loader_factory_bundle, @@ -87,7 +89,6 @@ class MockDedicatedWorker mojo::Remote<blink::mojom::DedicatedWorkerHostFactory> factory_; mojo::Remote<blink::mojom::BrowserInterfaceBroker> browser_interface_broker_; - mojo::Remote<blink::mojom::DedicatedWorkerHost> remote_host_; }; class DedicatedWorkerServiceImplTest @@ -157,7 +158,7 @@ class TestDedicatedWorkerServiceObserver const TestDedicatedWorkerServiceObserver& other) = delete; // DedicatedWorkerService::Observer: - void OnWorkerStarted( + void OnWorkerCreated( DedicatedWorkerId dedicated_worker_id, int worker_process_id, GlobalFrameRoutingId ancestor_render_frame_host_id) override { @@ -172,7 +173,7 @@ class TestDedicatedWorkerServiceObserver if (on_worker_event_callback_) std::move(on_worker_event_callback_).Run(); } - void OnBeforeWorkerTerminated( + void OnBeforeWorkerDestroyed( DedicatedWorkerId dedicated_worker_id, GlobalFrameRoutingId ancestor_render_frame_host_id) override { size_t removed = dedicated_worker_infos_.erase(dedicated_worker_id); diff --git a/chromium/content/browser/worker_host/mock_shared_worker.cc b/chromium/content/browser/worker_host/mock_shared_worker.cc index 7425cb6cafb..160e14b192a 100644 --- a/chromium/content/browser/worker_host/mock_shared_worker.cc +++ b/chromium/content/browser/worker_host/mock_shared_worker.cc @@ -103,8 +103,8 @@ void MockSharedWorkerFactory::CreateSharedWorker( preference_watcher_receiver, mojo::PendingRemote<blink::mojom::WorkerContentSettingsProxy> content_settings, - blink::mojom::ServiceWorkerProviderInfoForClientPtr - service_worker_provider_info, + blink::mojom::ServiceWorkerContainerInfoForClientPtr + service_worker_container_info, const base::Optional<base::UnguessableToken>& appcache_host_id, blink::mojom::WorkerMainScriptLoadParamsPtr main_script_load_params, std::unique_ptr<blink::PendingURLLoaderFactoryBundle> @@ -178,6 +178,10 @@ bool MockSharedWorkerClient::CheckReceivedOnScriptLoadFailed() { return true; } +void MockSharedWorkerClient::ResetReceiver() { + receiver_.reset(); +} + void MockSharedWorkerClient::OnCreated( blink::mojom::SharedWorkerCreationContextType creation_context_type) { DCHECK(!on_created_received_); diff --git a/chromium/content/browser/worker_host/mock_shared_worker.h b/chromium/content/browser/worker_host/mock_shared_worker.h index 318611b50d7..2398a4002a4 100644 --- a/chromium/content/browser/worker_host/mock_shared_worker.h +++ b/chromium/content/browser/worker_host/mock_shared_worker.h @@ -22,7 +22,7 @@ #include "third_party/blink/public/common/messaging/message_port_channel.h" #include "third_party/blink/public/mojom/renderer_preferences.mojom.h" #include "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom.h" -#include "third_party/blink/public/mojom/service_worker/service_worker_provider.mojom.h" +#include "third_party/blink/public/mojom/service_worker/service_worker_container.mojom.h" #include "third_party/blink/public/mojom/worker/shared_worker_factory.mojom.h" #include "third_party/blink/public/mojom/worker/worker_content_settings_proxy.mojom.h" @@ -86,8 +86,8 @@ class MockSharedWorkerFactory : public blink::mojom::SharedWorkerFactory { preference_watcher_receiver, mojo::PendingRemote<blink::mojom::WorkerContentSettingsProxy> content_settings, - blink::mojom::ServiceWorkerProviderInfoForClientPtr - service_worker_provider_info, + blink::mojom::ServiceWorkerContainerInfoForClientPtr + service_worker_container_info, const base::Optional<base::UnguessableToken>& appcache_host_id, blink::mojom::WorkerMainScriptLoadParamsPtr main_script_load_params, std::unique_ptr<blink::PendingURLLoaderFactoryBundle> @@ -129,6 +129,10 @@ class MockSharedWorkerClient : public blink::mojom::SharedWorkerClient { bool CheckNotReceivedOnFeatureUsed(); bool CheckReceivedOnScriptLoadFailed(); + // Resets the receiver, allowing the caller to simulate losing the connection + // with the client. + void ResetReceiver(); + private: // blink::mojom::SharedWorkerClient methods: void OnCreated(blink::mojom::SharedWorkerCreationContextType diff --git a/chromium/content/browser/worker_host/shared_worker_host.cc b/chromium/content/browser/worker_host/shared_worker_host.cc index 5350ebb2cbc..f7a745dc184 100644 --- a/chromium/content/browser/worker_host/shared_worker_host.cc +++ b/chromium/content/browser/worker_host/shared_worker_host.cc @@ -45,12 +45,9 @@ namespace content { // RAII helper class for talking to SharedWorkerDevToolsManager. class SharedWorkerHost::ScopedDevToolsHandle { public: - ScopedDevToolsHandle(SharedWorkerHost* owner, - bool* out_pause_on_start, - base::UnguessableToken* out_devtools_worker_token) - : owner_(owner) { + explicit ScopedDevToolsHandle(SharedWorkerHost* owner) : owner_(owner) { SharedWorkerDevToolsManager::GetInstance()->WorkerCreated( - owner, out_pause_on_start, out_devtools_worker_token); + owner, &pause_on_start_, &dev_tools_token_); } ~ScopedDevToolsHandle() { @@ -65,8 +62,22 @@ class SharedWorkerHost::ScopedDevToolsHandle { owner_, std::move(agent_remote), std::move(agent_host_receiver)); } + bool pause_on_start() const { return pause_on_start_; } + + const base::UnguessableToken& dev_tools_token() const { + return dev_tools_token_; + } + private: SharedWorkerHost* owner_; + + // Indicates if the worker should be paused when it is started. This is set + // when a dev tools agent host already exists for that shared worker, which + // happens when a shared worker is restarted while it is being debugged. + bool pause_on_start_; + + base::UnguessableToken dev_tools_token_; + DISALLOW_COPY_AND_ASSIGN(ScopedDevToolsHandle); }; @@ -99,7 +110,8 @@ SharedWorkerHost::SharedWorkerHost(SharedWorkerServiceImpl* service, scoped_process_host_ref_( std::make_unique<ScopedProcessHostRef>(worker_process_host)), scoped_process_host_observer_(this), - next_connection_request_id_(1) { + next_connection_request_id_(1), + devtools_handle_(std::make_unique<ScopedDevToolsHandle>(this)) { DCHECK(worker_process_host_); DCHECK(worker_process_host_->IsInitializedAndNotDead()); @@ -109,6 +121,9 @@ SharedWorkerHost::SharedWorkerHost(SharedWorkerServiceImpl* service, worker_receiver_ = worker_.BindNewPipeAndPassReceiver(); scoped_process_host_observer_.Add(worker_process_host_); + + service_->NotifyWorkerCreated(id_, worker_process_host_->GetID(), + devtools_handle_->dev_tools_token()); } SharedWorkerHost::~SharedWorkerHost() { @@ -116,18 +131,17 @@ SharedWorkerHost::~SharedWorkerHost() { // Attempt to notify the worker before disconnecting. if (worker_) worker_->Terminate(); - - // Notify the service that each client still connected will be removed and - // that the worker will terminate. - for (const auto& client : clients_) { - service_->NotifyClientRemoved(id_, client.render_frame_host_id); - } - service_->NotifyWorkerTerminating(id_); } else { // Tell clients that this worker failed to start. for (const ClientInfo& info : clients_) info.client->OnScriptLoadFailed(/*error_message=*/""); } + + // Notify the service that each client still connected will be removed and + // that the worker will terminate. + for (const auto& client : clients_) + service_->NotifyClientRemoved(id_, client.render_frame_host_id); + service_->NotifyBeforeWorkerDestroyed(id_); } void SharedWorkerHost::Start( @@ -139,7 +153,8 @@ void SharedWorkerHost::Start( base::WeakPtr<ServiceWorkerObjectHost> controller_service_worker_object_host, blink::mojom::FetchClientSettingsObjectPtr - outside_fetch_client_settings_object) { + outside_fetch_client_settings_object, + const GURL& final_response_url) { DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK(!started_); DCHECK(main_script_load_params); @@ -147,6 +162,7 @@ void SharedWorkerHost::Start( DCHECK(!subresource_loader_factories->pending_default_factory()); started_ = true; + final_response_url_ = final_response_url; auto options = blink::mojom::WorkerOptions::New( instance_.script_type(), instance_.credentials_mode(), instance_.name()); @@ -156,11 +172,6 @@ void SharedWorkerHost::Start( instance_.creation_address_space(), std::move(outside_fetch_client_settings_object))); - // Register with DevTools. - bool pause_on_start; - devtools_handle_ = std::make_unique<ScopedDevToolsHandle>( - this, &pause_on_start, &dev_tools_token_); - auto renderer_preferences = blink::mojom::RendererPreferences::New(); GetContentClient()->browser()->UpdateRendererPreferencesForWorker( worker_process_host_->GetBrowserContext(), renderer_preferences.get()); @@ -210,10 +221,10 @@ void SharedWorkerHost::Start( factory_->CreateSharedWorker( std::move(info), instance_.constructor_origin(), GetContentClient()->browser()->GetUserAgent(), - GetContentClient()->browser()->GetUserAgentMetadata(), pause_on_start, - dev_tools_token_, std::move(renderer_preferences), - std::move(preference_watcher_receiver), std::move(content_settings), - service_worker_handle_->TakeProviderInfo(), + GetContentClient()->browser()->GetUserAgentMetadata(), + devtools_handle_->pause_on_start(), devtools_handle_->dev_tools_token(), + std::move(renderer_preferences), std::move(preference_watcher_receiver), + std::move(content_settings), service_worker_handle_->TakeContainerInfo(), appcache_handle_ ? base::make_optional(appcache_handle_->appcache_host_id()) : base::nullopt, @@ -239,14 +250,6 @@ void SharedWorkerHost::Start( // Monitor the lifetime of the worker. worker_.set_disconnect_handler(base::BindOnce( &SharedWorkerHost::OnWorkerConnectionLost, weak_factory_.GetWeakPtr())); - - // Notify the service that the worker was started and that some clients were - // already connected. - service_->NotifyWorkerStarted(id_, worker_process_host_->GetID(), - dev_tools_token_); - for (const auto& client : clients_) { - service_->NotifyClientAdded(id_, client.render_frame_host_id); - } } // This is similar to @@ -401,10 +404,8 @@ void SharedWorkerHost::OnReadyForInspection( mojo::PendingRemote<blink::mojom::DevToolsAgent> agent_remote, mojo::PendingReceiver<blink::mojom::DevToolsAgentHost> agent_host_receiver) { - if (devtools_handle_) { - devtools_handle_->WorkerReadyForInspection(std::move(agent_remote), - std::move(agent_host_receiver)); - } + devtools_handle_->WorkerReadyForInspection(std::move(agent_remote), + std::move(agent_host_receiver)); } void SharedWorkerHost::OnScriptLoadFailed(const std::string& error_message) { @@ -466,11 +467,8 @@ void SharedWorkerHost::AddClient( worker_->Connect(info.connection_request_id, port.ReleaseHandle()); - // Notify that a new client was added now. If the worker is not started, the - // Start() function will handle sending a notification for each existing - // client. - if (started_) - service_->NotifyClientAdded(id_, client_render_frame_host_id); + // Notify that a new client was added now. + service_->NotifyClientAdded(id_, client_render_frame_host_id); } void SharedWorkerHost::SetAppCacheHandle( @@ -488,17 +486,26 @@ void SharedWorkerHost::SetServiceWorkerHandle( void SharedWorkerHost::PruneNonExistentClients() { DCHECK(!started_); - // It isn't necessary to send a notification to the removed clients since they - // are about to be destroyed anyway. - clients_.remove_if([](const ClientInfo& client_info) { - return !RenderFrameHostImpl::FromID(client_info.render_frame_host_id); - }); + auto it = clients_.begin(); + auto end = clients_.end(); + while (it != end) { + if (!RenderFrameHostImpl::FromID(it->render_frame_host_id)) { + service_->NotifyClientRemoved(id_, it->render_frame_host_id); + it = clients_.erase(it); + } else { + ++it; + } + } } bool SharedWorkerHost::HasClients() const { return !clients_.empty(); } +const base::UnguessableToken& SharedWorkerHost::GetDevToolsToken() const { + return devtools_handle_->dev_tools_token(); +} + mojo::Remote<blink::mojom::SharedWorker> SharedWorkerHost::TerminateRemoteWorkerForTesting() { mojo::Remote<blink::mojom::SharedWorker> worker = std::move(worker_); @@ -516,11 +523,8 @@ void SharedWorkerHost::OnClientConnectionLost() { // We'll get a notification for each dropped connection. for (auto it = clients_.begin(); it != clients_.end(); ++it) { if (!it->client.is_connected()) { - // Notify the service that a client was removed while the worker was - // running. - if (started_) { - service_->NotifyClientRemoved(id_, it->render_frame_host_id); - } + // Notify the service that the client is gone. + service_->NotifyClientRemoved(id_, it->render_frame_host_id); clients_.erase(it); break; } diff --git a/chromium/content/browser/worker_host/shared_worker_host.h b/chromium/content/browser/worker_host/shared_worker_host.h index c39e2dec358..0d38378558c 100644 --- a/chromium/content/browser/worker_host/shared_worker_host.h +++ b/chromium/content/browser/worker_host/shared_worker_host.h @@ -95,7 +95,8 @@ class CONTENT_EXPORT SharedWorkerHost : public blink::mojom::SharedWorkerHost, base::WeakPtr<ServiceWorkerObjectHost> controller_service_worker_object_host, blink::mojom::FetchClientSettingsObjectPtr - outside_fetch_client_settings_object); + outside_fetch_client_settings_object, + const GURL& final_response_url); void AllowFileSystem(const GURL& url, base::OnceCallback<void(bool)> callback); @@ -131,16 +132,15 @@ class CONTENT_EXPORT SharedWorkerHost : public blink::mojom::SharedWorkerHost, // Returns true if this worker is connected to at least one client. bool HasClients() const; + bool started() const { return started_; } + + const GURL& final_response_url() const { return final_response_url_; } + SharedWorkerId id() const { return id_; } const SharedWorkerInstance& instance() const { return instance_; } - const base::UnguessableToken& dev_tools_token() const { - DCHECK(started_); - return dev_tools_token_; - } - - bool started() const { return started_; } + const base::UnguessableToken& GetDevToolsToken() const; // Signals the remote worker to terminate and returns the mojo::Remote // instance so the caller can be notified when the connection is lost. Should @@ -223,6 +223,7 @@ class CONTENT_EXPORT SharedWorkerHost : public blink::mojom::SharedWorkerHost, scoped_process_host_observer_; int next_connection_request_id_; + std::unique_ptr<ScopedDevToolsHandle> devtools_handle_; // This is the set of features that this worker has used. @@ -247,11 +248,11 @@ class CONTENT_EXPORT SharedWorkerHost : public blink::mojom::SharedWorkerHost, std::unique_ptr<ServiceWorkerMainResourceHandle> service_worker_handle_; - base::UnguessableToken dev_tools_token_; - // Indicates if Start() was invoked on this instance. bool started_ = false; + GURL final_response_url_; + base::WeakPtrFactory<SharedWorkerHost> weak_factory_{this}; DISALLOW_COPY_AND_ASSIGN(SharedWorkerHost); diff --git a/chromium/content/browser/worker_host/shared_worker_host_unittest.cc b/chromium/content/browser/worker_host/shared_worker_host_unittest.cc index ed7d5a06377..fc1723f7da5 100644 --- a/chromium/content/browser/worker_host/shared_worker_host_unittest.cc +++ b/chromium/content/browser/worker_host/shared_worker_host_unittest.cc @@ -102,19 +102,17 @@ class SharedWorkerHostTest : public testing::Test { client_remote; mojo::PendingAssociatedReceiver<blink::mojom::ServiceWorkerContainerHost> host_receiver; - auto provider_info = - blink::mojom::ServiceWorkerProviderInfoForClient::New(); - provider_info->client_receiver = + auto container_info = + blink::mojom::ServiceWorkerContainerInfoForClient::New(); + container_info->client_receiver = client_remote.InitWithNewEndpointAndPassReceiver(); host_receiver = - provider_info->host_remote.InitWithNewEndpointAndPassReceiver(); + container_info->host_remote.InitWithNewEndpointAndPassReceiver(); helper_->context()->CreateContainerHostForWorker( std::move(host_receiver), mock_render_process_host_.GetID(), - std::move(client_remote), - blink::mojom::ServiceWorkerClientType::kSharedWorker, - DedicatedWorkerId(), host->id()); - service_worker_handle->OnCreatedProviderHost(std::move(provider_info)); + std::move(client_remote), ServiceWorkerClientInfo(host->id())); + service_worker_handle->OnCreatedContainerHost(std::move(container_info)); host->SetServiceWorkerHandle(std::move(service_worker_handle)); host->Start(std::move(factory), std::move(main_script_load_params), @@ -124,7 +122,8 @@ class SharedWorkerHostTest : public testing::Test { blink::mojom::FetchClientSettingsObject::New( network::mojom::ReferrerPolicy::kDefault, GURL() /* outgoing_referrer */, - blink::mojom::InsecureRequestsPolicy::kDoNotUpgrade)); + blink::mojom::InsecureRequestsPolicy::kDoNotUpgrade), + GURL() /* final_response_url */); } MessagePortChannel AddClient( diff --git a/chromium/content/browser/worker_host/shared_worker_service_impl.cc b/chromium/content/browser/worker_host/shared_worker_service_impl.cc index 2aaae6f415a..fca0343ce04 100644 --- a/chromium/content/browser/worker_host/shared_worker_service_impl.cc +++ b/chromium/content/browser/worker_host/shared_worker_service_impl.cc @@ -76,9 +76,11 @@ void SharedWorkerServiceImpl::RemoveObserver(Observer* observer) { void SharedWorkerServiceImpl::EnumerateSharedWorkers(Observer* observer) { for (const auto& host : worker_hosts_) { + observer->OnWorkerCreated(host->id(), host->GetProcessHost()->GetID(), + host->GetDevToolsToken()); if (host->started()) { - observer->OnWorkerStarted(host->id(), host->GetProcessHost()->GetID(), - host->dev_tools_token()); + observer->OnFinalResponseURLDetermined(host->id(), + host->final_response_url()); } } } @@ -134,8 +136,7 @@ void SharedWorkerServiceImpl::ConnectToWorker( return; } - RenderFrameHost* main_frame = - render_frame_host->frame_tree_node()->frame_tree()->GetMainFrame(); + RenderFrameHost* main_frame = render_frame_host->frame_tree()->GetMainFrame(); if (!GetContentClient()->browser()->AllowSharedWorker( info->url, render_frame_host->ComputeSiteForCookies().RepresentativeUrl(), @@ -185,12 +186,9 @@ void SharedWorkerServiceImpl::ConnectToWorker( ScriptLoadFailed(std::move(client), /*error_message=*/""); return; } - std::string storage_domain; - std::string partition_name; - bool in_memory; - GetContentClient()->browser()->GetStoragePartitionConfigForSite( - storage_partition_->browser_context(), site_instance->GetSiteURL(), - /*can_be_default=*/true, &storage_domain, &partition_name, &in_memory); + auto storage_partition_config = + GetContentClient()->browser()->GetStoragePartitionConfigForSite( + storage_partition_->browser_context(), site_instance->GetSiteURL()); SharedWorkerInstance instance( info->url, info->options->type, info->options->credentials, @@ -199,7 +197,8 @@ void SharedWorkerServiceImpl::ConnectToWorker( creation_context_type); host = CreateWorker(shared_worker_id_generator_.GenerateNextId(), instance, std::move(info->outside_fetch_client_settings_object), - client_render_frame_host_id, storage_domain, message_port, + client_render_frame_host_id, + storage_partition_config.partition_domain(), message_port, std::move(blob_url_loader_factory)); host->AddClient(std::move(client), client_render_frame_host_id, message_port); } @@ -211,20 +210,20 @@ void SharedWorkerServiceImpl::DestroyHost(SharedWorkerHost* host) { worker_hosts_.erase(worker_hosts_.find(host)); } -void SharedWorkerServiceImpl::NotifyWorkerStarted( +void SharedWorkerServiceImpl::NotifyWorkerCreated( SharedWorkerId shared_worker_id, int worker_process_id, const base::UnguessableToken& dev_tools_token) { for (Observer& observer : observers_) { - observer.OnWorkerStarted(shared_worker_id, worker_process_id, + observer.OnWorkerCreated(shared_worker_id, worker_process_id, dev_tools_token); } } -void SharedWorkerServiceImpl::NotifyWorkerTerminating( +void SharedWorkerServiceImpl::NotifyBeforeWorkerDestroyed( SharedWorkerId shared_worker_id) { for (Observer& observer : observers_) - observer.OnBeforeWorkerTerminated(shared_worker_id); + observer.OnBeforeWorkerDestroyed(shared_worker_id); } void SharedWorkerServiceImpl::NotifyClientAdded( @@ -402,7 +401,8 @@ void SharedWorkerServiceImpl::StartWorker( host->Start(std::move(factory), std::move(main_script_load_params), std::move(subresource_loader_factories), std::move(controller), std::move(controller_service_worker_object_host), - std::move(outside_fetch_client_settings_object)); + std::move(outside_fetch_client_settings_object), + final_response_url); for (Observer& observer : observers_) observer.OnFinalResponseURLDetermined(host->id(), final_response_url); } diff --git a/chromium/content/browser/worker_host/shared_worker_service_impl.h b/chromium/content/browser/worker_host/shared_worker_service_impl.h index b263dcc827e..a0f823c7e01 100644 --- a/chromium/content/browser/worker_host/shared_worker_service_impl.h +++ b/chromium/content/browser/worker_host/shared_worker_service_impl.h @@ -71,10 +71,10 @@ class CONTENT_EXPORT SharedWorkerServiceImpl : public SharedWorkerService { // Virtual for testing. virtual void DestroyHost(SharedWorkerHost* host); - void NotifyWorkerStarted(SharedWorkerId shared_worker_id, + void NotifyWorkerCreated(SharedWorkerId shared_worker_id, int worker_process_id, const base::UnguessableToken& dev_tools_token); - void NotifyWorkerTerminating(SharedWorkerId shared_worker_id); + void NotifyBeforeWorkerDestroyed(SharedWorkerId shared_worker_id); void NotifyClientAdded(SharedWorkerId shared_worker_id, GlobalFrameRoutingId render_frame_host_id); void NotifyClientRemoved(SharedWorkerId shared_worker_id, diff --git a/chromium/content/browser/worker_host/shared_worker_service_impl_unittest.cc b/chromium/content/browser/worker_host/shared_worker_service_impl_unittest.cc index 219b88b2ba9..56681102fe4 100644 --- a/chromium/content/browser/worker_host/shared_worker_service_impl_unittest.cc +++ b/chromium/content/browser/worker_host/shared_worker_service_impl_unittest.cc @@ -1272,45 +1272,48 @@ class TestSharedWorkerServiceObserver : public SharedWorkerService::Observer { ~TestSharedWorkerServiceObserver() override = default; // SharedWorkerService::Observer: - void OnWorkerStarted(SharedWorkerId shared_worker_id, + void OnWorkerCreated(SharedWorkerId shared_worker_id, int worker_process_id, const base::UnguessableToken& dev_tools_token) override { - EXPECT_TRUE(running_workers_.insert({shared_worker_id, {}}).second); + EXPECT_TRUE(shared_workers_.insert({shared_worker_id, {}}).second); } - void OnBeforeWorkerTerminated(SharedWorkerId shared_worker_id) override { - EXPECT_EQ(1u, running_workers_.erase(shared_worker_id)); + void OnBeforeWorkerDestroyed(SharedWorkerId shared_worker_id) override { + auto it = shared_workers_.find(shared_worker_id); + EXPECT_TRUE(it != shared_workers_.end()); + EXPECT_EQ(0u, it->second.size()); + shared_workers_.erase(it); } void OnFinalResponseURLDetermined(SharedWorkerId shared_worker_id, const GURL& url) override {} void OnClientAdded( SharedWorkerId shared_worker_id, GlobalFrameRoutingId client_render_frame_host_id) override { - auto it = running_workers_.find(shared_worker_id); - EXPECT_TRUE(it != running_workers_.end()); + auto it = shared_workers_.find(shared_worker_id); + EXPECT_TRUE(it != shared_workers_.end()); std::set<GlobalFrameRoutingId>& clients = it->second; EXPECT_TRUE(clients.insert(client_render_frame_host_id).second); } void OnClientRemoved( SharedWorkerId shared_worker_id, GlobalFrameRoutingId client_render_frame_host_id) override { - auto it = running_workers_.find(shared_worker_id); - EXPECT_TRUE(it != running_workers_.end()); + auto it = shared_workers_.find(shared_worker_id); + EXPECT_TRUE(it != shared_workers_.end()); std::set<GlobalFrameRoutingId>& clients = it->second; EXPECT_EQ(1u, clients.erase(client_render_frame_host_id)); } - size_t GetWorkerCount() { return running_workers_.size(); } + size_t GetWorkerCount() { return shared_workers_.size(); } size_t GetClientCount() { size_t client_count = 0; - for (const auto& worker : running_workers_) + for (const auto& worker : shared_workers_) client_count += worker.second.size(); return client_count; } private: base::flat_map<SharedWorkerId, std::set<GlobalFrameRoutingId>> - running_workers_; + shared_workers_; DISALLOW_COPY_AND_ASSIGN(TestSharedWorkerServiceObserver); }; @@ -1515,4 +1518,62 @@ TEST_F(SharedWorkerServiceImplTest, CollapseDuplicateNotifications) { EXPECT_TRUE(worker.CheckReceivedTerminate()); } +// This test ensures that OnClientRemoved is still invoked if the connection +// with the client was lost. +TEST_F(SharedWorkerServiceImplTest, Observer_OnClientConnectionLost) { + TestSharedWorkerServiceObserver observer; + + ScopedObserver<SharedWorkerService, SharedWorkerService::Observer> + scoped_observer(&observer); + scoped_observer.Add(content::BrowserContext::GetDefaultStoragePartition( + browser_context_.get()) + ->GetSharedWorkerService()); + + std::unique_ptr<TestWebContents> web_contents = + CreateWebContents(GURL("http://example.com/")); + TestRenderFrameHost* render_frame_host = web_contents->GetMainFrame(); + MockRenderProcessHost* renderer_host = render_frame_host->GetProcess(); + const int process_id = renderer_host->GetID(); + renderer_host->OverrideBinderForTesting( + blink::mojom::SharedWorkerFactory::Name_, + base::BindRepeating(&SharedWorkerServiceImplTest::BindSharedWorkerFactory, + base::Unretained(this), process_id)); + + MockSharedWorkerClient client; + MessagePortChannel local_port; + const GURL kUrl("http://example.com/w.js"); + ConnectToSharedWorker( + MakeSharedWorkerConnector(render_frame_host->GetGlobalFrameRoutingId()), + kUrl, "name", &client, &local_port); + + mojo::PendingReceiver<blink::mojom::SharedWorkerFactory> factory_receiver = + WaitForFactoryReceiver(process_id); + MockSharedWorkerFactory factory(std::move(factory_receiver)); + base::RunLoop().RunUntilIdle(); + + mojo::Remote<blink::mojom::SharedWorkerHost> worker_host; + mojo::PendingReceiver<blink::mojom::SharedWorker> worker_receiver; + EXPECT_TRUE(factory.CheckReceivedCreateSharedWorker( + kUrl, "name", network::mojom::ContentSecurityPolicyType::kReport, + &worker_host, &worker_receiver)); + MockSharedWorker worker(std::move(worker_receiver)); + base::RunLoop().RunUntilIdle(); + + int connection_request_id; + MessagePortChannel port; + EXPECT_TRUE(worker.CheckReceivedConnect(&connection_request_id, &port)); + + EXPECT_TRUE(client.CheckReceivedOnCreated()); + + EXPECT_EQ(1u, observer.GetWorkerCount()); + EXPECT_EQ(1u, observer.GetClientCount()); + + // Simulate losing the client's connection. + client.ResetReceiver(); + base::RunLoop().RunUntilIdle(); + + EXPECT_EQ(0u, observer.GetWorkerCount()); + EXPECT_EQ(0u, observer.GetClientCount()); +} + } // namespace content diff --git a/chromium/content/browser/worker_host/worker_browsertest.cc b/chromium/content/browser/worker_host/worker_browsertest.cc index 45ca330b100..584769097ab 100644 --- a/chromium/content/browser/worker_host/worker_browsertest.cc +++ b/chromium/content/browser/worker_host/worker_browsertest.cc @@ -10,7 +10,6 @@ #include "base/strings/utf_string_conversions.h" #include "base/synchronization/lock.h" #include "base/system/sys_info.h" -#include "base/task/post_task.h" #include "base/test/bind_test_util.h" #include "base/test/scoped_feature_list.h" #include "base/test/test_timeouts.h" @@ -39,6 +38,7 @@ #include "net/base/escape.h" #include "net/base/filename_util.h" #include "net/cookies/canonical_cookie.h" +#include "net/cookies/cookie_inclusion_status.h" #include "net/dns/mock_host_resolver.h" #include "net/ssl/ssl_server_config.h" #include "net/test/embedded_test_server/embedded_test_server.h" @@ -136,7 +136,7 @@ class WorkerTest : public ContentBrowserTest, static void QuitUIMessageLoop(base::OnceClosure callback, bool is_main_frame /* unused */) { - base::PostTask(FROM_HERE, {BrowserThread::UI}, std::move(callback)); + GetUIThreadTaskRunner({})->PostTask(FROM_HERE, std::move(callback)); } void NavigateAndWaitForAuth(const GURL& url) { @@ -168,7 +168,7 @@ class WorkerTest : public ContentBrowserTest, cookie_manager->SetCanonicalCookie( *cookie, cookie_url, options, base::BindLambdaForTesting( - [&](net::CanonicalCookie::CookieInclusionStatus set_cookie_result) { + [&](net::CookieInclusionStatus set_cookie_result) { EXPECT_TRUE(set_cookie_result.IsInclude()); run_loop.Quit(); })); diff --git a/chromium/content/browser/worker_host/worker_script_fetch_initiator.cc b/chromium/content/browser/worker_host/worker_script_fetch_initiator.cc index 09ae3d82c04..06fb42d08f9 100644 --- a/chromium/content/browser/worker_host/worker_script_fetch_initiator.cc +++ b/chromium/content/browser/worker_host/worker_script_fetch_initiator.cc @@ -19,7 +19,6 @@ #include "content/browser/file_system/file_system_url_loader_factory.h" #include "content/browser/loader/browser_initiated_resource_request.h" #include "content/browser/loader/file_url_loader_factory.h" -#include "content/browser/loader/url_loader_throttles.h" #include "content/browser/navigation_subresource_loader_params.h" #include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h" @@ -38,6 +37,7 @@ #include "content/public/browser/render_frame_host.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/shared_cors_origin_access_list.h" +#include "content/public/browser/url_loader_throttles.h" #include "content/public/common/content_client.h" #include "content/public/common/content_features.h" #include "content/public/common/referrer.h" diff --git a/chromium/content/browser/worker_host/worker_script_fetcher.cc b/chromium/content/browser/worker_host/worker_script_fetcher.cc index 9a369dbdc12..1370acfcd73 100644 --- a/chromium/content/browser/worker_host/worker_script_fetcher.cc +++ b/chromium/content/browser/worker_host/worker_script_fetcher.cc @@ -90,15 +90,11 @@ void WorkerScriptFetcher::Start( // workers (https://crbug.com/906991). int32_t routing_id = MSG_ROUTING_NONE; - // Get a unique request id across browser-initiated navigations and navigation - // preloads. - int request_id = GlobalRequestID::MakeBrowserInitiated().request_id; - url_loader_ = blink::ThrottlingURLLoader::CreateLoaderAndStart( std::move(shared_url_loader_factory), std::move(throttles), routing_id, - request_id, network::mojom::kURLLoadOptionNone, resource_request_.get(), - this, kWorkerScriptLoadTrafficAnnotation, - base::ThreadTaskRunnerHandle::Get()); + GlobalRequestID::MakeBrowserInitiated().request_id, + network::mojom::kURLLoadOptionNone, resource_request_.get(), this, + kWorkerScriptLoadTrafficAnnotation, base::ThreadTaskRunnerHandle::Get()); } void WorkerScriptFetcher::OnReceiveResponse( diff --git a/chromium/content/browser/worker_host/worker_script_loader.cc b/chromium/content/browser/worker_host/worker_script_loader.cc index f07152c1314..ff57e776e42 100644 --- a/chromium/content/browser/worker_host/worker_script_loader.cc +++ b/chromium/content/browser/worker_host/worker_script_loader.cc @@ -10,7 +10,7 @@ #include "content/browser/loader/navigation_loader_interceptor.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h" #include "content/browser/service_worker/service_worker_main_resource_handle_core.h" -#include "content/browser/service_worker/service_worker_navigation_loader_interceptor.h" +#include "content/browser/service_worker/service_worker_main_resource_loader_interceptor.h" #include "content/browser/worker_host/worker_script_fetch_initiator.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -50,7 +50,7 @@ WorkerScriptLoader::WorkerScriptLoader( return; } auto service_worker_interceptor = - ServiceWorkerNavigationLoaderInterceptor::CreateForWorker( + ServiceWorkerMainResourceLoaderInterceptor::CreateForWorker( resource_request_, process_id, dedicated_worker_id, shared_worker_id, service_worker_handle_); diff --git a/chromium/content/browser/worker_host/worker_script_loader_factory.cc b/chromium/content/browser/worker_host/worker_script_loader_factory.cc index fe4fe754fe6..386d6772c2c 100644 --- a/chromium/content/browser/worker_host/worker_script_loader_factory.cc +++ b/chromium/content/browser/worker_host/worker_script_loader_factory.cc @@ -7,9 +7,9 @@ #include <memory> #include "base/feature_list.h" +#include "content/browser/service_worker/service_worker_host.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h" #include "content/browser/service_worker/service_worker_main_resource_handle_core.h" -#include "content/browser/service_worker/service_worker_provider_host.h" #include "content/browser/service_worker/service_worker_version.h" #include "content/browser/worker_host/worker_script_fetch_initiator.h" #include "content/browser/worker_host/worker_script_loader.h" diff --git a/chromium/content/browser/worker_host/worker_script_loader_factory_unittest.cc b/chromium/content/browser/worker_host/worker_script_loader_factory_unittest.cc index be1b1620e88..c3a3d34ad6c 100644 --- a/chromium/content/browser/worker_host/worker_script_loader_factory_unittest.cc +++ b/chromium/content/browser/worker_host/worker_script_loader_factory_unittest.cc @@ -93,7 +93,7 @@ class WorkerScriptLoaderFactoryTest : public testing::Test { WorkerScriptLoaderFactory::BrowserContextGetter browser_context_getter_; }; -TEST_F(WorkerScriptLoaderFactoryTest, ServiceWorkerProviderHost) { +TEST_F(WorkerScriptLoaderFactoryTest, ServiceWorkerContainerHost) { // Make the factory. auto factory = std::make_unique<WorkerScriptLoaderFactory>( kProcessId, DedicatedWorkerId(), SharedWorkerId(), |