Title: [292527] trunk/Source
Revision
292527
Author
carlo...@webkit.org
Date
2022-04-07 03:15:35 -0700 (Thu, 07 Apr 2022)

Log Message

[GTK][WPE] RemoteInspector add support for IPv6
https://bugs.webkit.org/show_bug.cgi?id=238797

Reviewed by Adrian Perez de Castro.

Source/_javascript_Core:

* inspector/remote/glib/RemoteInspectorServer.cpp:
(Inspector::RemoteInspectorServer::start): Receive a GSocketAddress instead of address and port parameters.
* inspector/remote/glib/RemoteInspectorServer.h:

Source/WebKit:

Make it possible to connect to remote inspector server using IPv6 address.

* UIProcess/API/glib/WebKitInitialize.cpp:
(WebKit::initializeRemoteInspectorServer): Parse IPv6 address and build GSocketAddress to pass to inspector ot
HTTP server.
* UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp:
(WebKit::RemoteInspectorProtocolHandler::handleRequest): RemoteInspectorClient now expects host and port in a
single String.
* UIProcess/Inspector/glib/RemoteInspectorClient.cpp:
(WebKit::RemoteInspectorClient::RemoteInspectorClient): Receive the host and port in a String.
* UIProcess/Inspector/glib/RemoteInspectorClient.h:
* UIProcess/Inspector/glib/RemoteInspectorHTTPServer.cpp:
* UIProcess/Inspector/glib/RemoteInspectorHTTPServer.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (292526 => 292527)


--- trunk/Source/_javascript_Core/ChangeLog	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/_javascript_Core/ChangeLog	2022-04-07 10:15:35 UTC (rev 292527)
@@ -1,3 +1,14 @@
+2022-04-07  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK][WPE] RemoteInspector add support for IPv6
+        https://bugs.webkit.org/show_bug.cgi?id=238797
+
+        Reviewed by Adrian Perez de Castro.
+
+        * inspector/remote/glib/RemoteInspectorServer.cpp:
+        (Inspector::RemoteInspectorServer::start): Receive a GSocketAddress instead of address and port parameters.
+        * inspector/remote/glib/RemoteInspectorServer.h:
+
 2022-04-06  Saam Barati  <sbar...@apple.com>
 
         Call Structure::get instead of Structure::getConcurrently on the mutator thread

Modified: trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.cpp (292526 => 292527)


--- trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.cpp	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.cpp	2022-04-07 10:15:35 UTC (rev 292527)
@@ -182,16 +182,16 @@
         g_signal_handlers_disconnect_matched(m_service.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
 }
 
