summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorTobias Christiansen <tobyase@serenityos.org>2022-10-19 16:56:08 +0200
committerLinus Groh <mail@linusgroh.de>2022-10-19 17:30:58 +0200
commit3f5a620b5d0e90e548c2854905ed656b34002ca5 (patch)
tree64ff9965964b6ed4f023cb3784169ba649c93c86 /Userland/Services
parentdfc3a4772b0d3fc330ef9c77e566f78a4922ead8 (diff)
downloadserenity-3f5a620b5d0e90e548c2854905ed656b34002ca5.zip
WebContent+Friends: Add get_element_attribute IPC and plumbing
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.cpp17
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.h1
-rw-r--r--Userland/Services/WebContent/WebContentServer.ipc1
3 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp
index b935b4c62a..a003cf6207 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.cpp
+++ b/Userland/Services/WebContent/ConnectionFromClient.cpp
@@ -473,6 +473,23 @@ Messages::WebContentServer::QuerySelectorAllResponse ConnectionFromClient::query
return { return_list };
}
+Messages::WebContentServer::GetElementAttributeResponse ConnectionFromClient::get_element_attribute(i32 element_id, String const& name)
+{
+ auto* node = Web::DOM::Node::from_id(element_id);
+ if (!node)
+ return Optional<String> {};
+
+ if (!node->is_element())
+ return Optional<String> {};
+
+ auto& element = verify_cast<Web::DOM::Element>(*node);
+
+ if (!element.has_attribute(name))
+ return Optional<String> {};
+
+ return { element.get_attribute(name) };
+}
+
Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text()
{
return page().focused_context().selected_text();
diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h
index 7033926340..d342add598 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.h
+++ b/Userland/Services/WebContent/ConnectionFromClient.h
@@ -81,6 +81,7 @@ private:
virtual Messages::WebContentServer::GetDocumentElementResponse get_document_element() override;
virtual Messages::WebContentServer::QuerySelectorAllResponse query_selector_all(i32 start_node_id, String const& selector) override;
+ virtual Messages::WebContentServer::GetElementAttributeResponse get_element_attribute(i32 element_id, String const& name) override;
virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override;
virtual Messages::WebContentServer::GetSessionStorageEntriesResponse get_session_storage_entries() override;
diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc
index d54bd22737..99be81958d 100644
--- a/Userland/Services/WebContent/WebContentServer.ipc
+++ b/Userland/Services/WebContent/WebContentServer.ipc
@@ -39,6 +39,7 @@ endpoint WebContentServer
get_document_element() => (Optional<i32> node_id)
query_selector_all(i32 start_node_id, String selector) => (Optional<Vector<i32>> elements_ids)
+ get_element_attribute(i32 element_id, String name) => (Optional<String> attribute)
run_javascript(String js_source) =|