ladybird/Userland/Libraries/LibWebView/ChromeProcess.h
Timothy Flynn 5f8d852dae LibWebView+UI: Migrate Ladybird's command line flags to LibWebView
Currently, if we want to add a new e.g. WebContent command line option,
we have to add it to all of Qt, AppKit, and headless-browser. (Or worse,
we only add it to one of these, and we have feature disparity).

To prevent this, this moves command line flags to WebView::Application.
The flags are assigned to ChromeOptions and WebContentOptions structs.
Each chrome can still add its platform-specific options; for example,
the Qt chrome has a flag to enable Qt networking.

There should be no behavior change here, other than that AppKit will now
support command line flags that were previously only supported by Qt.
2024-08-01 11:38:42 +02:00

73 lines
2 KiB
C++

/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/Function.h>
#include <AK/OwnPtr.h>
#include <AK/Types.h>
#include <LibCore/Socket.h>
#include <LibIPC/ConnectionFromClient.h>
#include <LibIPC/Forward.h>
#include <LibIPC/MultiServer.h>
#include <LibWebView/Options.h>
#include <LibWebView/UIProcessClientEndpoint.h>
#include <LibWebView/UIProcessServerEndpoint.h>
namespace WebView {
class UIProcessConnectionFromClient final
: public IPC::ConnectionFromClient<UIProcessClientEndpoint, UIProcessServerEndpoint> {
C_OBJECT(UIProcessConnectionFromClient);
public:
virtual ~UIProcessConnectionFromClient() override = default;
virtual void die() override;
Function<void(Vector<URL::URL> const&)> on_new_tab;
Function<void(Vector<URL::URL> const&)> on_new_window;
private:
UIProcessConnectionFromClient(NonnullOwnPtr<Core::LocalSocket>, int client_id);
virtual void create_new_tab(Vector<ByteString> const& urls) override;
virtual void create_new_window(Vector<ByteString> const& urls) override;
};
class ChromeProcess {
AK_MAKE_NONCOPYABLE(ChromeProcess);
AK_MAKE_DEFAULT_MOVABLE(ChromeProcess);
public:
enum class ProcessDisposition : u8 {
ContinueMainProcess,
ExitProcess,
};
static ErrorOr<ChromeProcess> create();
~ChromeProcess();
ErrorOr<ProcessDisposition> connect(Vector<ByteString> const& raw_urls, NewWindow new_window);
Function<void(Vector<URL::URL> const&)> on_new_tab;
Function<void(Vector<URL::URL> const&)> on_new_window;
private:
ChromeProcess() = default;
ErrorOr<void> connect_as_client(ByteString const& socket_path, Vector<ByteString> const& raw_urls, NewWindow new_window);
ErrorOr<void> connect_as_server(ByteString const& socket_path);
OwnPtr<IPC::MultiServer<UIProcessConnectionFromClient>> m_server_connection;
OwnPtr<Core::File> m_pid_file;
ByteString m_pid_path;
ByteString m_socket_path;
};
}