-bool RemoteInspectorServer::start(const char* address, unsigned port)
+bool RemoteInspectorServer::start(GRefPtr<GSocketAddress>&& socketAddress)
 {
     m_service = adoptGRef(g_socket_service_new());
     g_signal_connect(m_service.get(), "incoming", G_CALLBACK(incomingConnectionCallback), this);
 
-    GRefPtr<GSocketAddress> socketAddress = adoptGRef(g_inet_socket_address_new_from_string(address, port));
     GRefPtr<GSocketAddress> effectiveAddress;
     GUniqueOutPtr<GError> error;
     if (!g_socket_listener_add_address(G_SOCKET_LISTENER(m_service.get()), socketAddress.get(), G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, nullptr, &effectiveAddress.outPtr(), &error.outPtr())) {
-        g_warning("Failed to start remote inspector server on %s:%u: %s\n", address, port, error->message);
+        GUniquePtr<char> address(g_socket_connectable_to_string(G_SOCKET_CONNECTABLE(socketAddress.get())));
+        g_warning("Failed to start remote inspector server on %s: %s", address.get(), error->message);
         return false;
     }
 

Modified: trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.h (292526 => 292527)


--- trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.h	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/_javascript_Core/inspector/remote/glib/RemoteInspectorServer.h	2022-04-07 10:15:35 UTC (rev 292527)
@@ -33,6 +33,7 @@
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/glib/SocketConnection.h>
 
+typedef struct _GSocketAddress GSocketAddress;
 typedef struct _GSocketConnection GSocketConnection;
 typedef struct _GSocketService GSocketService;
 
@@ -43,7 +44,7 @@
     JS_EXPORT_PRIVATE static RemoteInspectorServer& singleton();
     ~RemoteInspectorServer();
 
-    JS_EXPORT_PRIVATE bool start(const char* address, unsigned port);
+    JS_EXPORT_PRIVATE bool start(GRefPtr<GSocketAddress>&&);
     bool isRunning() const { return !!m_service; }
     uint16_t port() const { return m_port; }
 

Modified: trunk/Source/WebKit/ChangeLog (292526 => 292527)


--- trunk/Source/WebKit/ChangeLog	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/WebKit/ChangeLog	2022-04-07 10:15:35 UTC (rev 292527)
@@ -1,3 +1,24 @@
+2022-04-07  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK][WPE] RemoteInspector add support for IPv6
+        https://bugs.webkit.org/show_bug.cgi?id=238797
+
+        Reviewed by Adrian Perez de Castro.
+
+        Make it possible to connect to remote inspector server using IPv6 address.
+
+        * UIProcess/API/glib/WebKitInitialize.cpp:
+        (WebKit::initializeRemoteInspectorServer): Parse IPv6 address and build GSocketAddress to pass to inspector ot
+        HTTP server.
+        * UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp:
+        (WebKit::RemoteInspectorProtocolHandler::handleRequest): RemoteInspectorClient now expects host and port in a
+        single String.
+        * UIProcess/Inspector/glib/RemoteInspectorClient.cpp:
+        (WebKit::RemoteInspectorClient::RemoteInspectorClient): Receive the host and port in a String.
+        * UIProcess/Inspector/glib/RemoteInspectorClient.h:
+        * UIProcess/Inspector/glib/RemoteInspectorHTTPServer.cpp:
+        * UIProcess/Inspector/glib/RemoteInspectorHTTPServer.h:
+
 2022-04-06  Chris Dumez  <cdu...@apple.com>
 
         Improve API::SerializedScriptValue::deserialize to not allocate a new JSContext every second

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitInitialize.cpp (292526 => 292527)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitInitialize.cpp	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitInitialize.cpp	2022-04-07 10:15:35 UTC (rev 292527)
@@ -30,7 +30,9 @@
 #include "WebKit2Initialize.h"
 #include <_javascript_Core/RemoteInspector.h>
 #include <_javascript_Core/RemoteInspectorServer.h>
+#include <limits>
 #include <mutex>
