diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 987afc4013..ac473ae670 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_is_element_enabled = [this](i32 element_id) { - return active_tab().view().is_element_enabled(element_id); - }; - new_tab.webdriver_endpoints().on_serialize_source = [this]() { return active_tab().view().serialize_source(); }; diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp index 541f3f1f88..edd3bf6a70 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::IsElementEnabledResponse WebDriverConnection::is_element_enabled(i32 element_id) -{ - dbgln("WebDriverConnection: is_element_enabled {}", element_id); - if (auto browser_window = m_browser_window.strong_ref()) { - auto& tab = browser_window->active_tab(); - if (tab.webdriver_endpoints().on_is_element_enabled) - return { tab.webdriver_endpoints().on_is_element_enabled(element_id) }; - } - return { false }; -} - Messages::WebDriverSessionClient::TakeScreenshotResponse WebDriverConnection::take_screenshot() { dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: take_screenshot"); diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h index 7e5007ecae..6bb7a3662c 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::IsElementEnabledResponse is_element_enabled(i32 element_id) override; virtual Messages::WebDriverSessionClient::TakeScreenshotResponse take_screenshot() override; virtual Messages::WebDriverSessionClient::TakeElementScreenshotResponse take_element_screenshot(i32 element_id) override; diff --git a/Userland/Applications/Browser/WebDriverEndpoints.h b/Userland/Applications/Browser/WebDriverEndpoints.h index 7aed04734d..45b21cf875 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 on_is_element_enabled; Function on_take_element_screenshot; Function on_serialize_source; Function const& json_arguments, Optional const& timeout, bool async)> on_execute_script; diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc index 5a358b9533..c5b97f71ac 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) => () - is_element_enabled(i32 element_id) => (bool enabled) take_screenshot() => (Gfx::ShareableBitmap data) take_element_screenshot(i32 element_id) => (Gfx::ShareableBitmap data) } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 899294f7d4..8a7f03570b 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); } -bool OutOfProcessWebView::is_element_enabled(i32 element_id) -{ - return client().is_element_enabled(element_id); -} - void OutOfProcessWebView::set_content_filters(Vector filters) { client().async_set_content_filters(filters); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 926e6cc7ae..e7c533c2d7 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); - bool is_element_enabled(i32 element_id); void set_content_filters(Vector); void set_proxy_mappings(Vector proxies, HashMap mappings); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 23c55f1165..07385fece1 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -525,26 +524,6 @@ static Gfx::IntRect calculate_absolute_rect_of_element(Web::Page const& page, We }; } -Messages::WebContentServer::IsElementEnabledResponse ConnectionFromClient::is_element_enabled(i32 element_id) -{ - auto element = find_element_by_id(element_id); - if (!element.has_value()) - return { false }; - - auto* document = page().top_level_browsing_context().active_document(); - if (!document) - return { false }; - - bool enabled = !document->is_xml_document(); - - if (enabled && is(*element)) { - auto& form_associated_element = dynamic_cast(*element); - enabled = form_associated_element.enabled(); - } - - return { enabled }; -} - Messages::WebContentServer::TakeElementScreenshotResponse ConnectionFromClient::take_element_screenshot(i32 element_id) { auto element = find_element_by_id(element_id); diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index 51b37d17b3..42211eed65 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::IsElementEnabledResponse is_element_enabled(i32 element_id) override; virtual Messages::WebContentServer::TakeElementScreenshotResponse take_element_screenshot(i32 element_id) override; virtual Messages::WebContentServer::TakeDocumentScreenshotResponse take_document_screenshot() override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index 219b6c580d..6178a26256 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) => () - is_element_enabled(i32 element_id) => (bool enabled) take_element_screenshot(i32 element_id) => (Gfx::ShareableBitmap data) take_document_screenshot() => (Gfx::ShareableBitmap data) diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index f4b146fc13..733f60b135 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -20,4 +20,5 @@ endpoint WebDriverClient { get_element_text(String element_id) => (Web::WebDriver::Response response) get_element_tag_name(String element_id) => (Web::WebDriver::Response response) get_element_rect(String element_id) => (Web::WebDriver::Response response) + is_element_enabled(String element_id) => (Web::WebDriver::Response response) } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index cfbe77124b..7205e94099 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -688,6 +689,31 @@ Messages::WebDriverClient::GetElementRectResponse WebDriverConnection::get_eleme return body; } +// 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled +Messages::WebDriverClient::IsElementEnabledResponse WebDriverConnection::is_element_enabled(String const& element_id) +{ + // 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)); + + // 4. Let enabled be a boolean initially set to true if the current browsing context’s active document’s type is not "xml". + // 5. Otherwise, let enabled to false and jump to the last step of this algorithm. + bool enabled = !m_page_host.page().top_level_browsing_context().active_document()->is_xml_document(); + + // 6. Set enabled to false if a form control is disabled. + if (enabled && is(*element)) { + auto& form_associated_element = dynamic_cast(*element); + enabled = form_associated_element.enabled(); + } + + // 7. Return success with data enabled. + return make_success_response(enabled); +} + // 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 8675993775..d6fa957799 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -50,6 +50,7 @@ private: virtual Messages::WebDriverClient::GetElementTextResponse get_element_text(String const& element_id) override; virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(String const& element_id) override; virtual Messages::WebDriverClient::GetElementRectResponse get_element_rect(String const& element_id) override; + virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(String const& element_id) 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 287cec4b27..8e4e131da8 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -717,8 +717,7 @@ Web::WebDriver::Response Client::handle_is_element_enabled(Vector co { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//enabled"); auto* session = TRY(find_session_with_id(parameters[0])); - auto result = TRY(session->is_element_enabled(parameters[1])); - return make_json_value(result); + return session->web_content_connection().is_element_enabled(parameters[1]); } // 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index e4b6b3fb25..c314f71857 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -312,26 +312,6 @@ static ErrorOr get_known_connected_element(StringVie return maybe_element_id.release_value(); } -// 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled -Web::WebDriver::Response Session::is_element_enabled(StringView parameter_element_id) -{ - // 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 enabled be a boolean initially set to true if the current browsing context’s active document’s type is not "xml". - // 5. Otherwise, let enabled to false and jump to the last step of this algorithm. - // 6. Set enabled to false if a form control is disabled. - auto enabled = m_browser_connection->is_element_enabled(element_id); - - // 7. Return success with data enabled. - return JsonValue { enabled }; -} - // 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source Web::WebDriver::Response Session::get_source() { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index b20ffab75a..623c390bd1 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 is_element_enabled(StringView element_id); Web::WebDriver::Response get_source(); Web::WebDriver::Response execute_script(JsonValue const& payload); Web::WebDriver::Response execute_async_script(JsonValue const& payload);