#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader.h"
#include <algorithm>
#include <optional>
#include <utility>
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/checked_math.h"
#include "base/rand_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/unguessable_token.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/base/load_flags.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/network/public/cpp/cross_origin_embedder_policy.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/blocked_by_response_reason.mojom-shared.h"
#include "services/network/public/mojom/fetch_api.mojom-blink.h"
#include "third_party/blink/public/common/client_hints/client_hints.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/permissions_policy/permissions_policy.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
#include "third_party/blink/public/mojom/blob/blob_registry.mojom-blink.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-blink.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-shared.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_data.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/renderer/platform/back_forward_cache_utils.h"
#include "third_party/blink/renderer/platform/exported/wrapped_resource_request.h"
#include "third_party/blink/renderer/platform/exported/wrapped_resource_response.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/traced_value.h"
#include "third_party/blink/renderer/platform/loader/cors/cors.h"
#include "third_party/blink/renderer/platform/loader/cors/cors_error_string.h"
#include "third_party/blink/renderer/platform/loader/fetch/back_forward_cache_loader_helper.h"
#include "third_party/blink/renderer/platform/loader/fetch/code_cache_host.h"
#include "third_party/blink/renderer/platform/loader/fetch/console_logger.h"
#include "third_party/blink/renderer/platform/loader/fetch/detachable_use_counter.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_utils.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_error.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher_properties.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_load_observer.h"
#include "third_party/blink/renderer/platform/loader/fetch/response_body_loader.h"
#include "third_party/blink/renderer/platform/loader/fetch/shared_buffer_bytes_consumer.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/background_response_processor.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/cached_metadata_handler.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/request_conversion.h"
#include "third_party/blink/renderer/platform/loader/mixed_content_autoupgrade_status.h"
#include "third_party/blink/renderer/platform/network/http_names.h"
#include "third_party/blink/renderer/platform/network/http_parsers.h"
#include "third_party/blink/renderer/platform/network/mime/mime_type_registry.h"
#include "third_party/blink/renderer/platform/network/network_utils.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/weborigin/reporting_disposition.h"
#include "third_party/blink/renderer/platform/weborigin/scheme_registry.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "url/url_constants.h"
namespace blink {
namespace {
enum class RequestOutcome { … };
const char* RequestOutcomeToString(RequestOutcome outcome) { … }
constexpr double kUkmSamplingRate = …;
bool IsThrottlableRequestContext(mojom::blink::RequestContextType context) { … }
void LogMixedAutoupgradeMetrics(blink::MixedContentAutoupgradeStatus status,
std::optional<int> response_or_error_code,
ukm::SourceId source_id,
ukm::UkmRecorder* recorder,
Resource* resource) { … }
bool RequestContextObserveResponse(mojom::blink::RequestContextType type) { … }
SchedulingPolicy::Feature GetFeatureFromRequestContextType(
mojom::blink::RequestContextType type) { … }
std::optional<mojom::WebFeature> PreflightResultToWebFeature(
network::mojom::PrivateNetworkAccessPreflightResult result) { … }
bool ShouldActivateCacheAwareLoading(const ResourceFetcher* fetcher,
const Resource* resource) { … }
std::unique_ptr<network::ResourceRequest> CreateNetworkRequest(
const ResourceRequestHead& request_head,
ResourceRequestBody& request_body) { … }
}
ResourceLoader::ResourceLoader(ResourceFetcher* fetcher,
ResourceLoadScheduler* scheduler,
Resource* resource,
ContextLifecycleNotifier* context,
ResourceRequestBody request_body,
uint32_t inflight_keepalive_bytes)
: … { … }
ResourceLoader::~ResourceLoader() = default;
void ResourceLoader::Trace(Visitor* visitor) const { … }
void ResourceLoader::Start() { … }
void ResourceLoader::DidStartLoadingResponseBodyInternal(
BytesConsumer& bytes_consumer) { … }
void ResourceLoader::Run() { … }
void ResourceLoader::DidReceiveDecodedData(
const String& data,
std::unique_ptr<ParkableStringImpl::SecureDigest> digest) { … }
void ResourceLoader::DidFinishLoadingBody() { … }
void ResourceLoader::DidFailLoadingBody() { … }
void ResourceLoader::DidCancelLoadingBody() { … }
void ResourceLoader::StartFetch() { … }
void ResourceLoader::Release(
ResourceLoadScheduler::ReleaseOption option,
const ResourceLoadScheduler::TrafficReportHints& hints) { … }
void ResourceLoader::Restart() { … }
void ResourceLoader::SetDefersLoading(LoaderFreezeMode mode) { … }
void ResourceLoader::DidChangePriority(ResourceLoadPriority load_priority,
int intra_priority_value) { … }
void ResourceLoader::ScheduleCancel() { … }
void ResourceLoader::CancelTimerFired(TimerBase*) { … }
void ResourceLoader::Cancel() { … }
bool ResourceLoader::IsLoading() const { … }
void ResourceLoader::CancelForRedirectAccessCheckError(
const KURL& new_url,
ResourceRequestBlockedReason blocked_reason) { … }
static bool IsManualRedirectFetchRequest(const ResourceRequestHead& request) { … }
bool ResourceLoader::WillFollowRedirect(
const WebURL& new_url,
const net::SiteForCookies& new_site_for_cookies,
const WebString& new_referrer,
network::mojom::ReferrerPolicy new_referrer_policy,
const WebString& new_method,
const WebURLResponse& passed_redirect_response,
bool& has_devtools_request_id,
std::vector<std::string>* removed_headers,
net::HttpRequestHeaders& modified_headers,
bool insecure_scheme_was_upgraded) { … }
void ResourceLoader::DidSendData(uint64_t bytes_sent,
uint64_t total_bytes_to_be_sent) { … }
FetchContext& ResourceLoader::Context() const { … }
void ResourceLoader::DidReceiveResponse(
const WebURLResponse& response,
absl::variant<mojo::ScopedDataPipeConsumerHandle, SegmentedBuffer> body,
std::optional<mojo_base::BigBuffer> cached_metadata) { … }
void ResourceLoader::DidReceiveDataForTesting(base::span<const char> data) { … }
void ResourceLoader::DidReceiveResponseInternal(
const ResourceResponse& response,
std::optional<mojo_base::BigBuffer> cached_metadata) { … }
void ResourceLoader::DidReceiveData(base::span<const char> data) { … }
void ResourceLoader::DidReceiveDataImpl(
absl::variant<SegmentedBuffer, base::span<const char>> data) { … }
void ResourceLoader::DidReceiveTransferSizeUpdate(int transfer_size_diff) { … }
void ResourceLoader::DidFinishLoadingFirstPartInMultipart() { … }
void ResourceLoader::DidFinishLoading(base::TimeTicks response_end_time,
int64_t encoded_data_length,
uint64_t encoded_body_length,
int64_t decoded_body_length) { … }
void ResourceLoader::DidFail(const WebURLError& error,
base::TimeTicks response_end_time,
int64_t encoded_data_length,
uint64_t encoded_body_length,
int64_t decoded_body_length) { … }
void ResourceLoader::CountFeature(blink::mojom::WebFeature feature) { … }
void ResourceLoader::HandleError(const ResourceError& error) { … }
void ResourceLoader::RequestSynchronously() { … }
void ResourceLoader::RequestAsynchronously() { … }
void ResourceLoader::Dispose() { … }
bool ResourceLoader::ShouldBeKeptAliveWhenDetached() const { … }
void ResourceLoader::AbortResponseBodyLoading() { … }
scoped_refptr<base::SingleThreadTaskRunner>
ResourceLoader::GetLoadingTaskRunner() { … }
void ResourceLoader::OnProgress(uint64_t delta) { … }
void ResourceLoader::FinishedCreatingBlob(
const scoped_refptr<BlobDataHandle>& blob) { … }
std::optional<ResourceRequestBlockedReason>
ResourceLoader::CheckResponseNosniff(
mojom::blink::RequestContextType request_context,
const ResourceResponse& response) { … }
void ResourceLoader::HandleDataUrl() { … }
bool ResourceLoader::ShouldBlockRequestBasedOnSubresourceFilterDnsAliasCheck(
const Vector<String>& dns_aliases,
const KURL& request_url,
const KURL& original_url,
ResourceType resource_type,
const ResourceRequestHead& initial_request,
const ResourceLoaderOptions& options,
const ResourceRequest::RedirectInfo redirect_info) { … }
void ResourceLoader::CountPrivateNetworkAccessPreflightResult(
network::mojom::PrivateNetworkAccessPreflightResult result) { … }
void ResourceLoader::CancelIfWebBundleTokenMatches(
const base::UnguessableToken& web_bundle_token) { … }
}