+#include <wtf/glib/GRefPtr.h>
 #include <wtf/glib/GUniquePtr.h>
 
 namespace WebKit {
@@ -46,7 +48,7 @@
     if (Inspector::RemoteInspectorServer::singleton().isRunning())
         return;
 
-    auto parseAddress = [](const char* address, guint64& port) -> GUniquePtr<char> {
+    auto parseAddress = [](const char* address) -> GRefPtr<GSocketAddress> {
         if (!address || !address[0])
             return nullptr;
 
@@ -57,29 +59,37 @@
 
         *portPtr = '\0';
         portPtr++;
-        port = g_ascii_strtoull(portPtr, nullptr, 10);
-        if (!port)
+        auto port = g_ascii_strtoull(portPtr, nullptr, 10);
+        if (!port || port > std::numeric_limits<uint16_t>::max())
             return nullptr;
 
-        return inspectorAddress;
+        char* addressPtr = inspectorAddress.get();
+        if (addressPtr[0] == '[' && *(portPtr - 2) == ']') {
+            // Strip the square brackets.
+            addressPtr++;
+            *(portPtr - 2) = '\0';
+        }
+
+        return adoptGRef(g_inet_socket_address_new_from_string(addressPtr, port));
     };
 
-    guint64 inspectorHTTPPort;
-    auto inspectorHTTPAddress = parseAddress(httpAddress, inspectorHTTPPort);
-    guint64 inspectorPort;
-    auto inspectorAddress = !httpAddress ? parseAddress(address, inspectorPort) : GUniquePtr<char>();
-    if (!inspectorHTTPAddress && !inspectorAddress)
+    auto inspectorHTTPAddress = parseAddress(httpAddress);
+    GRefPtr<GSocketAddress> inspectorAddress;
+    if (inspectorHTTPAddress)
+        inspectorAddress = adoptGRef(G_SOCKET_ADDRESS(g_inet_socket_address_new(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(inspectorHTTPAddress.get())), 0)));
+    else
+        inspectorAddress = parseAddress(address);
+    if (!inspectorHTTPAddress && !inspectorAddress) {
+        g_warning("Failed to start remote inspector server on %s: invalid address", address ? address : httpAddress);
         return;
+    }
 
-    if (!Inspector::RemoteInspectorServer::singleton().start(inspectorAddress ? inspectorAddress.get() : inspectorHTTPAddress.get(), inspectorAddress ? inspectorPort : 0))
+    if (!Inspector::RemoteInspectorServer::singleton().start(WTFMove(inspectorAddress)))
         return;
 
-    Inspector::RemoteInspector::setInspectorServerAddress(address);
-
-    if (httpAddress) {
-        inspectorAddress.reset(g_strdup_printf("%s:%u", inspectorHTTPAddress.get(), Inspector::RemoteInspectorServer::singleton().port()));
-        Inspector::RemoteInspector::setInspectorServerAddress(inspectorAddress.get());
-        RemoteInspectorHTTPServer::singleton().start(inspectorHTTPAddress.get(), inspectorHTTPPort, Inspector::RemoteInspectorServer::singleton().port());
+    if (inspectorHTTPAddress) {
+        if (RemoteInspectorHTTPServer::singleton().start(WTFMove(inspectorHTTPAddress), Inspector::RemoteInspectorServer::singleton().port()))
+            Inspector::RemoteInspector::setInspectorServerAddress(RemoteInspectorHTTPServer::singleton().inspectorServerAddress().utf8());
     } else
         Inspector::RemoteInspector::setInspectorServerAddress(address);
 }

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp (292526 => 292527)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp	2022-04-07 10:15:35 UTC (rev 292527)
@@ -121,7 +121,7 @@
     }
 
     auto* client = m_inspectorClients.ensure(requestURL.hostAndPort(), [this, &requestURL] {
-        return makeUnique<RemoteInspectorClient>(requestURL.host().utf8().data(), requestURL.port().value(), *this);
+        return makeUnique<RemoteInspectorClient>(requestURL.hostAndPort(), *this);
     }).iterator->value.get();
 
     auto* html = client->buildTargetListPage(RemoteInspectorClient::InspectorType::UI);

Modified: trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp (292526 => 292527)


--- trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp	2022-04-07 10:15:35 UTC (rev 292527)
@@ -167,8 +167,8 @@
     return messageHandlers;
 }
 
