| 
									
										
										
										
											2022-10-03 21:04:15 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-10-29 01:46:02 +02:00
										 |  |  |  * Copyright (c) 2022-2023, networkException <networkexception@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-10-03 21:04:15 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 18:08:00 -07:00
										 |  |  | #include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-10 17:03:45 -04:00
										 |  |  | #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
 | 
					
						
							|  |  |  | #include <LibWeb/HTML/CORSSettingAttribute.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-23 04:10:01 +02:00
										 |  |  | #include <LibWeb/HTML/Scripting/ImportMap.h>
 | 
					
						
							| 
									
										
										
										
											2023-02-25 10:42:45 -07:00
										 |  |  | #include <LibWeb/HTML/Scripting/ModuleMap.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-03 21:04:15 +02:00
										 |  |  | #include <LibWeb/HTML/Scripting/ModuleScript.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-10 17:03:45 -04:00
										 |  |  | #include <LibWeb/ReferrerPolicy/ReferrerPolicy.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-03 21:04:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::HTML { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 09:48:10 -07:00
										 |  |  | enum class TopLevelModule { | 
					
						
							| 
									
										
										
										
											2023-11-09 18:08:00 -07:00
										 |  |  |     Yes, | 
					
						
							| 
									
										
										
										
											2024-03-05 09:48:10 -07:00
										 |  |  |     No | 
					
						
							| 
									
										
										
										
											2023-11-09 18:08:00 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-29 01:46:02 +02:00
										 |  |  | using OnFetchScriptComplete = JS::NonnullGCPtr<JS::HeapFunction<void(JS::GCPtr<Script>)>>; | 
					
						
							| 
									
										
										
										
											2024-03-05 09:48:10 -07:00
										 |  |  | using PerformTheFetchHook = JS::GCPtr<JS::HeapFunction<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)>>; | 
					
						
							| 
									
										
										
										
											2023-10-29 01:46:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | OnFetchScriptComplete create_on_fetch_script_complete(JS::Heap& heap, Function<void(JS::GCPtr<Script>)> function); | 
					
						
							| 
									
										
										
										
											2024-03-05 09:48:10 -07:00
										 |  |  | PerformTheFetchHook create_perform_the_fetch_hook(JS::Heap& heap, Function<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function); | 
					
						
							| 
									
										
										
										
											2022-10-03 21:04:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-10 17:03:45 -04:00
										 |  |  | // https://html.spec.whatwg.org/multipage/webappapis.html#script-fetch-options
 | 
					
						
							|  |  |  | struct ScriptFetchOptions { | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-nonce
 | 
					
						
							|  |  |  |     String cryptographic_nonce {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-integrity
 | 
					
						
							|  |  |  |     String integrity_metadata {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-parser
 | 
					
						
							| 
									
										
										
										
											2023-09-12 23:18:17 +01:00
										 |  |  |     Fetch::Infrastructure::Request::ParserMetadata parser_metadata { Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted }; | 
					
						
							| 
									
										
										
										
											2023-05-10 17:03:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-credentials
 | 
					
						
							|  |  |  |     Fetch::Infrastructure::Request::CredentialsMode credentials_mode { Fetch::Infrastructure::Request::CredentialsMode::SameOrigin }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-referrer-policy
 | 
					
						
							| 
									
										
										
										
											2024-03-05 09:35:25 -07:00
										 |  |  |     ReferrerPolicy::ReferrerPolicy referrer_policy { ReferrerPolicy::ReferrerPolicy::EmptyString }; | 
					
						
							| 
									
										
										
										
											2023-05-10 17:03:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-render-blocking
 | 
					
						
							|  |  |  |     bool render_blocking { false }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-fetch-priority
 | 
					
						
							|  |  |  |     Fetch::Infrastructure::Request::Priority fetch_priority {}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-29 02:51:32 +01:00
										 |  |  | // https://html.spec.whatwg.org/multipage/webappapis.html#default-classic-script-fetch-options
 | 
					
						
							|  |  |  | ScriptFetchOptions default_classic_script_fetch_options(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-17 12:14:18 +01:00
										 |  |  | class FetchContext : public JS::GraphLoadingState::HostDefined { | 
					
						
							|  |  |  |     JS_CELL(FetchContext, JS::GraphLoadingState::HostDefined); | 
					
						
							| 
									
										
										
										
											2024-04-06 10:16:04 -07:00
										 |  |  |     JS_DECLARE_ALLOCATOR(FetchContext); | 
					
						
							| 
									
										
										
										
											2023-11-17 12:14:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-12-11 12:23:04 +01:00
										 |  |  |     JS::Value parse_error;                                    // [[ParseError]]
 | 
					
						
							|  |  |  |     Fetch::Infrastructure::Request::Destination destination;  // [[Destination]]
 | 
					
						
							| 
									
										
										
										
											2024-03-05 09:48:10 -07:00
										 |  |  |     PerformTheFetchHook perform_fetch;                        // [[PerformFetch]]
 | 
					
						
							| 
									
										
										
										
											2023-12-11 12:23:04 +01:00
										 |  |  |     JS::NonnullGCPtr<EnvironmentSettingsObject> fetch_client; // [[FetchClient]]
 | 
					
						
							| 
									
										
										
										
											2023-11-17 12:14:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-03-05 09:48:10 -07:00
										 |  |  |     FetchContext(JS::Value parse_error, Fetch::Infrastructure::Request::Destination destination, PerformTheFetchHook perform_fetch, EnvironmentSettingsObject& fetch_client) | 
					
						
							| 
									
										
										
										
											2023-10-29 02:53:26 +01:00
										 |  |  |         : parse_error(parse_error) | 
					
						
							|  |  |  |         , destination(destination) | 
					
						
							|  |  |  |         , perform_fetch(perform_fetch) | 
					
						
							|  |  |  |         , fetch_client(fetch_client) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-17 12:14:18 +01:00
										 |  |  |     void visit_edges(Visitor& visitor) override | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         Base::visit_edges(visitor); | 
					
						
							|  |  |  |         visitor.visit(parse_error); | 
					
						
							|  |  |  |         visitor.visit(perform_fetch); | 
					
						
							|  |  |  |         visitor.visit(fetch_client); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-10-29 02:53:26 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  | ByteString module_type_from_module_request(JS::ModuleRequest const&); | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  | WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referring_script, ByteString const& specifier); | 
					
						
							|  |  |  | WebIDL::ExceptionOr<Optional<URL::URL>> resolve_imports_match(ByteString const& normalized_specifier, Optional<URL::URL> as_url, ModuleSpecifierMap const&); | 
					
						
							|  |  |  | Optional<URL::URL> resolve_url_like_module_specifier(ByteString const& specifier, URL::URL const& base_url); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | WebIDL::ExceptionOr<void> fetch_classic_script(JS::NonnullGCPtr<HTMLScriptElement>, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, String character_encoding, OnFetchScriptComplete on_complete); | 
					
						
							|  |  |  | WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete); | 
					
						
							| 
									
										
										
										
											2024-05-23 13:57:08 +01:00
										 |  |  | WebIDL::ExceptionOr<JS::NonnullGCPtr<ClassicScript>> fetch_a_classic_worker_imported_script(URL::URL const&, HTML::EnvironmentSettingsObject&, PerformTheFetchHook = nullptr); | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  | WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete); | 
					
						
							|  |  |  | WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete); | 
					
						
							| 
									
										
										
										
											2024-03-05 09:48:10 -07:00
										 |  |  | void fetch_internal_module_script_graph(JS::Realm&, JS::ModuleRequest const& module_request, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, Script& referring_script, HashTable<ModuleLocationTuple> const& visited_set, PerformTheFetchHook, OnFetchScriptComplete on_complete); | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  | void fetch_external_module_script_graph(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete); | 
					
						
							|  |  |  | void fetch_inline_module_script_graph(JS::Realm&, ByteString const& filename, ByteString const& source_text, URL::URL const& base_url, EnvironmentSettingsObject& settings_object, OnFetchScriptComplete on_complete); | 
					
						
							|  |  |  | void fetch_single_imported_module_script(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject& settings_object, Fetch::Infrastructure::Request::Referrer, JS::ModuleRequest const&, PerformTheFetchHook, OnFetchScriptComplete on_complete); | 
					
						
							| 
									
										
										
										
											2022-10-03 21:04:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 09:48:10 -07:00
										 |  |  | void fetch_descendants_of_a_module_script(JS::Realm&, JavaScriptModuleScript& module_script, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination, HashTable<ModuleLocationTuple> visited_set, PerformTheFetchHook, OnFetchScriptComplete callback); | 
					
						
							|  |  |  | void fetch_descendants_of_and_link_a_module_script(JS::Realm&, JavaScriptModuleScript&, EnvironmentSettingsObject&, Fetch::Infrastructure::Request::Destination, PerformTheFetchHook, OnFetchScriptComplete on_complete); | 
					
						
							| 
									
										
										
										
											2022-10-03 21:04:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-03 21:23:17 +01:00
										 |  |  | Fetch::Infrastructure::Request::Destination fetch_destination_from_module_type(Fetch::Infrastructure::Request::Destination, ByteString const&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  | void fetch_single_module_script(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject& settings_object, Web::Fetch::Infrastructure::Request::ReferrerType const&, Optional<JS::ModuleRequest> const&, TopLevelModule, PerformTheFetchHook, OnFetchScriptComplete callback); | 
					
						
							| 
									
										
										
										
											2022-10-03 21:04:15 +02:00
										 |  |  | } |