2023-04-20 17:41:32 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
|
|
|
|
|
|
*
|
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <AK/JsonObject.h>
|
2024-02-03 09:09:33 -07:00
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
2023-04-20 17:41:32 +01:00
|
|
|
|
#include <LibWeb/HTML/BrowsingContext.h>
|
2024-02-03 09:09:33 -07:00
|
|
|
|
#include <LibWeb/HTML/TraversableNavigable.h>
|
2023-04-20 17:41:32 +01:00
|
|
|
|
#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.
|
2024-02-03 09:09:33 -07:00
|
|
|
|
|
|
|
|
|
|
// NOTE: We look at the active browsing context's active document's node navigable instead.
|
|
|
|
|
|
// Because a Browsing context's top-level traversable is this navigable's top level traversable.
|
|
|
|
|
|
// Ref: https://html.spec.whatwg.org/multipage/document-sequences.html#bc-traversable
|
|
|
|
|
|
auto traversable_navigable = window.associated_browsing_context()->active_document()->navigable()->traversable_navigable();
|
|
|
|
|
|
|
|
|
|
|
|
auto identifier = traversable_navigable->is_top_level_traversable()
|
2023-04-20 17:41:32 +01:00
|
|
|
|
? 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.
|
2024-02-03 09:09:33 -07:00
|
|
|
|
object.set(identifier, traversable_navigable->window_handle().to_byte_string());
|
2023-04-20 17:41:32 +01:00
|
|
|
|
|
|
|
|
|
|
return object;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|