WindowEnvironmentSettingsObject.cpp 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/WindowObject.h>
  7. #include <LibWeb/DOM/Document.h>
  8. #include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
  9. namespace Web::HTML {
  10. WindowEnvironmentSettingsObject::WindowEnvironmentSettingsObject(DOM::Window& window, JS::ExecutionContext& execution_context)
  11. : EnvironmentSettingsObject(execution_context)
  12. , m_window(window)
  13. {
  14. }
  15. // https://html.spec.whatwg.org/multipage/window-object.html#set-up-a-window-environment-settings-object
  16. void WindowEnvironmentSettingsObject::setup(AK::URL& creation_url, JS::ExecutionContext& execution_context)
  17. {
  18. // 1. Let realm be the value of execution context's Realm component.
  19. auto* realm = execution_context.realm;
  20. VERIFY(realm);
  21. // 2. Let window be realm's global object.
  22. // NOTE: We want to store the Window impl rather than the WindowObject.
  23. auto& window = verify_cast<Bindings::WindowObject>(realm->global_object()).impl();
  24. // 3. Let settings object be a new environment settings object whose algorithms are defined as follows:
  25. // NOTE: See the functions defined for this class.
  26. auto settings_object = adopt_own(*new WindowEnvironmentSettingsObject(window, execution_context));
  27. // FIXME: 4. If reservedEnvironment is non-null, then:
  28. // FIXME: 1. Set settings object's id to reservedEnvironment's id, target browsing context to reservedEnvironment's target browsing context, and active service worker to reservedEnvironment's active service worker.
  29. // FIXME: 2. Set reservedEnvironment's id to the empty string.
  30. // FIXME: 5. Otherwise, set settings object's id to a new unique opaque string, settings object's target browsing context to null, and settings object's active service worker to null.
  31. settings_object->target_browsing_context = nullptr;
  32. // FIXME: 6. Set settings object's creation URL to creationURL, settings object's top-level creation URL to topLevelCreationURL, and settings object's top-level origin to topLevelOrigin.
  33. settings_object->creation_url = creation_url;
  34. // 7. Set realm's [[HostDefined]] field to settings object.
  35. realm->set_host_defined(move(settings_object));
  36. }
  37. // https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:responsible-document
  38. RefPtr<DOM::Document> WindowEnvironmentSettingsObject::responsible_document()
  39. {
  40. // Return window's associated Document.
  41. return m_window->associated_document();
  42. }
  43. // https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:api-url-character-encoding
  44. String WindowEnvironmentSettingsObject::api_url_character_encoding()
  45. {
  46. // Return the current character encoding of window's associated Document.
  47. return m_window->associated_document().encoding_or_default();
  48. }
  49. // https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:api-base-url
  50. AK::URL WindowEnvironmentSettingsObject::api_base_url()
  51. {
  52. // FIXME: Return the current base URL of window's associated Document.
  53. // (This currently just returns the current document URL, not accounting for <base> elements and such)
  54. return m_window->associated_document().url();
  55. }
  56. // https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:concept-settings-object-origin
  57. Origin WindowEnvironmentSettingsObject::origin()
  58. {
  59. // Return the origin of window's associated Document.
  60. return m_window->associated_document().origin();
  61. }
  62. // https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:concept-settings-object-cross-origin-isolated-capability
  63. CanUseCrossOriginIsolatedAPIs WindowEnvironmentSettingsObject::cross_origin_isolated_capability()
  64. {
  65. // FIXME: Return true if both of the following hold, and false otherwise:
  66. // 1. realm's agent cluster's cross-origin-isolation mode is "concrete", and
  67. // 2. window's associated Document is allowed to use the "cross-origin-isolated" feature.
  68. TODO();
  69. }
  70. }