Clean up RTCDataChannel
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Mar 2017 21:42:19 +0000 (21:42 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Mar 2017 21:42:19 +0000 (21:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169732

LayoutTests/imported/w3c:

Patch by Youenn Fablet <youenn@apple.com> on 2017-03-30
Reviewed by Chris Dumez.

* web-platform-tests/webrtc/RTCDataChannelEvent-constructor-expected.txt:

Source/JavaScriptCore:

Patch by Youenn Fablet <youenn@apple.com> on 2017-03-30
Reviewed by Chris Dumez.

* runtime/CommonIdentifiers.h: Adding RTCDataChannelEvent.

Source/WebCore:

Patch by Youenn Fablet  <youenn@apple.com> and Jon Lee <jonlee@apple.com> on 2017-03-30
Reviewed by Chris Dumez.

Test: webrtc/datachannel/datachannel-event.html
      webrtc/datachannel/bufferedAmountLowThreshold.html

Making RTCDataChannel interface closer to the spec updating implementation accordingly.
See https://w3c.github.io/webrtc-pc/#rtcdatachannel.
In particular adding RTCDataChannelEvent constructor, and missing bufferedAmount related attributes.
Doing some additional cleaning refactoring.

Making bufferedAmountIsDecreasing take a bufferedAmount argument so that we get the actual value passed by
libwebrtc without needing to get it from the libwebrtc network thread again.
In the future, we should store the bufferedAmount value in RTCDataChannel and update its value on each libwebrtc
OnBufferedAmountChange. Special treatment may be needed when the data channel is closed, in which case the bufferedAmount should just be
updated to increase in the send method.

Added some FIXMEs as RTCDataChannel is not aligned with the spec related to send and bufferedAmount.

* Modules/mediastream/RTCDataChannel.cpp:
(WebCore::RTCDataChannel::send):
(WebCore::RTCDataChannel::close):
(WebCore::RTCDataChannel::didChangeReadyState):
(WebCore::RTCDataChannel::bufferedAmountIsDecreasing):
* Modules/mediastream/RTCDataChannel.h:
* Modules/mediastream/RTCDataChannel.idl:
* Modules/mediastream/RTCDataChannelEvent.cpp:
(WebCore::RTCDataChannelEvent::create):
(WebCore::RTCDataChannelEvent::RTCDataChannelEvent):
(WebCore::RTCDataChannelEvent::channel):
* Modules/mediastream/RTCDataChannelEvent.h:
* Modules/mediastream/RTCDataChannelEvent.idl:
* Modules/mediastream/RTCPeerConnection.idl:
* Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp:
(WebCore::LibWebRTCDataChannelHandler::OnStateChange):
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::LibWebRTCMediaEndpoint::addDataChannel):
* WebCore.xcodeproj/project.pbxproj:
* dom/EventNames.h:
* platform/mediastream/RTCDataChannelHandler.h:
* platform/mediastream/RTCDataChannelHandlerClient.h:
* platform/mediastream/RTCDataChannelState.h: Added.
* platform/mediastream/RTCPeerConnectionHandlerClient.h:
* platform/mock/RTCDataChannelHandlerMock.cpp:
(WebCore::RTCDataChannelHandlerMock::setClient):
(WebCore::RTCDataChannelHandlerMock::close):
* platform/mock/RTCNotifiersMock.cpp:
(WebCore::IceConnectionNotifier::IceConnectionNotifier):
(WebCore::SignalingStateNotifier::SignalingStateNotifier):
(WebCore::DataChannelStateNotifier::DataChannelStateNotifier):
* platform/mock/RTCNotifiersMock.h:

LayoutTests:

Patch by Youenn Fablet <youenn@apple.com> on 2017-03-30
Reviewed by Chris Dumez.

* webrtc/datachannel/bufferedAmountLowThreshold-expected.txt: Added.
* webrtc/datachannel/bufferedAmountLowThreshold.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214627 268f45cc-cd09-0410-ab3c-d52691b4dbfc

30 files changed:
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannelEvent-constructor-expected.txt
LayoutTests/webrtc/datachannel/basic.html
LayoutTests/webrtc/datachannel/bufferedAmountLowThreshold-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/datachannel/bufferedAmountLowThreshold.html [new file with mode: 0644]
LayoutTests/webrtc/datachannel/datachannel-event-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/datachannel/datachannel-event.html [new file with mode: 0644]
LayoutTests/webrtc/routines.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCDataChannel.cpp
Source/WebCore/Modules/mediastream/RTCDataChannel.h
Source/WebCore/Modules/mediastream/RTCDataChannel.idl
Source/WebCore/Modules/mediastream/RTCDataChannelEvent.cpp
Source/WebCore/Modules/mediastream/RTCDataChannelEvent.h
Source/WebCore/Modules/mediastream/RTCDataChannelEvent.idl
Source/WebCore/Modules/mediastream/RTCPeerConnection.idl
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/EventNames.h
Source/WebCore/platform/mediastream/RTCDataChannelHandler.h
Source/WebCore/platform/mediastream/RTCDataChannelHandlerClient.h
Source/WebCore/platform/mediastream/RTCDataChannelState.h [new file with mode: 0644]
Source/WebCore/platform/mediastream/RTCPeerConnectionHandlerClient.h
Source/WebCore/platform/mock/RTCDataChannelHandlerMock.cpp
Source/WebCore/platform/mock/RTCNotifiersMock.cpp
Source/WebCore/platform/mock/RTCNotifiersMock.h

index 25f8c31..2b1a703 100644 (file)
@@ -1,3 +1,13 @@
+2017-03-30  Youenn Fablet  <youenn@apple.com>
+
+        Clean up RTCDataChannel
+        https://bugs.webkit.org/show_bug.cgi?id=169732
+
+        Reviewed by Chris Dumez.
+
+        * webrtc/datachannel/bufferedAmountLowThreshold-expected.txt: Added.
+        * webrtc/datachannel/bufferedAmountLowThreshold.html: Added.
+
 2017-03-30  Chris Dumez  <cdumez@apple.com>
 
         svg/animations/animations-paused-in-background-page.html is flaky
index 569bb7b..e219ab9 100644 (file)
@@ -1,3 +1,12 @@
+2017-03-30  Youenn Fablet  <youenn@apple.com>
+
+        Clean up RTCDataChannel
+        https://bugs.webkit.org/show_bug.cgi?id=169732
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/webrtc/RTCDataChannelEvent-constructor-expected.txt:
+
 2017-03-28  Youenn Fablet  <youenn@apple.com>
 
         Fix addIceCandidate after r214441
index cf99333..2d56805 100644 (file)
@@ -1,6 +1,6 @@
 
-FAIL RTCDataChannelEvent constructor without a required argument. Can't find variable: RTCDataChannelEvent
-FAIL RTCDataChannelEvent constructor with channel passed as null. assert_throws: function "function () { new RTCDataChannelEvent('type', { channel: null }); }" threw object "ReferenceError: Can't find variable: RTCDataChannelEvent" ("ReferenceError") expected object "TypeError" ("TypeError")
-FAIL RTCDataChannelEvent constructor with a channel passed as undefined. assert_throws: function "function () { new RTCDataChannelEvent('type', { channel: undefined }); }" threw object "ReferenceError: Can't find variable: RTCDataChannelEvent" ("ReferenceError") expected object "TypeError" ("TypeError")
-FAIL RTCDataChannelEvent constructor with full arguments. Can't find variable: RTCDataChannelEvent
+PASS RTCDataChannelEvent constructor without a required argument. 
+PASS RTCDataChannelEvent constructor with channel passed as null. 
+PASS RTCDataChannelEvent constructor with a channel passed as undefined. 
+PASS RTCDataChannelEvent constructor with full arguments. 
 
index 8845f76..2c9dead 100644 (file)
@@ -95,7 +95,7 @@ promise_test((test) => {
                 remoteChannel = event.channel;
                 remoteChannel.onmessage = receiveMessages;
             };
-        }, (candidate) => { return candidate && candidate.candidate.toLowerCase().indexOf("udp") == -1; });
+        }, { filterOutICECandidate: (candidate) => { return candidate && candidate.candidate.toLowerCase().indexOf("udp") == -1; } });
     });
 }, "Basic data channel exchange from offerer to receiver using UDP only");
 
