Title: [230548] trunk
Revision
230548
Author
you...@apple.com
Date
2018-04-11 14:49:28 -0700 (Wed, 11 Apr 2018)

Log Message

Preventively expect UTF8 strings from libwebrtc SDP and error messages
https://bugs.webkit.org/show_bug.cgi?id=184509

Reviewed by Eric Carlson.

Source/WebCore:

Make WebCore code expect any libwebrtc string to contain UTF-8.
Currently SDPs do not contain any UTF-8 specific character
but https://tools.ietf.org/html/rfc4566 allows it.

Add Internals API to set track id so that we can inject UTF-8 inside some WebRTC tests.
Test: webrtc/utf8-sdp.html

* Modules/mediastream/MediaStreamTrack.h:
(WebCore::MediaStreamTrack::setIdForTesting):
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::fromStdString):
(WebCore::fromSessionDescription):
(WebCore::LibWebRTCMediaEndpoint::doSetLocalDescription):
(WebCore::LibWebRTCMediaEndpoint::doSetRemoteDescription):
(WebCore::LibWebRTCMediaEndpoint::mediaStreamFromRTCStream):
(WebCore::LibWebRTCMediaEndpoint::addRemoteTrack):
(WebCore::LibWebRTCMediaEndpoint::addDataChannel):
(WebCore::LibWebRTCMediaEndpoint::OnIceCandidate):
(WebCore::LibWebRTCMediaEndpoint::createSessionDescriptionSucceeded):
(WebCore::LibWebRTCMediaEndpoint::createSessionDescriptionFailed):
(WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionFailed):
(WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionFailed):
(WebCore::trackId): Deleted.
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::fromStdString):
(WebCore::LibWebRTCPeerConnectionBackend::doAddIceCandidate):
(WebCore::createReceiverForSource):
* platform/mediastream/MediaStreamTrackPrivate.h:
(WebCore::MediaStreamTrackPrivate::setIdForTesting):
* testing/Internals.cpp:
(WebCore::Internals::setMediaStreamTrackIdentifier):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* webrtc/utf8-sdp-expected.txt: Added.
* webrtc/utf8-sdp.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (230547 => 230548)


--- trunk/LayoutTests/ChangeLog	2018-04-11 21:06:48 UTC (rev 230547)
+++ trunk/LayoutTests/ChangeLog	2018-04-11 21:49:28 UTC (rev 230548)
@@ -1,3 +1,13 @@
+2018-04-11  Youenn Fablet  <you...@apple.com>
+
+        Preventively expect UTF8 strings from libwebrtc SDP and error messages
+        https://bugs.webkit.org/show_bug.cgi?id=184509
+
+        Reviewed by Eric Carlson.
+
+        * webrtc/utf8-sdp-expected.txt: Added.
+        * webrtc/utf8-sdp.html: Added.
+
 2018-04-11  Alicia Boya García  <ab...@igalia.com>
 
         [GTK] Unreviewed test gardening

Added: trunk/LayoutTests/webrtc/utf8-sdp-expected.txt (0 => 230548)


--- trunk/LayoutTests/webrtc/utf8-sdp-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webrtc/utf8-sdp-expected.txt	2018-04-11 21:49:28 UTC (rev 230548)
@@ -0,0 +1,4 @@
+
+
+PASS Testing video exchange with UTF-8 track id 
+

Added: trunk/LayoutTests/webrtc/utf8-sdp.html (0 => 230548)


--- trunk/LayoutTests/webrtc/utf8-sdp.html	                        (rev 0)
+++ trunk/LayoutTests/webrtc/utf8-sdp.html	2018-04-11 21:49:28 UTC (rev 230548)
@@ -0,0 +1,39 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing UTF-8 content in SDP</title>
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <video id="video" autoplay=""></video>
+        <script src =""
+        <script>
+promise_test(async (test) => {
+    if (!window.internals)
+        return Promise.reject("internals required");
+
+    const unicodeString = '世界你好';
+
+    const stream = await navigator.mediaDevices.getUserMedia({video: true});
+    internals.setMediaStreamTrackIdentifier(stream.getVideoTracks()[0], unicodeString);
+
+    const remoteStream = await new Promise((resolve, reject) => {
+        createConnections((firstConnection) => {
+            firstConnection.addTrack(stream.getVideoTracks()[0], stream);
+        }, (secondConnection) => {
+            secondConnection._ontrack_ = (trackEvent) => {
+                resolve(trackEvent.streams[0]);
+            };
+        });
+        setTimeout(() => reject("Test timed out"), 5000);
+    });
+
+    assert_equals(unicodeString, remoteStream.getVideoTracks()[0].id);
+    video.srcObject = remoteStream;
+    return video.play();
+}, "Testing video exchange with UTF-8 track id");
+        </script>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (230547 => 230548)


