Jelajahi Sumber

LibWeb: Add helper to create default classic script fetch options

networkException 1 tahun lalu
induk
melakukan
dd90ed11b3

+ 15 - 0
Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp

@@ -32,6 +32,21 @@ OnFetchScriptComplete create_on_fetch_script_complete(JS::Heap& heap, Function<v
     return JS::create_heap_function(heap, move(function));
 }
 
+ScriptFetchOptions default_classic_script_fetch_options()
+{
+    // The default classic script fetch options are a script fetch options whose cryptographic nonce is the empty string,
+    // integrity metadata is the empty string, parser metadata is "not-parser-inserted", credentials mode is "same-origin",
+    // referrer policy is the empty string, and fetch priority is "auto".
+    return ScriptFetchOptions {
+        .cryptographic_nonce = {},
+        .integrity_metadata = {},
+        .parser_metadata = Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted,
+        .credentials_mode = Fetch::Infrastructure::Request::CredentialsMode::SameOrigin,
+        .referrer_policy = {},
+        .fetch_priority = Fetch::Infrastructure::Request::Priority::Auto
+    };
+}
+
 // https://html.spec.whatwg.org/multipage/webappapis.html#module-type-from-module-request
 DeprecatedString module_type_from_module_request(JS::ModuleRequest const& module_request)
 {

+ 3 - 0
Userland/Libraries/LibWeb/HTML/Scripting/Fetching.h

@@ -43,6 +43,9 @@ struct ScriptFetchOptions {
     Fetch::Infrastructure::Request::Priority fetch_priority {};
 };
 
+// https://html.spec.whatwg.org/multipage/webappapis.html#default-classic-script-fetch-options
+ScriptFetchOptions default_classic_script_fetch_options();
+
 DeprecatedString module_type_from_module_request(JS::ModuleRequest const&);
 WebIDL::ExceptionOr<AK::URL> resolve_module_specifier(Optional<Script&> referring_script, DeprecatedString const& specifier);
 WebIDL::ExceptionOr<Optional<AK::URL>> resolve_imports_match(DeprecatedString const& normalized_specifier, Optional<AK::URL> as_url, ModuleSpecifierMap const&);