Changeset 155794 in webkit


Ignore:
Timestamp:
Sep 14, 2013 7:25:14 PM (11 years ago)
Author:
eric.carlson@apple.com
Message:

MediaStream API: Update RTCDataChannel
https://bugs.webkit.org/show_bug.cgi?id=121102

Reviewed by Sam Weinig.

Source/WebCore:

Based on https://chromium.googlesource.com/chromium/blink/+/c6975c41956acded7cf0363012d7d6b69d0c6d96,
and https://chromium.googlesource.com/chromium/blink/+/214dab0bd6385f573c918ba5ce58a5aa206ce186.

No new tests, existing tests updated.

  • Modules/mediastream/RTCDataChannel.cpp:

(WebCore::RTCDataChannel::create): Take an options Dictionary.
(WebCore::RTCDataChannel::didChangeReadyState): String -> AtomicString. Early return if the

state hasn't changed.

(WebCore::RTCDataChannel::binaryType): String -> AtomicString.
(WebCore::RTCDataChannel::setBinaryType): String -> AtomicString.

  • Modules/mediastream/RTCDataChannel.h:
  • Modules/mediastream/RTCDataChannel.idl:
  • Modules/mediastream/RTCPeerConnection.cpp:

(WebCore::RTCPeerConnection::createDataChannel): Take an options struct.

  • platform/mediastream/RTCDataChannelHandler.h:
  • platform/mediastream/RTCPeerConnectionHandler.h:

(WebCore::RTCDataChannelInit::RTCDataChannelInit): Take an options struct.

