diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 0a63aca6b5..0d9c50b8f1 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -2370,6 +2370,8 @@ void generate_constructor_implementation(IDL::Interface const& interface) # include #elif __has_include() # include +#elif __has_include() +# include #elif __has_include() # include #elif __has_include() @@ -2648,8 +2650,9 @@ using namespace Web::NavigationTiming; using namespace Web::RequestIdleCallback; using namespace Web::ResizeObserver; using namespace Web::Selection; -using namespace Web::XHR; using namespace Web::URL; +using namespace Web::WebSockets; +using namespace Web::XHR; namespace Web::Bindings { diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/main.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/main.cpp index 2400156f8a..5bec84bedf 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/main.cpp @@ -85,7 +85,7 @@ int main(int argc, char** argv) 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; builder.append(namespace_); builder.append("::"); diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index fc74355c7b..ac91e1757d 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -205,7 +205,6 @@ set(SOURCES HTML/SyntaxHighlighter/SyntaxHighlighter.cpp HTML/TagNames.cpp HTML/TextMetrics.cpp - HTML/WebSocket.cpp HTML/Worker.cpp HTML/WorkerDebugConsoleClient.cpp HTML/WorkerGlobalScope.cpp @@ -310,6 +309,7 @@ set(SOURCES WebAssembly/WebAssemblyTableObject.cpp WebAssembly/WebAssemblyTablePrototype.cpp WebContentClient.cpp + WebSockets/WebSocket.cpp XHR/EventNames.cpp XHR/XMLHttpRequest.cpp XHR/XMLHttpRequestEventTarget.cpp @@ -519,7 +519,6 @@ libweb_js_wrapper(HTML/PromiseRejectionEvent) libweb_js_wrapper(HTML/Storage) libweb_js_wrapper(HTML/SubmitEvent) libweb_js_wrapper(HTML/TextMetrics) -libweb_js_wrapper(HTML/WebSocket) libweb_js_wrapper(HTML/Worker) libweb_js_wrapper(HTML/WorkerGlobalScope) libweb_js_wrapper(HTML/WorkerLocation) @@ -547,6 +546,7 @@ libweb_js_wrapper(UIEvents/MouseEvent) libweb_js_wrapper(UIEvents/UIEvent) libweb_js_wrapper(URL/URL) libweb_js_wrapper(URL/URLSearchParams ITERABLE) +libweb_js_wrapper(WebSockets/WebSocket) libweb_js_wrapper(XHR/ProgressEvent) libweb_js_wrapper(XHR/XMLHttpRequest) libweb_js_wrapper(XHR/XMLHttpRequestEventTarget) diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 8bbd0754fe..ec1567986d 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -219,7 +219,6 @@ class WorkerDebugConsoleClient; class Storage; class SubmitEvent; class TextMetrics; -class WebSocket; class WindowEnvironmentSettingsObject; class Worker; class WorkerEnvironmentSettingsObject; @@ -270,6 +269,10 @@ namespace Web::Selection { class Selection; } +namespace Web::WebSockets { +class WebSocket; +} + namespace Web::Layout { enum class LayoutMode; enum class PaintPhase; diff --git a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp similarity index 85% rename from Userland/Libraries/LibWeb/HTML/WebSocket.cpp rename to Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp index e6b924fa78..854962fcbe 100644 --- a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp +++ b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp @@ -23,10 +23,10 @@ #include #include #include -#include #include +#include -namespace Web::HTML { +namespace Web::WebSockets { WebSocketClientManager& WebSocketClientManager::the() { @@ -52,7 +52,7 @@ RefPtr WebSocketClientManager::connect(const AK::URL& 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> WebSocket::create_with_global_object(Bindings::WindowObject& window, const String& 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 { if (!m_websocket) @@ -122,27 +122,27 @@ WebSocket::ReadyState WebSocket::ready_state() const 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 { if (!m_websocket) 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. 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 { if (!m_websocket) 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. 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 WebSocket::close(u16 code, const String& reason) { // HACK : we should have an Optional @@ -162,7 +162,7 @@ DOM::ExceptionOr WebSocket::close(u16 code, const String& reason) return {}; } -// https://html.spec.whatwg.org/multipage/web-sockets.html#the-websocket-interface +// https://websockets.spec.whatwg.org/#the-websocket-interface DOM::ExceptionOr WebSocket::send(const String& data) { auto state = ready_state(); @@ -176,44 +176,44 @@ DOM::ExceptionOr WebSocket::send(const String& data) 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() { // 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] // 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() { - 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) { // 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 - CloseEventInit event_init {}; + HTML::CloseEventInit event_init {}; event_init.was_clean = was_clean; event_init.code = code; 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) { if (m_websocket->ready_state() != Protocol::WebSocket::ReadyState::Open) return; if (is_text) { 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.origin = url(); - dispatch_event(MessageEvent::create(EventNames::message, event_init)); + dispatch_event(HTML::MessageEvent::create(HTML::EventNames::message, event_init)); return; } @@ -223,10 +223,10 @@ void WebSocket::on_message(ByteBuffer message, bool is_text) } else if (m_binary_type == "arraybuffer") { // type indicates that the data is Binary and binaryType is "arraybuffer" auto& global_object = wrapper()->global_object(); - MessageEventInit event_init; + HTML::MessageEventInit event_init; event_init.data = JS::ArrayBuffer::create(global_object, message); event_init.origin = url(); - dispatch_event(MessageEvent::create(EventNames::message, event_init)); + dispatch_event(HTML::MessageEvent::create(HTML::EventNames::message, event_init)); return; } diff --git a/Userland/Libraries/LibWeb/HTML/WebSocket.h b/Userland/Libraries/LibWeb/WebSockets/WebSocket.h similarity index 99% rename from Userland/Libraries/LibWeb/HTML/WebSocket.h rename to Userland/Libraries/LibWeb/WebSockets/WebSocket.h index 29a141be89..79c93192bd 100644 --- a/Userland/Libraries/LibWeb/HTML/WebSocket.h +++ b/Userland/Libraries/LibWeb/WebSockets/WebSocket.h @@ -28,7 +28,7 @@ class WebSocketClient; class WebSocket; } -namespace Web::HTML { +namespace Web::WebSockets { class WebSocketClientManager : public Core::Object { C_OBJECT_ABSTRACT(WebSocketClientManager) diff --git a/Userland/Libraries/LibWeb/HTML/WebSocket.idl b/Userland/Libraries/LibWeb/WebSockets/WebSocket.idl similarity index 100% rename from Userland/Libraries/LibWeb/HTML/WebSocket.idl rename to Userland/Libraries/LibWeb/WebSockets/WebSocket.idl