#include "third_party/blink/renderer/platform/loader/fetch/url_loader/dedicated_or_shared_worker_fetch_context_impl.h"
#include <utility>
#include "base/functional/bind.h"
#include "base/ranges/algorithm.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/loader/loader_constants.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_fetch_handler_bypass_option.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_provider.mojom.h"
#include "third_party/blink/public/platform/child_url_loader_factory_bundle.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_provider_context.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/resource_load_info_notifier_wrapper.h"
#include "third_party/blink/public/platform/url_loader_throttle_provider.h"
#include "third_party/blink/public/platform/weak_wrapper_resource_load_info_notifier.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/public/platform/web_url_request_extra_data.h"
#include "third_party/blink/public/platform/websocket_handshake_throttle_provider.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/url_loader.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/url_loader_factory.h"
#include "url/url_constants.h"
namespace blink {
DedicatedOrSharedWorkerFetchContextImpl::RewriteURLFunction g_rewrite_url = …;
namespace {
void CreateServiceWorkerSubresourceLoaderFactory(
CrossVariantMojoRemote<mojom::ServiceWorkerContainerHostInterfaceBase>
service_worker_container_host,
const WebString& client_id,
std::unique_ptr<network::PendingSharedURLLoaderFactory> fallback_factory,
mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver,
scoped_refptr<base::SequencedTaskRunner> task_runner) { … }
}
class DedicatedOrSharedWorkerFetchContextImpl::Factory
: public URLLoaderFactory { … };
DedicatedOrSharedWorkerFetchContextImpl::
DedicatedOrSharedWorkerFetchContextImpl(
const RendererPreferences& renderer_preferences,
mojo::PendingReceiver<mojom::blink::RendererPreferenceWatcher>
preference_watcher_receiver,
mojo::PendingReceiver<mojom::blink::ServiceWorkerWorkerClient>
service_worker_client_receiver,
mojo::PendingRemote<mojom::blink::ServiceWorkerWorkerClientRegistry>
pending_service_worker_worker_client_registry,
CrossVariantMojoRemote<mojom::ServiceWorkerContainerHostInterfaceBase>
service_worker_container_host,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_loader_factory,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_fallback_factory,
mojo::PendingReceiver<mojom::blink::SubresourceLoaderUpdater>
pending_subresource_loader_updater,
std::unique_ptr<URLLoaderThrottleProvider> throttle_provider,
std::unique_ptr<WebSocketHandshakeThrottleProvider>
websocket_handshake_throttle_provider,
Vector<String> cors_exempt_header_list,
mojo::PendingRemote<mojom::ResourceLoadInfoNotifier>
pending_resource_load_info_notifier)
: … { … }
scoped_refptr<WebDedicatedOrSharedWorkerFetchContext>
DedicatedOrSharedWorkerFetchContextImpl::CloneForNestedWorkerDeprecated(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
scoped_refptr<WebDedicatedOrSharedWorkerFetchContext>
DedicatedOrSharedWorkerFetchContextImpl::CloneForNestedWorker(
WebServiceWorkerProviderContext* service_worker_provider_context,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_loader_factory,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_fallback_factory,
CrossVariantMojoReceiver<mojom::SubresourceLoaderUpdaterInterfaceBase>
pending_subresource_loader_updater,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
void DedicatedOrSharedWorkerFetchContextImpl::SetAncestorFrameToken(
const LocalFrameToken& token) { … }
void DedicatedOrSharedWorkerFetchContextImpl::set_site_for_cookies(
const net::SiteForCookies& site_for_cookies) { … }
void DedicatedOrSharedWorkerFetchContextImpl::set_top_frame_origin(
const WebSecurityOrigin& top_frame_origin) { … }
void DedicatedOrSharedWorkerFetchContextImpl::SetTerminateSyncLoadEvent(
base::WaitableEvent* terminate_sync_load_event) { … }
void DedicatedOrSharedWorkerFetchContextImpl::InitializeOnWorkerThread(
AcceptLanguagesWatcher* watcher) { … }
URLLoaderFactory*
DedicatedOrSharedWorkerFetchContextImpl::GetURLLoaderFactory() { … }
std::unique_ptr<URLLoaderFactory>
DedicatedOrSharedWorkerFetchContextImpl::WrapURLLoaderFactory(
CrossVariantMojoRemote<network::mojom::URLLoaderFactoryInterfaceBase>
url_loader_factory) { … }
std::optional<WebURL> DedicatedOrSharedWorkerFetchContextImpl::WillSendRequest(
const WebURL& url) { … }
void DedicatedOrSharedWorkerFetchContextImpl::FinalizeRequest(
WebURLRequest& request) { … }
WebVector<std::unique_ptr<URLLoaderThrottle>>
DedicatedOrSharedWorkerFetchContextImpl::CreateThrottles(
const network::ResourceRequest& request) { … }
mojom::ControllerServiceWorkerMode
DedicatedOrSharedWorkerFetchContextImpl::GetControllerServiceWorkerMode()
const { … }
void DedicatedOrSharedWorkerFetchContextImpl::SetIsOnSubframe(
bool is_on_sub_frame) { … }
bool DedicatedOrSharedWorkerFetchContextImpl::IsOnSubframe() const { … }
net::SiteForCookies DedicatedOrSharedWorkerFetchContextImpl::SiteForCookies()
const { … }
std::optional<WebSecurityOrigin>
DedicatedOrSharedWorkerFetchContextImpl::TopFrameOrigin() const { … }
void DedicatedOrSharedWorkerFetchContextImpl::SetSubresourceFilterBuilder(
std::unique_ptr<WebDocumentSubresourceFilter::Builder>
subresource_filter_builder) { … }
std::unique_ptr<WebDocumentSubresourceFilter>
DedicatedOrSharedWorkerFetchContextImpl::TakeSubresourceFilter() { … }
std::unique_ptr<WebSocketHandshakeThrottle>
DedicatedOrSharedWorkerFetchContextImpl::CreateWebSocketHandshakeThrottle(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
void DedicatedOrSharedWorkerFetchContextImpl::SetIsOfflineMode(
bool is_offline_mode) { … }
void DedicatedOrSharedWorkerFetchContextImpl::OnControllerChanged(
mojom::ControllerServiceWorkerMode mode) { … }
void DedicatedOrSharedWorkerFetchContextImpl::
set_controller_service_worker_mode(
mojom::ControllerServiceWorkerMode mode) { … }
void DedicatedOrSharedWorkerFetchContextImpl::set_client_id(
const WebString& client_id) { … }
WebString DedicatedOrSharedWorkerFetchContextImpl::GetAcceptLanguages() const { … }
std::unique_ptr<ResourceLoadInfoNotifierWrapper>
DedicatedOrSharedWorkerFetchContextImpl::
CreateResourceLoadInfoNotifierWrapper() { … }
DedicatedOrSharedWorkerFetchContextImpl::
~DedicatedOrSharedWorkerFetchContextImpl() = default;
scoped_refptr<DedicatedOrSharedWorkerFetchContextImpl>
DedicatedOrSharedWorkerFetchContextImpl::CloneForNestedWorkerInternal(
mojo::PendingReceiver<mojom::blink::ServiceWorkerWorkerClient>
service_worker_client_receiver,
mojo::PendingRemote<mojom::blink::ServiceWorkerWorkerClientRegistry>
service_worker_worker_client_registry,
CrossVariantMojoRemote<mojom::ServiceWorkerContainerHostInterfaceBase>
service_worker_container_host,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_loader_factory,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_fallback_factory,
mojo::PendingReceiver<mojom::blink::SubresourceLoaderUpdater>
pending_subresource_loader_updater,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
void DedicatedOrSharedWorkerFetchContextImpl::
ResetServiceWorkerURLLoaderFactory() { … }
void DedicatedOrSharedWorkerFetchContextImpl::UpdateSubresourceLoaderFactories(
std::unique_ptr<PendingURLLoaderFactoryBundle>
subresource_loader_factories) { … }
void DedicatedOrSharedWorkerFetchContextImpl::NotifyUpdate(
const RendererPreferences& new_prefs) { … }
void DedicatedOrSharedWorkerFetchContextImpl::
ResetWeakWrapperResourceLoadInfoNotifier() { … }
scoped_refptr<WebDedicatedOrSharedWorkerFetchContext>
WebDedicatedOrSharedWorkerFetchContext::Create(
WebServiceWorkerProviderContext* provider_context,
const RendererPreferences& renderer_preferences,
CrossVariantMojoReceiver<mojom::RendererPreferenceWatcherInterfaceBase>
watcher_receiver,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_loader_factory,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_fallback_factory,
CrossVariantMojoReceiver<mojom::SubresourceLoaderUpdaterInterfaceBase>
pending_subresource_loader_updater,
const WebVector<WebString>& web_cors_exempt_header_list,
mojo::PendingRemote<mojom::ResourceLoadInfoNotifier>
pending_resource_load_info_notifier) { … }
void WebDedicatedOrSharedWorkerFetchContext::InstallRewriteURLFunction(
RewriteURLFunction rewrite_url) { … }
}