#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/loader/fetch/resource.h"
#include <stdint.h>
#include <algorithm>
#include <cassert>
#include <memory>
#include <utility>
#include "base/task/single_thread_task_runner.h"
#include "base/time/default_clock.h"
#include "build/build_config.h"
#include "services/network/public/mojom/fetch_api.mojom-blink.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-shared.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/instrumentation/histogram.h"
#include "third_party/blink/renderer/platform/instrumentation/instance_counters.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/loader/cors/cors.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/integrity_metadata.h"
#include "third_party/blink/renderer/platform/loader/fetch/memory_cache.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_client.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_client_walker.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_finish_observer.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_load_timing.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/background_response_processor.h"
#include "third_party/blink/renderer/platform/network/http_parsers.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
namespace {
void NotifyFinishObservers(
HeapHashSet<WeakMember<ResourceFinishObserver>>* observers) { … }
void GetSharedBufferMemoryDump(SharedBuffer* buffer,
const String& dump_prefix,
WebProcessMemoryDump* memory_dump) { … }
}
const char* const kHeadersToIgnoreAfterRevalidation[] = …;
const char* const kHeaderPrefixesToIgnoreAfterRevalidation[] = …;
static inline bool ShouldUpdateHeaderAfterRevalidation(
const AtomicString& header) { … }
namespace {
const base::Clock* g_clock_for_testing = …;
}
static inline base::Time Now() { … }
Resource::Resource(const ResourceRequestHead& request,
ResourceType type,
const ResourceLoaderOptions& options)
: … { … }
Resource::~Resource() { … }
void Resource::Trace(Visitor* visitor) const { … }
void Resource::SetLoader(ResourceLoader* loader) { … }
void Resource::CheckResourceIntegrity() { … }
void Resource::NotifyFinished() { … }
void Resource::MarkClientFinished(ResourceClient* client) { … }
void Resource::AppendData(
absl::variant<SegmentedBuffer, base::span<const char>> data) { … }
void Resource::AppendDataImpl(SegmentedBuffer&& buffer) { … }
void Resource::AppendDataImpl(base::span<const char> data) { … }
void Resource::NotifyDataReceived(base::span<const char> data) { … }
void Resource::SetResourceBuffer(scoped_refptr<SharedBuffer> resource_buffer) { … }
void Resource::ClearData() { … }
void Resource::TriggerNotificationForFinishObservers(
base::SingleThreadTaskRunner* task_runner) { … }
void Resource::SetDataBufferingPolicy(
DataBufferingPolicy data_buffering_policy) { … }
static bool NeedsSynchronousCacheHit(ResourceType type,
const ResourceLoaderOptions& options) { … }
void Resource::FinishAsError(const ResourceError& error,
base::SingleThreadTaskRunner* task_runner) { … }
void Resource::Finish(base::TimeTicks load_response_end,
base::SingleThreadTaskRunner* task_runner) { … }
AtomicString Resource::HttpContentType() const { … }
bool Resource::MustRefetchDueToIntegrityMetadata(
const FetchParameters& params) const { … }
const scoped_refptr<const SecurityOrigin>& Resource::GetOrigin() const { … }
void Resource::DidDownloadToBlob(scoped_refptr<BlobDataHandle>) { … }
static base::TimeDelta CurrentAge(const ResourceResponse& response,
base::Time response_timestamp) { … }
static base::TimeDelta FreshnessLifetime(const ResourceResponse& response,
base::Time response_timestamp) { … }
base::TimeDelta Resource::FreshnessLifetime() const { … }
static bool CanUseResponse(const ResourceResponse& response,
bool allow_stale,
base::Time response_timestamp) { … }
const ResourceRequestHead& Resource::LastResourceRequest() const { … }
const ResourceResponse& Resource::LastResourceResponse() const { … }
size_t Resource::RedirectChainSize() const { … }
void Resource::SetRevalidatingRequest(const ResourceRequestHead& request) { … }
bool Resource::WillFollowRedirect(const ResourceRequest& new_request,
const ResourceResponse& redirect_response) { … }
void Resource::SetResponse(const ResourceResponse& response) { … }
void Resource::ResponseReceived(const ResourceResponse& response) { … }
void Resource::SetSerializedCachedMetadata(mojo_base::BigBuffer data) { … }
String Resource::ReasonNotDeletable() const { … }
void Resource::DidAddClient(ResourceClient* client) { … }
void Resource::WillAddClientOrObserver() { … }
void Resource::AddClient(ResourceClient* client,
base::SingleThreadTaskRunner* task_runner) { … }
void Resource::RemoveClient(ResourceClient* client) { … }
void Resource::AddFinishObserver(ResourceFinishObserver* client,
base::SingleThreadTaskRunner* task_runner) { … }
void Resource::RemoveFinishObserver(ResourceFinishObserver* client) { … }
void Resource::DidRemoveClientOrObserver() { … }
void Resource::AllClientsAndObserversRemoved() { … }
void Resource::SetDecodedSize(size_t decoded_size) { … }
void Resource::SetEncodedSize(size_t encoded_size) { … }
void Resource::FinishPendingClients() { … }
Resource::MatchStatus Resource::CanReuse(const FetchParameters& params) const { … }
void Resource::Prune() { … }
void Resource::OnPurgeMemory() { … }
void Resource::OnMemoryDump(WebMemoryDumpLevelOfDetail level_of_detail,
WebProcessMemoryDump* memory_dump) const { … }
String Resource::GetMemoryDumpName() const { … }
void Resource::SetCachePolicyBypassingCache() { … }
void Resource::ClearRangeRequestHeader() { … }
void Resource::RevalidationSucceeded(
const ResourceResponse& validating_response) { … }
void Resource::RevalidationFailed() { … }
void Resource::MarkAsPreload() { … }
void Resource::MatchPreload(const FetchParameters& params) { … }
bool Resource::CanReuseRedirectChain() const { … }
bool Resource::HasCacheControlNoStoreHeader() const { … }
bool Resource::MustReloadDueToVaryHeader(
const ResourceRequest& new_request) const { … }
bool Resource::MustRevalidateDueToCacheHeaders(bool allow_stale) const { … }
static bool ShouldRevalidateStaleResponse(const ResourceResponse& response,
base::Time response_timestamp) { … }
bool Resource::ShouldRevalidateStaleResponse() const { … }
bool Resource::StaleRevalidationRequested() const { … }
bool Resource::NetworkAccessed() const { … }
bool Resource::CanUseCacheValidator() const { … }
size_t Resource::CalculateOverheadSize() const { … }
void Resource::DidChangePriority(ResourceLoadPriority load_priority,
int intra_priority_value) { … }
void Resource::UpdateResourceWidth(const AtomicString& resource_width) { … }
static const char* InitiatorTypeNameToString(
const AtomicString& initiator_type_name) { … }
const char* Resource::ResourceTypeToString(
ResourceType type,
const AtomicString& fetch_initiator_name) { … }
bool Resource::IsLoadEventBlockingResourceType() const { … }
void Resource::SetClockForTesting(const base::Clock* clock) { … }
bool Resource::AppendTopFrameSiteForMetrics(const SecurityOrigin& origin) { … }
void Resource::SetIsAdResource() { … }
void Resource::UpdateMemoryCacheLastAccessedTime() { … }
std::unique_ptr<BackgroundResponseProcessorFactory>
Resource::MaybeCreateBackgroundResponseProcessorFactory() { … }
}