mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibWebView+WebContent: Port JS console handling to String
This commit is contained in:
parent
bbcd8bd97c
commit
a8d3252f93
Notes:
github-actions[bot]
2025-02-28 12:09:54 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/a8d3252f936 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3686
14 changed files with 58 additions and 56 deletions
|
@ -71,7 +71,7 @@ InspectorClient::InspectorClient(ViewImplementation& content_web_view, ViewImple
|
|||
builder.append_escaped_for_json(properties.fonts.serialized());
|
||||
builder.append("\");"sv);
|
||||
|
||||
m_inspector_web_view.run_javascript(builder.string_view());
|
||||
m_inspector_web_view.run_javascript(MUST(builder.to_string()));
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_accessibility_tree = [this](auto const& accessibility_tree) {
|
||||
|
@ -94,7 +94,7 @@ InspectorClient::InspectorClient(ViewImplementation& content_web_view, ViewImple
|
|||
}
|
||||
builder.append("]);"sv);
|
||||
|
||||
m_inspector_web_view.run_javascript(builder.string_view());
|
||||
m_inspector_web_view.run_javascript(MUST(builder.to_string()));
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_style_sheet_source = [this](Web::CSS::StyleSheetIdentifier const& identifier, auto const& base_url, String const& source) {
|
||||
|
@ -199,7 +199,7 @@ InspectorClient::InspectorClient(ViewImplementation& content_web_view, ViewImple
|
|||
m_inspector_web_view.on_inspector_executed_console_script = [this](auto const& script) {
|
||||
append_console_source(script);
|
||||
|
||||
m_content_web_view.js_console_input(script.to_byte_string());
|
||||
m_content_web_view.js_console_input(script);
|
||||
};
|
||||
|
||||
m_inspector_web_view.on_inspector_exported_inspector_html = [this](String const& html) {
|
||||
|
@ -280,7 +280,7 @@ void InspectorClient::inspect()
|
|||
|
||||
void InspectorClient::reset()
|
||||
{
|
||||
static constexpr auto script = "inspector.reset();"sv;
|
||||
static auto script = "inspector.reset();"_string;
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
|
||||
m_body_or_frameset_node_id.clear();
|
||||
|
@ -310,7 +310,7 @@ void InspectorClient::clear_selection()
|
|||
m_content_web_view.clear_highlighted_dom_node();
|
||||
m_content_web_view.clear_inspected_dom_node();
|
||||
|
||||
static constexpr auto script = "inspector.clearInspectedDOMNode();"sv;
|
||||
static auto script = "inspector.clearInspectedDOMNode();"_string;
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
}
|
||||
|
||||
|
@ -350,7 +350,7 @@ void InspectorClient::load_cookies()
|
|||
json_cookies.serialize(builder);
|
||||
builder.append(");"sv);
|
||||
|
||||
m_inspector_web_view.run_javascript(builder.string_view());
|
||||
m_inspector_web_view.run_javascript(MUST(builder.to_string()));
|
||||
}
|
||||
|
||||
void InspectorClient::context_menu_edit_dom_node()
|
||||
|
@ -717,7 +717,7 @@ void InspectorClient::handle_console_message(i32 message_index)
|
|||
request_console_messages();
|
||||
}
|
||||
|
||||
void InspectorClient::handle_console_messages(i32 start_index, ReadonlySpan<ByteString> message_types, ReadonlySpan<ByteString> messages)
|
||||
void InspectorClient::handle_console_messages(i32 start_index, ReadonlySpan<String> message_types, ReadonlySpan<String> messages)
|
||||
{
|
||||
auto end_index = start_index + static_cast<i32>(message_types.size()) - 1;
|
||||
if (end_index <= m_highest_received_message_index) {
|
||||
|
@ -787,7 +787,7 @@ void InspectorClient::append_console_output(StringView html)
|
|||
|
||||
void InspectorClient::clear_console_output()
|
||||
{
|
||||
static constexpr auto script = "inspector.clearConsoleOutput();"sv;
|
||||
static auto script = "inspector.clearConsoleOutput();"_string;
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
}
|
||||
|
||||
|
@ -801,7 +801,7 @@ void InspectorClient::begin_console_group(StringView label, bool start_expanded)
|
|||
|
||||
void InspectorClient::end_console_group()
|
||||
{
|
||||
static constexpr auto script = "inspector.endConsoleGroup();"sv;
|
||||
static auto script = "inspector.endConsoleGroup();"_string;
|
||||
m_inspector_web_view.run_javascript(script);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ private:
|
|||
|
||||
void request_console_messages();
|
||||
void handle_console_message(i32 message_index);
|
||||
void handle_console_messages(i32 start_index, ReadonlySpan<ByteString> message_types, ReadonlySpan<ByteString> messages);
|
||||
void handle_console_messages(i32 start_index, ReadonlySpan<String> message_types, ReadonlySpan<String> messages);
|
||||
|
||||
void append_console_source(StringView);
|
||||
void append_console_message(StringView);
|
||||
|
|
|
@ -393,14 +393,14 @@ void ViewImplementation::debug_request(ByteString const& request, ByteString con
|
|||
client().async_debug_request(page_id(), request, argument);
|
||||
}
|
||||
|
||||
void ViewImplementation::run_javascript(StringView js_source)
|
||||
void ViewImplementation::run_javascript(String js_source)
|
||||
{
|
||||
client().async_run_javascript(page_id(), js_source);
|
||||
client().async_run_javascript(page_id(), move(js_source));
|
||||
}
|
||||
|
||||
void ViewImplementation::js_console_input(ByteString const& js_source)
|
||||
void ViewImplementation::js_console_input(String js_source)
|
||||
{
|
||||
client().async_js_console_input(page_id(), js_source);
|
||||
client().async_js_console_input(page_id(), move(js_source));
|
||||
}
|
||||
|
||||
void ViewImplementation::js_console_request_messages(i32 start_index)
|
||||
|
|
|
@ -127,8 +127,8 @@ public:
|
|||
|
||||
void debug_request(ByteString const& request, ByteString const& argument = {});
|
||||
|
||||
void run_javascript(StringView);
|
||||
void js_console_input(ByteString const& js_source);
|
||||
void run_javascript(String);
|
||||
void js_console_input(String);
|
||||
void js_console_request_messages(i32 start_index);
|
||||
|
||||
void alert_closed();
|
||||
|
@ -216,7 +216,7 @@ public:
|
|||
Function<void(Optional<Web::UniqueNodeID> const& node_id)> on_finshed_editing_dom_node;
|
||||
Function<void(String const&)> on_received_dom_node_html;
|
||||
Function<void(i32 message_id)> on_received_console_message;
|
||||
Function<void(i32 start_index, Vector<ByteString> const& message_types, Vector<ByteString> const& messages)> on_received_console_messages;
|
||||
Function<void(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)> on_received_console_messages;
|
||||
Function<void(i32 count_waiting)> on_resource_status_change;
|
||||
Function<void()> on_restore_window;
|
||||
Function<void(Gfx::IntPoint)> on_reposition_window;
|
||||
|
|
|
@ -374,7 +374,7 @@ void WebContentClient::did_output_js_console_message(u64 page_id, i32 message_in
|
|||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_get_js_console_messages(u64 page_id, i32 start_index, Vector<ByteString> const& message_types, Vector<ByteString> const& messages)
|
||||
void WebContentClient::did_get_js_console_messages(u64 page_id, i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_received_console_messages)
|
||||
|
|
|
@ -80,7 +80,7 @@ private:
|
|||
virtual void did_take_screenshot(u64 page_id, Gfx::ShareableBitmap const& screenshot) override;
|
||||
virtual void did_get_internal_page_info(u64 page_id, PageInfoType, String const&) override;
|
||||
virtual void did_output_js_console_message(u64 page_id, i32 message_index) override;
|
||||
virtual void did_get_js_console_messages(u64 page_id, i32 start_index, Vector<ByteString> const& message_types, Vector<ByteString> const& messages) override;
|
||||
virtual void did_get_js_console_messages(u64 page_id, i32 start_index, Vector<String> const& message_types, Vector<String> const& messages) override;
|
||||
virtual void did_change_favicon(u64 page_id, Gfx::ShareableBitmap const&) override;
|
||||
virtual void did_request_alert(u64 page_id, String const&) override;
|
||||
virtual void did_request_confirm(u64 page_id, String const&) override;
|
||||
|
|
|
@ -1150,7 +1150,7 @@ void ConnectionFromClient::set_system_visibility_state(u64 page_id, Web::HTML::V
|
|||
page->page().top_level_traversable()->set_system_visibility_state(visibility_state);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::js_console_input(u64 page_id, ByteString const& js_source)
|
||||
void ConnectionFromClient::js_console_input(u64 page_id, String const& js_source)
|
||||
{
|
||||
auto page = this->page(page_id);
|
||||
if (!page.has_value())
|
||||
|
@ -1159,7 +1159,7 @@ void ConnectionFromClient::js_console_input(u64 page_id, ByteString const& js_so
|
|||
page->js_console_input(js_source);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::run_javascript(u64 page_id, ByteString const& js_source)
|
||||
void ConnectionFromClient::run_javascript(u64 page_id, String const& js_source)
|
||||
{
|
||||
if (auto page = this->page(page_id); page.has_value())
|
||||
page->run_javascript(js_source);
|
||||
|
|
|
@ -111,8 +111,8 @@ private:
|
|||
virtual void handle_file_return(u64 page_id, i32 error, Optional<IPC::File> const& file, i32 request_id) override;
|
||||
virtual void set_system_visibility_state(u64 page_id, Web::HTML::VisibilityState) override;
|
||||
|
||||
virtual void js_console_input(u64 page_id, ByteString const&) override;
|
||||
virtual void run_javascript(u64 page_id, ByteString const&) override;
|
||||
virtual void js_console_input(u64 page_id, String const&) override;
|
||||
virtual void run_javascript(u64 page_id, String const&) override;
|
||||
virtual void js_console_request_messages(u64 page_id, i32) override;
|
||||
|
||||
virtual void alert_closed(u64 page_id) override;
|
||||
|
|
|
@ -738,13 +738,13 @@ void PageClient::initialize_js_console(Web::DOM::Document& document)
|
|||
document.set_console_client(console_client);
|
||||
}
|
||||
|
||||
void PageClient::js_console_input(ByteString const& js_source)
|
||||
void PageClient::js_console_input(StringView js_source)
|
||||
{
|
||||
if (m_top_level_document_console_client)
|
||||
m_top_level_document_console_client->handle_input(js_source);
|
||||
}
|
||||
|
||||
void PageClient::run_javascript(ByteString const& js_source)
|
||||
void PageClient::run_javascript(StringView js_source)
|
||||
{
|
||||
auto* active_document = page().top_level_browsing_context().active_document();
|
||||
|
||||
|
@ -787,7 +787,7 @@ void PageClient::console_peer_did_misbehave(char const* reason)
|
|||
client().did_misbehave(reason);
|
||||
}
|
||||
|
||||
void PageClient::did_get_js_console_messages(i32 start_index, Vector<ByteString> message_types, Vector<ByteString> messages)
|
||||
void PageClient::did_get_js_console_messages(i32 start_index, Vector<String> message_types, Vector<String> messages)
|
||||
{
|
||||
client().async_did_get_js_console_messages(m_id, start_index, move(message_types), move(messages));
|
||||
}
|
||||
|
|
|
@ -82,12 +82,12 @@ public:
|
|||
void ready_to_paint();
|
||||
|
||||
void initialize_js_console(Web::DOM::Document& document);
|
||||
void js_console_input(ByteString const& js_source);
|
||||
void run_javascript(ByteString const& js_source);
|
||||
void js_console_input(StringView js_source);
|
||||
void run_javascript(StringView js_source);
|
||||
void js_console_request_messages(i32 start_index);
|
||||
void did_output_js_console_message(i32 message_index);
|
||||
void console_peer_did_misbehave(char const* reason);
|
||||
void did_get_js_console_messages(i32 start_index, Vector<ByteString> message_types, Vector<ByteString> messages);
|
||||
void did_get_js_console_messages(i32 start_index, Vector<String> message_types, Vector<String> messages);
|
||||
|
||||
Vector<Web::CSS::StyleSheetIdentifier> list_style_sheets() const;
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ endpoint WebContentClient
|
|||
did_change_audio_play_state(u64 page_id, Web::HTML::AudioPlayState play_state) =|
|
||||
|
||||
did_output_js_console_message(u64 page_id, i32 message_index) =|
|
||||
did_get_js_console_messages(u64 page_id, i32 start_index, Vector<ByteString> message_types, Vector<ByteString> messages) =|
|
||||
did_get_js_console_messages(u64 page_id, i32 start_index, Vector<String> message_types, Vector<String> messages) =|
|
||||
|
||||
did_finish_text_test(u64 page_id, String text) =|
|
||||
did_set_test_timeout(u64 page_id, double milliseconds) =|
|
||||
|
|
|
@ -43,7 +43,7 @@ void WebContentConsoleClient::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(m_console_global_environment_extensions);
|
||||
}
|
||||
|
||||
void WebContentConsoleClient::handle_input(ByteString const& js_source)
|
||||
void WebContentConsoleClient::handle_input(StringView js_source)
|
||||
{
|
||||
if (!m_console_global_environment_extensions)
|
||||
return;
|
||||
|
@ -58,16 +58,16 @@ void WebContentConsoleClient::handle_input(ByteString const& js_source)
|
|||
|
||||
if (result.value().has_value()) {
|
||||
m_console_global_environment_extensions->set_most_recent_result(result.value().value());
|
||||
print_html(JS::MarkupGenerator::html_from_value(*result.value()).release_value_but_fixme_should_propagate_errors().to_byte_string());
|
||||
print_html(JS::MarkupGenerator::html_from_value(*result.value()).release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentConsoleClient::report_exception(JS::Error const& exception, bool in_promise)
|
||||
{
|
||||
print_html(JS::MarkupGenerator::html_from_error(exception, in_promise).release_value_but_fixme_should_propagate_errors().to_byte_string());
|
||||
print_html(JS::MarkupGenerator::html_from_error(exception, in_promise).release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
|
||||
void WebContentConsoleClient::print_html(ByteString const& line)
|
||||
void WebContentConsoleClient::print_html(String const& line)
|
||||
{
|
||||
m_message_log.append({ .type = ConsoleOutput::Type::HTML, .data = line });
|
||||
m_client->did_output_js_console_message(m_message_log.size() - 1);
|
||||
|
@ -75,11 +75,11 @@ void WebContentConsoleClient::print_html(ByteString const& line)
|
|||
|
||||
void WebContentConsoleClient::clear_output()
|
||||
{
|
||||
m_message_log.append({ .type = ConsoleOutput::Type::Clear, .data = "" });
|
||||
m_message_log.append({ .type = ConsoleOutput::Type::Clear, .data = String {} });
|
||||
m_client->did_output_js_console_message(m_message_log.size() - 1);
|
||||
}
|
||||
|
||||
void WebContentConsoleClient::begin_group(ByteString const& label, bool start_expanded)
|
||||
void WebContentConsoleClient::begin_group(String const& label, bool start_expanded)
|
||||
{
|
||||
m_message_log.append({ .type = start_expanded ? ConsoleOutput::Type::BeginGroup : ConsoleOutput::Type::BeginGroupCollapsed, .data = label });
|
||||
m_client->did_output_js_console_message(m_message_log.size() - 1);
|
||||
|
@ -87,7 +87,7 @@ void WebContentConsoleClient::begin_group(ByteString const& label, bool start_ex
|
|||
|
||||
void WebContentConsoleClient::end_group()
|
||||
{
|
||||
m_message_log.append({ .type = ConsoleOutput::Type::EndGroup, .data = "" });
|
||||
m_message_log.append({ .type = ConsoleOutput::Type::EndGroup, .data = String {} });
|
||||
m_client->did_output_js_console_message(m_message_log.size() - 1);
|
||||
}
|
||||
|
||||
|
@ -105,8 +105,8 @@ void WebContentConsoleClient::send_messages(i32 start_index)
|
|||
}
|
||||
|
||||
// FIXME: Replace with a single Vector of message structs
|
||||
Vector<ByteString> message_types;
|
||||
Vector<ByteString> messages;
|
||||
Vector<String> message_types;
|
||||
Vector<String> messages;
|
||||
message_types.ensure_capacity(messages_to_send);
|
||||
messages.ensure_capacity(messages_to_send);
|
||||
|
||||
|
@ -114,26 +114,26 @@ void WebContentConsoleClient::send_messages(i32 start_index)
|
|||
auto& message = m_message_log[i];
|
||||
switch (message.type) {
|
||||
case ConsoleOutput::Type::HTML:
|
||||
message_types.append("html"sv);
|
||||
message_types.append("html"_string);
|
||||
break;
|
||||
case ConsoleOutput::Type::Clear:
|
||||
message_types.append("clear"sv);
|
||||
message_types.append("clear"_string);
|
||||
break;
|
||||
case ConsoleOutput::Type::BeginGroup:
|
||||
message_types.append("group"sv);
|
||||
message_types.append("group"_string);
|
||||
break;
|
||||
case ConsoleOutput::Type::BeginGroupCollapsed:
|
||||
message_types.append("groupCollapsed"sv);
|
||||
message_types.append("groupCollapsed"_string);
|
||||
break;
|
||||
case ConsoleOutput::Type::EndGroup:
|
||||
message_types.append("groupEnd"sv);
|
||||
message_types.append("groupEnd"_string);
|
||||
break;
|
||||
}
|
||||
|
||||
messages.append(message.data);
|
||||
}
|
||||
|
||||
m_client->did_get_js_console_messages(start_index, message_types, messages);
|
||||
m_client->did_get_js_console_messages(start_index, move(message_types), move(messages));
|
||||
}
|
||||
|
||||
void WebContentConsoleClient::clear()
|
||||
|
@ -215,7 +215,7 @@ JS::ThrowCompletionOr<JS::Value> WebContentConsoleClient::printer(JS::Console::L
|
|||
html.appendff("</tbody>");
|
||||
html.appendff("</table>");
|
||||
html.appendff("</div>");
|
||||
print_html(html.string_view());
|
||||
print_html(MUST(html.to_string()));
|
||||
|
||||
auto output = TRY(generically_format_values(table_args));
|
||||
m_console->output_debug_message(log_level, output);
|
||||
|
@ -234,13 +234,13 @@ JS::ThrowCompletionOr<JS::Value> WebContentConsoleClient::printer(JS::Console::L
|
|||
html.appendff("-> {}<br>", escape_html_entities(function_name));
|
||||
html.append("</span>"sv);
|
||||
|
||||
print_html(html.string_view());
|
||||
print_html(MUST(html.to_string()));
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
if (log_level == JS::Console::LogLevel::Group || log_level == JS::Console::LogLevel::GroupCollapsed) {
|
||||
auto group = arguments.get<JS::Console::Group>();
|
||||
begin_group(ByteString::formatted("<span style='{}'>{}</span>", styling, escape_html_entities(group.label)), log_level == JS::Console::LogLevel::Group);
|
||||
begin_group(MUST(String::formatted("<span style='{}'>{}</span>", styling, escape_html_entities(group.label))), log_level == JS::Console::LogLevel::Group);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
|
@ -272,7 +272,7 @@ JS::ThrowCompletionOr<JS::Value> WebContentConsoleClient::printer(JS::Console::L
|
|||
|
||||
html.append(escape_html_entities(output));
|
||||
html.append("</span>"sv);
|
||||
print_html(html.string_view());
|
||||
print_html(MUST(html.to_string()));
|
||||
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <AK/Weakable.h>
|
||||
#include <LibJS/Console.h>
|
||||
|
@ -25,7 +26,7 @@ class WebContentConsoleClient final : public JS::ConsoleClient {
|
|||
public:
|
||||
virtual ~WebContentConsoleClient() override;
|
||||
|
||||
void handle_input(ByteString const& js_source);
|
||||
void handle_input(StringView js_source);
|
||||
void send_messages(i32 start_index);
|
||||
void report_exception(JS::Error const&, bool) override;
|
||||
|
||||
|
@ -46,8 +47,8 @@ private:
|
|||
GC::Ptr<ConsoleGlobalEnvironmentExtensions> m_console_global_environment_extensions;
|
||||
|
||||
void clear_output();
|
||||
void print_html(ByteString const& line);
|
||||
void begin_group(ByteString const& label, bool start_expanded);
|
||||
void print_html(String const& line);
|
||||
void begin_group(String const& label, bool start_expanded);
|
||||
virtual void end_group() override;
|
||||
|
||||
struct ConsoleOutput {
|
||||
|
@ -59,7 +60,7 @@ private:
|
|||
EndGroup,
|
||||
};
|
||||
Type type;
|
||||
ByteString data;
|
||||
String data;
|
||||
};
|
||||
Vector<ConsoleOutput> m_message_log;
|
||||
|
||||
|
|
|
@ -48,8 +48,11 @@ endpoint WebContentServer
|
|||
highlight_dom_node(u64 page_id, Web::UniqueNodeID node_id, Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element) =|
|
||||
inspect_accessibility_tree(u64 page_id) =|
|
||||
get_hovered_node_id(u64 page_id) =|
|
||||
js_console_input(u64 page_id, ByteString js_source) =|
|
||||
|
||||
js_console_input(u64 page_id, String js_source) =|
|
||||
js_console_request_messages(u64 page_id, i32 start_index) =|
|
||||
run_javascript(u64 page_id, String js_source) =|
|
||||
|
||||
list_style_sheets(u64 page_id) =|
|
||||
request_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier identifier) =|
|
||||
|
||||
|
@ -68,8 +71,6 @@ endpoint WebContentServer
|
|||
|
||||
request_internal_page_info(u64 page_id, WebView::PageInfoType type) =|
|
||||
|
||||
run_javascript(u64 page_id, ByteString js_source) =|
|
||||
|
||||
get_selected_text(u64 page_id) => (ByteString selection)
|
||||
select_all(u64 page_id) =|
|
||||
paste(u64 page_id, String text) =|
|
||||
|
|
Loading…
Add table
Reference in a new issue