⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 230548 in webkit


Ignore:
Timestamp:
Apr 11, 2018, 2:49:28 PM (9 years ago)
Author:
youenn@apple.com
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.
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r230531 r230548  
     12018-04-11  Youenn Fablet  <youenn@apple.com>
     2
     3        Preventively expect UTF8 strings from libwebrtc SDP and error messages
     4        https://bugs.webkit.org/show_bug.cgi?id=184509
     5
     6        Reviewed by Eric Carlson.
     7
     8        * webrtc/utf8-sdp-expected.txt: Added.
     9        * webrtc/utf8-sdp.html: Added.
     10
    1112018-04-11  Alicia Boya García  <aboya@igalia.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r230544 r230548  
     12018-04-11  Youenn Fablet  <youenn@apple.com>
     2
     3        Preventively expect UTF8 strings from libwebrtc SDP and error messages
     4        https://bugs.webkit.org/show_bug.cgi?id=184509
     5
     6        Reviewed by Eric Carlson.
     7
     8        Make WebCore code expect any libwebrtc string to contain UTF-8.
     9        Currently SDPs do not contain any UTF-8 specific character
     10        but https://tools.ietf.org/html/rfc4566 allows it.
     11
     12        Add Internals API to set track id so that we can inject UTF-8 inside some WebRTC tests.
     13        Test: webrtc/utf8-sdp.html
     14
     15        * Modules/mediastream/MediaStreamTrack.h:
     16        (WebCore::MediaStreamTrack::setIdForTesting):
     17        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
     18        (WebCore::fromStdString):
     19        (WebCore::fromSessionDescription):
     20        (WebCore::LibWebRTCMediaEndpoint::doSetLocalDescription):
     21        (WebCore::LibWebRTCMediaEndpoint::doSetRemoteDescription):
     22        (WebCore::LibWebRTCMediaEndpoint::mediaStreamFromRTCStream):
     23        (WebCore::LibWebRTCMediaEndpoint::addRemoteTrack):
     24        (WebCore::LibWebRTCMediaEndpoint::addDataChannel):
     25        (WebCore::LibWebRTCMediaEndpoint::OnIceCandidate):
     26        (WebCore::LibWebRTCMediaEndpoint::createSessionDescriptionSucceeded):
     27        (WebCore::LibWebRTCMediaEndpoint::createSessionDescriptionFailed):
     28        (WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionFailed):
     29        (WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionFailed):
     30        (WebCore::trackId): Deleted.
     31        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
     32        (WebCore::fromStdString):
     33        (WebCore::LibWebRTCPeerConnectionBackend::doAddIceCandidate):
     34        (WebCore::createReceiverForSource):
     35        * platform/mediastream/MediaStreamTrackPrivate.h:
     36        (WebCore::MediaStreamTrackPrivate::setIdForTesting):
     37        * testing/Internals.cpp:
     38        (WebCore::Internals::setMediaStreamTrackIdentifier):
     39        * testing/Internals.h:
     40        * testing/Internals.idl:
     41
    1422018-04-11  Said Abou-Hallawa  <sabouhallawa@apple.com>
    243
  • trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h

    r226412 r230548  
    139139    bool hasPendingActivity() const final;
    140140
     141    void setIdForTesting(String&& id) { m_private->setIdForTesting(WTFMove(id)); }
     142
    141143protected:
    142144    MediaStreamTrack(ScriptExecutionContext&, Ref<MediaStreamTrackPrivate>&&);
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

    r230342 r230548  
    5858namespace WebCore {
    5959
     60static inline String fromStdString(const std::string& value)
     61{
     62    return String::fromUTF8(value.data(), value.length());
     63}
     64
    6065LibWebRTCMediaEndpoint::LibWebRTCMediaEndpoint(LibWebRTCPeerConnectionBackend& peerConnection, LibWebRTCProvider& client)
    6166    : m_peerConnectionBackend(peerConnection)
    … …  
    117122    std::string sdp;
    118123    description->ToString(&sdp);
    119     String sdpString(sdp.data(), sdp.size());
    120 
    121     return RTCSessionDescription::create(fromSessionDescriptionType(*description), WTFMove(sdpString));
     124
     125    return RTCSessionDescription::create(fromSessionDescriptionType(*description), fromStdString(sdp));
    122126}
    123127
    … …  
    161165
    162166    if (!sessionDescription) {
    163         String errorMessage(error.description.data(), error.description.size());
    164         m_peerConnectionBackend.setLocalDescriptionFailed(Exception { OperationError, WTFMove(errorMessage) });
     167        m_peerConnectionBackend.setLocalDescriptionFailed(Exception { OperationError, fromStdString(error.description) });
    165168        return;
    166169    }
    … …  
    182185    std::unique_ptr<webrtc::SessionDescriptionInterface> sessionDescription(webrtc::CreateSessionDescription(sessionDescriptionType(description.type()), description.sdp().utf8().data(), &error));
    183186    if (!sessionDescription) {
    184         String errorMessage(error.description.data(), error.description.size());
    185         m_peerConnectionBackend.setRemoteDescriptionFailed(Exception { OperationError, WTFMove(errorMessage) });
     187        m_peerConnectionBackend.setRemoteDescriptionFailed(Exception { OperationError, fromStdString(error.description) });
    186188        return;
    187189    }
    … …  
    302304    if (track)
    303305        m_id = track->id();
    304 }
    305 
    306 static inline String fromStdString(const std::string& value)
    307 {
    308     return String(value.data(), value.length());
    309306}
    310307
    … …  
    619616}
    620617
    621 static inline String trackId(webrtc::MediaStreamTrackInterface& videoTrack)
    622 {
    623     return String(videoTrack.id().data(), videoTrack.id().size());
    624 }
    625 
    626618MediaStream& LibWebRTCMediaEndpoint::mediaStreamFromRTCStream(webrtc::MediaStreamInterface& rtcStream)
    627619{
    628620    auto mediaStream = m_streams.ensure(&rtcStream, [&rtcStream, this] {
    629621        auto label = rtcStream.label();
    630         auto stream = MediaStream::create(*m_peerConnectionBackend.connection().scriptExecutionContext(), MediaStreamPrivate::create({ }, String(label.data(), label.size())));
     622        auto stream = MediaStream::create(*m_peerConnectionBackend.connection().scriptExecutionContext(), MediaStreamPrivate::create({ }, fromStdString(label)));
    631623        auto streamPointer = stream.ptr();
    632624        m_peerConnectionBackend.addRemoteStream(WTFMove(stream));
    … …  
    668660    case cricket::MEDIA_TYPE_AUDIO: {
    669661        rtc::scoped_refptr<webrtc::AudioTrackInterface> audioTrack = static_cast<webrtc::AudioTrackInterface*>(rtcTrack);
    670         auto audioReceiver = m_peerConnectionBackend.audioReceiver(trackId(*rtcTrack));
     662        auto audioReceiver = m_peerConnectionBackend.audioReceiver(fromStdString(rtcTrack->id()));
    671663
    672664        receiver = WTFMove(audioReceiver.receiver);
    … …  
    676668    case cricket::MEDIA_TYPE_VIDEO: {
    677669        rtc::scoped_refptr<webrtc::VideoTrackInterface> videoTrack = static_cast<webrtc::VideoTrackInterface*>(rtcTrack);
    678         auto videoReceiver = m_peerConnectionBackend.videoReceiver(trackId(*rtcTrack));
     670        auto videoReceiver = m_peerConnectionBackend.videoReceiver(fromStdString(rtcTrack->id()));
    679671
    680672        receiver = WTFMove(videoReceiver.receiver);
    … …  
    767759    init.maxPacketLifeTime = dataChannel->maxRetransmitTime();
    768760    init.maxRetransmits = dataChannel->maxRetransmits();
    769     init.protocol = String(protocol.data(), protocol.size());
     761    init.protocol = fromStdString(protocol);
    770762    init.negotiated = dataChannel->negotiated();
    771763    init.id = dataChannel->id();
    … …  
    775767    auto handler =  std::make_unique<LibWebRTCDataChannelHandler>(WTFMove(dataChannel));
    776768    ASSERT(m_peerConnectionBackend.connection().scriptExecutionContext());
    777     auto channel = RTCDataChannel::create(*m_peerConnectionBackend.connection().scriptExecutionContext(), WTFMove(handler), String(label.data(), label.size()), WTFMove(init));
     769    auto channel = RTCDataChannel::create(*m_peerConnectionBackend.connection().scriptExecutionContext(), WTFMove(handler), fromStdString(label), WTFMove(init));
    778770
    779771    if (isOpened) {
    … …  
    873865    std::string sdp;
    874866    rtcCandidate->ToString(&sdp);
    875     String candidateSDP(sdp.data(), sdp.size());
    876 
    877     auto mid = rtcCandidate->sdp_mid();
    878     String candidateMid(mid.data(), mid.size());
    879867
    880868    auto sdpMLineIndex = safeCast<unsigned short>(rtcCandidate->sdp_mline_index());
    881869
    882     callOnMainThread([protectedThis = makeRef(*this), mid = WTFMove(candidateMid), sdp = WTFMove(candidateSDP), sdpMLineIndex] {
    883         if (protectedThis->isStopped())
    884             return;
    885         protectedThis->m_peerConnectionBackend.newICECandidate(String(sdp), String(mid), sdpMLineIndex);
     870    callOnMainThread([protectedThis = makeRef(*this), mid = fromStdString(rtcCandidate->sdp_mid()), sdp = fromStdString(sdp), sdpMLineIndex]() mutable {
     871        if (protectedThis->isStopped())
     872            return;
     873        protectedThis->m_peerConnectionBackend.newICECandidate(WTFMove(sdp), WTFMove(mid), sdpMLineIndex);
    886874    });
    887875}
    … …  
    896884    std::string sdp;
    897885    description->ToString(&sdp);
    898     String sdpString(sdp.data(), sdp.size());
    899 
    900     callOnMainThread([protectedThis = makeRef(*this), sdp = WTFMove(sdpString)] {
     886
     887    callOnMainThread([protectedThis = makeRef(*this), sdp = fromStdString(sdp)]() mutable {
    901888        if (protectedThis->isStopped())
    902889            return;
    903890        if (protectedThis->m_isInitiator)
    904             protectedThis->m_peerConnectionBackend.createOfferSucceeded(String(sdp));
     891            protectedThis->m_peerConnectionBackend.createOfferSucceeded(WTFMove(sdp));
    905892        else
    906             protectedThis->m_peerConnectionBackend.createAnswerSucceeded(String(sdp));
     893            protectedThis->m_peerConnectionBackend.createAnswerSucceeded(WTFMove(sdp));
    907894    });
    908895}
    … …  
    910897void LibWebRTCMediaEndpoint::createSessionDescriptionFailed(const std::string& errorMessage)
    911898{
    912     String error(errorMessage.data(), errorMessage.size());
    913     callOnMainThread([protectedThis = makeRef(*this), error = WTFMove(error)] () mutable {
     899    callOnMainThread([protectedThis = makeRef(*this), error = fromStdString(errorMessage)] () mutable {
    914900        if (protectedThis->isStopped())
    915901            return;
    … …  
    932918void LibWebRTCMediaEndpoint::setLocalSessionDescriptionFailed(const std::string& errorMessage)
    933919{
    934     String error(errorMessage.data(), errorMessage.size());
    935     callOnMainThread([protectedThis = makeRef(*this), error = WTFMove(error)] () mutable {
     920    callOnMainThread([protectedThis = makeRef(*this), error = fromStdString(errorMessage)] () mutable {
    936921        if (protectedThis->isStopped())
    937922            return;
    … …  
    951936void LibWebRTCMediaEndpoint::setRemoteSessionDescriptionFailed(const std::string& errorMessage)
    952937{
    953     String error(errorMessage.data(), errorMessage.size());
    954     callOnMainThread([protectedThis = makeRef(*this), error = WTFMove(error)] () mutable {
     938    callOnMainThread([protectedThis = makeRef(*this), error = fromStdString(errorMessage)] () mutable {
    955939        if (protectedThis->isStopped())
    956940            return;
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp

    r230152 r230548  
    210210
    211211    if (!rtcCandidate) {
    212         String message(error.description.data(), error.description.size());
    213         addIceCandidateFailed(Exception { OperationError, WTFMove(message) });
     212        addIceCandidateFailed(Exception { OperationError, String::fromUTF8(error.description.data(), error.description.length()) });
    214213        return;
    215214    }
    … …  
    238237static inline Ref<RTCRtpReceiver> createReceiverForSource(ScriptExecutionContext& context, Ref<RealtimeMediaSource>&& source)
    239238{
    240     String id = source->id();
    241     auto remoteTrackPrivate = MediaStreamTrackPrivate::create(WTFMove(source), WTFMove(id));
     239    auto remoteTrackPrivate = MediaStreamTrackPrivate::create(WTFMove(source), String { source->id() });
    242240    auto remoteTrack = MediaStreamTrack::create(context, WTFMove(remoteTrackPrivate));
    243241
  • trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h

    r223728 r230548  
    101101    ReadyState readyState() const { return m_readyState; }
    102102
     103    void setIdForTesting(String&& id) { m_id = WTFMove(id); }
     104
    103105private:
    104106    MediaStreamTrackPrivate(Ref<RealtimeMediaSource>&&, String&& id);
  • trunk/Source/WebCore/testing/Internals.cpp

    r230211 r230548  
    42874287}
    42884288
     4289void Internals::setMediaStreamTrackIdentifier(MediaStreamTrack& track, String&& id)
     4290{
     4291    track.setIdForTesting(WTFMove(id));
     4292}
    42894293#endif
    42904294
  • trunk/Source/WebCore/testing/Internals.h

    r229475 r230548  
    623623    void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
    624624    void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
     625    void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
    625626#endif
    626627
  • trunk/Source/WebCore/testing/Internals.idl

    r229475 r230548  
    567567    [Conditional=MEDIA_STREAM] void removeMediaStreamTrack(MediaStream stream, MediaStreamTrack track);
    568568    [Conditional=MEDIA_STREAM] void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack track);
     569    [Conditional=MEDIA_STREAM] void setMediaStreamTrackIdentifier(MediaStreamTrack track, DOMString identifier);
    569570
    570571    Promise<void> clearCacheStorageMemoryRepresentation();
Note: See TracChangeset for help on using the changeset viewer.