1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +00:00

WebContent+Friends: Add IPC and plumbing for WebDriver endpoint

To use the `GET /session/{id}/element/{id}/css/{property name}`
WebDriver endpoint, two new IPC calls through the Browser are
implemented:
    - get_active_documents_type returns the type of the active document,
      which is either "xml" or "html"
    - get_computed_value_for_element returns the computed CSS value (as
      String) for the given element and CSS property name
This commit is contained in:
Tobias Christiansen 2022-10-20 12:02:47 +02:00 committed by Linus Groh
parent eda566d112
commit 202b2be1f2
7 changed files with 70 additions and 0 deletions

View file

@ -18,6 +18,7 @@
#include <LibJS/Parser.h>
#include <LibJS/Runtime/ConsoleObject.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/NodeList.h>
@ -517,6 +518,49 @@ Messages::WebContentServer::GetElementPropertyResponse ConnectionFromClient::get
return { string_or_error.release_value() };
}
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* node = Web::DOM::Node::from_id(element_id);
if (!node)
return { "" };
if (!node->is_element())
return { "" };
auto& element = verify_cast<Web::DOM::Element>(*node);
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::GetSelectedTextResponse ConnectionFromClient::get_selected_text()
{
return page().focused_context().selected_text();