diff options
author | Tobias Christiansen <tobyase@serenityos.org> | 2022-10-19 20:45:25 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-19 22:30:06 +0200 |
commit | 3db92885cd7e28a098e268f5f85faae1a139fe20 (patch) | |
tree | 2ebdf264585f777966e5e2cf040ad8cdc7a499b7 /Userland/Services | |
parent | 6641c99c806afec9b9c58c13a05291b8b3241289 (diff) | |
download | serenity-3db92885cd7e28a098e268f5f85faae1a139fe20.zip |
WebContent+Friends: Add get_element_property IPC and plumbing
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/WebContent/ConnectionFromClient.cpp | 27 | ||||
-rw-r--r-- | Userland/Services/WebContent/ConnectionFromClient.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebContentServer.ipc | 1 |
3 files changed, 29 insertions, 0 deletions
diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index a003cf6207..c2dec08eaf 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -490,6 +490,33 @@ Messages::WebContentServer::GetElementAttributeResponse ConnectionFromClient::ge return { element.get_attribute(name) }; } +Messages::WebContentServer::GetElementPropertyResponse ConnectionFromClient::get_element_property(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); + + auto property_or_error = element.get(name); + if (property_or_error.is_throw_completion()) + return Optional<String> {}; + + auto property = property_or_error.release_value(); + + if (property.is_undefined()) + return Optional<String> {}; + + auto string_or_error = property.to_string(element.vm()); + if (string_or_error.is_error()) + return Optional<String> {}; + + return { string_or_error.release_value() }; +} + 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 d342add598..7406a98536 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -82,6 +82,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::GetElementPropertyResponse get_element_property(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 99be81958d..1f9bd696ff 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -40,6 +40,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) + get_element_property(i32 element_id, String name) => (Optional<String> property) run_javascript(String js_source) =| |