Title: [249710] trunk
Revision
249710
Author
you...@apple.com
Date
2019-09-10 05:04:45 -0700 (Tue, 10 Sep 2019)

Log Message

Add support to RTCDataChannel.send(Blob)
https://bugs.webkit.org/show_bug.cgi?id=201377

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/webrtc/RTCDataChannel-send-blob-order-expected.txt: Added.
* web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html: Added.
* web-platform-tests/webrtc/RTCDataChannel-send-expected.txt:

Source/WebCore:

Make use of NetworkSendQueue to enqueue and send properly messages.
Test: imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html

* Modules/mediastream/RTCDataChannel.cpp:
(WebCore::RTCDataChannel::createMessageQueue):
(WebCore::RTCDataChannel::RTCDataChannel):
(WebCore::RTCDataChannel::send):
(WebCore::RTCDataChannel::close):
* Modules/mediastream/RTCDataChannel.h:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (249709 => 249710)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2019-09-10 10:53:59 UTC (rev 249709)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2019-09-10 12:04:45 UTC (rev 249710)
@@ -1,3 +1,14 @@
+2019-09-10  Youenn Fablet  <you...@apple.com>
+
+        Add support to RTCDataChannel.send(Blob)
+        https://bugs.webkit.org/show_bug.cgi?id=201377
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/webrtc/RTCDataChannel-send-blob-order-expected.txt: Added.
+        * web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html: Added.
+        * web-platform-tests/webrtc/RTCDataChannel-send-expected.txt:
+
 2019-09-09  Joonghun Park  <jh718.p...@samsung.com>
 
         getComputedStyle for line-height: normal should return the keyword instead of a length

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order-expected.txt (0 => 249710)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order-expected.txt	2019-09-10 12:04:45 UTC (rev 249710)
@@ -0,0 +1,3 @@
+
+PASS Data channel should send data following the order of the send call 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html (0 => 249710)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html	2019-09-10 12:04:45 UTC (rev 249710)
@@ -0,0 +1,37 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>RTCDataChannel.prototype.send for blobs</title>
+<script src=""
+<script src=""
+<script src=""
+<script>
+promise_test(async t => {
+    [channel1, channel2] = await createDataChannelPair();
+
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
+    const data1 = new Blob(['blob']);
+    const data1Size = data1.size;
+    const data2 = new ArrayBuffer(8);
+    const data2Size = data2.byteLength;
+
+    let firstMessage = true;
+
+    channel2.binaryType = "arraybuffer";
+    channel2._onmessage_ = t.step_func((e) => {
+        if (firstMessage) {
+            assert_equals(e.data.byteLength, data1Size);
+            firstMessage = false;
+            return;
+        }
+        assert_equals(e.data.byteLength, data2Size);
+        done();
+    });
+
+    channel1.send(data1);
+    channel1.send(data2);
+
+    return promise;
+}, 'Data channel should send data following the order of the send call');
+</script>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-expected.txt (249709 => 249710)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-expected.txt	2019-09-10 10:53:59 UTC (rev 249709)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-expected.txt	2019-09-10 12:04:45 UTC (rev 249710)
@@ -5,8 +5,8 @@
 PASS Data channel should ignore binaryType and always receive string message as string 
 PASS Data channel should be able to send Uint8Array message and receive as ArrayBuffer 
 PASS Data channel should be able to send ArrayBuffer message and receive as ArrayBuffer 
-FAIL Data channel should be able to send Blob message and receive as ArrayBuffer promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
+PASS Data channel should be able to send Blob message and receive as ArrayBuffer 
 PASS Data channel should be able to send ArrayBuffer message and receive as Blob 
 FAIL Data channel binaryType should receive message as Blob by default assert_equals: Expect initial binaryType value to be blob expected "blob" but got "arraybuffer"
-FAIL Sending multiple messages with different types should succeed and be received assert_unreached: Unexpected promise rejection: NotSupportedError: The operation is not supported. Reached unreachable code
+PASS Sending multiple messages with different types should succeed and be received 
 

Modified: trunk/Source/WebCore/ChangeLog (249709 => 249710)


--- trunk/Source/WebCore/ChangeLog	2019-09-10 10:53:59 UTC (rev 249709)
+++ trunk/Source/WebCore/ChangeLog	2019-09-10 12:04:45 UTC (rev 249710)
@@ -1,3 +1,20 @@
+2019-09-10  Youenn Fablet  <you...@apple.com>
+
+        Add support to RTCDataChannel.send(Blob)
+        https://bugs.webkit.org/show_bug.cgi?id=201377
+
+        Reviewed by Chris Dumez.
+
+        Make use of NetworkSendQueue to enqueue and send properly messages.
+        Test: imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html
+
+        * Modules/mediastream/RTCDataChannel.cpp:
+        (WebCore::RTCDataChannel::createMessageQueue):
+        (WebCore::RTCDataChannel::RTCDataChannel):
+        (WebCore::RTCDataChannel::send):
+        (WebCore::RTCDataChannel::close):
+        * Modules/mediastream/RTCDataChannel.h:
+
 2019-09-10  Ryosuke Niwa  <rn...@webkit.org>
 
         Option + arrow moves caret past whitespace on iOS

Modified: trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp (249709 => 249710)


--- trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp	2019-09-10 10:53:59 UTC (rev 249709)
+++ trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp	2019-09-10 12:04:45 UTC (rev 249710)
@@ -29,13 +29,10 @@
 #if ENABLE(WEB_RTC)
 
 #include "Blob.h"
