Contexts.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/JsonObject.h>
  7. #include <LibWeb/HTML/BrowsingContext.h>
  8. #include <LibWeb/HTML/WindowProxy.h>
  9. #include <LibWeb/WebDriver/Contexts.h>
  10. namespace Web::WebDriver {
  11. // https://w3c.github.io/webdriver/#dfn-windowproxy-reference-object
  12. JsonObject window_proxy_reference_object(HTML::WindowProxy const& window)
  13. {
  14. // 1. Let identifier be the web window identifier if the associated browsing context of window is a top-level browsing context.
  15. // Otherwise let it be the web frame identifier.
  16. auto identifier = window.associated_browsing_context()->is_top_level()
  17. ? WEB_WINDOW_IDENTIFIER
  18. : WEB_FRAME_IDENTIFIER;
  19. // 2. Return a JSON Object initialized with the following properties:
  20. JsonObject object;
  21. // identifier
  22. // Associated window handle of the window’s browsing context.
  23. object.set(identifier, window.associated_browsing_context()->window_handle().to_deprecated_string());
  24. return object;
  25. }
  26. }