Browse Source

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.
Linus Groh 3 years ago
parent
commit
fb1dca2c4b

+ 4 - 1
Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp

@@ -2370,6 +2370,8 @@ void generate_constructor_implementation(IDL::Interface const& interface)
 #    include <LibWeb/SVG/@name@.h>
 #elif __has_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>)
 #    include <LibWeb/XHR/@name@.h>
 #elif __has_include(<LibWeb/URL/@name@.h>)
@@ -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 {
 

+ 1 - 1
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("::");

+ 2 - 2
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)

+ 4 - 1
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;

+ 22 - 22
Userland/Libraries/LibWeb/HTML/WebSocket.cpp → Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp

@@ -23,10 +23,10 @@
 #include <LibWeb/HTML/EventHandler.h>
 #include <LibWeb/HTML/EventNames.h>
 #include <LibWeb/HTML/MessageEvent.h>
-#include <LibWeb/HTML/WebSocket.h>
 #include <LibWeb/Origin.h>
+#include <LibWeb/WebSockets/WebSocket.h>
 
-namespace Web::HTML {
+namespace Web::WebSockets {
 
 WebSocketClientManager& WebSocketClientManager::the()
 {
@@ -52,7 +52,7 @@ RefPtr<Protocol::WebSocket> 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<NonnullRefPtr<WebSocket>> 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<void> WebSocket::close(u16 code, const String& reason)
 {
     // HACK : we should have an Optional<u16>
@@ -162,7 +162,7 @@ DOM::ExceptionOr<void> 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<void> WebSocket::send(const String& data)
 {
     auto state = ready_state();
@@ -176,44 +176,44 @@ DOM::ExceptionOr<void> 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;
     }
 

+ 1 - 1
Userland/Libraries/LibWeb/HTML/WebSocket.h → 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)

+ 0 - 0
Userland/Libraries/LibWeb/HTML/WebSocket.idl → Userland/Libraries/LibWeb/WebSockets/WebSocket.idl