-RemoteInspectorClient::RemoteInspectorClient(const char* address, unsigned port, RemoteInspectorObserver& observer)
-    : m_hostAndPort(String::fromUTF8(address) + ':' + String::number(port))
+RemoteInspectorClient::RemoteInspectorClient(String&& hostAndPort, RemoteInspectorObserver& observer)
+    : m_hostAndPort(WTFMove(hostAndPort))
     , m_observer(observer)
     , m_cancellable(adoptGRef(g_cancellable_new()))
 {

Modified: trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.h (292526 => 292527)


--- trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.h	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.h	2022-04-07 10:15:35 UTC (rev 292527)
@@ -51,7 +51,7 @@
 class RemoteInspectorClient {
     WTF_MAKE_FAST_ALLOCATED();
 public:
-    RemoteInspectorClient(const char* address, unsigned port, RemoteInspectorObserver&);
+    RemoteInspectorClient(String&& hostAndPort, RemoteInspectorObserver&);
     ~RemoteInspectorClient();
 
     const String& hostAndPort() const { return m_hostAndPort; }

Modified: trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorHTTPServer.cpp (292526 => 292527)


--- trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorHTTPServer.cpp	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorHTTPServer.cpp	2022-04-07 10:15:35 UTC (rev 292527)
@@ -42,18 +42,14 @@
     return server;
 }
 
-bool RemoteInspectorHTTPServer::start(const char* address, unsigned port, unsigned inspectorPort)
+bool RemoteInspectorHTTPServer::start(GRefPtr<GSocketAddress>&& socketAddress, unsigned inspectorPort)
 {
     m_server = adoptGRef(soup_server_new("server-header", "WebKitInspectorHTTPServer ", nullptr));
-    GRefPtr<GSocketAddress> socketAddress = adoptGRef(g_inet_socket_address_new_from_string(address, port));
-    if (!socketAddress) {
-        g_warning("Failed to start remote inspector HTTP server on %s:%u: invalid address", address, port);
-        return false;
-    }
 
     GUniqueOutPtr<GError> error;
     if (!soup_server_listen(m_server.get(), socketAddress.get(), static_cast<SoupServerListenOptions>(0), &error.outPtr())) {
-        g_warning("Failed to start remote inspector HTTP server on %s:%u: %s", address, port, error->message);
+        GUniquePtr<char> address(g_socket_connectable_to_string(G_SOCKET_CONNECTABLE(socketAddress.get())));
+        g_warning("Failed to start remote inspector HTTP server on %s: %s", address.get(), error->message);
         return false;
     }
 
@@ -78,11 +74,23 @@
             httpServer.handleWebSocket(path, connection);
         }, this, nullptr);
 
-    m_client = makeUnique<RemoteInspectorClient>(address, inspectorPort, *this);
+    auto* inetAddress = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(socketAddress.get()));
+    GUniquePtr<char> host(g_inet_address_to_string(inetAddress));
+    GUniquePtr<char> inspectorServerAddress;
+    if (g_inet_address_get_family(inetAddress) == G_SOCKET_FAMILY_IPV6)
+        inspectorServerAddress.reset(g_strdup_printf("[%s]:%u", host.get(), inspectorPort));
+    else
+        inspectorServerAddress.reset(g_strdup_printf("%s:%u", host.get(), inspectorPort));
+    m_client = makeUnique<RemoteInspectorClient>(String::fromUTF8(inspectorServerAddress.get()), *this);
 
     return true;
 }
 
+const String& RemoteInspectorHTTPServer::inspectorServerAddress() const
+{
+    return m_client ? m_client->hostAndPort() : emptyString();
+}
+
 unsigned RemoteInspectorHTTPServer::handleRequest(const char* path, SoupMessageHeaders* responseHeaders, SoupMessageBody* responseBody) const
 {
     if (g_str_equal(path, "/")) {

Modified: trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorHTTPServer.h (292526 => 292527)


--- trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorHTTPServer.h	2022-04-07 10:11:54 UTC (rev 292526)
+++ trunk/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorHTTPServer.h	2022-04-07 10:15:35 UTC (rev 292527)
@@ -38,8 +38,9 @@
     static RemoteInspectorHTTPServer& singleton();
     ~RemoteInspectorHTTPServer() = default;
 
-    bool start(const char* address, unsigned port, unsigned inspectorPort);
+    bool start(GRefPtr<GSocketAddress>&&, unsigned inspectorPort);
     bool isRunning() const { return !!m_server; }
+    const String& inspectorServerAddress() const;
 
     void sendMessageToFrontend(uint64_t connectionID, uint64_t targetID, const String& message) const;
     void targetDidClose(uint64_t connectionID, uint64_t targetID);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to