DocumentLoading.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibWeb/DOM/Document.h>
  9. #include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
  10. namespace Web {
  11. bool build_xml_document(DOM::Document& document, ByteBuffer const& data, Optional<String> content_encoding);
  12. JS::GCPtr<DOM::Document> load_document(HTML::NavigationParams const& navigation_params);
  13. bool can_load_document_with_type(MimeSniff::MimeType const&);
  14. // https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-ua-inline
  15. template<typename MutateDocument>
  16. JS::NonnullGCPtr<DOM::Document> create_document_for_inline_content(JS::GCPtr<HTML::Navigable> navigable, Optional<String> navigation_id, MutateDocument mutate_document)
  17. {
  18. auto& vm = navigable->vm();
  19. // 1. Let origin be a new opaque origin.
  20. URL::Origin origin {};
  21. // 2. Let coop be a new opener policy.
  22. auto coop = HTML::OpenerPolicy {};
  23. // 3. Let coopEnforcementResult be a new opener policy enforcement result with
  24. // url: response's URL
  25. // origin: origin
  26. // opener policy: coop
  27. HTML::OpenerPolicyEnforcementResult coop_enforcement_result {
  28. .url = URL::URL("about:error"), // AD-HOC
  29. .origin = origin,
  30. .opener_policy = coop
  31. };
  32. // 4. Let navigationParams be a new navigation params with
  33. // id: navigationId
  34. // navigable: navigable
  35. // request: null
  36. // response: a new response
  37. // origin: origin
  38. // fetch controller: null
  39. // commit early hints: null
  40. // COOP enforcement result: coopEnforcementResult
  41. // reserved environment: null
  42. // policy container: a new policy container
  43. // final sandboxing flag set: an empty set
  44. // opener policy: coop
  45. // FIXME: navigation timing type: navTimingType
  46. // about base URL: null
  47. auto response = Fetch::Infrastructure::Response::create(vm);
  48. response->url_list().append(URL::URL("about:error")); // AD-HOC: https://github.com/whatwg/html/issues/9122
  49. auto navigation_params = vm.heap().allocate_without_realm<HTML::NavigationParams>();
  50. navigation_params->id = navigation_id;
  51. navigation_params->navigable = navigable;
  52. navigation_params->request = nullptr;
  53. navigation_params->response = response;
  54. navigation_params->fetch_controller = nullptr;
  55. navigation_params->commit_early_hints = nullptr;
  56. navigation_params->coop_enforcement_result = move(coop_enforcement_result);
  57. navigation_params->reserved_environment = {};
  58. navigation_params->origin = move(origin);
  59. navigation_params->policy_container = HTML::PolicyContainer {};
  60. navigation_params->final_sandboxing_flag_set = HTML::SandboxingFlagSet {};
  61. navigation_params->opener_policy = move(coop);
  62. navigation_params->about_base_url = {};
  63. // 5. Let document be the result of creating and initializing a Document object given "html", "text/html", and navigationParams.
  64. auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params).release_value_but_fixme_should_propagate_errors();
  65. // 6. Either associate document with a custom rendering that is not rendered using the normal Document rendering rules, or mutate document until it represents the content the
  66. // user agent wants to render.
  67. mutate_document(*document);
  68. // 7. Return document.
  69. return document;
  70. }
  71. }