1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:47:35 +00:00

LibWebView+WebContent: Add APIs to manipulate DOM nodes

This adds APIs to allow Ispector clients to:
* Change a DOM text or comment node's text data.
* Add, replace, or remove a DOM element's attribute.
* Change a DOM element's tag.
This commit is contained in:
Timothy Flynn 2023-11-19 10:42:11 -05:00 committed by Andreas Kling
parent 18a4455d43
commit 4cfeb41c4b
10 changed files with 138 additions and 0 deletions

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <LibWebView/Attribute.h>
template<>
ErrorOr<void> IPC::encode(Encoder& encoder, WebView::Attribute const& attribute)
{
TRY(encoder.encode(attribute.name));
TRY(encoder.encode(attribute.value));
return {};
}
template<>
ErrorOr<WebView::Attribute> IPC::decode(Decoder& decoder)
{
auto name = TRY(decoder.decode<String>());
auto value = TRY(decoder.decode<String>());
return WebView::Attribute { move(name), move(value) };
}

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <LibIPC/Forward.h>
namespace WebView {
struct Attribute {
String name;
String value;
};
}
namespace IPC {
template<>
ErrorOr<void> encode(Encoder&, WebView::Attribute const&);
template<>
ErrorOr<WebView::Attribute> decode(Decoder&);
}

View file

@ -1,6 +1,7 @@
include(${SerenityOS_SOURCE_DIR}/Meta/CMake/public_suffix.cmake)
set(SOURCES
Attribute.cpp
CookieJar.cpp
Database.cpp
History.cpp

View file

@ -18,6 +18,7 @@ class OutOfProcessWebView;
class ViewImplementation;
class WebContentClient;
struct Attribute;
struct CookieStorageKey;
struct SearchEngine;

View file

@ -181,6 +181,21 @@ i32 ViewImplementation::get_hovered_node_id()
return client().get_hovered_node_id();
}
void ViewImplementation::set_dom_node_text(i32 node_id, String text)
{
client().async_set_dom_node_text(node_id, move(text));
}
Optional<i32> ViewImplementation::set_dom_node_tag(i32 node_id, String name)
{
return client().set_dom_node_tag(node_id, move(name));
}
void ViewImplementation::replace_dom_node_attribute(i32 node_id, String name, Vector<Attribute> replacement_attributes)
{
client().async_replace_dom_node_attribute(node_id, move(name), move(replacement_attributes));
}
void ViewImplementation::debug_request(DeprecatedString const& request, DeprecatedString const& argument)
{
client().async_debug_request(request, argument);

View file

@ -63,6 +63,10 @@ public:
void clear_inspected_dom_node();
i32 get_hovered_node_id();
void set_dom_node_text(i32 node_id, String text);
Optional<i32> set_dom_node_tag(i32 node_id, String name);
void replace_dom_node_attribute(i32 node_id, String name, Vector<Attribute> replacement_attributes);
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = {});
void run_javascript(StringView);