diff options
Diffstat (limited to 'Userland')
7 files changed, 30 insertions, 0 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 180427f9d5..c6dd766936 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -590,6 +590,10 @@ void BrowserWindow::create_new_tab(URL url, bool activate) return active_tab().view().query_selector_all(start_node_id, selector); }; + new_tab.on_get_element_attribute = [this](i32 element_id, String const& name) { + return active_tab().view().get_element_attribute(element_id, name); + }; + new_tab.load(url); dbgln_if(SPAM_DEBUG, "Added new tab {:p}, loading {}", &new_tab, url); diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index b0489b679c..bc3d3f755c 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -70,6 +70,7 @@ public: Function<OrderedHashMap<String, String>()> on_get_session_storage_entries; Function<Optional<i32>()> on_get_document_element; Function<Optional<Vector<i32>>(i32 start_node_id, String const&)> on_query_selector_all; + Function<Optional<String>(i32 element_id, String const&)> on_get_element_attribute; enum class InspectorTarget { Document, diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index dc934da070..026a3d338b 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -525,6 +525,11 @@ Optional<Vector<i32>> OutOfProcessWebView::query_selector_all(i32 start_node_id, return client().query_selector_all(start_node_id, selector); } +Optional<String> OutOfProcessWebView::get_element_attribute(i32 element_id, String const& name) +{ + return client().get_element_attribute(element_id, name); +} + void OutOfProcessWebView::set_content_filters(Vector<String> filters) { client().async_set_content_filters(filters); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 90765ef547..d7d325a816 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -60,6 +60,7 @@ public: Optional<i32> get_document_element(); Optional<Vector<i32>> query_selector_all(i32 start_node_id, String const& selector); + Optional<String> get_element_attribute(i32 element_id, String const& name); void set_content_filters(Vector<String>); void set_proxy_mappings(Vector<String> proxies, HashMap<String, size_t> mappings); 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) =| |