LayoutTests:

  • fast/mediastream/RTCPeerConnection-datachannel-expected.txt:
  • fast/mediastream/RTCPeerConnection-datachannel.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r155767 r155794  
     12013-09-14  Eric Carlson  <eric.carlson@apple.com>
     2
     3        MediaStream API: Update RTCDataChannel
     4        https://bugs.webkit.org/show_bug.cgi?id=121102
     5
     6        Reviewed by Sam Weinig.
     7
     8        * fast/mediastream/RTCPeerConnection-datachannel-expected.txt:
     9        * fast/mediastream/RTCPeerConnection-datachannel.html:
     10
    1112013-09-14  Zan Dobersek  <zdobersek@igalia.com>
    212
  • trunk/LayoutTests/fast/mediastream/RTCPeerConnection-datachannel-expected.txt

    r140310 r155794  
    88PASS dc = pc.createDataChannel("label2", {}); did not throw exception.
    99PASS dc.reliable is true
    10 PASS dc = pc.createDataChannel("label3", {reliable:true}); did not throw exception.
     10PASS dc = pc.createDataChannel("label3", {ordered:true}); did not throw exception.
    1111PASS dc.reliable is true
    12 PASS dc = pc.createDataChannel("label3", {reliable:false}); did not throw exception.
     12PASS dc = pc.createDataChannel("label3", {ordered:false}); did not throw exception.
     13PASS dc.reliable is false
     14PASS dc = pc.createDataChannel("label3", {maxRetransmits:0}); did not throw exception.
     15PASS dc.reliable is false
     16PASS dc = pc.createDataChannel("label3", {maxRetransmitTime:0}); did not throw exception.
    1317PASS dc.reliable is false
    1418PASS pc is connected
  • trunk/LayoutTests/fast/mediastream/RTCPeerConnection-datachannel.html

    r155270 r155794  
    8787shouldNotThrow('dc = pc.createDataChannel("label2", {});');
    8888shouldBe("dc.reliable", "true");
    89 shouldNotThrow('dc = pc.createDataChannel("label3", {reliable:true});');
     89shouldNotThrow('dc = pc.createDataChannel("label3", {ordered:true});');
    9090shouldBe("dc.reliable", "true");
    91 shouldNotThrow('dc = pc.createDataChannel("label3", {reliable:false});');
     91shouldNotThrow('dc = pc.createDataChannel("label3", {ordered:false});');
     92shouldBe("dc.reliable", "false");
     93shouldNotThrow('dc = pc.createDataChannel("label3", {maxRetransmits:0});');
     94shouldBe("dc.reliable", "false");
     95shouldNotThrow('dc = pc.createDataChannel("label3", {maxRetransmitTime:0});');
    9296shouldBe("dc.reliable", "false");
    9397
  • trunk/Source/WebCore/ChangeLog

    r155792 r155794  
     12013-09-14  Eric Carlson  <eric.carlson@apple.com>
     2
     3        MediaStream API: Update RTCDataChannel
     4        https://bugs.webkit.org/show_bug.cgi?id=121102
     5
     6        Reviewed by Sam Weinig.
     7
     8        Based on https://chromium.googlesource.com/chromium/blink/+/c6975c41956acded7cf0363012d7d6b69d0c6d96,
     9        and https://chromium.googlesource.com/chromium/blink/+/214dab0bd6385f573c918ba5ce58a5aa206ce186.
     10
     11        No new tests, existing tests updated.
     12
     13        * Modules/mediastream/RTCDataChannel.cpp:
     14        (WebCore::RTCDataChannel::create): Take an options Dictionary.
     15        (WebCore::RTCDataChannel::didChangeReadyState): String -> AtomicString. Early return if the
     16            state hasn't changed.
     17        (WebCore::RTCDataChannel::binaryType): String -> AtomicString.
     18        (WebCore::RTCDataChannel::setBinaryType): String -> AtomicString.
     19        * Modules/mediastream/RTCDataChannel.h:
     20        * Modules/mediastream/RTCDataChannel.idl:
     21
     22        * Modules/mediastream/RTCPeerConnection.cpp:
     23        (WebCore::RTCPeerConnection::createDataChannel): Take an options struct.
     24        * platform/mediastream/RTCDataChannelHandler.h:
     25
     26        * platform/mediastream/RTCPeerConnectionHandler.h:
     27        (WebCore::RTCDataChannelInit::RTCDataChannelInit): Take an options struct.
     28
    1292013-09-14  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
    230
  • trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp

    r155792 r155794  
    3030
    3131#include "Blob.h"
     32#include "Dictionary.h"
    3233#include "Event.h"
    3334#include "ExceptionCode.h"
     
    3839#include <runtime/ArrayBuffer.h>
    3940#include <runtime/ArrayBufferView.h>
     41#include <wtf/NeverDestroyed.h>
    4042
    4143namespace WebCore {
    4244
    43 PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, RTCPeerConnectionHandler* peerConnectionHandler, const String& label, bool reliable, ExceptionCode& ec)
    44 {
    45     OwnPtr<RTCDataChannelHandler> handler = peerConnectionHandler->createDataChannel(label, reliable);
     45static const AtomicString& blobKeyword()
     46{
     47    static NeverDestroyed<AtomicString> blob("blob", AtomicString::ConstructFromLiteral);
     48    return blob;
     49}
     50
     51static const AtomicString& arraybufferKeyword()
     52{
     53    static NeverDestroyed<AtomicString> arraybuffer("arraybuffer", AtomicString::ConstructFromLiteral);
     54    return arraybuffer;
     55}
     56
     57PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, RTCPeerConnectionHandler* peerConnectionHandler, const String& label, const Dictionary& options, ExceptionCode& ec)
     58{
     59    RTCDataChannelInit initData;
     60    options.get("ordered", initData.ordered);
     61    options.get("negotiated", initData.negotiated);
     62    options.get("id", initData.id);
     63    options.get("maxRetransmits", initData.maxRetransmits);
     64    options.get("maxRetransmitTime", initData.maxRetransmitTime);
     65    options.get("protocol", initData.protocol);
     66
     67    OwnPtr<RTCDataChannelHandler> handler = peerConnectionHandler->createDataChannel(label, initData);
    4668    if (!handler) {
    4769        ec = NOT_SUPPORTED_ERR;
     
    107129}
    108130
    109 String RTCDataChannel::readyState() const
    110 {
     131AtomicString RTCDataChannel::readyState() const
     132{
     133    static NeverDestroyed<AtomicString> connectingState("connecting", AtomicString::ConstructFromLiteral);
     134    static NeverDestroyed<AtomicString> openState("open", AtomicString::ConstructFromLiteral);
     135    static NeverDestroyed<AtomicString> closingState("closing", AtomicString::ConstructFromLiteral);
     136    static NeverDestroyed<AtomicString> closedState("closed", AtomicString::ConstructFromLiteral);
     137   
    111138    switch (m_readyState) {
    112139    case ReadyStateConnecting:
    113         return ASCIILiteral("connecting");
     140        return connectingState;
    114141    case ReadyStateOpen:
    115         return ASCIILiteral("open");
     142        return openState;
    116143    case ReadyStateClosing:
    117         return ASCIILiteral("closing");
     144        return closingState;
    118145    case ReadyStateClosed:
    119         return ASCIILiteral("closed");
     146        return closedState;
    120147    }
    121148
    122149    ASSERT_NOT_REACHED();
    123     return String();
     150    return emptyAtom;
    124151}
    125152
     
    129156}
    130157
    131 String RTCDataChannel::binaryType() const
     158AtomicString RTCDataChannel::binaryType() const
    132159{
    133160    switch (m_binaryType) {
    134161    case BinaryTypeBlob:
    135         return ASCIILiteral("blob");
     162        return blobKeyword();
    136163    case BinaryTypeArrayBuffer:
    137         return ASCIILiteral("arraybuffer");
    138     }
     164        return arraybufferKeyword();
     165    }
     166
    139167    ASSERT_NOT_REACHED();
    140     return String();
    141 }
    142 
    143 void RTCDataChannel::setBinaryType(const String& binaryType, ExceptionCode& ec)
    144 {
    145     if (binaryType == "blob")
     168    return emptyAtom;
     169}
     170
     171void RTCDataChannel::setBinaryType(const AtomicString& binaryType, ExceptionCode& ec)
     172{
     173    if (binaryType == blobKeyword())
    146174        ec = NOT_SUPPORTED_ERR;
    147     else if (binaryType == "arraybuffer")
     175    else if (binaryType == arraybufferKeyword())
    148176        m_binaryType = BinaryTypeArrayBuffer;
    149177    else
     
    157185        return;
    158186    }
     187
    159188    if (!m_handler->sendStringData(data)) {
    160189        // FIXME: Decide what the right exception here is.
     
    206235void RTCDataChannel::didChangeReadyState(ReadyState newState)
    207236{
    208     if (m_stopped || m_readyState == ReadyStateClosed)
     237    if (m_stopped || m_readyState == ReadyStateClosed || m_readyState == newState)
    209238        return;
    210239
     
    240269        return;
    241270    }
     271
    242272    if (m_binaryType == BinaryTypeArrayBuffer) {
    243273        RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(data, dataLength);
  • trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h

    r155792 r155794  
    3535
    3636namespace JSC {
    37 class ArrayBuffer;
    38 class ArrayBufferView;
     37    class ArrayBuffer;
     38    class ArrayBufferView;
    3939}
    4040
     
    4242
    4343class Blob;
     44class Dictionary;
    4445class RTCDataChannelHandler;
    4546class RTCPeerConnectionHandler;
     
    4748class RTCDataChannel : public RefCounted<RTCDataChannel>, public ScriptWrappable, public EventTarget, public RTCDataChannelHandlerClient {
    4849public:
    49     static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, const String& label, bool reliable, ExceptionCode&);
    5050    static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, PassOwnPtr<RTCDataChannelHandler>);
     51    static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, const String& , const Dictionary&, ExceptionCode&);
    5152    ~RTCDataChannel();
    5253
     
    5859    bool negotiated() const;
    5960    unsigned short id() const;
    60     String readyState() const;
     61    AtomicString readyState() const;
    6162    unsigned long bufferedAmount() const;
    6263
    63     String binaryType() const;
    64     void setBinaryType(const String&, ExceptionCode&);
     64    AtomicString binaryType() const;
     65    void setBinaryType(const AtomicString&, ExceptionCode&);
    6566
    6667    void send(const String&, ExceptionCode&);
     
    9697    virtual void refEventTarget() OVERRIDE { ref(); }
    9798    virtual void derefEventTarget() OVERRIDE { deref(); }
     99
    98100    EventTargetData m_eventTargetData;
    99101    ScriptExecutionContext* m_scriptExecutionContext;
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp

    r155346 r155794  
    450450    }
    451451
    452     bool reliable = true;
    453     options.get("reliable", reliable);
    454     RefPtr<RTCDataChannel> channel = RTCDataChannel::create(scriptExecutionContext(), m_peerHandler.get(), label, reliable, ec);
    455     if (ec)
    456         return 0;
     452    RefPtr<RTCDataChannel> channel = RTCDataChannel::create(scriptExecutionContext(), m_peerHandler.get(), label, options, ec);
     453    if (ec)
     454        return 0;
     455
    457456    m_dataChannels.append(channel);
    458457    return channel.release();
  • trunk/Source/WebCore/platform/mediastream/RTCPeerConnectionHandler.h

    r141984 r155794  
    5252class RTCVoidRequest;
    5353
     54struct RTCDataChannelInit {
     55public:
     56    RTCDataChannelInit()
     57        : ordered(true)
     58        , maxRetransmitTime(-1)
     59        , maxRetransmits(-1)
     60        , negotiated(false)
     61        , id(-1) { }
     62    bool ordered;
     63    int maxRetransmitTime;
     64    int maxRetransmits;
     65    String protocol;
     66    bool negotiated;
     67    int id;
     68};
     69
    5470class RTCPeerConnectionHandler {
    5571public:
     
    7086    virtual void removeStream(PassRefPtr<MediaStreamDescriptor>) = 0;
    7187    virtual void getStats(PassRefPtr<RTCStatsRequest>) = 0;
    72     virtual PassOwnPtr<RTCDataChannelHandler> createDataChannel(const String& label, bool reliable) = 0;
     88    virtual PassOwnPtr<RTCDataChannelHandler> createDataChannel(const String& label, const RTCDataChannelInit&) = 0;
    7389    virtual PassOwnPtr<RTCDTMFSenderHandler> createDTMFSender(PassRefPtr<MediaStreamComponent>) = 0;
    7490    virtual void stop() = 0;
Note: See TracChangeset for help on using the changeset viewer.