--- trunk/Source/WebCore/ChangeLog	2018-04-11 21:06:48 UTC (rev 230547)
+++ trunk/Source/WebCore/ChangeLog	2018-04-11 21:49:28 UTC (rev 230548)
@@ -1,3 +1,44 @@
+2018-04-11  Youenn Fablet  <you...@apple.com>
+
+        Preventively expect UTF8 strings from libwebrtc SDP and error messages
+        https://bugs.webkit.org/show_bug.cgi?id=184509
+
+        Reviewed by Eric Carlson.
+
+        Make WebCore code expect any libwebrtc string to contain UTF-8.
+        Currently SDPs do not contain any UTF-8 specific character
+        but https://tools.ietf.org/html/rfc4566 allows it.
+
+        Add Internals API to set track id so that we can inject UTF-8 inside some WebRTC tests.
+        Test: webrtc/utf8-sdp.html
+
+        * Modules/mediastream/MediaStreamTrack.h:
+        (WebCore::MediaStreamTrack::setIdForTesting):
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::fromStdString):
+        (WebCore::fromSessionDescription):
+        (WebCore::LibWebRTCMediaEndpoint::doSetLocalDescription):
+        (WebCore::LibWebRTCMediaEndpoint::doSetRemoteDescription):
+        (WebCore::LibWebRTCMediaEndpoint::mediaStreamFromRTCStream):
+        (WebCore::LibWebRTCMediaEndpoint::addRemoteTrack):
+        (WebCore::LibWebRTCMediaEndpoint::addDataChannel):
+        (WebCore::LibWebRTCMediaEndpoint::OnIceCandidate):
+        (WebCore::LibWebRTCMediaEndpoint::createSessionDescriptionSucceeded):
+        (WebCore::LibWebRTCMediaEndpoint::createSessionDescriptionFailed):
+        (WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionFailed):
+        (WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionFailed):
+        (WebCore::trackId): Deleted.
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
+        (WebCore::fromStdString):
+        (WebCore::LibWebRTCPeerConnectionBackend::doAddIceCandidate):
+        (WebCore::createReceiverForSource):
+        * platform/mediastream/MediaStreamTrackPrivate.h:
+        (WebCore::MediaStreamTrackPrivate::setIdForTesting):
+        * testing/Internals.cpp:
+        (WebCore::Internals::setMediaStreamTrackIdentifier):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2018-04-11  Said Abou-Hallawa  <sabouhall...@apple.com>
 
         Cache glyphs (using display lists) when painting at high frequency

Modified: trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h (230547 => 230548)


--- trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h	2018-04-11 21:06:48 UTC (rev 230547)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h	2018-04-11 21:49:28 UTC (rev 230548)
@@ -138,6 +138,8 @@
     // ActiveDOMObject API.
     bool hasPendingActivity() const final;
 
+    void setIdForTesting(String&& id) { m_private->setIdForTesting(WTFMove(id)); }
+
 protected:
     MediaStreamTrack(ScriptExecutionContext&, Ref<MediaStreamTrackPrivate>&&);
 

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp (230547 => 230548)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp	2018-04-11 21:06:48 UTC (rev 230547)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp	2018-04-11 21:49:28 UTC (rev 230548)
@@ -57,6 +57,11 @@
 
 namespace WebCore {
 
+static inline String fromStdString(const std::string& value)
+{
+    return String::fromUTF8(value.data(), value.length());
+}
+
 LibWebRTCMediaEndpoint::LibWebRTCMediaEndpoint(LibWebRTCPeerConnectionBackend& peerConnection, LibWebRTCProvider& client)
     : m_peerConnectionBackend(peerConnection)
     , m_peerConnectionFactory(*client.factory())
@@ -116,9 +121,8 @@
 
     std::string sdp;
     description->ToString(&sdp);
-    String sdpString(sdp.data(), sdp.size());
 
-    return RTCSessionDescription::create(fromSessionDescriptionType(*description), WTFMove(sdpString));
+    return RTCSessionDescription::create(fromSessionDescriptionType(*description), fromStdString(sdp));
 }
 
 // FIXME: We might want to create a new object only if the session actually changed for all description getters.
@@ -160,8 +164,7 @@
     std::unique_ptr<webrtc::SessionDescriptionInterface> sessionDescription(webrtc::CreateSessionDescription(sessionDescriptionType(description.type()), description.sdp().utf8().data(), &error));
 
     if (!sessionDescription) {
-        String errorMessage(error.description.data(), error.description.size());
-        m_peerConnectionBackend.setLocalDescriptionFailed(Exception { OperationError, WTFMove(errorMessage) });
+        m_peerConnectionBackend.setLocalDescriptionFailed(Exception { OperationError, fromStdString(error.description) });
         return;
     }
 
@@ -181,8 +184,7 @@
     webrtc::SdpParseError error;
     std::unique_ptr<webrtc::SessionDescriptionInterface> sessionDescription(webrtc::CreateSessionDescription(sessionDescriptionType(description.type()), description.sdp().utf8().data(), &error));
     if (!sessionDescription) {
-        String errorMessage(error.description.data(), error.description.size());
-        m_peerConnectionBackend.setRemoteDescriptionFailed(Exception { OperationError, WTFMove(errorMessage) });
+        m_peerConnectionBackend.setRemoteDescriptionFailed(Exception { OperationError, fromStdString(error.description) });
         return;
     }
     m_backend->SetRemoteDescription(&m_setRemoteSessionDescriptionObserver, sessionDescription.release());
@@ -303,11 +305,6 @@
         m_id = track->id();
 }
 
-static inline String fromStdString(const std::string& value)
-{
-    return String(value.data(), value.length());
-}
-
 static inline void fillRTCStats(RTCStatsReport::Stats& stats, const webrtc::RTCStats& rtcStats)
 {
     stats.timestamp = Performance::reduceTimeResolution(Seconds::fromMicroseconds(rtcStats.timestamp_us())).milliseconds();
@@ -618,16 +615,11 @@
     });
 }
 
