mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-02 15:46:33 +00:00
Everywhere: Hoist the Libraries folder to the top-level
This commit is contained in:
parent
950e819ee7
commit
93712b24bf
Notes:
github-actions[bot]
2024-11-10 11:51:52 +00:00
Author: https://github.com/trflynn89
Commit: 93712b24bf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2256
Reviewed-by: https://github.com/sideshowbarker
4547 changed files with 104 additions and 113 deletions
75
Libraries/LibWeb/WebSockets/WebSocket.h
Normal file
75
Libraries/LibWeb/WebSockets/WebSocket.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022, Dex♪ <dexes.ttp@gmail.com>
|
||||
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibRequests/Forward.h>
|
||||
#include <LibRequests/WebSocket.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
#define ENUMERATE_WEBSOCKET_EVENT_HANDLERS(E) \
|
||||
E(onerror, HTML::EventNames::error) \
|
||||
E(onclose, HTML::EventNames::close) \
|
||||
E(onopen, HTML::EventNames::open) \
|
||||
E(onmessage, HTML::EventNames::message)
|
||||
|
||||
namespace Web::WebSockets {
|
||||
|
||||
class WebSocket final : public DOM::EventTarget {
|
||||
WEB_PLATFORM_OBJECT(WebSocket, DOM::EventTarget);
|
||||
JS_DECLARE_ALLOCATOR(WebSocket);
|
||||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<WebSocket>> construct_impl(JS::Realm&, String const& url, Optional<Variant<String, Vector<String>>> const& protocols);
|
||||
|
||||
virtual ~WebSocket() override;
|
||||
|
||||
WebIDL::ExceptionOr<String> url() const { return TRY_OR_THROW_OOM(vm(), m_url.to_string()); }
|
||||
void set_url(URL::URL url) { m_url = move(url); }
|
||||
|
||||
#undef __ENUMERATE
|
||||
#define __ENUMERATE(attribute_name, event_name) \
|
||||
void set_##attribute_name(WebIDL::CallbackType*); \
|
||||
WebIDL::CallbackType* attribute_name();
|
||||
ENUMERATE_WEBSOCKET_EVENT_HANDLERS(__ENUMERATE)
|
||||
#undef __ENUMERATE
|
||||
|
||||
Requests::WebSocket::ReadyState ready_state() const;
|
||||
String extensions() const;
|
||||
WebIDL::ExceptionOr<String> protocol() const;
|
||||
|
||||
String const& binary_type() { return m_binary_type; }
|
||||
void set_binary_type(String const& type) { m_binary_type = type; }
|
||||
|
||||
WebIDL::ExceptionOr<void> close(Optional<u16> code, Optional<String> reason);
|
||||
WebIDL::ExceptionOr<void> send(Variant<JS::Handle<WebIDL::BufferSource>, JS::Handle<FileAPI::Blob>, String> const& data);
|
||||
|
||||
private:
|
||||
void on_open();
|
||||
void on_message(ByteBuffer message, bool is_text);
|
||||
void on_error();
|
||||
void on_close(u16 code, String reason, bool was_clean);
|
||||
|
||||
WebSocket(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
ErrorOr<void> establish_web_socket_connection(URL::URL& url_record, Vector<String>& protocols, HTML::EnvironmentSettingsObject& client);
|
||||
|
||||
URL::URL m_url;
|
||||
String m_binary_type { "blob"_string };
|
||||
RefPtr<Requests::WebSocket> m_websocket;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue