diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 8525b9dafc..e6d4c12fab 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -611,14 +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_active_documents_type = [this]() { - return active_tab().view().get_active_documents_type(); - }; - - new_tab.webdriver_endpoints().on_get_computed_value_for_element = [this](i32 element_id, String const& property_name) { - return active_tab().view().get_computed_value_for_element(element_id, property_name); - }; - new_tab.webdriver_endpoints().on_get_element_text = [this](i32 element_id) { return active_tab().view().get_element_text(element_id); }; diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp index 76b014c835..0b5da0dd3f 100644 --- a/Userland/Applications/Browser/WebDriverConnection.cpp +++ b/Userland/Applications/Browser/WebDriverConnection.cpp @@ -146,28 +146,6 @@ void WebDriverConnection::scroll_element_into_view(i32 element_id) } } -Messages::WebDriverSessionClient::GetActiveDocumentsTypeResponse WebDriverConnection::get_active_documents_type() -{ - dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_active_documents_type"); - if (auto browser_window = m_browser_window.strong_ref()) { - auto& tab = browser_window->active_tab(); - if (tab.webdriver_endpoints().on_get_active_documents_type) - return { tab.webdriver_endpoints().on_get_active_documents_type() }; - } - return { "" }; -} - -Messages::WebDriverSessionClient::GetComputedValueForElementResponse WebDriverConnection::get_computed_value_for_element(i32 element_id, String const& property_name) -{ - dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_computed_value_for_element"); - if (auto browser_window = m_browser_window.strong_ref()) { - auto& tab = browser_window->active_tab(); - if (tab.webdriver_endpoints().on_get_computed_value_for_element) - return { tab.webdriver_endpoints().on_get_computed_value_for_element(element_id, property_name) }; - } - return { "" }; -} - Messages::WebDriverSessionClient::GetElementTextResponse WebDriverConnection::get_element_text(i32 element_id) { dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_element_text"); diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h index 336f50c74f..7bb71ea999 100644 --- a/Userland/Applications/Browser/WebDriverConnection.h +++ b/Userland/Applications/Browser/WebDriverConnection.h @@ -49,8 +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::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; virtual Messages::WebDriverSessionClient::GetElementTagNameResponse get_element_tag_name(i32 element_id) override; virtual Messages::WebDriverSessionClient::GetElementRectResponse get_element_rect(i32 element_id) override; diff --git a/Userland/Applications/Browser/WebDriverEndpoints.h b/Userland/Applications/Browser/WebDriverEndpoints.h index 98881c9aba..9b89dca8b4 100644 --- a/Userland/Applications/Browser/WebDriverEndpoints.h +++ b/Userland/Applications/Browser/WebDriverEndpoints.h @@ -24,8 +24,6 @@ public: ~WebDriverEndpoints() = default; Function on_scroll_element_into_view; - Function on_get_active_documents_type; - Function on_get_computed_value_for_element; Function on_get_element_text; Function on_get_element_tag_name; Function on_get_element_rect; diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc index 330a0881c7..16989327a8 100644 --- a/Userland/Applications/Browser/WebDriverSessionClient.ipc +++ b/Userland/Applications/Browser/WebDriverSessionClient.ipc @@ -25,8 +25,6 @@ endpoint WebDriverSessionClient { add_cookie(Web::Cookie::ParsedCookie cookie) =| update_cookie(Web::Cookie::Cookie cookie) =| scroll_element_into_view(i32 element_id) => () - 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) get_element_tag_name(i32 element_id) => (String tag_name) get_element_rect(i32 element_id) => (Gfx::IntRect rect) diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index b1d3f380e4..1a47b173fc 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -559,16 +559,6 @@ void OutOfProcessWebView::scroll_element_into_view(i32 element_id) return client().scroll_element_into_view(element_id); } -String OutOfProcessWebView::get_active_documents_type() -{ - return client().get_active_documents_type(); -} - -String OutOfProcessWebView::get_computed_value_for_element(i32 element_id, String const& property_name) -{ - return client().get_computed_value_for_element(element_id, property_name); -} - String OutOfProcessWebView::get_element_text(i32 element_id) { return client().get_element_text(element_id); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 3ce5712080..68ed2afee0 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -64,8 +64,6 @@ public: OrderedHashMap get_session_storage_entries(); void scroll_element_into_view(i32 element_id); - 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); String get_element_tag_name(i32 element_id); Gfx::IntRect get_element_rect(i32 element_id); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 6dcf480da2..b122df7edc 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -495,44 +494,6 @@ void ConnectionFromClient::scroll_element_into_view(i32 element_id) element->scroll_into_view(options); } -Messages::WebContentServer::GetActiveDocumentsTypeResponse ConnectionFromClient::get_active_documents_type() -{ - auto* active_document = page().top_level_browsing_context().active_document(); - - if (!active_document) - return { "" }; - - auto type = active_document->document_type(); - - switch (type) { - case Web::DOM::Document::Type::HTML: - return { "html" }; - break; - case Web::DOM::Document::Type::XML: - return { "xml" }; - break; - } - - return { "" }; -} - -Messages::WebContentServer::GetComputedValueForElementResponse ConnectionFromClient::get_computed_value_for_element(i32 element_id, String const& property_name) -{ - auto element = find_element_by_id(element_id); - if (!element.has_value()) - return { "" }; - - auto property_id = Web::CSS::property_id_from_string(property_name); - - auto computed_values = element->computed_css_values(); - if (!computed_values) - return { "" }; - - auto style_value = computed_values->property(property_id); - - return { style_value->to_string() }; -} - Messages::WebContentServer::GetElementTextResponse ConnectionFromClient::get_element_text(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 b4d6f306fb..a2dce5887c 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -84,8 +84,6 @@ private: virtual void js_console_request_messages(i32) override; virtual void scroll_element_into_view(i32 element_id) 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; virtual Messages::WebContentServer::GetElementTagNameResponse get_element_tag_name(i32 element_id) override; virtual Messages::WebContentServer::GetElementRectResponse get_element_rect(i32 element_id) override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index fcc6340d13..dd8352ed78 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -43,8 +43,6 @@ endpoint WebContentServer js_console_request_messages(i32 start_index) =| scroll_element_into_view(i32 element_id) => () - 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) get_element_tag_name(i32 element_id) => (String tag_name) get_element_rect(i32 element_id) => (Gfx::IntRect rect) diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index 7db76b59d7..d4d748a334 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -16,4 +16,5 @@ endpoint WebDriverClient { 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) + get_element_css_value(String element_id, String name) => (Web::WebDriver::Response response) } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index b39420a4e9..f84a98e2f2 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -555,6 +558,38 @@ Messages::WebDriverClient::GetElementPropertyResponse WebDriverConnection::get_e return make_success_response({}); } +// 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value +Messages::WebDriverClient::GetElementCssValueResponse WebDriverConnection::get_element_css_value(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)); + + // 4. Let computed value be the result of the first matching condition: + String computed_value; + + // -> current browsing context’s active document’s type is not "xml" + if (!m_page_host.page().top_level_browsing_context().active_document()->is_xml_document()) { + // computed value of parameter property name from element’s style declarations. property name is obtained from url variables. + auto property = Web::CSS::property_id_from_string(name); + + if (auto* computed_values = element->computed_css_values()) + computed_value = computed_values->property(property)->to_string(); + } + // -> Otherwise + else { + // "" (empty string) + computed_value = String::empty(); + } + + // 5. Return success with data computed value. + return make_success_response(move(computed_value)); +} + // 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 79000352a4..6bf3c6f01d 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -46,6 +46,7 @@ private: 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; + virtual Messages::WebDriverClient::GetElementCssValueResponse get_element_css_value(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 8afa7c822a..e8979e30ed 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -677,12 +677,11 @@ Web::WebDriver::Response Client::handle_get_element_property(Vector // 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value // GET /session/{session id}/element/{element id}/css/{property name} -Web::WebDriver::Response Client::handle_get_element_css_value(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_get_element_css_value(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//css/"); auto* session = TRY(find_session_with_id(parameters[0])); - auto result = TRY(session->get_element_css_value(payload, parameters[1], parameters[2])); - return make_json_value(result); + return session->web_content_connection().get_element_css_value(parameters[1], parameters[2]); } // 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index 06030a8ff1..c12204d358 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -323,32 +323,6 @@ static ErrorOr get_known_connected_element(StringVie return maybe_element_id.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) -{ - // 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 computed value be the result of the first matching condition: - // -> current browsing context’s active document’s type is not "xml" - // computed value of parameter property name from element’s style declarations. property name is obtained from url variables. - // -> Otherwise - // "" (empty string) - auto active_documents_type = m_browser_connection->get_active_documents_type(); - if (active_documents_type == "xml") - return JsonValue(""); - - auto computed_value = m_browser_connection->get_computed_value_for_element(element_id, property_name); - - // 5. Return success with data computed value. - return JsonValue(computed_value); -} - // 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text Web::WebDriver::Response Session::get_element_text(JsonValue const&, StringView parameter_element_id) { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index 8328fec20e..9b1081f447 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_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); Web::WebDriver::Response get_element_rect(StringView element_id);