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

Everywhere: Merge the WebSocket service into RequestServer

This keeps the APIs separate as they are wildly different, a future
improvement could be to somehow unify the APIs (if possible).

Closes #23080.
This commit is contained in:
Ali Mohammad Pur 2024-03-06 01:50:52 +01:00 committed by Jelle Raaijmakers
parent daf5484d6b
commit 6dfb2f9dc8
56 changed files with 231 additions and 845 deletions

View file

@ -40,8 +40,6 @@ set(GENERATED_SOURCES
../../Services/WebContent/WebContentServerEndpoint.h
../../Services/WebContent/WebDriverClientEndpoint.h
../../Services/WebContent/WebDriverServerEndpoint.h
../../Services/WebSocket/WebSocketClientEndpoint.h
../../Services/WebSocket/WebSocketServerEndpoint.h
NativeStyleSheetSource.cpp
)

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "WebSocketClientAdapter.h"
#include <LibProtocol/Request.h>
#include <LibProtocol/RequestClient.h>
#include <LibWebView/RequestServerAdapter.h>
@ -94,6 +95,14 @@ RefPtr<Web::ResourceLoaderConnectorRequest> RequestServerAdapter::start_request(
return RequestServerRequestAdapter::try_create(protocol_request.release_nonnull()).release_value_but_fixme_should_propagate_errors();
}
RefPtr<Web::WebSockets::WebSocketClientSocket> RequestServerAdapter::websocket_connect(AK::URL const& url, AK::ByteString const& origin, Vector<AK::ByteString> const& protocols)
{
auto underlying_websocket = m_protocol_client->websocket_connect(url, origin, protocols);
if (!underlying_websocket)
return {};
return WebSocketClientSocketAdapter::create(underlying_websocket.release_nonnull());
}
void RequestServerAdapter::prefetch_dns(URL const& url)
{
m_protocol_client->ensure_connection(url, RequestServer::CacheLevel::ResolveOnly);

View file

@ -9,6 +9,7 @@
#include <AK/Function.h>
#include <AK/URL.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/WebSockets/WebSocket.h>
namespace Protocol {
class Request;
@ -46,6 +47,7 @@ public:
virtual void preconnect(URL const& url) override;
virtual RefPtr<Web::ResourceLoaderConnectorRequest> start_request(ByteString const& method, URL const&, HashMap<ByteString, ByteString> const& request_headers = {}, ReadonlyBytes request_body = {}, Core::ProxyData const& = {}) override;
virtual RefPtr<Web::WebSockets::WebSocketClientSocket> websocket_connect(const URL&, ByteString const& origin, Vector<ByteString> const& protocols) override;
private:
RefPtr<Protocol::RequestClient> m_protocol_client;

View file

@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibProtocol/RequestClient.h>
#include <LibProtocol/WebSocket.h>
#include <LibProtocol/WebSocketClient.h>
#include <LibWebView/WebSocketClientAdapter.h>
namespace WebView {
@ -107,30 +107,4 @@ void WebSocketClientSocketAdapter::close(u16 code, ByteString reason)
m_websocket->close(code, reason);
}
ErrorOr<NonnullRefPtr<WebSocketClientManagerAdapter>> WebSocketClientManagerAdapter::try_create(NonnullRefPtr<Protocol::WebSocketClient> websocket_client)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) WebSocketClientManagerAdapter(move(websocket_client)));
}
ErrorOr<NonnullRefPtr<WebSocketClientManagerAdapter>> WebSocketClientManagerAdapter::try_create()
{
auto websocket_client = TRY(Protocol::WebSocketClient::try_create());
return adopt_nonnull_ref_or_enomem(new (nothrow) WebSocketClientManagerAdapter(move(websocket_client)));
}
WebSocketClientManagerAdapter::WebSocketClientManagerAdapter(NonnullRefPtr<Protocol::WebSocketClient> websocket_client)
: m_websocket_client(move(websocket_client))
{
}
WebSocketClientManagerAdapter::~WebSocketClientManagerAdapter() = default;
RefPtr<Web::WebSockets::WebSocketClientSocket> WebSocketClientManagerAdapter::connect(const URL& url, ByteString const& origin, Vector<ByteString> const& protocols)
{
auto underlying_websocket = m_websocket_client->connect(url, origin, protocols);
if (!underlying_websocket)
return {};
return WebSocketClientSocketAdapter::create(underlying_websocket.release_nonnull());
}
}

View file

@ -13,7 +13,7 @@
namespace Protocol {
class WebSocket;
class WebSocketClient;
class RequestClient;
};
namespace WebView {
@ -38,19 +38,4 @@ private:
NonnullRefPtr<Protocol::WebSocket> m_websocket;
};
class WebSocketClientManagerAdapter : public Web::WebSockets::WebSocketClientManager {
public:
static ErrorOr<NonnullRefPtr<WebSocketClientManagerAdapter>> try_create(NonnullRefPtr<Protocol::WebSocketClient>);
static ErrorOr<NonnullRefPtr<WebSocketClientManagerAdapter>> try_create();
virtual ~WebSocketClientManagerAdapter() override;
virtual RefPtr<Web::WebSockets::WebSocketClientSocket> connect(const URL&, ByteString const& origin, Vector<ByteString> const& protocols) override;
private:
WebSocketClientManagerAdapter(NonnullRefPtr<Protocol::WebSocketClient>);
NonnullRefPtr<Protocol::WebSocketClient> m_websocket_client;
};
}