mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:27:35 +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:
parent
daf5484d6b
commit
6dfb2f9dc8
56 changed files with 231 additions and 845 deletions
|
@ -66,6 +66,10 @@ namespace Web {
|
|||
constexpr auto default_user_agent = "Mozilla/5.0 (" OS_STRING "; " CPU_STRING ") " BROWSER_NAME "/" BROWSER_VERSION ""sv;
|
||||
constexpr auto default_platform = OS_STRING " " CPU_STRING ""sv;
|
||||
|
||||
namespace WebSockets {
|
||||
class WebSocketClientSocket;
|
||||
}
|
||||
|
||||
class ResourceLoaderConnectorRequest : public RefCounted<ResourceLoaderConnectorRequest> {
|
||||
public:
|
||||
virtual ~ResourceLoaderConnectorRequest();
|
||||
|
@ -97,6 +101,7 @@ public:
|
|||
virtual void preconnect(URL const&) = 0;
|
||||
|
||||
virtual RefPtr<ResourceLoaderConnectorRequest> start_request(ByteString const& method, URL const&, HashMap<ByteString, ByteString> const& request_headers = {}, ReadonlyBytes request_body = {}, Core::ProxyData const& = {}) = 0;
|
||||
virtual RefPtr<Web::WebSockets::WebSocketClientSocket> websocket_connect(const URL&, ByteString const& origin, Vector<ByteString> const& protocols) = 0;
|
||||
|
||||
protected:
|
||||
explicit ResourceLoaderConnector();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <LibWeb/HTML/MessageEvent.h>
|
||||
#include <LibWeb/HTML/Origin.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||
#include <LibWeb/WebIDL/Buffers.h>
|
||||
#include <LibWeb/WebIDL/DOMException.h>
|
||||
|
@ -29,28 +30,8 @@ namespace Web::WebSockets {
|
|||
|
||||
JS_DEFINE_ALLOCATOR(WebSocket);
|
||||
|
||||
static RefPtr<WebSocketClientManager> s_websocket_client_manager;
|
||||
|
||||
void WebSocketClientManager::initialize(RefPtr<WebSocketClientManager> websocket_client_manager)
|
||||
{
|
||||
s_websocket_client_manager = websocket_client_manager;
|
||||
}
|
||||
|
||||
WebSocketClientManager& WebSocketClientManager::the()
|
||||
{
|
||||
if (!s_websocket_client_manager) [[unlikely]] {
|
||||
dbgln("Web::WebSockets::WebSocketClientManager was not initialized!");
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
return *s_websocket_client_manager;
|
||||
}
|
||||
|
||||
WebSocketClientSocket::WebSocketClientSocket() = default;
|
||||
|
||||
WebSocketClientSocket::~WebSocketClientSocket() = default;
|
||||
|
||||
WebSocketClientManager::WebSocketClientManager() = default;
|
||||
|
||||
// https://websockets.spec.whatwg.org/#dom-websocket-websocket
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebSocket>> WebSocket::construct_impl(JS::Realm& realm, String const& url, Optional<Variant<String, Vector<String>>> const& protocols)
|
||||
{
|
||||
|
@ -148,7 +129,7 @@ ErrorOr<void> WebSocket::establish_web_socket_connection(URL& url_record, Vector
|
|||
for (auto const& protocol : protocols)
|
||||
TRY(protcol_byte_strings.try_append(protocol.to_byte_string()));
|
||||
|
||||
m_websocket = WebSocketClientManager::the().connect(url_record, origin_string, protcol_byte_strings);
|
||||
m_websocket = ResourceLoader::the().connector().websocket_connect(url_record, origin_string, protcol_byte_strings);
|
||||
m_websocket->on_open = [weak_this = make_weak_ptr<WebSocket>()] {
|
||||
if (!weak_this)
|
||||
return;
|
||||
|
|
|
@ -114,19 +114,7 @@ public:
|
|||
Function<CertificateAndKey()> on_certificate_requested;
|
||||
|
||||
protected:
|
||||
explicit WebSocketClientSocket();
|
||||
};
|
||||
|
||||
class WebSocketClientManager : public Core::EventReceiver {
|
||||
C_OBJECT_ABSTRACT(WebSocketClientManager)
|
||||
public:
|
||||
static void initialize(RefPtr<WebSocketClientManager>);
|
||||
static WebSocketClientManager& the();
|
||||
|
||||
virtual RefPtr<WebSocketClientSocket> connect(URL const&, ByteString const& origin, Vector<ByteString> const& protocols) = 0;
|
||||
|
||||
protected:
|
||||
explicit WebSocketClientManager();
|
||||
explicit WebSocketClientSocket() = default;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue