Title: [247680] trunk/Source/WebKit
Revision
247680
Author
[email protected]
Date
2019-07-22 01:47:02 -0700 (Mon, 22 Jul 2019)

Log Message

[SOUP] WebSockets: use new api to send text messages
https://bugs.webkit.org/show_bug.cgi?id=199936

Reviewed by Michael Catanzaro.

New API allows to include null character in text messages.

* NetworkProcess/soup/WebSocketTaskSoup.cpp:
(WebKit::WebSocketTask::didReceiveMessageCallback): Pass data size to String::fromUTF8().
(WebKit::WebSocketTask::sendString): Use soup_websocket_connection_send_message() instead of
soup_websocket_connection_send_text() when available. Also use
StrictConversionReplacingUnpairedSurrogatesWithFFFD options when converting to UTF-8.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (247679 => 247680)


--- trunk/Source/WebKit/ChangeLog	2019-07-22 03:35:38 UTC (rev 247679)
+++ trunk/Source/WebKit/ChangeLog	2019-07-22 08:47:02 UTC (rev 247680)
@@ -1,3 +1,18 @@
+2019-07-22  Carlos Garcia Campos  <[email protected]>
+
+        [SOUP] WebSockets: use new api to send text messages
+        https://bugs.webkit.org/show_bug.cgi?id=199936
+
+        Reviewed by Michael Catanzaro.
+
+        New API allows to include null character in text messages.
+
+        * NetworkProcess/soup/WebSocketTaskSoup.cpp:
+        (WebKit::WebSocketTask::didReceiveMessageCallback): Pass data size to String::fromUTF8().
+        (WebKit::WebSocketTask::sendString): Use soup_websocket_connection_send_message() instead of
+        soup_websocket_connection_send_text() when available. Also use
+        StrictConversionReplacingUnpairedSurrogatesWithFFFD options when converting to UTF-8.
+
 2019-07-21  Wenson Hsieh  <[email protected]>
 
         [iOS] [WebKit2] Add limited support for -isPosition:atBoundary:inDirection: in WKContentView

Modified: trunk/Source/WebKit/NetworkProcess/soup/WebSocketTaskSoup.cpp (247679 => 247680)


--- trunk/Source/WebKit/NetworkProcess/soup/WebSocketTaskSoup.cpp	2019-07-22 03:35:38 UTC (rev 247679)
+++ trunk/Source/WebKit/NetworkProcess/soup/WebSocketTaskSoup.cpp	2019-07-22 08:47:02 UTC (rev 247680)
@@ -86,17 +86,17 @@
     if (g_cancellable_is_cancelled(task->m_cancellable.get()))
         return;
 
+    gsize dataSize;
+    const auto* data = "" &dataSize);
+
     switch (dataType) {
     case SOUP_WEBSOCKET_DATA_TEXT:
-        task->m_channel.didReceiveText(String::fromUTF8(static_cast<const char*>(g_bytes_get_data(message, nullptr))));
+        task->m_channel.didReceiveText(String::fromUTF8(static_cast<const char*>(data), dataSize));
         break;
-    case SOUP_WEBSOCKET_DATA_BINARY: {
-        gsize dataSize;
-        auto data = "" &dataSize);
+    case SOUP_WEBSOCKET_DATA_BINARY:
         task->m_channel.didReceiveBinaryData(static_cast<const uint8_t*>(data), dataSize);
         break;
     }
-    }
 }
 
 void WebSocketTask::didReceiveErrorCallback(WebSocketTask* task, GError* error)
@@ -139,8 +139,16 @@
 
 void WebSocketTask::sendString(const String& text, CompletionHandler<void()>&& callback)
 {
-    if (m_connection && soup_websocket_connection_get_state(m_connection.get()) == SOUP_WEBSOCKET_STATE_OPEN)
-        soup_websocket_connection_send_text(m_connection.get(), text.utf8().data());
+    if (m_connection && soup_websocket_connection_get_state(m_connection.get()) == SOUP_WEBSOCKET_STATE_OPEN) {
+        CString utf8 = text.utf8(StrictConversionReplacingUnpairedSurrogatesWithFFFD);
+#if SOUP_CHECK_VERSION(2, 67, 3)
+        // Soup is going to copy the data immediately, so we can use g_bytes_new_static() here to avoid more data copies.
+        GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_static(utf8.data(), utf8.length()));
+        soup_websocket_connection_send_message(m_connection.get(), SOUP_WEBSOCKET_DATA_TEXT, bytes.get());
+#else
+        soup_websocket_connection_send_text(m_connection.get(), utf8.data());
+#endif
+    }
     callback();
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to