Fetching.h 6.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2022-2023, networkException <networkexception@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
  8. #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
  9. #include <LibWeb/HTML/CORSSettingAttribute.h>
  10. #include <LibWeb/HTML/Scripting/ImportMap.h>
  11. #include <LibWeb/HTML/Scripting/ModuleMap.h>
  12. #include <LibWeb/HTML/Scripting/ModuleScript.h>
  13. #include <LibWeb/ReferrerPolicy/ReferrerPolicy.h>
  14. namespace Web::HTML {
  15. enum class IsTopLevel {
  16. No,
  17. Yes,
  18. };
  19. using OnFetchScriptComplete = JS::NonnullGCPtr<JS::HeapFunction<void(JS::GCPtr<Script>)>>;
  20. using PerformTheFetchHook = JS::GCPtr<JS::HeapFunction<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, IsTopLevel, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)>>;
  21. OnFetchScriptComplete create_on_fetch_script_complete(JS::Heap& heap, Function<void(JS::GCPtr<Script>)> function);
  22. PerformTheFetchHook create_perform_the_fetch_hook(JS::Heap& heap, Function<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, IsTopLevel, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function);
  23. // https://html.spec.whatwg.org/multipage/webappapis.html#script-fetch-options
  24. struct ScriptFetchOptions {
  25. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-nonce
  26. String cryptographic_nonce {};
  27. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-integrity
  28. String integrity_metadata {};
  29. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-parser
  30. Fetch::Infrastructure::Request::ParserMetadata parser_metadata { Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted };
  31. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-credentials
  32. Fetch::Infrastructure::Request::CredentialsMode credentials_mode { Fetch::Infrastructure::Request::CredentialsMode::SameOrigin };
  33. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-referrer-policy
  34. Optional<ReferrerPolicy::ReferrerPolicy> referrer_policy;
  35. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-render-blocking
  36. bool render_blocking { false };
  37. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-fetch-priority
  38. Fetch::Infrastructure::Request::Priority fetch_priority {};
  39. };
  40. // https://html.spec.whatwg.org/multipage/webappapis.html#default-classic-script-fetch-options
  41. ScriptFetchOptions default_classic_script_fetch_options();
  42. struct FetchContext : JS::GraphLoadingState::HostDefined {
  43. FetchContext(JS::GCPtr<JS::Value> parse_error, Fetch::Infrastructure::Request::Destination destination, JS::GCPtr<JS::Promise> perform_fetch, EnvironmentSettingsObject& fetch_client)
  44. : parse_error(parse_error)
  45. , destination(destination)
  46. , perform_fetch(perform_fetch)
  47. , fetch_client(fetch_client)
  48. {
  49. }
  50. JS::GCPtr<JS::Value> parse_error; // [[ParseError]]
  51. Fetch::Infrastructure::Request::Destination destination; // [[Destination]]
  52. JS::GCPtr<JS::Promise> perform_fetch; // [[PerformFetch]]
  53. EnvironmentSettingsObject& fetch_client; // [[FetchClient]]
  54. };
  55. DeprecatedString module_type_from_module_request(JS::ModuleRequest const&);
  56. WebIDL::ExceptionOr<AK::URL> resolve_module_specifier(Optional<Script&> referring_script, DeprecatedString const& specifier);
  57. WebIDL::ExceptionOr<Optional<AK::URL>> resolve_imports_match(DeprecatedString const& normalized_specifier, Optional<AK::URL> as_url, ModuleSpecifierMap const&);
  58. Optional<AK::URL> resolve_url_like_module_specifier(DeprecatedString const& specifier, AK::URL const& base_url);
  59. WebIDL::ExceptionOr<void> fetch_classic_script(JS::NonnullGCPtr<HTMLScriptElement>, AK::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, String character_encoding, OnFetchScriptComplete on_complete);
  60. WebIDL::ExceptionOr<void> fetch_classic_worker_script(AK::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);
  61. 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, OnFetchScriptComplete on_complete);
  62. void fetch_external_module_script_graph(JS::Realm&, AK::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete);
  63. void fetch_inline_module_script_graph(JS::Realm&, DeprecatedString const& filename, DeprecatedString const& source_text, AK::URL const& base_url, EnvironmentSettingsObject& settings_object, OnFetchScriptComplete on_complete);
  64. void fetch_single_imported_module_script(JS::Realm&, AK::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject& settings_object, Fetch::Infrastructure::Request::Referrer, JS::ModuleRequest const&, OnFetchScriptComplete on_complete);
  65. 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, OnFetchScriptComplete callback);
  66. void fetch_descendants_of_and_link_a_module_script(JS::Realm&, JavaScriptModuleScript&, EnvironmentSettingsObject&, Fetch::Infrastructure::Request::Destination, OnFetchScriptComplete on_complete);
  67. enum class TopLevelModule {
  68. Yes,
  69. No
  70. };
  71. void fetch_single_module_script(JS::Realm&, AK::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, OnFetchScriptComplete callback);
  72. }