mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 18:15:09 +00:00
LibWeb: Move WebSocket into the Web::WebSockets namespace
WebSockets got moved from the HTML standard to their own, the new WebSockets Standard (https://websockets.spec.whatwg.org). Move the IDL file and implementation into a new WebSockets directory and C++ namespace accordingly.
This commit is contained in:
parent
c001e3f2fd
commit
fb1dca2c4b
7 changed files with 34 additions and 28 deletions
|
@ -2370,6 +2370,8 @@ void generate_constructor_implementation(IDL::Interface const& interface)
|
||||||
# include <LibWeb/SVG/@name@.h>
|
# include <LibWeb/SVG/@name@.h>
|
||||||
#elif __has_include(<LibWeb/Selection/@name@.h>)
|
#elif __has_include(<LibWeb/Selection/@name@.h>)
|
||||||
# include <LibWeb/Selection/@name@.h>
|
# include <LibWeb/Selection/@name@.h>
|
||||||
|
#elif __has_include(<LibWeb/WebSockets/@name@.h>)
|
||||||
|
# include <LibWeb/WebSockets/@name@.h>
|
||||||
#elif __has_include(<LibWeb/XHR/@name@.h>)
|
#elif __has_include(<LibWeb/XHR/@name@.h>)
|
||||||
# include <LibWeb/XHR/@name@.h>
|
# include <LibWeb/XHR/@name@.h>
|
||||||
#elif __has_include(<LibWeb/URL/@name@.h>)
|
#elif __has_include(<LibWeb/URL/@name@.h>)
|
||||||
|
@ -2648,8 +2650,9 @@ using namespace Web::NavigationTiming;
|
||||||
using namespace Web::RequestIdleCallback;
|
using namespace Web::RequestIdleCallback;
|
||||||
using namespace Web::ResizeObserver;
|
using namespace Web::ResizeObserver;
|
||||||
using namespace Web::Selection;
|
using namespace Web::Selection;
|
||||||
using namespace Web::XHR;
|
|
||||||
using namespace Web::URL;
|
using namespace Web::URL;
|
||||||
|
using namespace Web::WebSockets;
|
||||||
|
using namespace Web::XHR;
|
||||||
|
|
||||||
namespace Web::Bindings {
|
namespace Web::Bindings {
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto interface = IDL::Parser(path, data, import_base_path).parse();
|
auto interface = IDL::Parser(path, data, import_base_path).parse();
|
||||||
|
|
||||||
if (namespace_.is_one_of("Crypto", "CSS", "DOM", "Encoding", "HTML", "UIEvents", "Geometry", "HighResolutionTime", "IntersectionObserver", "NavigationTiming", "RequestIdleCallback", "ResizeObserver", "SVG", "Selection", "XHR", "URL")) {
|
if (namespace_.is_one_of("Crypto", "CSS", "DOM", "Encoding", "HTML", "UIEvents", "Geometry", "HighResolutionTime", "IntersectionObserver", "NavigationTiming", "RequestIdleCallback", "ResizeObserver", "SVG", "Selection", "URL", "WebSockets", "XHR")) {
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(namespace_);
|
builder.append(namespace_);
|
||||||
builder.append("::");
|
builder.append("::");
|
||||||
|
|
|
@ -205,7 +205,6 @@ set(SOURCES
|
||||||
HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
|
HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
|
||||||
HTML/TagNames.cpp
|
HTML/TagNames.cpp
|
||||||
HTML/TextMetrics.cpp
|
HTML/TextMetrics.cpp
|
||||||
HTML/WebSocket.cpp
|
|
||||||
HTML/Worker.cpp
|
HTML/Worker.cpp
|
||||||
HTML/WorkerDebugConsoleClient.cpp
|
HTML/WorkerDebugConsoleClient.cpp
|
||||||
HTML/WorkerGlobalScope.cpp
|
HTML/WorkerGlobalScope.cpp
|
||||||
|
@ -310,6 +309,7 @@ set(SOURCES
|
||||||
WebAssembly/WebAssemblyTableObject.cpp
|
WebAssembly/WebAssemblyTableObject.cpp
|
||||||
WebAssembly/WebAssemblyTablePrototype.cpp
|
WebAssembly/WebAssemblyTablePrototype.cpp
|
||||||
WebContentClient.cpp
|
WebContentClient.cpp
|
||||||
|
WebSockets/WebSocket.cpp
|
||||||
XHR/EventNames.cpp
|
XHR/EventNames.cpp
|
||||||
XHR/XMLHttpRequest.cpp
|
XHR/XMLHttpRequest.cpp
|
||||||
XHR/XMLHttpRequestEventTarget.cpp
|
XHR/XMLHttpRequestEventTarget.cpp
|
||||||
|
@ -519,7 +519,6 @@ libweb_js_wrapper(HTML/PromiseRejectionEvent)
|
||||||
libweb_js_wrapper(HTML/Storage)
|
libweb_js_wrapper(HTML/Storage)
|
||||||
libweb_js_wrapper(HTML/SubmitEvent)
|
libweb_js_wrapper(HTML/SubmitEvent)
|
||||||
libweb_js_wrapper(HTML/TextMetrics)
|
libweb_js_wrapper(HTML/TextMetrics)
|
||||||
libweb_js_wrapper(HTML/WebSocket)
|
|
||||||
libweb_js_wrapper(HTML/Worker)
|
libweb_js_wrapper(HTML/Worker)
|
||||||
libweb_js_wrapper(HTML/WorkerGlobalScope)
|
libweb_js_wrapper(HTML/WorkerGlobalScope)
|
||||||
libweb_js_wrapper(HTML/WorkerLocation)
|
libweb_js_wrapper(HTML/WorkerLocation)
|
||||||
|
@ -547,6 +546,7 @@ libweb_js_wrapper(UIEvents/MouseEvent)
|
||||||
libweb_js_wrapper(UIEvents/UIEvent)
|
libweb_js_wrapper(UIEvents/UIEvent)
|
||||||
libweb_js_wrapper(URL/URL)
|
libweb_js_wrapper(URL/URL)
|
||||||
libweb_js_wrapper(URL/URLSearchParams ITERABLE)
|
libweb_js_wrapper(URL/URLSearchParams ITERABLE)
|
||||||
|
libweb_js_wrapper(WebSockets/WebSocket)
|
||||||
libweb_js_wrapper(XHR/ProgressEvent)
|
libweb_js_wrapper(XHR/ProgressEvent)
|
||||||
libweb_js_wrapper(XHR/XMLHttpRequest)
|
libweb_js_wrapper(XHR/XMLHttpRequest)
|
||||||
libweb_js_wrapper(XHR/XMLHttpRequestEventTarget)
|
libweb_js_wrapper(XHR/XMLHttpRequestEventTarget)
|
||||||
|
|
|
@ -219,7 +219,6 @@ class WorkerDebugConsoleClient;
|
||||||
class Storage;
|
class Storage;
|
||||||
class SubmitEvent;
|
class SubmitEvent;
|
||||||
class TextMetrics;
|
class TextMetrics;
|
||||||
class WebSocket;
|
|
||||||
class WindowEnvironmentSettingsObject;
|
class WindowEnvironmentSettingsObject;
|
||||||
class Worker;
|
class Worker;
|
||||||
class WorkerEnvironmentSettingsObject;
|
class WorkerEnvironmentSettingsObject;
|
||||||
|
@ -270,6 +269,10 @@ namespace Web::Selection {
|
||||||
class Selection;
|
class Selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Web::WebSockets {
|
||||||
|
class WebSocket;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Web::Layout {
|
namespace Web::Layout {
|
||||||
enum class LayoutMode;
|
enum class LayoutMode;
|
||||||
enum class PaintPhase;
|
enum class PaintPhase;
|
||||||
|
|
|
@ -23,10 +23,10 @@
|
||||||
#include <LibWeb/HTML/EventHandler.h>
|
#include <LibWeb/HTML/EventHandler.h>
|
||||||
#include <LibWeb/HTML/EventNames.h>
|
#include <LibWeb/HTML/EventNames.h>
|
||||||
#include <LibWeb/HTML/MessageEvent.h>
|
#include <LibWeb/HTML/MessageEvent.h>
|
||||||
#include <LibWeb/HTML/WebSocket.h>
|
|
||||||
#include <LibWeb/Origin.h>
|
#include <LibWeb/Origin.h>
|
||||||
|
#include <LibWeb/WebSockets/WebSocket.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::WebSockets {
|
||||||
|
|
||||||
WebSocketClientManager& WebSocketClientManager::the()
|
WebSocketClientManager& WebSocketClientManager::the()
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@ RefPtr<Protocol::WebSocket> WebSocketClientManager::connect(const AK::URL& url)
|
||||||
return m_websocket_client->connect(url);
|
return m_websocket_client->connect(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#the-websocket-interface
|
// https://websockets.spec.whatwg.org/#the-websocket-interface
|
||||||
DOM::ExceptionOr<NonnullRefPtr<WebSocket>> WebSocket::create_with_global_object(Bindings::WindowObject& window, const String& url)
|
DOM::ExceptionOr<NonnullRefPtr<WebSocket>> WebSocket::create_with_global_object(Bindings::WindowObject& window, const String& url)
|
||||||
{
|
{
|
||||||
AK::URL url_record(url);
|
AK::URL url_record(url);
|
||||||
|
@ -103,7 +103,7 @@ WebSocket::~WebSocket()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#the-websocket-interface
|
// https://websockets.spec.whatwg.org/#the-websocket-interface
|
||||||
WebSocket::ReadyState WebSocket::ready_state() const
|
WebSocket::ReadyState WebSocket::ready_state() const
|
||||||
{
|
{
|
||||||
if (!m_websocket)
|
if (!m_websocket)
|
||||||
|
@ -122,27 +122,27 @@ WebSocket::ReadyState WebSocket::ready_state() const
|
||||||
return WebSocket::ReadyState::Closed;
|
return WebSocket::ReadyState::Closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#the-websocket-interface
|
// https://websockets.spec.whatwg.org/#the-websocket-interface
|
||||||
String WebSocket::extensions() const
|
String WebSocket::extensions() const
|
||||||
{
|
{
|
||||||
if (!m_websocket)
|
if (!m_websocket)
|
||||||
return String::empty();
|
return String::empty();
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol
|
// https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
||||||
// FIXME: Change the extensions attribute's value to the extensions in use, if it is not the null value.
|
// FIXME: Change the extensions attribute's value to the extensions in use, if it is not the null value.
|
||||||
return String::empty();
|
return String::empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#the-websocket-interface
|
// https://websockets.spec.whatwg.org/#the-websocket-interface
|
||||||
String WebSocket::protocol() const
|
String WebSocket::protocol() const
|
||||||
{
|
{
|
||||||
if (!m_websocket)
|
if (!m_websocket)
|
||||||
return String::empty();
|
return String::empty();
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol
|
// https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
||||||
// FIXME: Change the protocol attribute's value to the subprotocol in use, if it is not the null value.
|
// FIXME: Change the protocol attribute's value to the subprotocol in use, if it is not the null value.
|
||||||
return String::empty();
|
return String::empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#the-websocket-interface
|
// https://websockets.spec.whatwg.org/#the-websocket-interface
|
||||||
DOM::ExceptionOr<void> WebSocket::close(u16 code, const String& reason)
|
DOM::ExceptionOr<void> WebSocket::close(u16 code, const String& reason)
|
||||||
{
|
{
|
||||||
// HACK : we should have an Optional<u16>
|
// HACK : we should have an Optional<u16>
|
||||||
|
@ -162,7 +162,7 @@ DOM::ExceptionOr<void> WebSocket::close(u16 code, const String& reason)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#the-websocket-interface
|
// https://websockets.spec.whatwg.org/#the-websocket-interface
|
||||||
DOM::ExceptionOr<void> WebSocket::send(const String& data)
|
DOM::ExceptionOr<void> WebSocket::send(const String& data)
|
||||||
{
|
{
|
||||||
auto state = ready_state();
|
auto state = ready_state();
|
||||||
|
@ -176,44 +176,44 @@ DOM::ExceptionOr<void> WebSocket::send(const String& data)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol
|
// https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
||||||
void WebSocket::on_open()
|
void WebSocket::on_open()
|
||||||
{
|
{
|
||||||
// 1. Change the readyState attribute's value to OPEN (1).
|
// 1. Change the readyState attribute's value to OPEN (1).
|
||||||
// 2. Change the extensions attribute's value to the extensions in use, if it is not the null value. [WSP]
|
// 2. Change the extensions attribute's value to the extensions in use, if it is not the null value. [WSP]
|
||||||
// 3. Change the protocol attribute's value to the subprotocol in use, if it is not the null value. [WSP]
|
// 3. Change the protocol attribute's value to the subprotocol in use, if it is not the null value. [WSP]
|
||||||
dispatch_event(DOM::Event::create(EventNames::open));
|
dispatch_event(DOM::Event::create(HTML::EventNames::open));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol
|
// https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
||||||
void WebSocket::on_error()
|
void WebSocket::on_error()
|
||||||
{
|
{
|
||||||
dispatch_event(DOM::Event::create(EventNames::error));
|
dispatch_event(DOM::Event::create(HTML::EventNames::error));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol
|
// https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
||||||
void WebSocket::on_close(u16 code, String reason, bool was_clean)
|
void WebSocket::on_close(u16 code, String reason, bool was_clean)
|
||||||
{
|
{
|
||||||
// 1. Change the readyState attribute's value to CLOSED. This is handled by the Protocol's WebSocket
|
// 1. Change the readyState attribute's value to CLOSED. This is handled by the Protocol's WebSocket
|
||||||
// 2. If [needed], fire an event named error at the WebSocket object. This is handled by the Protocol's WebSocket
|
// 2. If [needed], fire an event named error at the WebSocket object. This is handled by the Protocol's WebSocket
|
||||||
CloseEventInit event_init {};
|
HTML::CloseEventInit event_init {};
|
||||||
event_init.was_clean = was_clean;
|
event_init.was_clean = was_clean;
|
||||||
event_init.code = code;
|
event_init.code = code;
|
||||||
event_init.reason = move(reason);
|
event_init.reason = move(reason);
|
||||||
dispatch_event(CloseEvent::create(EventNames::close, event_init));
|
dispatch_event(HTML::CloseEvent::create(HTML::EventNames::close, event_init));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol
|
// https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
||||||
void WebSocket::on_message(ByteBuffer message, bool is_text)
|
void WebSocket::on_message(ByteBuffer message, bool is_text)
|
||||||
{
|
{
|
||||||
if (m_websocket->ready_state() != Protocol::WebSocket::ReadyState::Open)
|
if (m_websocket->ready_state() != Protocol::WebSocket::ReadyState::Open)
|
||||||
return;
|
return;
|
||||||
if (is_text) {
|
if (is_text) {
|
||||||
auto text_message = String(ReadonlyBytes(message));
|
auto text_message = String(ReadonlyBytes(message));
|
||||||
MessageEventInit event_init;
|
HTML::MessageEventInit event_init;
|
||||||
event_init.data = JS::js_string(wrapper()->vm(), text_message);
|
event_init.data = JS::js_string(wrapper()->vm(), text_message);
|
||||||
event_init.origin = url();
|
event_init.origin = url();
|
||||||
dispatch_event(MessageEvent::create(EventNames::message, event_init));
|
dispatch_event(HTML::MessageEvent::create(HTML::EventNames::message, event_init));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,10 +223,10 @@ void WebSocket::on_message(ByteBuffer message, bool is_text)
|
||||||
} else if (m_binary_type == "arraybuffer") {
|
} else if (m_binary_type == "arraybuffer") {
|
||||||
// type indicates that the data is Binary and binaryType is "arraybuffer"
|
// type indicates that the data is Binary and binaryType is "arraybuffer"
|
||||||
auto& global_object = wrapper()->global_object();
|
auto& global_object = wrapper()->global_object();
|
||||||
MessageEventInit event_init;
|
HTML::MessageEventInit event_init;
|
||||||
event_init.data = JS::ArrayBuffer::create(global_object, message);
|
event_init.data = JS::ArrayBuffer::create(global_object, message);
|
||||||
event_init.origin = url();
|
event_init.origin = url();
|
||||||
dispatch_event(MessageEvent::create(EventNames::message, event_init));
|
dispatch_event(HTML::MessageEvent::create(HTML::EventNames::message, event_init));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class WebSocketClient;
|
||||||
class WebSocket;
|
class WebSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::WebSockets {
|
||||||
|
|
||||||
class WebSocketClientManager : public Core::Object {
|
class WebSocketClientManager : public Core::Object {
|
||||||
C_OBJECT_ABSTRACT(WebSocketClientManager)
|
C_OBJECT_ABSTRACT(WebSocketClientManager)
|
Loading…
Add table
Add a link
Reference in a new issue