Fetching.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. DeprecatedString module_type_from_module_request(JS::ModuleRequest const&);
  36. WebIDL::ExceptionOr<AK::URL> resolve_module_specifier(Optional<Script&> referring_script, DeprecatedString const& specifier);
  37. WebIDL::ExceptionOr<Optional<AK::URL>> resolve_imports_match(DeprecatedString const& normalized_specifier, Optional<AK::URL> as_url, ModuleSpecifierMap const&);
  38. Optional<AK::URL> resolve_url_like_module_specifier(DeprecatedString const& specifier, AK::URL const& base_url);
  39. 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);
  40. 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);
  41. void fetch_external_module_script_graph(JS::Realm&, AK::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete);
  42. void fetch_inline_module_script_graph(JS::Realm& realm, DeprecatedString const& filename, DeprecatedString const& source_text, AK::URL const& base_url, EnvironmentSettingsObject& settings_object, OnFetchScriptComplete on_complete);
  43. 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);
  44. void fetch_descendants_of_and_link_a_module_script(JS::Realm&, JavaScriptModuleScript& module_script, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination, HashTable<ModuleLocationTuple> const& visited_set, OnFetchScriptComplete on_complete);
  45. enum class TopLevelModule {
  46. Yes,
  47. No
  48. };
  49. 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);
  50. }