diff options
Diffstat (limited to 'Userland/Libraries/LibWeb/WebDriver/Contexts.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/WebDriver/Contexts.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/WebDriver/Contexts.cpp b/Userland/Libraries/LibWeb/WebDriver/Contexts.cpp new file mode 100644 index 0000000000..a36b08df94 --- /dev/null +++ b/Userland/Libraries/LibWeb/WebDriver/Contexts.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023, Linus Groh <linusg@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/JsonObject.h> +#include <LibWeb/HTML/BrowsingContext.h> +#include <LibWeb/HTML/WindowProxy.h> +#include <LibWeb/WebDriver/Contexts.h> + +namespace Web::WebDriver { + +// https://w3c.github.io/webdriver/#dfn-windowproxy-reference-object +JsonObject window_proxy_reference_object(HTML::WindowProxy const& window) +{ + // 1. Let identifier be the web window identifier if the associated browsing context of window is a top-level browsing context. + // Otherwise let it be the web frame identifier. + auto identifier = window.associated_browsing_context()->is_top_level() + ? WEB_WINDOW_IDENTIFIER + : WEB_FRAME_IDENTIFIER; + + // 2. Return a JSON Object initialized with the following properties: + JsonObject object; + + // identifier + // Associated window handle of the window’s browsing context. + object.set(identifier, window.associated_browsing_context()->window_handle().to_deprecated_string()); + + return object; +} + +} |