chromium/third_party/blink/renderer/core/script/script_loader.cc

/*
 * Copyright (C) 1999 Lars Knoll ([email protected])
 *           (C) 1999 Antti Koivisto ([email protected])
 *           (C) 2001 Dirk Mueller ([email protected])
 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights
 * reserved.
 * Copyright (C) 2008 Nikolas Zimmermann <[email protected]>
 *
 * 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.
 */

#include "third_party/blink/renderer/core/script/script_loader.h"

#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.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/renderer/bindings/core/v8/sanitize_script_errors.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/dom/scriptable_document_parser.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/frame/attribution_src_loader.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.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/html/html_document.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/inspector/console_message.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/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/render_blocking_resource_manager.h"
#include "third_party/blink/renderer/core/loader/subresource_integrity_helper.h"
#include "third_party/blink/renderer/core/loader/url_matcher.h"
#include "third_party/blink/renderer/core/loader/web_bundle/script_web_bundle.h"
#include "third_party/blink/renderer/core/script/classic_pending_script.h"
#include "third_party/blink/renderer/core/script/classic_script.h"
#include "third_party/blink/renderer/core/script/import_map.h"
#include "third_party/blink/renderer/core/script/js_module_script.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/script/module_pending_script.h"
#include "third_party/blink/renderer/core/script/pending_import_map.h"
#include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/script/script_element_base.h"
#include "third_party/blink/renderer/core/script/script_runner.h"
#include "third_party/blink/renderer/core/script_type_names.h"
#include "third_party/blink/renderer/core/speculation_rules/document_speculation_rules.h"
#include "third_party/blink/renderer/core/speculation_rules/speculation_rule_set.h"
#include "third_party/blink/renderer/core/speculation_rules/speculation_rules_metrics.h"
#include "third_party/blink/renderer/core/svg_names.h"
#include "third_party/blink/renderer/core/trustedtypes/trusted_types_util.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string.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_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/subresource_integrity.h"
#include "third_party/blink/renderer/platform/network/mime/mime_type_registry.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/task_attribution_tracker.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/weborigin/security_policy.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/text/string_hash.h"
#include "third_party/blink/renderer/platform/wtf/text/string_view.h"

namespace blink {

namespace {

scheduler::TaskAttributionInfo* GetRunningTask(ScriptState* script_state) {}

}  // namespace

ScriptLoader::ScriptLoader(ScriptElementBase* element,
                           const CreateElementFlags flags)
    :{}

ScriptLoader::~ScriptLoader() {}

void ScriptLoader::Trace(Visitor* visitor) const {}

// <specdef
// href="https://html.spec.whatwg.org/C/#script-processing-model">
//
// <spec>When a script element el that is not parser-inserted experiences one of
// the events listed in the following list, the user agent must immediately
// prepare the script element el:</spec>
//
// The following three `PrepareScript()` are for non-parser-inserted scripts and
// thus
// - Should deny ParserBlockingInline scripts.
// - Should return nullptr, i.e. there should no PendingScript to be controlled
//   by parsers.
// - TextPosition is not given.

// <spec step="A">The script element becomes connected.</spec>
void ScriptLoader::DidNotifySubtreeInsertionsToDocument() {}

// <spec step="B">The script element is connected and a node or document
// fragment is inserted into the script element, after any script elements
// inserted at that time.</spec>
void ScriptLoader::ChildrenChanged(
    const ContainerNode::ChildrenChange& change) {}

// <spec step="C">The script element is connected and has a src attribute set
// where previously the element had no such attribute.</spec>
void ScriptLoader::HandleSourceAttribute(const String& source_url) {}

void ScriptLoader::HandleAsyncAttribute() {}

void ScriptLoader::Removed() {}

void ScriptLoader::DocumentBaseURLChanged() {}

namespace {

// <specdef href="https://html.spec.whatwg.org/C/#prepare-the-script-element">
bool IsValidClassicScriptTypeAndLanguage(const String& type,
                                         const String& language) {}

bool IsSameSite(const KURL& url, const Document& element_document) {}

bool IsDocumentReloadedOrFormSubmitted(const Document& element_document) {}

// Common eligibility conditions for the interventions below.
bool IsEligibleCommon(const Document& element_document) {}

// [Intervention, ForceInOrderScript, crbug.com/1344772]
bool IsEligibleForForceInOrder(const Document& element_document) {}

// [Intervention, DelayAsyncScriptExecution, crbug.com/1340837]
bool IsEligibleForDelay(const Resource& resource,
                        const Document& element_document,
                        const ScriptElementBase& element) {}

// [Intervention, LowPriorityScriptLoading, crbug.com/1365763]
bool IsEligibleForLowPriorityScriptLoading(const Document& element_document,
                                           const ScriptElementBase& element,
                                           const KURL& url) {}

// [Intervention, SelectiveInOrderScript, crbug.com/1356396]
bool IsEligibleForSelectiveInOrder(const Resource& resource,
                                   const Document& element_document) {}

ScriptRunner::DelayReasons DetermineDelayReasonsToWait(
    ScriptRunner* script_runner,
    bool is_eligible_for_delay) {}

}  // namespace

ScriptLoader::ScriptTypeAtPrepare ScriptLoader::GetScriptTypeAtPrepare(
    const String& type,
    const String& language) {}

bool ScriptLoader::BlockForNoModule(ScriptTypeAtPrepare script_type,
                                    bool nomodule) {}

// Corresponds to
// https://html.spec.whatwg.org/C/#module-script-credentials-mode
// which is a translation of the CORS settings attribute in the context of
// module scripts. This is used in:
//   - Step 17 of
//     https://html.spec.whatwg.org/C/#prepare-the-script-element
//   - Step 6 of obtaining a preloaded module script
//     https://html.spec.whatwg.org/C/#link-type-modulepreload.
network::mojom::CredentialsMode ScriptLoader::ModuleScriptCredentialsMode(
    CrossOriginAttributeValue cross_origin) {}

// <specdef href="https://html.spec.whatwg.org/C/#prepare-the-script-element">
PendingScript* ScriptLoader::PrepareScript(
    ParserBlockingInlineOption parser_blocking_inline_option,
    const TextPosition& script_start_position) {}

ScriptSchedulingType ScriptLoader::GetScriptSchedulingTypePerSpec(
    Document& element_document,
    ParserBlockingInlineOption parser_blocking_inline_option) const {}

void ScriptLoader::FetchModuleScriptTree(
    const KURL& url,
    ResourceFetcher* fetch_client_settings_object_fetcher,
    Modulator* modulator,
    const ScriptFetchOptions& options) {}

PendingScript* ScriptLoader::TakePendingScript(
    ScriptSchedulingType scheduling_type) {}

void ScriptLoader::NotifyFinished() {}

// <specdef href="https://html.spec.whatwg.org/C/#prepare-the-script-element">
bool ScriptLoader::IsScriptForEventSupported() const {}

String ScriptLoader::GetScriptText() const {}

void ScriptLoader::AddSpeculationRuleSet(SpeculationRuleSet::Source* source) {}

SpeculationRuleSet* ScriptLoader::RemoveSpeculationRuleSet() {}

}  // namespace blink