#include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
#include <string>
#include <utility>
#include <vector>
#include "base/containers/queue.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/devtools/service_worker_devtools_agent_host.h"
#include "content/browser/devtools/service_worker_devtools_manager.h"
#include "content/browser/loader/navigation_url_loader_impl.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/navigation_request.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_metrics.h"
#include "content/browser/service_worker/service_worker_version.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/global_request_id.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.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 "net/base/request_priority.h"
#include "net/http/http_util.h"
#include "net/log/net_log.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/cpp/single_request_url_loader_factory.h"
#include "services/network/public/cpp/url_loader_factory_builder.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/early_hints.mojom.h"
#include "third_party/blink/public/common/service_worker/embedded_worker_status.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h"
namespace content {
namespace {
BASE_FEATURE(…);
bool g_force_disable_high_priority_fetch_response_callback = …;
void NotifyNavigationPreloadRequestSent(const network::ResourceRequest& request,
const std::pair<int, int>& worker_id,
const std::string& request_id) { … }
void NotifyNavigationPreloadResponseReceived(
const GURL& url,
network::mojom::URLResponseHeadPtr response,
const std::pair<int, int>& worker_id,
const std::string& request_id) { … }
void NotifyNavigationPreloadCompleted(
const network::URLLoaderCompletionStatus& status,
const std::pair<int, int>& worker_id,
const std::string& request_id) { … }
class DelegatingURLLoaderClient final : public network::mojom::URLLoaderClient { … };
EventType;
EventType RequestDestinationToEventType(
network::mojom::RequestDestination destination) { … }
const net::NetworkTrafficAnnotationTag kNavigationPreloadTrafficAnnotation = …;
void GrantFileAccessToProcess(int process_id,
const std::vector<base::FilePath>& file_paths) { … }
scoped_refptr<network::SharedURLLoaderFactory>
CreateNetworkFactoryForNavigationPreload(FrameTreeNode& frame_tree_node,
StoragePartitionImpl& partition) { … }
}
class ServiceWorkerFetchDispatcher::ResponseCallback
: public blink::mojom::ServiceWorkerFetchResponseCallback { … };
class ServiceWorkerFetchDispatcher::URLLoaderAssets
: public base::RefCounted<ServiceWorkerFetchDispatcher::URLLoaderAssets> { … };
ServiceWorkerFetchDispatcher::ServiceWorkerFetchDispatcher(
blink::mojom::FetchAPIRequestPtr request,
network::mojom::RequestDestination destination,
const std::string& client_id,
const std::string& resulting_client_id,
scoped_refptr<ServiceWorkerVersion> version,
base::OnceClosure prepare_callback,
FetchCallback fetch_callback,
bool is_offline_capability_check)
: … { … }
ServiceWorkerFetchDispatcher::~ServiceWorkerFetchDispatcher() { … }
void ServiceWorkerFetchDispatcher::Run() { … }
void ServiceWorkerFetchDispatcher::DidWaitForActivation() { … }
void ServiceWorkerFetchDispatcher::StartWorker() { … }
void ServiceWorkerFetchDispatcher::DidStartWorker(
blink::ServiceWorkerStatusCode status) { … }
void ServiceWorkerFetchDispatcher::DispatchFetchEvent() { … }
void ServiceWorkerFetchDispatcher::DidFailToDispatch(
std::unique_ptr<ResponseCallback> response_callback,
blink::ServiceWorkerStatusCode status) { … }
void ServiceWorkerFetchDispatcher::DidFail(
blink::ServiceWorkerStatusCode status) { … }
void ServiceWorkerFetchDispatcher::DidFinish(
int request_id,
FetchEventResult fetch_result,
blink::mojom::FetchAPIResponsePtr response,
blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream,
blink::mojom::ServiceWorkerFetchEventTimingPtr timing) { … }
void ServiceWorkerFetchDispatcher::RunCallback(
blink::ServiceWorkerStatusCode status,
FetchEventResult fetch_result,
blink::mojom::FetchAPIResponsePtr response,
blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream,
blink::mojom::ServiceWorkerFetchEventTimingPtr timing) { … }
const char* ServiceWorkerFetchDispatcher::FetchEventResultToSuffix(
FetchEventResult result) { … }
bool ServiceWorkerFetchDispatcher::MaybeStartNavigationPreload(
const network::ResourceRequest& original_request,
scoped_refptr<ServiceWorkerContextWrapper> context_wrapper,
int frame_tree_node_id) { … }
ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType()
const { … }
bool ServiceWorkerFetchDispatcher::IsEventDispatched() const { … }
scoped_refptr<network::SharedURLLoaderFactory>
ServiceWorkerFetchDispatcher::CreateNetworkURLLoaderFactory(
scoped_refptr<ServiceWorkerContextWrapper> context_wrapper,
int frame_tree_node_id) { … }
void ServiceWorkerFetchDispatcher::OnFetchEventFinished(
base::WeakPtr<ServiceWorkerFetchDispatcher> fetch_dispatcher,
ServiceWorkerVersion* version,
int event_finish_id,
scoped_refptr<URLLoaderAssets> url_loader_assets,
blink::mojom::ServiceWorkerEventStatus status) { … }
void ServiceWorkerFetchDispatcher::
ForceDisableHighPriorityFetchResponseCallbackForTesting(
bool force_disable) { … }
}