chromium/third_party/blink/renderer/platform/loader/fetch/resource.cc

/*
    Copyright (C) 1998 Lars Knoll ([email protected])
    Copyright (C) 2001 Dirk Mueller ([email protected])
    Copyright (C) 2002 Waldo Bastian ([email protected])
    Copyright (C) 2006 Samuel Weinig ([email protected])
    Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
    rights reserved.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#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) {}

}  // namespace

// These response headers are not copied from a revalidated response to the
// cached response headers. For compatibility, this list is based on Chromium's
// net/http/http_response_headers.cc.
const char* const kHeadersToIgnoreAfterRevalidation[] =;

// Some header prefixes mean "Don't copy this header from a 304 response.".
// Rather than listing all the relevant headers, we can consolidate them into
// this list, also grabbed from Chromium's net/http/http_response_headers.cc.
const char* const kHeaderPrefixesToIgnoreAfterRevalidation[] =;

static inline bool ShouldUpdateHeaderAfterRevalidation(
    const AtomicString& header) {}

namespace {
const base::Clock* g_clock_for_testing =;

}  // namespace

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) {}

// TODO(toyoshim): Consider to generate automatically. https://crbug.com/675515.
static const char* InitiatorTypeNameToString(
    const AtomicString& initiator_type_name) {}

const char* Resource::ResourceTypeToString(
    ResourceType type,
    const AtomicString& fetch_initiator_name) {}

bool Resource::IsLoadEventBlockingResourceType() const {}

// static
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() {}

}  // namespace blink