#include "third_party/blink/renderer/modules/service_worker/web_service_worker_fetch_context_impl.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/single_thread_task_runner.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/cookies/site_for_cookies.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "third_party/blink/public/common/loader/loader_constants.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/platform/url_loader_throttle_provider.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_factory.h"
#include "third_party/blink/renderer/platform/loader/internet_disconnected_url_loader.h"
namespace blink {
scoped_refptr<WebServiceWorkerFetchContext>
WebServiceWorkerFetchContext::Create(
const RendererPreferences& renderer_preferences,
const WebURL& worker_script_url,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_script_loader_factory,
const WebURL& script_url_to_skip_throttling,
std::unique_ptr<URLLoaderThrottleProvider> throttle_provider,
std::unique_ptr<WebSocketHandshakeThrottleProvider>
websocket_handshake_throttle_provider,
CrossVariantMojoReceiver<
mojom::blink::RendererPreferenceWatcherInterfaceBase>
preference_watcher_receiver,
CrossVariantMojoReceiver<
mojom::blink::SubresourceLoaderUpdaterInterfaceBase>
pending_subresource_loader_updater,
const WebVector<WebString>& web_cors_exempt_header_list,
const bool is_third_party_context) { … }
WebServiceWorkerFetchContextImpl::WebServiceWorkerFetchContextImpl(
const RendererPreferences& renderer_preferences,
const KURL& worker_script_url,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_script_loader_factory,
const KURL& script_url_to_skip_throttling,
std::unique_ptr<URLLoaderThrottleProvider> throttle_provider,
std::unique_ptr<WebSocketHandshakeThrottleProvider>
websocket_handshake_throttle_provider,
mojo::PendingReceiver<mojom::blink::RendererPreferenceWatcher>
preference_watcher_receiver,
mojo::PendingReceiver<mojom::blink::SubresourceLoaderUpdater>
pending_subresource_loader_updater,
Vector<String> cors_exempt_header_list,
const bool is_third_party_context)
: … { … }
WebServiceWorkerFetchContextImpl::~WebServiceWorkerFetchContextImpl() = default;
void WebServiceWorkerFetchContextImpl::SetTerminateSyncLoadEvent(
base::WaitableEvent* terminate_sync_load_event) { … }
void WebServiceWorkerFetchContextImpl::InitializeOnWorkerThread(
AcceptLanguagesWatcher* watcher) { … }
URLLoaderFactory* WebServiceWorkerFetchContextImpl::GetURLLoaderFactory() { … }
std::unique_ptr<URLLoaderFactory>
WebServiceWorkerFetchContextImpl::WrapURLLoaderFactory(
CrossVariantMojoRemote<network::mojom::URLLoaderFactoryInterfaceBase>
url_loader_factory) { … }
URLLoaderFactory* WebServiceWorkerFetchContextImpl::GetScriptLoaderFactory() { … }
void WebServiceWorkerFetchContextImpl::FinalizeRequest(WebURLRequest& request) { … }
WebVector<std::unique_ptr<URLLoaderThrottle>>
WebServiceWorkerFetchContextImpl::CreateThrottles(
const network::ResourceRequest& request) { … }
mojom::ControllerServiceWorkerMode
WebServiceWorkerFetchContextImpl::GetControllerServiceWorkerMode() const { … }
net::SiteForCookies WebServiceWorkerFetchContextImpl::SiteForCookies() const { … }
std::optional<WebSecurityOrigin>
WebServiceWorkerFetchContextImpl::TopFrameOrigin() const { … }
std::unique_ptr<WebSocketHandshakeThrottle>
WebServiceWorkerFetchContextImpl::CreateWebSocketHandshakeThrottle(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
void WebServiceWorkerFetchContextImpl::UpdateSubresourceLoaderFactories(
std::unique_ptr<PendingURLLoaderFactoryBundle>
subresource_loader_factories) { … }
void WebServiceWorkerFetchContextImpl::NotifyUpdate(
const RendererPreferences& new_prefs) { … }
WebString WebServiceWorkerFetchContextImpl::GetAcceptLanguages() const { … }
void WebServiceWorkerFetchContextImpl::SetIsOfflineMode(bool is_offline_mode) { … }
}