-static inline String trackId(webrtc::MediaStreamTrackInterface& videoTrack)
-{
-    return String(videoTrack.id().data(), videoTrack.id().size());
-}
-
 MediaStream& LibWebRTCMediaEndpoint::mediaStreamFromRTCStream(webrtc::MediaStreamInterface& rtcStream)
 {
     auto mediaStream = m_streams.ensure(&rtcStream, [&rtcStream, this] {
         auto label = rtcStream.label();
-        auto stream = MediaStream::create(*m_peerConnectionBackend.connection().scriptExecutionContext(), MediaStreamPrivate::create({ }, String(label.data(), label.size())));
+        auto stream = MediaStream::create(*m_peerConnectionBackend.connection().scriptExecutionContext(), MediaStreamPrivate::create({ }, fromStdString(label)));
         auto streamPointer = stream.ptr();
         m_peerConnectionBackend.addRemoteStream(WTFMove(stream));
         return streamPointer;
@@ -667,7 +659,7 @@
         return;
     case cricket::MEDIA_TYPE_AUDIO: {
         rtc::scoped_refptr<webrtc::AudioTrackInterface> audioTrack = static_cast<webrtc::AudioTrackInterface*>(rtcTrack);
-        auto audioReceiver = m_peerConnectionBackend.audioReceiver(trackId(*rtcTrack));
+        auto audioReceiver = m_peerConnectionBackend.audioReceiver(fromStdString(rtcTrack->id()));
 
         receiver = WTFMove(audioReceiver.receiver);
         audioReceiver.source->setSourceTrack(WTFMove(audioTrack));
@@ -675,7 +667,7 @@
     }
     case cricket::MEDIA_TYPE_VIDEO: {
         rtc::scoped_refptr<webrtc::VideoTrackInterface> videoTrack = static_cast<webrtc::VideoTrackInterface*>(rtcTrack);
-        auto videoReceiver = m_peerConnectionBackend.videoReceiver(trackId(*rtcTrack));
+        auto videoReceiver = m_peerConnectionBackend.videoReceiver(fromStdString(rtcTrack->id()));
 
         receiver = WTFMove(videoReceiver.receiver);
         videoReceiver.source->setSourceTrack(WTFMove(videoTrack));
@@ -766,7 +758,7 @@
     init.ordered = dataChannel->ordered();
     init.maxPacketLifeTime = dataChannel->maxRetransmitTime();
     init.maxRetransmits = dataChannel->maxRetransmits();
-    init.protocol = String(protocol.data(), protocol.size());
+    init.protocol = fromStdString(protocol);
     init.negotiated = dataChannel->negotiated();
     init.id = dataChannel->id();
 
@@ -774,7 +766,7 @@
 
     auto handler =  std::make_unique<LibWebRTCDataChannelHandler>(WTFMove(dataChannel));
     ASSERT(m_peerConnectionBackend.connection().scriptExecutionContext());
-    auto channel = RTCDataChannel::create(*m_peerConnectionBackend.connection().scriptExecutionContext(), WTFMove(handler), String(label.data(), label.size()), WTFMove(init));
+    auto channel = RTCDataChannel::create(*m_peerConnectionBackend.connection().scriptExecutionContext(), WTFMove(handler), fromStdString(label), WTFMove(init));
 
     if (isOpened) {
         callOnMainThread([channel = channel.copyRef()] {
@@ -872,17 +864,13 @@
 
     std::string sdp;
     rtcCandidate->ToString(&sdp);
-    String candidateSDP(sdp.data(), sdp.size());
 
-    auto mid = rtcCandidate->sdp_mid();
-    String candidateMid(mid.data(), mid.size());
-
     auto sdpMLineIndex = safeCast<unsigned short>(rtcCandidate->sdp_mline_index());
 
-    callOnMainThread([protectedThis = makeRef(*this), mid = WTFMove(candidateMid), sdp = WTFMove(candidateSDP), sdpMLineIndex] {
+    callOnMainThread([protectedThis = makeRef(*this), mid = fromStdString(rtcCandidate->sdp_mid()), sdp = fromStdString(sdp), sdpMLineIndex]() mutable {
         if (protectedThis->isStopped())
             return;
-        protectedThis->m_peerConnectionBackend.newICECandidate(String(sdp), String(mid), sdpMLineIndex);
+        protectedThis->m_peerConnectionBackend.newICECandidate(WTFMove(sdp), WTFMove(mid), sdpMLineIndex);
     });
 }
 
@@ -895,22 +883,20 @@
 {
     std::string sdp;
     description->ToString(&sdp);
-    String sdpString(sdp.data(), sdp.size());
 
-    callOnMainThread([protectedThis = makeRef(*this), sdp = WTFMove(sdpString)] {
+    callOnMainThread([protectedThis = makeRef(*this), sdp = fromStdString(sdp)]() mutable {
         if (protectedThis->isStopped())
             return;
         if (protectedThis->m_isInitiator)
-            protectedThis->m_peerConnectionBackend.createOfferSucceeded(String(sdp));
+            protectedThis->m_peerConnectionBackend.createOfferSucceeded(WTFMove(sdp));
         else
-            protectedThis->m_peerConnectionBackend.createAnswerSucceeded(String(sdp));
+            protectedThis->m_peerConnectionBackend.createAnswerSucceeded(WTFMove(sdp));
     });
 }
 
 void LibWebRTCMediaEndpoint::createSessionDescriptionFailed(const std::string& errorMessage)
 {
-    String error(errorMessage.data(), errorMessage.size());
-    callOnMainThread([protectedThis = makeRef(*this), error = WTFMove(error)] () mutable {
+    callOnMainThread([protectedThis = makeRef(*this), error = fromStdString(errorMessage)] () mutable {
         if (protectedThis->isStopped())
             return;
         if (protectedThis->m_isInitiator)
@@ -931,8 +917,7 @@
 
 void LibWebRTCMediaEndpoint::setLocalSessionDescriptionFailed(const std::string& errorMessage)
 {
-    String error(errorMessage.data(), errorMessage.size());
-    callOnMainThread([protectedThis = makeRef(*this), error = WTFMove(error)] () mutable {
+    callOnMainThread([protectedThis = makeRef(*this), error = fromStdString(errorMessage)] () mutable {
         if (protectedThis->isStopped())
             return;
         protectedThis->m_peerConnectionBackend.setLocalDescriptionFailed(Exception { OperationError, WTFMove(error) });
@@ -950,8 +935,7 @@
 
 void LibWebRTCMediaEndpoint::setRemoteSessionDescriptionFailed(const std::string& errorMessage)
 {
-    String error(errorMessage.data(), errorMessage.size());
-    callOnMainThread([protectedThis = makeRef(*this), error = WTFMove(error)] () mutable {
+    callOnMainThread([protectedThis = makeRef(*this), error = fromStdString(errorMessage)] () mutable {
         if (protectedThis->isStopped())
             return;
         protectedThis->m_peerConnectionBackend.setRemoteDescriptionFailed(Exception { OperationError, WTFMove(error) });

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp (230547 => 230548)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp	2018-04-11 21:06:48 UTC (rev 230547)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp	2018-04-11 21:49:28 UTC (rev 230548)
@@ -209,8 +209,7 @@
     std::unique_ptr<webrtc::IceCandidateInterface> rtcCandidate(webrtc::CreateIceCandidate(candidate.sdpMid().utf8().data(), sdpMLineIndex, candidate.candidate().utf8().data(), &error));
 
     if (!rtcCandidate) {
-        String message(error.description.data(), error.description.size());
-        addIceCandidateFailed(Exception { OperationError, WTFMove(message) });
+        addIceCandidateFailed(Exception { OperationError, String::fromUTF8(error.description.data(), error.description.length()) });
         return;
     }
 
@@ -237,8 +236,7 @@
 
 static inline Ref<RTCRtpReceiver> createReceiverForSource(ScriptExecutionContext& context, Ref<RealtimeMediaSource>&& source)
 {
-    String id = source->id();
-    auto remoteTrackPrivate = MediaStreamTrackPrivate::create(WTFMove(source), WTFMove(id));
+    auto remoteTrackPrivate = MediaStreamTrackPrivate::create(WTFMove(source), String { source->id() });
     auto remoteTrack = MediaStreamTrack::create(context, WTFMove(remoteTrackPrivate));
 
     return RTCRtpReceiver::create(WTFMove(remoteTrack));

Modified: trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h (230547 => 230548)


--- trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h	2018-04-11 21:06:48 UTC (rev 230547)
+++ trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h	2018-04-11 21:49:28 UTC (rev 230548)
@@ -100,6 +100,8 @@
     enum class ReadyState { None, Live, Ended };
     ReadyState readyState() const { return m_readyState; }
 
+    void setIdForTesting(String&& id) { m_id = WTFMove(id); }
+
 private:
     MediaStreamTrackPrivate(Ref<RealtimeMediaSource>&&, String&& id);
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (230547 => 230548)


--- trunk/Source/WebCore/testing/Internals.cpp	2018-04-11 21:06:48 UTC (rev 230547)
+++ trunk/Source/WebCore/testing/Internals.cpp	2018-04-11 21:49:28 UTC (rev 230548)
@@ -4286,6 +4286,10 @@
     track.source().captureFailed();
 }
 
+void Internals::setMediaStreamTrackIdentifier(MediaStreamTrack& track, String&& id)
+{
+    track.setIdForTesting(WTFMove(id));
+}
 #endif
 
 String Internals::audioSessionCategory() const

Modified: trunk/Source/WebCore/testing/Internals.h (230547 => 230548)


--- trunk/Source/WebCore/testing/Internals.h	2018-04-11 21:06:48 UTC (rev 230547)
+++ trunk/Source/WebCore/testing/Internals.h	2018-04-11 21:49:28 UTC (rev 230548)
@@ -622,6 +622,7 @@
     void setMediaStreamTrackMuted(MediaStreamTrack&, bool);
     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
+    void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
 #endif
 
     String audioSessionCategory() const;

Modified: trunk/Source/WebCore/testing/Internals.idl (230547 => 230548)


--- trunk/Source/WebCore/testing/Internals.idl	2018-04-11 21:06:48 UTC (rev 230547)
+++ trunk/Source/WebCore/testing/Internals.idl	2018-04-11 21:49:28 UTC (rev 230548)
@@ -566,6 +566,7 @@
     [Conditional=MEDIA_STREAM] void setMediaStreamTrackMuted(MediaStreamTrack track, boolean muted);
     [Conditional=MEDIA_STREAM] void removeMediaStreamTrack(MediaStream stream, MediaStreamTrack track);
     [Conditional=MEDIA_STREAM] void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack track);
+    [Conditional=MEDIA_STREAM] void setMediaStreamTrackIdentifier(MediaStreamTrack track, DOMString identifier);
 
     Promise<void> clearCacheStorageMemoryRepresentation();
     Promise<DOMString> cacheStorageEngineRepresentation();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to