LibWebView+WebContent: Create a different console client for DevTools

Our existing WebContentConsoleClient is very specific to our home-grown
Inspector. It renders console output to an HTML string. For DevTools, we
will not want this behavior; we will want to send representations of raw
JS values.

This patch makes WebContentConsoleClient a base class to handle console
input from the user, either from the Inspector or from DevTools. It then
moves the HTML rendering needed for the Inspector to a new class,
InspectorConsoleClient. And we add a DevToolsConsoleClient (currently
just stubbed) to handle needs specific to DevTools.

We choose at runtime which console client to install, based on the
--devtools command line flag.
This commit is contained in:
Timothy Flynn 2025-02-24 09:48:13 -05:00 committed by Andreas Kling
commit 37f07c176a
Notes: github-actions[bot] 2025-02-28 12:09:47 +00:00
12 changed files with 419 additions and 229 deletions

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Console.h>
#include <LibJS/Forward.h>
#include <LibWeb/Forward.h>
#include <WebContent/Forward.h>
#include <WebContent/WebContentConsoleClient.h>
namespace WebContent {
class DevToolsConsoleClient final : public WebContentConsoleClient {
GC_CELL(DevToolsConsoleClient, WebContentConsoleClient);
GC_DECLARE_ALLOCATOR(DevToolsConsoleClient);
public:
static GC::Ref<DevToolsConsoleClient> create(JS::Realm&, JS::Console&, PageClient&);
virtual ~DevToolsConsoleClient() override;
private:
DevToolsConsoleClient(JS::Realm&, JS::Console&, PageClient&, ConsoleGlobalEnvironmentExtensions&);
virtual void handle_result(JS::Value) override;
virtual void report_exception(JS::Error const&, bool) override;
virtual void send_messages(i32 start_index) override;
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
};
}