-#include "Event.h"
 #include "EventNames.h"
 #include "MessageEvent.h"
-#include "RTCDataChannelHandler.h"
 #include "ScriptExecutionContext.h"
 #include "SharedBuffer.h"
-#include <_javascript_Core/ArrayBuffer.h>
 #include <_javascript_Core/ArrayBufferView.h>
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/NeverDestroyed.h>
@@ -66,6 +63,21 @@
     return channel;
 }
 
+NetworkSendQueue RTCDataChannel::createMessageQueue(Document& document, RTCDataChannel& channel)
+{
+    return { document, [&channel](const String& data) {
+        if (!channel.m_handler->sendStringData(data))
+            channel.scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Error sending string through RTCDataChannel."_s);
+    }, [&channel](auto* data, size_t length) {
+        if (!channel.m_handler->sendRawData(data, length))
+            channel.scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Error sending binary data through RTCDataChannel."_s);
+    }, [&channel](int errorCode) {
+        if (auto* context = channel.scriptExecutionContext())
+            context->addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Error ", errorCode, " in retrieving a blob data to be sent through RTCDataChannel."));
+        return NetworkSendQueue::Continue::Yes;
+    } };
+}
+
 RTCDataChannel::RTCDataChannel(ScriptExecutionContext& context, std::unique_ptr<RTCDataChannelHandler>&& handler, String&& label, RTCDataChannelInit&& options)
     : ActiveDOMObject(&context)
     , m_handler(WTFMove(handler))
@@ -72,6 +84,7 @@
     , m_scheduledEventTimer(*this, &RTCDataChannel::scheduledEventTimerFired)
     , m_label(WTFMove(label))
     , m_options(WTFMove(options))
+    , m_messageQueue(createMessageQueue(downcast<Document>(context), *this))
 {
 }
 
@@ -114,45 +127,35 @@
     if (m_readyState != RTCDataChannelState::Open)
         return Exception { InvalidStateError };
 
-    if (!m_handler->sendStringData(data)) {
-        // FIXME: Decide what the right exception here is.
-        return Exception { SyntaxError };
-    }
-
+    m_messageQueue.enqueue(data);
     return { };
 }
 
-ExceptionOr<void> RTCDataChannel::sendRawData(const char* data, size_t length)
+ExceptionOr<void> RTCDataChannel::send(ArrayBuffer& data)
 {
     if (m_readyState != RTCDataChannelState::Open)
         return Exception { InvalidStateError };
 
-    if (!length)
-        return { };
-
-    if (!m_handler->sendRawData(data, length)) {
-        // FIXME: Decide what the right exception here is.
-        return Exception { SyntaxError };
-    }
-
+    m_messageQueue.enqueue(data, 0, data.byteLength());
     return { };
 }
 
+ExceptionOr<void> RTCDataChannel::send(ArrayBufferView& data)
+{
+    if (m_readyState != RTCDataChannelState::Open)
+        return Exception { InvalidStateError };
 
-ExceptionOr<void> RTCDataChannel::send(ArrayBuffer& data)
-{
-    return sendRawData(static_cast<const char*>(data.data()), data.byteLength());
+    m_messageQueue.enqueue(*data.unsharedBuffer(), data.byteOffset(), data.byteLength());
+    return { };
 }
 
-ExceptionOr<void> RTCDataChannel::send(ArrayBufferView& data)
+ExceptionOr<void> RTCDataChannel::send(Blob& blob)
 {
-    return sendRawData(static_cast<const char*>(data.baseAddress()), data.byteLength());
-}
+    if (m_readyState != RTCDataChannelState::Open)
+        return Exception { InvalidStateError };
 
-ExceptionOr<void> RTCDataChannel::send(Blob&)
-{
-    // FIXME: Implement.
-    return Exception { NotSupportedError };
+    m_messageQueue.enqueue(blob);
+    return { };
 }
 
 void RTCDataChannel::close()
@@ -163,6 +166,8 @@
     m_stopped = true;
     m_readyState = RTCDataChannelState::Closed;
 
+    m_messageQueue.clear();
+
     m_handler->close();
     m_handler = nullptr;
     unsetPendingActivity(*this);

Modified: trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h (249709 => 249710)


--- trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h	2019-09-10 10:53:59 UTC (rev 249709)
+++ trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h	2019-09-10 12:04:45 UTC (rev 249710)
@@ -31,6 +31,7 @@
 #include "Event.h"
 #include "EventTarget.h"
 #include "ExceptionOr.h"
+#include "NetworkSendQueue.h"
 #include "RTCDataChannelHandler.h"
 #include "RTCDataChannelHandlerClient.h"
 #include "ScriptWrappable.h"
@@ -80,6 +81,8 @@
 private:
     RTCDataChannel(ScriptExecutionContext&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&);
 
+    static NetworkSendQueue createMessageQueue(Document&, RTCDataChannel&);
+
     void scheduleDispatchEvent(Ref<Event>&&);
     void scheduledEventTimerFired();
 
@@ -89,8 +92,6 @@
     void refEventTarget() final { ref(); }
     void derefEventTarget() final { deref(); }
 
-    ExceptionOr<void> sendRawData(const char* data, size_t length);
-
     // ActiveDOMObject API
     void stop() final;
     const char* activeDOMObjectName() const final { return "RTCDataChannel"; }
@@ -118,6 +119,8 @@
     String m_label;
     RTCDataChannelInit m_options;
     size_t m_bufferedAmountLowThreshold { 0 };
+
+    NetworkSendQueue m_messageQueue;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to