#include "third_party/blink/renderer/core/loader/preload_helper.h"
#include "base/metrics/histogram_functions.h"
#include "base/timer/elapsed_timer.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_prescient_networking.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_idle_request_options.h"
#include "third_party/blink/renderer/core/css/media_list.h"
#include "third_party/blink/renderer/core/css/media_query_evaluator.h"
#include "third_party/blink/renderer/core/css/parser/sizes_attribute_parser.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/frame/frame_console.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/viewport_data.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/html/blocking_attribute.h"
#include "third_party/blink/renderer/core/html/parser/html_preload_scanner.h"
#include "third_party/blink/renderer/core/html/parser/html_srcset_parser.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/loader/alternate_signed_exchange_resource_info.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/fetch_priority_attribute.h"
#include "third_party/blink/renderer/core/loader/link_load_parameters.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_fetch_request.h"
#include "third_party/blink/renderer/core/loader/pending_link_preload.h"
#include "third_party/blink/renderer/core/loader/render_blocking_resource_manager.h"
#include "third_party/blink/renderer/core/loader/resource/css_style_sheet_resource.h"
#include "third_party/blink/renderer/core/loader/resource/font_resource.h"
#include "third_party/blink/renderer/core/loader/resource/image_resource.h"
#include "third_party/blink/renderer/core/loader/resource/link_dictionary_resource.h"
#include "third_party/blink/renderer/core/loader/resource/link_prefetch_resource.h"
#include "third_party/blink/renderer/core/loader/resource/script_resource.h"
#include "third_party/blink/renderer/core/loader/subresource_integrity_helper.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/viewport_description.h"
#include "third_party/blink/renderer/core/scheduler/scripted_idle_task_controller.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/script/script_loader.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/loader/fetch/raw_resource.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h"
#include "third_party/blink/renderer/platform/loader/link_header.h"
#include "third_party/blink/renderer/platform/loader/subresource_integrity.h"
#include "third_party/blink/renderer/platform/network/mime/mime_type_registry.h"
namespace blink {
namespace {
class LoadDictionaryWhenIdleTask final : public IdleTask { … };
void SendMessageToConsoleForPossiblyNullDocument(
ConsoleMessage* console_message,
Document* document,
LocalFrame* frame) { … }
bool IsSupportedType(ResourceType resource_type, const String& mime_type) { … }
MediaValuesCached* CreateMediaValues(
Document& document,
const ViewportDescription* viewport_description) { … }
bool MediaMatches(const String& media,
MediaValues* media_values,
const ExecutionContext* execution_context) { … }
KURL GetBestFitImageURL(const Document& document,
const KURL& base_url,
MediaValues* media_values,
const KURL& href,
const String& image_srcset,
const String& image_sizes) { … }
bool IsValidButUnsupportedAsAttribute(const String& as) { … }
bool IsNetworkHintAllowed(PreloadHelper::LoadLinksFromHeaderMode mode) { … }
bool IsResourceLoadAllowed(PreloadHelper::LoadLinksFromHeaderMode mode,
bool is_viewport_dependent) { … }
bool IsCompressionDictionaryLoadAllowed(
PreloadHelper::LoadLinksFromHeaderMode mode) { … }
}
void PreloadHelper::DnsPrefetchIfNeeded(
const LinkLoadParameters& params,
Document* document,
LocalFrame* frame,
LinkCaller caller) { … }
void PreloadHelper::PreconnectIfNeeded(
const LinkLoadParameters& params,
Document* document,
LocalFrame* frame,
LinkCaller caller) { … }
std::optional<ResourceType> PreloadHelper::GetResourceTypeFromAsAttribute(
const String& as) { … }
void PreloadHelper::PreloadIfNeeded(
const LinkLoadParameters& params,
Document& document,
const KURL& base_url,
LinkCaller caller,
const ViewportDescription* viewport_description,
ParserDisposition parser_disposition,
PendingLinkPreload* pending_preload) { … }
void PreloadHelper::ModulePreloadIfNeeded(
const LinkLoadParameters& params,
Document& document,
const ViewportDescription* viewport_description,
PendingLinkPreload* client) { … }
void PreloadHelper::PrefetchIfNeeded(const LinkLoadParameters& params,
Document& document,
PendingLinkPreload* pending_preload) { … }
void PreloadHelper::LoadLinksFromHeader(
const String& header_value,
const KURL& base_url,
LocalFrame& frame,
Document* document,
LoadLinksFromHeaderMode mode,
const ViewportDescription* viewport_description,
std::unique_ptr<AlternateSignedExchangeResourceInfo>
alternate_resource_info,
const base::UnguessableToken* recursive_prefetch_token) { … }
void PreloadHelper::FetchCompressionDictionaryIfNeeded(
const LinkLoadParameters& params,
Document& document,
PendingLinkPreload* pending_preload) { … }
Resource* PreloadHelper::StartPreload(ResourceType type,
FetchParameters& params,
Document& document) { … }
}