Fetching.h 5.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/HTTP/Requests.h>
  8. #include <LibWeb/HTML/CORSSettingAttribute.h>
  9. #include <LibWeb/HTML/Scripting/ImportMap.h>
  10. #include <LibWeb/HTML/Scripting/ModuleMap.h>
  11. #include <LibWeb/HTML/Scripting/ModuleScript.h>
  12. #include <LibWeb/ReferrerPolicy/ReferrerPolicy.h>
  13. namespace Web::HTML {
  14. using OnFetchScriptComplete = JS::NonnullGCPtr<JS::HeapFunction<void(JS::GCPtr<Script>)>>;
  15. OnFetchScriptComplete create_on_fetch_script_complete(JS::Heap& heap, Function<void(JS::GCPtr<Script>)> function);
  16. // https://html.spec.whatwg.org/multipage/webappapis.html#script-fetch-options
  17. struct ScriptFetchOptions {
  18. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-nonce
  19. String cryptographic_nonce {};
  20. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-integrity
  21. String integrity_metadata {};
  22. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-parser
  23. Fetch::Infrastructure::Request::ParserMetadata parser_metadata { Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted };
  24. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-credentials
  25. Fetch::Infrastructure::Request::CredentialsMode credentials_mode { Fetch::Infrastructure::Request::CredentialsMode::SameOrigin };
  26. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-referrer-policy
  27. Optional<ReferrerPolicy::ReferrerPolicy> referrer_policy;
  28. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-render-blocking
  29. bool render_blocking { false };
  30. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-fetch-priority
  31. Fetch::Infrastructure::Request::Priority fetch_priority {};
  32. };
  33. // https://html.spec.whatwg.org/multipage/webappapis.html#default-classic-script-fetch-options
  34. ScriptFetchOptions default_classic_script_fetch_options();
  35. struct FetchContext : JS::GraphLoadingState::HostDefined {
  36. FetchContext(JS::GCPtr<JS::Value> parse_error, Fetch::Infrastructure::Request::Destination destination, JS::GCPtr<JS::Promise> perform_fetch, EnvironmentSettingsObject& fetch_client)
  37. : parse_error(parse_error)
  38. , destination(destination)
  39. , perform_fetch(perform_fetch)
  40. , fetch_client(fetch_client)
  41. {
  42. }
  43. JS::GCPtr<JS::Value> parse_error; // [[ParseError]]
  44. Fetch::Infrastructure::Request::Destination destination; // [[Destination]]
  45. JS::GCPtr<JS::Promise> perform_fetch; // [[PerformFetch]]
  46. EnvironmentSettingsObject& fetch_client; // [[FetchClient]]
  47. };
  48. DeprecatedString module_type_from_module_request(JS::ModuleRequest const&);
  49. WebIDL::ExceptionOr<AK::URL> resolve_module_specifier(Optional<Script&> referring_script, DeprecatedString const& specifier);
  50. WebIDL::ExceptionOr<Optional<AK::URL>> resolve_imports_match(DeprecatedString const& normalized_specifier, Optional<AK::URL> as_url, ModuleSpecifierMap const&);
  51. Optional<AK::URL> resolve_url_like_module_specifier(DeprecatedString const& specifier, AK::URL const& base_url);
  52. 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);
  53. 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);
  54. void fetch_external_module_script_graph(JS::Realm&, AK::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete);
  55. 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);
  56. 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);
  57. 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);
  58. void fetch_descendants_of_and_link_a_module_script(JS::Realm&, JavaScriptModuleScript&, EnvironmentSettingsObject&, Fetch::Infrastructure::Request::Destination, OnFetchScriptComplete on_complete);
  59. enum class TopLevelModule {
  60. Yes,
  61. No
  62. };
  63. 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);
  64. }