DocumentLoading.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 navigation_params);
  12. // https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-ua-inline
  13. template<typename MutateDocument>
  14. JS::NonnullGCPtr<DOM::Document> create_document_for_inline_content(JS::GCPtr<HTML::Navigable> navigable, Optional<String> navigation_id, MutateDocument mutate_document)
  15. {
  16. auto& vm = navigable->vm();
  17. // 1. Let origin be a new opaque origin.
  18. HTML::Origin origin {};
  19. // 2. Let coop be a new cross-origin opener policy.
  20. auto coop = HTML::CrossOriginOpenerPolicy {};
  21. // 3. Let coopEnforcementResult be a new cross-origin opener policy enforcement result with
  22. // url: response's URL
  23. // origin: origin
  24. // cross-origin opener policy: coop
  25. HTML::CrossOriginOpenerPolicyEnforcementResult coop_enforcement_result {
  26. .url = URL("about:error"), // AD-HOC
  27. .origin = origin,
  28. .cross_origin_opener_policy = coop
  29. };
  30. // 4. Let navigationParams be a new navigation params with
  31. // id: navigationId
  32. // navigable: navigable
  33. // request: null
  34. // response: a new response
  35. // origin: origin
  36. // fetch controller: null
  37. // commit early hints: null
  38. // COOP enforcement result: coopEnforcementResult
  39. // reserved environment: null
  40. // policy container: a new policy container
  41. // final sandboxing flag set: an empty set
  42. // cross-origin opener policy: coop
  43. // FIXME: navigation timing type: navTimingType
  44. // about base URL: null
  45. auto response = Fetch::Infrastructure::Response::create(vm);
  46. response->url_list().append(URL("about:error")); // AD-HOC: https://github.com/whatwg/html/issues/9122
  47. HTML::NavigationParams navigation_params {
  48. .id = navigation_id,
  49. .navigable = navigable,
  50. .request = {},
  51. .response = *response,
  52. .fetch_controller = nullptr,
  53. .commit_early_hints = nullptr,
  54. .coop_enforcement_result = move(coop_enforcement_result),
  55. .reserved_environment = {},
  56. .origin = move(origin),
  57. .policy_container = HTML::PolicyContainer {},
  58. .final_sandboxing_flag_set = HTML::SandboxingFlagSet {},
  59. .cross_origin_opener_policy = move(coop),
  60. .about_base_url = {},
  61. };
  62. // 5. Let document be the result of creating and initializing a Document object given "html", "text/html", and navigationParams.
  63. auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params).release_value_but_fixme_should_propagate_errors();
  64. // 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
  65. // user agent wants to render.
  66. mutate_document(*document);
  67. // 7. Return document.
  68. return document;
  69. }
  70. }