DocumentLoading.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.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. namespace Web {
  10. bool build_xml_document(DOM::Document& document, ByteBuffer const& data, Optional<String> content_encoding);
  11. JS::GCPtr<DOM::Document> load_document(HTML::NavigationParams const& navigation_params);
  12. bool can_load_document_with_type(MimeSniff::MimeType const&);
  13. // https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-ua-inline
  14. template<typename MutateDocument>
  15. JS::NonnullGCPtr<DOM::Document> create_document_for_inline_content(JS::GCPtr<HTML::Navigable> navigable, Optional<String> navigation_id, MutateDocument mutate_document)
  16. {
  17. auto& vm = navigable->vm();
  18. // 1. Let origin be a new opaque origin.
  19. HTML::Origin origin {};
  20. // 2. Let coop be a new cross-origin opener policy.
  21. auto coop = HTML::CrossOriginOpenerPolicy {};
  22. // 3. Let coopEnforcementResult be a new cross-origin opener policy enforcement result with
  23. // url: response's URL
  24. // origin: origin
  25. // cross-origin opener policy: coop
  26. HTML::CrossOriginOpenerPolicyEnforcementResult coop_enforcement_result {
  27. .url = URL::URL("about:error"), // AD-HOC
  28. .origin = origin,
  29. .cross_origin_opener_policy = coop
  30. };
  31. // 4. Let navigationParams be a new navigation params with
  32. // id: navigationId
  33. // navigable: navigable
  34. // request: null
  35. // response: a new response
  36. // origin: origin
  37. // fetch controller: null
  38. // commit early hints: null
  39. // COOP enforcement result: coopEnforcementResult
  40. // reserved environment: null
  41. // policy container: a new policy container
  42. // final sandboxing flag set: an empty set
  43. // cross-origin opener policy: coop
  44. // FIXME: navigation timing type: navTimingType
  45. // about base URL: null
  46. auto response = Fetch::Infrastructure::Response::create(vm);
  47. response->url_list().append(URL::URL("about:error")); // AD-HOC: https://github.com/whatwg/html/issues/9122
  48. HTML::NavigationParams navigation_params {
  49. .id = navigation_id,
  50. .navigable = navigable,
  51. .request = {},
  52. .response = *response,
  53. .fetch_controller = nullptr,
  54. .commit_early_hints = nullptr,
  55. .coop_enforcement_result = move(coop_enforcement_result),
  56. .reserved_environment = {},
  57. .origin = move(origin),
  58. .policy_container = HTML::PolicyContainer {},
  59. .final_sandboxing_flag_set = HTML::SandboxingFlagSet {},
  60. .cross_origin_opener_policy = move(coop),
  61. .about_base_url = {},
  62. };
  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. }