@@ -114,7 +114,7 @@ promise_test((test) => {
                 remoteChannel = event.channel;
                 remoteChannel.onmessage = receiveMessages;
             };
-        }, (candidate) => { return candidate && candidate.candidate.toLowerCase().indexOf("tcp") == -1; });
+        }, { filterOutICECandidate: (candidate) => { return candidate && candidate.candidate.toLowerCase().indexOf("tcp") == -1; } });
     });
 }, "Basic data channel exchange from offerer to receiver using TCP only");
 
@@ -136,7 +136,7 @@ promise_test((test) => {
 
         finishTest = resolve;
         createConnections((localConnection) => {
-            var init = { ordered: true, maxPacketLifeTime: 10, maxRetransmitTime: 11, protocol: "whatever", negotiated: false, id: "id" };
+            var init = { ordered: true, maxPacketLifeTime: 10, maxRetransmitTime: 11, protocol: "whatever", negotiated: false, id: 1 };
             localChannel = localConnection.createDataChannel('sendDataChannel', init);
             localChannel.onopen = () => { sendMessages(localChannel) };
         }, (remoteConnection) => {
diff --git a/LayoutTests/webrtc/datachannel/bufferedAmountLowThreshold-expected.txt b/LayoutTests/webrtc/datachannel/bufferedAmountLowThreshold-expected.txt
new file mode 100644 (file)
index 0000000..6ea0561
--- /dev/null
@@ -0,0 +1,7 @@
+CONSOLE MESSAGE: line 76: channel send is throwing
+CONSOLE MESSAGE: line 76: channel send is throwing
+
+PASS Default buffer threshold 
+PASS Large buffer threshold reached 
+PASS Medium buffer threshold not reached 
+
diff --git a/LayoutTests/webrtc/datachannel/bufferedAmountLowThreshold.html b/LayoutTests/webrtc/datachannel/bufferedAmountLowThreshold.html
new file mode 100644 (file)
index 0000000..185a7d4
--- /dev/null
@@ -0,0 +1,143 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Testing bufferedAmountLowThreashold RTCDataChannel attribute and event</title>
+    <script src="../../resources/testharness.js"></script>
+    <script src="../../resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script src ="../routines.js"></script>
+    <script>
+var localChannel;
+var remoteChannel;
+
+function closeDataChannels() {
+    localChannel.close();
+    remoteChannel.close();
+    closeConnections();
+}
+
+var longString = "abcdefgh";
+for (var cptr = 0; cptr < 14; ++cptr)
+    longString += longString;
+
+function sendMessages(channel)
+{
+    channel.send(longString);
+    channel.send(longString);
+}
+
+function receiveMessages(event) {
+    if (++counter === 1)
+        return;
+    finishTest();
+}
+
+var finishTest;
+
+promise_test((test) => {
+    counter = 0;
+    var gotEvent = false;
+    return new Promise((resolve, reject) => {
+        if (window.internals)
+            internals.useMockRTCPeerConnectionFactory("TwoRealPeerConnections");
+
+        finishTest = resolve;
+        createConnections((localConnection) => {
+            localChannel = localConnection.createDataChannel('sendDataChannel');
+            localChannel.onopen = () => { sendMessages(localChannel); };
+            localChannel.onbufferedamountlow = () => {
+                gotEvent = true;
+            }
+            assert_equals(localChannel.bufferedAmountLowThreshold, 0, "default bufferedAmountLowThreshold value");
+        }, (remoteConnection) => {
+            remoteConnection.ondatachannel = (event) => {
+                remoteChannel = event.channel;
+                remoteChannel.onmessage = receiveMessages;
+            };
+        });
+    }).then (() => {
+         return waitFor(500);
+    }).then (() => {
+        closeDataChannels();
+        assert_true(gotEvent, "got onbufferedamountlow event");
+    });
+}, "Default buffer threshold");
+
+function sendContinuouslyMessages(channel)
+{
+    try {
+        while (channel.bufferedAmount < 200000)
+            channel.send(longString);
+
+       setTimeout(() => sendContinuouslyMessages(channel), 1);
+    } catch(e) {
+        console.log("channel send is throwing");
+    }
+}
+
+promise_test((test) => {
+    counter = 0;
+    var gotEvent = false;
+    return new Promise((resolve, reject) => {
+        if (window.internals)
+            internals.useMockRTCPeerConnectionFactory("TwoRealPeerConnections");
+
+        finishTest = resolve;
+        createConnections((localConnection) => {
+            localChannel = localConnection.createDataChannel('sendDataChannel');
+            localChannel.onopen = () => {
+                sendContinuouslyMessages(localChannel);
+                localChannel.onbufferedamountlow = () => {
+                    gotEvent = true;
+                }
+            };
+            localChannel.bufferedAmountLowThreshold = 200000;
+        }, (remoteConnection) => {
+            remoteConnection.ondatachannel = (event) => {
+                remoteChannel = event.channel;
+                remoteChannel.onmessage = receiveMessages;
+            };
+        });
+    }).then (() => {
+         return waitFor(500);
+    }).then (() => {
+        closeDataChannels();
+        assert_true(gotEvent, "got onbufferedamountlow event");
+    });
+}, "Large buffer threshold reached");
+
+promise_test((test) => {
+    counter = 0;
+    var gotEvent = false;
+    return new Promise((resolve, reject) => {
+        if (window.internals)
+            internals.useMockRTCPeerConnectionFactory("TwoRealPeerConnections");
+
+        finishTest = resolve;
+        createConnections((localConnection) => {
+            localChannel = localConnection.createDataChannel('sendDataChannel');
+            localChannel.onopen = () => {
+                sendContinuouslyMessages(localChannel);
+                localChannel.onbufferedamountlow = () => {
+                    gotEvent = true;
+                }
+            };
+            localChannel.bufferedAmountLowThreshold = 100000;
+        }, (remoteConnection) => {
+            remoteConnection.ondatachannel = (event) => {
+                remoteChannel = event.channel;
+                remoteChannel.onmessage = receiveMessages;
+            };
+        });
+    }).then (() => {
+         return waitFor(500);
+    }).then (() => {
+        closeDataChannels();
+        assert_false(gotEvent, "got onbufferedamountlow event");
+    });
+}, "Medium buffer threshold not reached");
+    </script>
+  </body>
+</html>
diff --git a/LayoutTests/webrtc/datachannel/datachannel-event-expected.txt b/LayoutTests/webrtc/datachannel/datachannel-event-expected.txt
new file mode 100644 (file)
index 0000000..a04ecaa
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Testing data channel event constructor 
+
diff --git a/LayoutTests/webrtc/datachannel/datachannel-event.html b/LayoutTests/webrtc/datachannel/datachannel-event.html
new file mode 100644 (file)
index 0000000..a6cdd5b
--- /dev/null
@@ -0,0 +1,31 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Testing RTCDataChannelEvent</title>
+    <script src="../../resources/testharness.js"></script>
+    <script src="../../resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script>
+test(() => {
+    var pc = new RTCPeerConnection();
+    var channel = pc.createDataChannel("test");
+
+    assert_throws(new TypeError, () => new RTCDataChannelEvent());
+    assert_throws(new TypeError, () => new RTCDataChannelEvent("test"));
+    assert_throws(new TypeError, () => new RTCDataChannelEvent("test", undefined));
+    assert_throws(new TypeError, () => new RTCDataChannelEvent("test", { channel: 1 }));
+    assert_throws(new TypeError, () => new RTCDataChannelEvent(undefined, { channel: 1 }));
+
+    var event = new RTCDataChannelEvent("test", { channel: channel });
+    assert_equals(event.channel, channel, "channel passed in constructor should be used");
+    assert_equals(event.type, "test");
+    assert_equals(event.isTrusted, false, "trusted");
+    assert_equals(event.bubbles, false, "bubble");
+    assert_equals(event.cancelable, false, "cancelable");
+
+}, "Testing data channel event constructor");
+    </script>
+  </body>
+</html>
index fce0244..eee04a9 100644 (file)
@@ -2,16 +2,16 @@
 var localConnection;
 var remoteConnection;
 
-function createConnections(setupLocalConnection, setupRemoteConnection, filterOutICECandidate) {
+function createConnections(setupLocalConnection, setupRemoteConnection, options = { }) {
     localConnection = new RTCPeerConnection();
-    localConnection.onicecandidate = (event) => { iceCallback1(event, filterOutICECandidate) };
+    localConnection.onicecandidate = (event) => { iceCallback1(event, options.filterOutICECandidate) };
     setupLocalConnection(localConnection);
 
     remoteConnection = new RTCPeerConnection();
-    remoteConnection.onicecandidate = (event) => { iceCallback2(event, filterOutICECandidate) };
+    remoteConnection.onicecandidate = (event) => { iceCallback2(event, options.filterOutICECandidate) };
     setupRemoteConnection(remoteConnection);
 
-    localConnection.createOffer().then(gotDescription1, onCreateSessionDescriptionError);
+    localConnection.createOffer().then((desc) => gotDescription1(desc, options), onCreateSessionDescriptionError);
 
     return [localConnection, remoteConnection]
 }
@@ -27,15 +27,21 @@ function onCreateSessionDescriptionError(error)
     assert_unreached();
 }
 
-function gotDescription1(desc)
+function gotDescription1(desc, options)
 {
+    if (options.observeOffer)
+        options.observeOffer(desc);
+
     localConnection.setLocalDescription(desc);
     remoteConnection.setRemoteDescription(desc);
-    remoteConnection.createAnswer().then(gotDescription2, onCreateSessionDescriptionError);
+    remoteConnection.createAnswer().then((desc) => gotDescription2(desc, options), onCreateSessionDescriptionError);
 }
 
-function gotDescription2(desc)
+function gotDescription2(desc, options)
 {
+    if (options.observeAnswer)
+        options.observeAnswer(desc);
+
     remoteConnection.setLocalDescription(desc);
     localConnection.setRemoteDescription(desc);
 }
index c12ad33..b69813c 100644 (file)
@@ -1,3 +1,12 @@
+2017-03-30  Youenn Fablet  <youenn@apple.com>
+
+        Clean up RTCDataChannel
+        https://bugs.webkit.org/show_bug.cgi?id=169732
+
+        Reviewed by Chris Dumez.
+
+        * runtime/CommonIdentifiers.h: Adding RTCDataChannelEvent.
+
 2017-03-30  Saam Barati  <sbarati@apple.com>
 
         WebAssembly: pass Wasm::Context* to vmEntryToWasm when not using fast TLS
index 8adec3d..3c0293a 100644 (file)
     macro(ReferenceError) \
     macro(Reflect) \
     macro(RegExp) \
-    macro(Response) \
     macro(Request) \
+    macro(Response) \
+    macro(RTCDataChannel) \
+    macro(RTCDataChannelEvent) \
     macro(RTCDTMFToneChangeEvent) \
     macro(RTCIceCandidate) \
     macro(RTCIceTransport) \
index 55320a2..ba13c29 100644 (file)
@@ -1,3 +1,59 @@
+2017-03-30  Youenn Fablet  <youenn@apple.com> and Jon Lee <jonlee@apple.com>
+
+        Clean up RTCDataChannel
+        https://bugs.webkit.org/show_bug.cgi?id=169732
+
+        Reviewed by Chris Dumez.
+
+        Test: webrtc/datachannel/datachannel-event.html
+              webrtc/datachannel/bufferedAmountLowThreshold.html
+
+        Making RTCDataChannel interface closer to the spec updating implementation accordingly.
+        See https://w3c.github.io/webrtc-pc/#rtcdatachannel.
+        In particular adding RTCDataChannelEvent constructor, and missing bufferedAmount related attributes.
+        Doing some additional cleaning refactoring.
+
+        Making bufferedAmountIsDecreasing take a bufferedAmount argument so that we get the actual value passed by
+        libwebrtc without needing to get it from the libwebrtc network thread again.
+        In the future, we should store the bufferedAmount value in RTCDataChannel and update its value on each libwebrtc
+        OnBufferedAmountChange. Special treatment may be needed when the data channel is closed, in which case the bufferedAmount should just be
+        updated to increase in the send method.
+
+        Added some FIXMEs as RTCDataChannel is not aligned with the spec related to send and bufferedAmount.
+
+        * Modules/mediastream/RTCDataChannel.cpp:
+        (WebCore::RTCDataChannel::send):
+        (WebCore::RTCDataChannel::close):
+        (WebCore::RTCDataChannel::didChangeReadyState):
+        (WebCore::RTCDataChannel::bufferedAmountIsDecreasing):
+        * Modules/mediastream/RTCDataChannel.h:
+        * Modules/mediastream/RTCDataChannel.idl:
+        * Modules/mediastream/RTCDataChannelEvent.cpp:
+        (WebCore::RTCDataChannelEvent::create):
+        (WebCore::RTCDataChannelEvent::RTCDataChannelEvent):
+        (WebCore::RTCDataChannelEvent::channel):
+        * Modules/mediastream/RTCDataChannelEvent.h:
+        * Modules/mediastream/RTCDataChannelEvent.idl:
+        * Modules/mediastream/RTCPeerConnection.idl:
+        * Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp:
+        (WebCore::LibWebRTCDataChannelHandler::OnStateChange):
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::LibWebRTCMediaEndpoint::addDataChannel):
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/EventNames.h:
+        * platform/mediastream/RTCDataChannelHandler.h:
+        * platform/mediastream/RTCDataChannelHandlerClient.h:
+        * platform/mediastream/RTCDataChannelState.h: Added.
+        * platform/mediastream/RTCPeerConnectionHandlerClient.h:
+        * platform/mock/RTCDataChannelHandlerMock.cpp:
+        (WebCore::RTCDataChannelHandlerMock::setClient):
+        (WebCore::RTCDataChannelHandlerMock::close):
+        * platform/mock/RTCNotifiersMock.cpp:
+        (WebCore::IceConnectionNotifier::IceConnectionNotifier):
+        (WebCore::SignalingStateNotifier::SignalingStateNotifier):
+        (WebCore::DataChannelStateNotifier::DataChannelStateNotifier):
+        * platform/mock/RTCNotifiersMock.h:
+
 2017-03-30  Javier Fernandez  <jfernandez@igalia.com>
 
         [css-align] Adapt content-alignment properties to the new baseline syntax
index 9d2cf6c..270c2b2 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -71,30 +72,11 @@ RTCDataChannel::RTCDataChannel(ScriptExecutionContext& context, std::unique_ptr<
 {
 }
 
-const AtomicString& RTCDataChannel::readyState() const
-{
-    static NeverDestroyed<AtomicString> connectingState("connecting", AtomicString::ConstructFromLiteral);
-    static NeverDestroyed<AtomicString> openState("open", AtomicString::ConstructFromLiteral);
-    static NeverDestroyed<AtomicString> closingState("closing", AtomicString::ConstructFromLiteral);
-    static NeverDestroyed<AtomicString> closedState("closed", AtomicString::ConstructFromLiteral);
-
-    switch (m_readyState) {
-    case ReadyStateConnecting:
-        return connectingState;
-    case ReadyStateOpen:
-        return openState;
-    case ReadyStateClosing:
-        return closingState;
-    case ReadyStateClosed:
-        return closedState;
-    }
-
-    ASSERT_NOT_REACHED();
-    return emptyAtom;
-}
-
 size_t RTCDataChannel::bufferedAmount() const
 {
+    // FIXME: We should compute our own bufferedAmount and not count on m_handler which is made null at closing time.
+    if (m_stopped)
+        return 0;
     return m_handler->bufferedAmount();
 }
 
@@ -124,7 +106,8 @@ ExceptionOr<void> RTCDataChannel::setBinaryType(const AtomicString& binaryType)
 
 ExceptionOr<void> RTCDataChannel::send(const String& data)
 {
-    if (m_readyState != ReadyStateOpen)
+    // FIXME: We should only throw in Connected state.
+    if (m_readyState != RTCDataChannelState::Open)
         return Exception { INVALID_STATE_ERR };
 
     if (!m_handler->sendStringData(data)) {
@@ -137,7 +120,8 @@ ExceptionOr<void> RTCDataChannel::send(const String& data)
 
 ExceptionOr<void> RTCDataChannel::send(ArrayBuffer& data)
 {
-    if (m_readyState != ReadyStateOpen)
+    // FIXME: We should only throw in Connected state.
+    if (m_readyState != RTCDataChannelState::Open)
         return Exception { INVALID_STATE_ERR };
 
     size_t dataLength = data.byteLength();
@@ -156,6 +140,7 @@ ExceptionOr<void> RTCDataChannel::send(ArrayBuffer& data)
 
 ExceptionOr<void> RTCDataChannel::send(ArrayBufferView& data)
 {
+    // FIXME: We should only throw in Connected state.
     return send(*data.unsharedBuffer());
 }
 
@@ -171,7 +156,7 @@ void RTCDataChannel::close()
         return;
 
     m_stopped = true;
-    m_readyState = ReadyStateClosed;
+    m_readyState = RTCDataChannelState::Closed;
 
     m_handler->close();
     m_handler->setClient(nullptr);
@@ -179,18 +164,18 @@ void RTCDataChannel::close()
     unsetPendingActivity(this);
 }
 
-void RTCDataChannel::didChangeReadyState(ReadyState newState)
+void RTCDataChannel::didChangeReadyState(RTCDataChannelState newState)
 {
-    if (m_stopped || m_readyState == ReadyStateClosed || m_readyState == newState)
+    if (m_stopped || m_readyState == RTCDataChannelState::Closed || m_readyState == newState)
         return;
 
     m_readyState = newState;
 
     switch (m_readyState) {
-    case ReadyStateOpen:
+    case RTCDataChannelState::Open:
         scheduleDispatchEvent(Event::create(eventNames().openEvent, false, false));
         break;
-    case ReadyStateClosed:
+    case RTCDataChannelState::Closed:
         scheduleDispatchEvent(Event::create(eventNames().closeEvent, false, false));
         break;
     default:
@@ -231,13 +216,13 @@ void RTCDataChannel::didDetectError()
     scheduleDispatchEvent(Event::create(eventNames().errorEvent, false, false));
 }
 
-void RTCDataChannel::bufferedAmountIsDecreasing()
+void RTCDataChannel::bufferedAmountIsDecreasing(size_t amount)
 {
     if (m_stopped)
         return;
 
-    if (bufferedAmount() <= m_bufferedAmountLowThreshold)
-        scheduleDispatchEvent(Event::create(eventNames().bufferedAmountLowThresholdEvent, false, false));
+    if (amount <= m_bufferedAmountLowThreshold)
+        scheduleDispatchEvent(Event::create(eventNames().bufferedamountlowEvent, false, false));
 }
 
 void RTCDataChannel::stop()
index c35512b..a3bb5c6 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -57,7 +58,7 @@ public:
     std::optional<unsigned short> id() const { return m_options.id; };
 
     String label() const { return m_label; }
-    const AtomicString& readyState() const;
+    RTCDataChannelState readyState() const {return m_readyState; }
     size_t bufferedAmount() const;
     size_t bufferedAmountLowThreshold() const { return m_bufferedAmountLowThreshold; }
     void setBufferedAmountLowThreshold(size_t value) { m_bufferedAmountLowThreshold = value; }
@@ -90,20 +91,20 @@ private:
     // ActiveDOMObject API
     void stop() final;
     const char* activeDOMObjectName() const final { return "RTCDataChannel"; }
-    bool canSuspendForDocumentSuspension() const final { return m_readyState == ReadyStateClosed; }
+    bool canSuspendForDocumentSuspension() const final { return m_readyState == RTCDataChannelState::Closed; }
 
     // RTCDataChannelHandlerClient API
-    void didChangeReadyState(ReadyState) final;
+    void didChangeReadyState(RTCDataChannelState) final;
     void didReceiveStringData(const String&) final;
     void didReceiveRawData(const char*, size_t) final;
     void didDetectError() final;
-    void bufferedAmountIsDecreasing() final;
+    void bufferedAmountIsDecreasing(size_t) final;
 
     std::unique_ptr<RTCDataChannelHandler> m_handler;
 
+    // FIXME: m_stopped is probably redundant with m_readyState.
     bool m_stopped { false };
-
-    ReadyState m_readyState { ReadyStateConnecting };
+    RTCDataChannelState m_readyState { RTCDataChannelState::Connecting };
 
     enum class BinaryType { Blob, ArrayBuffer };
     BinaryType m_binaryType { BinaryType::ArrayBuffer };
index 5a8d3ed..ac064f9 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 [
     ActiveDOMObject,
     Conditional=WEB_RTC,
-    NoInterfaceObject,
+    EnabledAtRuntime=PeerConnection,
 ] interface RTCDataChannel : EventTarget {
-    readonly attribute DOMString label;
+    // FIXME: Add support for priority attribute.
+
+    readonly attribute USVString label;
     readonly attribute boolean ordered;
     readonly attribute unsigned short? maxPacketLifeTime;
     readonly attribute unsigned short? maxRetransmits;
-    readonly attribute DOMString protocol;
+    readonly attribute USVString protocol;
     readonly attribute boolean negotiated;
     readonly attribute unsigned short? id;
-    readonly attribute DOMString readyState;
+    readonly attribute RTCDataChannelState readyState;
     readonly attribute unsigned long bufferedAmount;
+    attribute unsigned long bufferedAmountLowThreshold;
 
     [SetterMayThrowException] attribute DOMString binaryType;
 
     [MayThrowException] void send(ArrayBuffer data);
     [MayThrowException] void send(ArrayBufferView data);
     [MayThrowException] void send(Blob data);
-    [MayThrowException] void send(DOMString data);
+    [MayThrowException] void send(USVString data);
 
     void close();
 
     attribute EventHandler onerror;
     attribute EventHandler onclose;
     attribute EventHandler onmessage;
+    attribute EventHandler onbufferedamountlow;
+};
+
+[
+    Conditional=WEB_RTC,
+    EnabledAtRuntime=PeerConnection,
+    ImplementedAs=RTCDataChannelState
+] enum RTCDataChannelState {
+    "connecting",
+    "open",
+    "closing",
+    "closed"
 };
index 17f81aa..4c80ce2 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -36,15 +37,26 @@ Ref<RTCDataChannelEvent> RTCDataChannelEvent::create(const AtomicString& type, b
     return adoptRef(*new RTCDataChannelEvent(type, canBubble, cancelable, WTFMove(channel)));
 }
 
+Ref<RTCDataChannelEvent> RTCDataChannelEvent::create(const AtomicString& type, Init&& initializer, IsTrusted isTrusted)
+{
+    return adoptRef(*new RTCDataChannelEvent(type, WTFMove(initializer), isTrusted));
+}
+
 RTCDataChannelEvent::RTCDataChannelEvent(const AtomicString& type, bool canBubble, bool cancelable, Ref<RTCDataChannel>&& channel)
     : Event(type, canBubble, cancelable)
     , m_channel(WTFMove(channel))
 {
 }
 
-RTCDataChannel* RTCDataChannelEvent::channel()
+RTCDataChannelEvent::RTCDataChannelEvent(const AtomicString& type, Init&& initializer, IsTrusted isTrusted)
+    : Event(type, initializer, isTrusted)
+    , m_channel(initializer.channel.releaseNonNull())
+{
+}
+
+RTCDataChannel& RTCDataChannelEvent::channel()
 {
-    return m_channel.ptr();
+    return m_channel.get();
 }
 
 EventInterface RTCDataChannelEvent::eventInterface() const
index 5241e27..1da89cd 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 namespace WebCore {
 
-class RTCDataChannelEvent : public Event {
+class RTCDataChannelEvent final : public Event {
 public:
+    struct Init : EventInit {
+        RefPtr<RTCDataChannel> channel;
+    };
+
     static Ref<RTCDataChannelEvent> create(const AtomicString& type, bool canBubble, bool cancelable, Ref<RTCDataChannel>&&);
+    static Ref<RTCDataChannelEvent> create(const AtomicString& type, Init&&, IsTrusted = IsTrusted::No);
 
-    RTCDataChannel* channel();
+    RTCDataChannel& channel();
 
     virtual EventInterface eventInterface() const;
 
 private:
     RTCDataChannelEvent(const AtomicString& type, bool canBubble, bool cancelable, Ref<RTCDataChannel>&&);
+    RTCDataChannelEvent(const AtomicString& type, Init&&, IsTrusted);
 
     Ref<RTCDataChannel> m_channel;
 };
index 3debbc9..3ced60e 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-// FIXME 169662: missing Constructor(DOMString type, RTCDataChannelEventInit eventInitDict)
 [
-    NoInterfaceObject,
     Conditional=WEB_RTC,
-    EnabledAtRuntime=PeerConnection
+    Constructor(DOMString type, RTCDataChannelEventInit eventInitDict),
+    EnabledAtRuntime=PeerConnection,
 ] interface RTCDataChannelEvent : Event {
     readonly attribute RTCDataChannel channel;
 };
+
+dictionary RTCDataChannelEventInit : EventInit {
+    required RTCDataChannel channel;
+};
index a83bbe6..977338a 100644 (file)
@@ -42,7 +42,7 @@ typedef RTCRtpTransceiverDirection RtpTransceiverDirection;
     unsigned short maxRetransmits;
     USVString protocol = "";
     boolean negotiated = false;
-    unsigned short id;
+    [EnforceRange] unsigned short id;
     // FIXME 169644: missing priority
 };
 
index 564b6d1..4296d75 100644 (file)
@@ -64,19 +64,19 @@ void LibWebRTCDataChannelHandler::close()
 
 void LibWebRTCDataChannelHandler::OnStateChange()
 {
-    RTCDataChannel::ReadyState state;
+    RTCDataChannelState state;
     switch (m_channel->state()) {
     case webrtc::DataChannelInterface::kConnecting:
-        state = RTCDataChannel::ReadyStateConnecting;
+        state = RTCDataChannelState::Connecting;
         break;
     case webrtc::DataChannelInterface::kOpen:
-        state = RTCDataChannel::ReadyStateOpen;
+        state = RTCDataChannelState::Open;
         break;
     case webrtc::DataChannelInterface::kClosing:
-        state = RTCDataChannel::ReadyStateClosing;
+        state = RTCDataChannelState::Closing;
         break;
     case webrtc::DataChannelInterface::kClosed:
-        state = RTCDataChannel::ReadyStateClosed;
+        state = RTCDataChannelState::Closed;
         break;
     }
     ASSERT(m_client);
@@ -104,8 +104,8 @@ void LibWebRTCDataChannelHandler::OnBufferedAmountChange(uint64_t previousAmount
     if (previousAmount <= m_channel->buffered_amount())
         return;
     ASSERT(m_client);
-    callOnMainThread([protectedClient = makeRef(*m_client)] {
-        protectedClient->bufferedAmountIsDecreasing();
+    callOnMainThread([protectedClient = makeRef(*m_client), amount = m_channel->buffered_amount()] {
+        protectedClient->bufferedAmountIsDecreasing(static_cast<size_t>(amount));
     });
 }
 
index f97fbcf..d837e00 100644 (file)
@@ -600,7 +600,7 @@ void LibWebRTCMediaEndpoint::addDataChannel(rtc::scoped_refptr<webrtc::DataChann
         callOnMainThread([channel = channel.copyRef()] {
             // FIXME: We should be able to write channel->didChangeReadyState(...)
             RTCDataChannelHandlerClient& client = channel.get();
-            client.didChangeReadyState(RTCDataChannel::ReadyStateOpen);
+            client.didChangeReadyState(RTCDataChannelState::Open);
         });
     }
 
index e6b660b..e663d7c 100644 (file)
                316DCB4F1E7910A6001B5F87 /* JSRTCSignalingState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 316DCB491E7910A6001B5F87 /* JSRTCSignalingState.cpp */; };
                316DCB501E7910A6001B5F87 /* JSRTCSignalingState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316DCB4A1E7910A6001B5F87 /* JSRTCSignalingState.h */; };
                316DCB8A1E7A6996001B5F87 /* RTCIceTransport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 316DCB881E7A6996001B5F87 /* RTCIceTransport.cpp */; };
+               316DE7021E83AE1D0084C261 /* RTCDataChannelState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316DE7011E83AE1D0084C261 /* RTCDataChannelState.h */; };
                316FE0710E6CCBEE00BF6088 /* JSCSSKeyframeRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 316FE06D0E6CCBEE00BF6088 /* JSCSSKeyframeRule.cpp */; };
                316FE0720E6CCBEE00BF6088 /* JSCSSKeyframeRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 316FE06E0E6CCBEE00BF6088 /* JSCSSKeyframeRule.h */; };
                316FE0730E6CCBEE00BF6088 /* JSCSSKeyframesRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 316FE06F0E6CCBEE00BF6088 /* JSCSSKeyframesRule.cpp */; };
                316DCB881E7A6996001B5F87 /* RTCIceTransport.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCIceTransport.cpp; sourceTree = "<group>"; };
                316DCB891E7A6996001B5F87 /* RTCIceTransport.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCIceTransport.idl; sourceTree = "<group>"; };
                316DCB8E1E7A6C79001B5F87 /* RTCIceTransportState.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCIceTransportState.idl; sourceTree = "<group>"; };
+               316DE7011E83AE1D0084C261 /* RTCDataChannelState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCDataChannelState.h; sourceTree = "<group>"; };
                316FE06D0E6CCBEE00BF6088 /* JSCSSKeyframeRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCSSKeyframeRule.cpp; sourceTree = "<group>"; };
                316FE06E0E6CCBEE00BF6088 /* JSCSSKeyframeRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCSSKeyframeRule.h; sourceTree = "<group>"; };
                316FE06F0E6CCBEE00BF6088 /* JSCSSKeyframesRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCSSKeyframesRule.cpp; sourceTree = "<group>"; };
                                3135910C1E7DDCB600F30630 /* RTCBundlePolicy.h */,
                                07221BA217CF0AD400848E51 /* RTCDataChannelHandler.h */,
                                07221BA317CF0AD400848E51 /* RTCDataChannelHandlerClient.h */,
+                               316DE7011E83AE1D0084C261 /* RTCDataChannelState.h */,
                                07221BA417CF0AD400848E51 /* RTCDTMFSenderHandler.h */,
                                07221BA517CF0AD400848E51 /* RTCDTMFSenderHandlerClient.h */,
                                07221BA617CF0AD400848E51 /* RTCIceCandidateDescriptor.cpp */,
                                FC9A0F75164094CF003D6B8D /* DOMCSSNamespace.h in Headers */,
                                9B3A8872145632F9003AE8F5 /* DOMDOMSettableTokenList.h in Headers */,
                                7AABA25A14BC613300AA9A11 /* DOMEditor.h in Headers */,
+                               316DE7021E83AE1D0084C261 /* RTCDataChannelState.h in Headers */,
                                BC1BDF25156C18C7001C1243 /* DOMError.h in Headers */,
                                2ED609BD1145B07100C8684E /* DOMFormData.h in Headers */,
                                A8185F3B09765766005826D9 /* DOMImplementation.h in Headers */,
index 02394e8..9d9c498 100644 (file)
@@ -67,7 +67,7 @@ namespace WebCore {
     macro(blocked) \
     macro(blur) \
     macro(boundary) \
-    macro(bufferedAmountLowThreshold) \
+    macro(bufferedamountlow) \
     macro(cached) \
     macro(cancel) \
     macro(canplay) \
index fd35778..c7d6b50 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index 981316d..92b433b 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,6 +27,7 @@
 
 #if ENABLE(WEB_RTC)
 
+#include "RTCDataChannelState.h"
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/text/WTFString.h>
 
@@ -33,20 +35,13 @@ namespace WebCore {
 
 class RTCDataChannelHandlerClient : public ThreadSafeRefCounted<RTCDataChannelHandlerClient> {
 public:
-    enum ReadyState {
-        ReadyStateConnecting = 0,
-        ReadyStateOpen = 1,
-        ReadyStateClosing = 2,
-        ReadyStateClosed = 3,
-    };
-
     virtual ~RTCDataChannelHandlerClient() { }
 
-    virtual void didChangeReadyState(ReadyState) = 0;
+    virtual void didChangeReadyState(RTCDataChannelState) = 0;
     virtual void didReceiveStringData(const String&) = 0;
     virtual void didReceiveRawData(const char*, size_t) = 0;
     virtual void didDetectError() = 0;
-    virtual void bufferedAmountIsDecreasing() = 0;
+    virtual void bufferedAmountIsDecreasing(size_t) = 0;
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/platform/mediastream/RTCDataChannelState.h b/Source/WebCore/platform/mediastream/RTCDataChannelState.h
new file mode 100644 (file)
index 0000000..2e99606
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_RTC)
+
+namespace WebCore {
+
+enum class RTCDataChannelState {
+    Connecting,
+    Open,
+    Closing,
+    Closed
+};
+
+}; // namespace WebCore
+
+#endif
index 50df1a4..956a9d6 100644 (file)
@@ -33,6 +33,9 @@
 
 #if ENABLE(WEB_RTC)
 
+#include "RTCIceConnectionState.h"
+#include "RTCIceGatheringState.h"
+#include "RTCSignalingState.h"
 #include <wtf/PassRefPtr.h>
 
 namespace WebCore {
@@ -43,38 +46,13 @@ class RTCIceCandidateDescriptor;
 
 class RTCPeerConnectionHandlerClient {
 public:
-    enum SignalingState {
-        SignalingStateStable = 1,
-        SignalingStateHaveLocalOffer = 2,
-        SignalingStateHaveRemoteOffer = 3,
-        SignalingStateHaveLocalPrAnswer = 4,
-        SignalingStateHaveRemotePrAnswer = 5,
-        SignalingStateClosed = 6,
-    };
-
-    enum IceConnectionState {
-        IceConnectionStateNew = 1,
-        IceConnectionStateChecking = 2,
-        IceConnectionStateConnected = 3,
-        IceConnectionStateCompleted = 4,
-        IceConnectionStateFailed = 5,
-        IceConnectionStateDisconnected = 6,
-        IceConnectionStateClosed = 7
-    };
-
-    enum IceGatheringState {
-        IceGatheringStateNew = 1,
-        IceGatheringStateGathering = 2,
-        IceGatheringStateComplete = 3
-    };
-
     virtual ~RTCPeerConnectionHandlerClient() { }
 
     virtual void negotiationNeeded() = 0;
     virtual void didGenerateIceCandidate(PassRefPtr<RTCIceCandidateDescriptor>) = 0;
-    virtual void didChangeSignalingState(SignalingState) = 0;
-    virtual void didChangeIceGatheringState(IceGatheringState) = 0;
-    virtual void didChangeIceConnectionState(IceConnectionState) = 0;
+    virtual void didChangeSignalingState(RTCSignalingState) = 0;
+    virtual void didChangeIceGatheringState(RTCIceGatheringState) = 0;
+    virtual void didChangeIceConnectionState(RTCIceConnectionState) = 0;
     virtual void didAddRemoteStream(PassRefPtr<MediaStreamPrivate>) = 0;
     virtual void didRemoveRemoteStream(MediaStreamPrivate*) = 0;
     virtual void didAddRemoteDataChannel(std::unique_ptr<RTCDataChannelHandler>) = 0;
index 8985e5c..56b88b6 100644 (file)
@@ -1,5 +1,6 @@
 /*
- *  Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  */
 
 #include "config.h"
+#include "RTCDataChannelHandlerMock.h"
 
 #if ENABLE(WEB_RTC)
 
-#include "RTCDataChannelHandlerMock.h"
-
 #include "RTCDataChannelHandlerClient.h"
 #include "RTCNotifiersMock.h"
 
@@ -46,8 +46,8 @@ void RTCDataChannelHandlerMock::setClient(RTCDataChannelHandlerClient* client)
         return;
 
     m_client = client;
-    RefPtr<DataChannelStateNotifier> notifier = adoptRef(new DataChannelStateNotifier(m_client, RTCDataChannelHandlerClient::ReadyStateOpen));
-    m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
+    auto notifier = adoptRef(*new DataChannelStateNotifier(m_client, RTCDataChannelState::Open));
+    m_timerEvents.append(adoptRef(new TimerEvent(this, WTFMove(notifier))));
 }
 
 bool RTCDataChannelHandlerMock::sendStringData(const String& string)
@@ -64,8 +64,8 @@ bool RTCDataChannelHandlerMock::sendRawData(const char* data, size_t size)
 
 void RTCDataChannelHandlerMock::close()
 {
-    RefPtr<DataChannelStateNotifier> notifier = adoptRef(new DataChannelStateNotifier(m_client, RTCDataChannelHandlerClient::ReadyStateClosed));
-    m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
+    auto notifier = adoptRef(*new DataChannelStateNotifier(m_client, RTCDataChannelState::Closed));
+    m_timerEvents.append(adoptRef(new TimerEvent(this, WTFMove(notifier))));
 }
 
 } // namespace WebCore
index d667d17..5080bf6 100644 (file)
@@ -1,5 +1,6 @@
 /*
- *  Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -67,7 +68,7 @@ void VoidRequestNotifier::fire()
         m_request->requestFailed(m_errorName);
 }
 
-IceConnectionNotifier::IceConnectionNotifier(RTCPeerConnectionHandlerClient* client, RTCPeerConnectionHandlerClient::IceConnectionState connectionState, RTCPeerConnectionHandlerClient::IceGatheringState gatheringState)
+IceConnectionNotifier::IceConnectionNotifier(RTCPeerConnectionHandlerClient* client, RTCIceConnectionState connectionState, RTCIceGatheringState gatheringState)
     : m_client(client)
     , m_connectionState(connectionState)
     , m_gatheringState(gatheringState)
@@ -80,7 +81,7 @@ void IceConnectionNotifier::fire()
     m_client->didChangeIceConnectionState(m_connectionState);
 }
 
-SignalingStateNotifier::SignalingStateNotifier(RTCPeerConnectionHandlerClient* client, RTCPeerConnectionHandlerClient::SignalingState signalingState)
+SignalingStateNotifier::SignalingStateNotifier(RTCPeerConnectionHandlerClient* client, RTCSignalingState signalingState)
     : m_client(client)
     , m_signalingState(signalingState)
 {
@@ -101,7 +102,7 @@ void RemoteDataChannelNotifier::fire()
     m_client->didAddRemoteDataChannel(std::make_unique<RTCDataChannelHandlerMock>("RTCDataChannelHandlerMock", RTCDataChannelInit()));
 }
 
-DataChannelStateNotifier::DataChannelStateNotifier(RTCDataChannelHandlerClient* client, RTCDataChannelHandlerClient::ReadyState state)
+DataChannelStateNotifier::DataChannelStateNotifier(RTCDataChannelHandlerClient* client, RTCDataChannelState state)
     : m_client(client)
     , m_state(state)
 {
index c39e95a..e640353 100644 (file)
@@ -67,25 +67,25 @@ private:
 
 class IceConnectionNotifier : public MockNotifier {
 public:
-    IceConnectionNotifier(RTCPeerConnectionHandlerClient*, RTCPeerConnectionHandlerClient::IceConnectionState, RTCPeerConnectionHandlerClient::IceGatheringState);
+    IceConnectionNotifier(RTCPeerConnectionHandlerClient*, RTCIceConnectionState, RTCIceGatheringState);
 
     void fire() override;
 
 private:
     RTCPeerConnectionHandlerClient* m_client;
-    RTCPeerConnectionHandlerClient::IceConnectionState m_connectionState;
-    RTCPeerConnectionHandlerClient::IceGatheringState m_gatheringState;
+    RTCIceConnectionState m_connectionState;
+    RTCIceGatheringState m_gatheringState;
 };
 
 class SignalingStateNotifier : public MockNotifier {
 public:
-    SignalingStateNotifier(RTCPeerConnectionHandlerClient*, RTCPeerConnectionHandlerClient::SignalingState);
+    SignalingStateNotifier(RTCPeerConnectionHandlerClient*, RTCSignalingState);
 
     void fire() override;
 
 private:
     RTCPeerConnectionHandlerClient* m_client;
-    RTCPeerConnectionHandlerClient::SignalingState m_signalingState;
+    RTCSignalingState m_signalingState;
 };
 
 class RemoteDataChannelNotifier : public MockNotifier {
@@ -100,13 +100,13 @@ private:
 
 class DataChannelStateNotifier : public MockNotifier {
 public:
-    DataChannelStateNotifier(RTCDataChannelHandlerClient*, RTCDataChannelHandlerClient::ReadyState);
+    DataChannelStateNotifier(RTCDataChannelHandlerClient*, RTCDataChannelState);
 
     void fire() override;
 
 private:
     RTCDataChannelHandlerClient* m_client;
-    RTCDataChannelHandlerClient::ReadyState m_state;
+    RTCDataChannelState m_state;
 };
 
 } // namespace WebCore