diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 3f50f2fe10..8525b9dafc 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -611,10 +611,6 @@ void BrowserWindow::create_new_tab(URL url, bool activate) active_tab().view().scroll_element_into_view(element_id); }; - new_tab.webdriver_endpoints().on_get_element_property = [this](i32 element_id, String const& name) { - return active_tab().view().get_element_property(element_id, name); - }; - new_tab.webdriver_endpoints().on_get_active_documents_type = [this]() { return active_tab().view().get_active_documents_type(); }; diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp index d2bf37c1a0..76b014c835 100644 --- a/Userland/Applications/Browser/WebDriverConnection.cpp +++ b/Userland/Applications/Browser/WebDriverConnection.cpp @@ -146,17 +146,6 @@ void WebDriverConnection::scroll_element_into_view(i32 element_id) } } -Messages::WebDriverSessionClient::GetElementPropertyResponse WebDriverConnection::get_element_property(i32 element_id, String const& name) -{ - dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_element_property"); - if (auto browser_window = m_browser_window.strong_ref()) { - auto& tab = browser_window->active_tab(); - if (tab.webdriver_endpoints().on_get_element_property) - return { tab.webdriver_endpoints().on_get_element_property(element_id, name) }; - } - return { {} }; -} - Messages::WebDriverSessionClient::GetActiveDocumentsTypeResponse WebDriverConnection::get_active_documents_type() { dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_active_documents_type"); diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h index 0ab70c8c3a..336f50c74f 100644 --- a/Userland/Applications/Browser/WebDriverConnection.h +++ b/Userland/Applications/Browser/WebDriverConnection.h @@ -49,7 +49,6 @@ public: virtual void add_cookie(Web::Cookie::ParsedCookie const&) override; virtual void update_cookie(Web::Cookie::Cookie const&) override; virtual void scroll_element_into_view(i32 element_id) override; - virtual Messages::WebDriverSessionClient::GetElementPropertyResponse get_element_property(i32 element_id, String const& name) override; virtual Messages::WebDriverSessionClient::GetActiveDocumentsTypeResponse get_active_documents_type() override; virtual Messages::WebDriverSessionClient::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) override; virtual Messages::WebDriverSessionClient::GetElementTextResponse get_element_text(i32 element_id) override; diff --git a/Userland/Applications/Browser/WebDriverEndpoints.h b/Userland/Applications/Browser/WebDriverEndpoints.h index 5e0f7f7551..98881c9aba 100644 --- a/Userland/Applications/Browser/WebDriverEndpoints.h +++ b/Userland/Applications/Browser/WebDriverEndpoints.h @@ -24,7 +24,6 @@ public: ~WebDriverEndpoints() = default; Function on_scroll_element_into_view; - Function(i32 element_id, String const&)> on_get_element_property; Function on_get_active_documents_type; Function on_get_computed_value_for_element; Function on_get_element_text; diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc index 4db32510d7..330a0881c7 100644 --- a/Userland/Applications/Browser/WebDriverSessionClient.ipc +++ b/Userland/Applications/Browser/WebDriverSessionClient.ipc @@ -25,7 +25,6 @@ endpoint WebDriverSessionClient { add_cookie(Web::Cookie::ParsedCookie cookie) =| update_cookie(Web::Cookie::Cookie cookie) =| scroll_element_into_view(i32 element_id) => () - get_element_property(i32 element_id, String name) => (Optional property) get_active_documents_type() => (String type) get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value) get_element_text(i32 element_id) => (String text) diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 600cbaa222..b1d3f380e4 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -559,11 +559,6 @@ void OutOfProcessWebView::scroll_element_into_view(i32 element_id) return client().scroll_element_into_view(element_id); } -Optional OutOfProcessWebView::get_element_property(i32 element_id, String const& name) -{ - return client().get_element_property(element_id, name); -} - String OutOfProcessWebView::get_active_documents_type() { return client().get_active_documents_type(); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 78bf002b41..3ce5712080 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -64,7 +64,6 @@ public: OrderedHashMap get_session_storage_entries(); void scroll_element_into_view(i32 element_id); - Optional get_element_property(i32 element_id, String const& name); String get_active_documents_type(); String get_computed_value_for_element(i32 element_id, String const& property_name); String get_element_text(i32 element_id); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 082d1886dd..6dcf480da2 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -495,28 +495,6 @@ void ConnectionFromClient::scroll_element_into_view(i32 element_id) element->scroll_into_view(options); } -Messages::WebContentServer::GetElementPropertyResponse ConnectionFromClient::get_element_property(i32 element_id, String const& name) -{ - auto element = find_element_by_id(element_id); - if (!element.has_value()) - return Optional {}; - - auto property_or_error = element->get(name); - if (property_or_error.is_throw_completion()) - return Optional {}; - - auto property = property_or_error.release_value(); - - if (property.is_undefined()) - return Optional {}; - - auto string_or_error = property.to_string(element->vm()); - if (string_or_error.is_error()) - return Optional {}; - - return { string_or_error.release_value() }; -} - Messages::WebContentServer::GetActiveDocumentsTypeResponse ConnectionFromClient::get_active_documents_type() { auto* active_document = page().top_level_browsing_context().active_document(); diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index 6434c5b7b3..b4d6f306fb 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -84,7 +84,6 @@ private: virtual void js_console_request_messages(i32) override; virtual void scroll_element_into_view(i32 element_id) override; - virtual Messages::WebContentServer::GetElementPropertyResponse get_element_property(i32 element_id, String const& name) override; virtual Messages::WebContentServer::GetActiveDocumentsTypeResponse get_active_documents_type() override; virtual Messages::WebContentServer::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) override; virtual Messages::WebContentServer::GetElementTextResponse get_element_text(i32 element_id) override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index a089e2abdd..fcc6340d13 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -43,7 +43,6 @@ endpoint WebContentServer js_console_request_messages(i32 start_index) =| scroll_element_into_view(i32 element_id) => () - get_element_property(i32 element_id, String name) => (Optional property) get_active_documents_type() => (String type) get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value) get_element_text(i32 element_id) => (String text) diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index 1cf93db5b2..7db76b59d7 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -15,4 +15,5 @@ endpoint WebDriverClient { find_elements_from_element(JsonValue payload, String element_id) => (Web::WebDriver::Response response) is_element_selected(String element_id) => (Web::WebDriver::Response response) get_element_attribute(String element_id, String name) => (Web::WebDriver::Response response) + get_element_property(String element_id, String name) => (Web::WebDriver::Response response) } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index ec06b2f0a5..b39420a4e9 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -524,6 +525,36 @@ Messages::WebDriverClient::GetElementAttributeResponse WebDriverConnection::get_ return make_success_response({}); } +// 12.4.3 Get Element Property, https://w3c.github.io/webdriver/#dfn-get-element-property +Messages::WebDriverClient::GetElementPropertyResponse WebDriverConnection::get_element_property(String const& element_id, String const& name) +{ + // 1. If the current browsing context is no longer open, return error with error code no such window. + TRY(ensure_open_top_level_browsing_context()); + + // FIXME: 2. Handle any user prompts and return its value if it is an error. + + // 3. Let element be the result of trying to get a known connected element with url variable element id. + auto* element = TRY(get_known_connected_element(element_id)); + + Optional result; + + // 4. Let property be the result of calling the Object.[[GetProperty]](name) on element. + if (auto property_or_error = element->get(name); !property_or_error.is_throw_completion()) { + auto property = property_or_error.release_value(); + + // 5. Let result be the value of property if not undefined, or null. + if (!property.is_undefined()) { + if (auto string_or_error = property.to_string(element->vm()); !string_or_error.is_error()) + result = string_or_error.release_value(); + } + } + + // 6. Return success with data result. + if (result.has_value()) + return make_success_response(result.release_value()); + return make_success_response({}); +} + // https://w3c.github.io/webdriver/#dfn-no-longer-open ErrorOr WebDriverConnection::ensure_open_top_level_browsing_context() { diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index 8182705572..79000352a4 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -45,6 +45,7 @@ private: virtual Messages::WebDriverClient::FindElementsFromElementResponse find_elements_from_element(JsonValue const& payload, String const& element_id) override; virtual Messages::WebDriverClient::IsElementSelectedResponse is_element_selected(String const& element_id) override; virtual Messages::WebDriverClient::GetElementAttributeResponse get_element_attribute(String const& element_id, String const& name) override; + virtual Messages::WebDriverClient::GetElementPropertyResponse get_element_property(String const& element_id, String const& name) override; ErrorOr ensure_open_top_level_browsing_context(); void restore_the_window(); diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index d0cebe18b2..8afa7c822a 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -668,12 +668,11 @@ Web::WebDriver::Response Client::handle_get_element_attribute(Vector // 12.4.3 Get Element Property, https://w3c.github.io/webdriver/#dfn-get-element-property // GET /session/{session id}/element/{element id}/property/{name} -Web::WebDriver::Response Client::handle_get_element_property(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_get_element_property(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//property/"); auto* session = TRY(find_session_with_id(parameters[0])); - auto result = TRY(session->get_element_property(payload, parameters[1], parameters[2])); - return make_json_value(result); + return session->web_content_connection().get_element_property(parameters[1], parameters[2]); } // 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index 9cab66be80..06030a8ff1 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -323,28 +323,6 @@ static ErrorOr get_known_connected_element(StringVie return maybe_element_id.release_value(); } -// 12.4.3 Get Element Property, https://w3c.github.io/webdriver/#dfn-get-element-property -Web::WebDriver::Response Session::get_element_property(JsonValue const&, StringView parameter_element_id, StringView name) -{ - // 1. If the current browsing context is no longer open, return error with error code no such window. - TRY(check_for_open_top_level_browsing_context_or_return_error()); - - // FIXME: 2. Handle any user prompts and return its value if it is an error. - - // 3. Let element be the result of trying to get a known connected element with url variable element id. - auto element_id = TRY(get_known_connected_element(parameter_element_id)); - - // 4. Let property be the result of calling the Object.[[GetProperty]](name) on element. - auto property = m_browser_connection->get_element_property(element_id, name); - - // 5. Let result be the value of property if not undefined, or null. - if (!property.has_value()) - return JsonValue(); - - // 6. Return success with data result. - return JsonValue(property.release_value()); -} - // 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value Web::WebDriver::Response Session::get_element_css_value(JsonValue const&, StringView parameter_element_id, StringView property_name) { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index d335c9baa3..8328fec20e 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -58,7 +58,6 @@ public: Web::WebDriver::Response get_window_handle(); ErrorOr> close_window(); Web::WebDriver::Response get_window_handles() const; - Web::WebDriver::Response get_element_property(JsonValue const& payload, StringView element_id, StringView name); Web::WebDriver::Response get_element_css_value(JsonValue const& payload, StringView element_id, StringView property_name); Web::WebDriver::Response get_element_text(JsonValue const& payload, StringView element_id); Web::WebDriver::Response get_element_tag_name(JsonValue const& payload, StringView element_id);