1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

Ladybird+LibWebView: Extract common JS console functionality to a helper

This creates WebView::ConsoleClient to handle functionality that will be
common to the JS consoles of all Ladybird chromes. This will let each
chrome focus on just the UI.

Note that this includes the `console.group` functionality that only the
Serenity chrome previously had. This was a FIXME in the Qt chrome, and
it is implemented such that all chromes will receive this functionality
for free.
This commit is contained in:
Timothy Flynn 2023-08-29 11:44:18 -04:00 committed by Andrew Kaster
parent c9b9278092
commit bf59e06d2a
11 changed files with 300 additions and 366 deletions

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/Span.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibWebView/Forward.h>
namespace WebView {
class ConsoleClient {
public:
explicit ConsoleClient(ViewImplementation& content_web_view, ViewImplementation& console_web_view);
~ConsoleClient();
void execute(StringView);
void clear();
void reset();
private:
void handle_console_message(i32 message_index);
void handle_console_messages(i32 start_index, ReadonlySpan<DeprecatedString> message_types, ReadonlySpan<DeprecatedString> messages);
void print_source(StringView);
void print_html(StringView);
void request_console_messages();
void request_console_messages(i32 start_index);
void begin_group(StringView label, bool start_expanded);
void end_group();
ViewImplementation& m_content_web_view;
ViewImplementation& m_console_web_view;
i32 m_highest_notified_message_index { -1 };
i32 m_highest_received_message_index { -1 };
bool m_waiting_for_messages { false };
struct Group {
int id { 0 };
DeprecatedString label;
};
Vector<Group> m_group_stack;
int m_next_group_id { 1 };
};
}