| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "modules/mediastream/RTCPeerConnection.h" | 33 #include "modules/mediastream/RTCPeerConnection.h" |
| 34 | 34 |
| 35 #include "bindings/v8/ArrayValue.h" | 35 #include "bindings/v8/ArrayValue.h" |
| 36 #include "bindings/v8/ExceptionState.h" | |
| 37 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 38 #include "core/dom/Event.h" | 37 #include "core/dom/Event.h" |
| 39 #include "core/dom/ExceptionCode.h" | 38 #include "core/dom/ExceptionCode.h" |
| 40 #include "core/dom/ScriptExecutionContext.h" | 39 #include "core/dom/ScriptExecutionContext.h" |
| 41 #include "core/html/VoidCallback.h" | 40 #include "core/html/VoidCallback.h" |
| 42 #include "core/loader/FrameLoader.h" | 41 #include "core/loader/FrameLoader.h" |
| 43 #include "core/loader/FrameLoaderClient.h" | 42 #include "core/loader/FrameLoaderClient.h" |
| 44 #include "core/page/Frame.h" | 43 #include "core/page/Frame.h" |
| 45 #include "core/platform/mediastream/RTCConfiguration.h" | 44 #include "core/platform/mediastream/RTCConfiguration.h" |
| 46 #include "core/platform/mediastream/RTCDataChannelHandler.h" | 45 #include "core/platform/mediastream/RTCDataChannelHandler.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 #include "modules/mediastream/RTCSessionDescriptionRequestImpl.h" | 56 #include "modules/mediastream/RTCSessionDescriptionRequestImpl.h" |
| 58 #include "modules/mediastream/RTCStatsCallback.h" | 57 #include "modules/mediastream/RTCStatsCallback.h" |
| 59 #include "modules/mediastream/RTCStatsRequestImpl.h" | 58 #include "modules/mediastream/RTCStatsRequestImpl.h" |
| 60 #include "modules/mediastream/RTCVoidRequestImpl.h" | 59 #include "modules/mediastream/RTCVoidRequestImpl.h" |
| 61 #include "public/platform/WebRTCDataChannelInit.h" | 60 #include "public/platform/WebRTCDataChannelInit.h" |
| 62 #include "public/platform/WebRTCICECandidate.h" | 61 #include "public/platform/WebRTCICECandidate.h" |
| 63 #include "public/platform/WebRTCSessionDescription.h" | 62 #include "public/platform/WebRTCSessionDescription.h" |
| 64 | 63 |
| 65 namespace WebCore { | 64 namespace WebCore { |
| 66 | 65 |
| 67 PassRefPtr<RTCConfiguration> RTCPeerConnection::parseConfiguration(const Diction
ary& configuration, ExceptionState& es) | 66 PassRefPtr<RTCConfiguration> RTCPeerConnection::parseConfiguration(const Diction
ary& configuration, ExceptionCode& ec) |
| 68 { | 67 { |
| 69 if (configuration.isUndefinedOrNull()) | 68 if (configuration.isUndefinedOrNull()) |
| 70 return 0; | 69 return 0; |
| 71 | 70 |
| 72 ArrayValue iceServers; | 71 ArrayValue iceServers; |
| 73 bool ok = configuration.get("iceServers", iceServers); | 72 bool ok = configuration.get("iceServers", iceServers); |
| 74 if (!ok || iceServers.isUndefinedOrNull()) { | 73 if (!ok || iceServers.isUndefinedOrNull()) { |
| 75 es.throwDOMException(TypeMismatchError); | 74 ec = TypeMismatchError; |
| 76 return 0; | 75 return 0; |
| 77 } | 76 } |
| 78 | 77 |
| 79 size_t numberOfServers; | 78 size_t numberOfServers; |
| 80 ok = iceServers.length(numberOfServers); | 79 ok = iceServers.length(numberOfServers); |
| 81 if (!ok) { | 80 if (!ok) { |
| 82 es.throwDOMException(TypeMismatchError); | 81 ec = TypeMismatchError; |
| 83 return 0; | 82 return 0; |
| 84 } | 83 } |
| 85 | 84 |
| 86 RefPtr<RTCConfiguration> rtcConfiguration = RTCConfiguration::create(); | 85 RefPtr<RTCConfiguration> rtcConfiguration = RTCConfiguration::create(); |
| 87 | 86 |
| 88 for (size_t i = 0; i < numberOfServers; ++i) { | 87 for (size_t i = 0; i < numberOfServers; ++i) { |
| 89 Dictionary iceServer; | 88 Dictionary iceServer; |
| 90 ok = iceServers.get(i, iceServer); | 89 ok = iceServers.get(i, iceServer); |
| 91 if (!ok) { | 90 if (!ok) { |
| 92 es.throwDOMException(TypeMismatchError); | 91 ec = TypeMismatchError; |
| 93 return 0; | 92 return 0; |
| 94 } | 93 } |
| 95 | 94 |
| 96 String urlString, username, credential; | 95 String urlString, username, credential; |
| 97 ok = iceServer.get("url", urlString); | 96 ok = iceServer.get("url", urlString); |
| 98 if (!ok) { | 97 if (!ok) { |
| 99 es.throwDOMException(TypeMismatchError); | 98 ec = TypeMismatchError; |
| 100 return 0; | 99 return 0; |
| 101 } | 100 } |
| 102 KURL url(KURL(), urlString); | 101 KURL url(KURL(), urlString); |
| 103 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("stun")
)) { | 102 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("stun")
)) { |
| 104 es.throwDOMException(TypeMismatchError); | 103 ec = TypeMismatchError; |
| 105 return 0; | 104 return 0; |
| 106 } | 105 } |
| 107 | 106 |
| 108 iceServer.get("username", username); | 107 iceServer.get("username", username); |
| 109 iceServer.get("credential", credential); | 108 iceServer.get("credential", credential); |
| 110 | 109 |
| 111 rtcConfiguration->appendServer(RTCIceServer::create(url, username, crede
ntial)); | 110 rtcConfiguration->appendServer(RTCIceServer::create(url, username, crede
ntial)); |
| 112 } | 111 } |
| 113 | 112 |
| 114 return rtcConfiguration.release(); | 113 return rtcConfiguration.release(); |
| 115 } | 114 } |
| 116 | 115 |
| 117 PassRefPtr<RTCPeerConnection> RTCPeerConnection::create(ScriptExecutionContext*
context, const Dictionary& rtcConfiguration, const Dictionary& mediaConstraints,
ExceptionState& es) | 116 PassRefPtr<RTCPeerConnection> RTCPeerConnection::create(ScriptExecutionContext*
context, const Dictionary& rtcConfiguration, const Dictionary& mediaConstraints,
ExceptionCode& ec) |
| 118 { | 117 { |
| 119 RefPtr<RTCConfiguration> configuration = parseConfiguration(rtcConfiguration
, es); | 118 RefPtr<RTCConfiguration> configuration = parseConfiguration(rtcConfiguration
, ec); |
| 120 if (es.hadException()) | 119 if (ec) |
| 121 return 0; | 120 return 0; |
| 122 | 121 |
| 123 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, es); | 122 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, ec); |
| 124 if (es.hadException()) | 123 if (ec) |
| 125 return 0; | 124 return 0; |
| 126 | 125 |
| 127 RefPtr<RTCPeerConnection> peerConnection = adoptRef(new RTCPeerConnection(co
ntext, configuration.release(), constraints.release(), es)); | 126 RefPtr<RTCPeerConnection> peerConnection = adoptRef(new RTCPeerConnection(co
ntext, configuration.release(), constraints.release(), ec)); |
| 128 peerConnection->suspendIfNeeded(); | 127 peerConnection->suspendIfNeeded(); |
| 129 if (es.hadException()) | 128 if (ec) |
| 130 return 0; | 129 return 0; |
| 131 | 130 |
| 132 return peerConnection.release(); | 131 return peerConnection.release(); |
| 133 } | 132 } |
| 134 | 133 |
| 135 RTCPeerConnection::RTCPeerConnection(ScriptExecutionContext* context, PassRefPtr
<RTCConfiguration> configuration, PassRefPtr<MediaConstraints> constraints, Exce
ptionState& es) | 134 RTCPeerConnection::RTCPeerConnection(ScriptExecutionContext* context, PassRefPtr
<RTCConfiguration> configuration, PassRefPtr<MediaConstraints> constraints, Exce
ptionCode& ec) |
| 136 : ActiveDOMObject(context) | 135 : ActiveDOMObject(context) |
| 137 , m_signalingState(SignalingStateStable) | 136 , m_signalingState(SignalingStateStable) |
| 138 , m_iceGatheringState(IceGatheringStateNew) | 137 , m_iceGatheringState(IceGatheringStateNew) |
| 139 , m_iceConnectionState(IceConnectionStateNew) | 138 , m_iceConnectionState(IceConnectionStateNew) |
| 140 , m_scheduledEventTimer(this, &RTCPeerConnection::scheduledEventTimerFired) | 139 , m_scheduledEventTimer(this, &RTCPeerConnection::scheduledEventTimerFired) |
| 141 , m_stopped(false) | 140 , m_stopped(false) |
| 142 { | 141 { |
| 143 ScriptWrappable::init(this); | 142 ScriptWrappable::init(this); |
| 144 Document* document = toDocument(m_scriptExecutionContext); | 143 Document* document = toDocument(m_scriptExecutionContext); |
| 145 | 144 |
| 146 if (!document->frame()) { | 145 if (!document->frame()) { |
| 147 es.throwDOMException(NotSupportedError); | 146 ec = NotSupportedError; |
| 148 return; | 147 return; |
| 149 } | 148 } |
| 150 | 149 |
| 151 m_peerHandler = RTCPeerConnectionHandler::create(this); | 150 m_peerHandler = RTCPeerConnectionHandler::create(this); |
| 152 if (!m_peerHandler) { | 151 if (!m_peerHandler) { |
| 153 es.throwDOMException(NotSupportedError); | 152 ec = NotSupportedError; |
| 154 return; | 153 return; |
| 155 } | 154 } |
| 156 | 155 |
| 157 document->frame()->loader()->client()->dispatchWillStartUsingPeerConnectionH
andler(m_peerHandler.get()); | 156 document->frame()->loader()->client()->dispatchWillStartUsingPeerConnectionH
andler(m_peerHandler.get()); |
| 158 | 157 |
| 159 if (!m_peerHandler->initialize(configuration, constraints)) { | 158 if (!m_peerHandler->initialize(configuration, constraints)) { |
| 160 es.throwDOMException(NotSupportedError); | 159 ec = NotSupportedError; |
| 161 return; | 160 return; |
| 162 } | 161 } |
| 163 } | 162 } |
| 164 | 163 |
| 165 RTCPeerConnection::~RTCPeerConnection() | 164 RTCPeerConnection::~RTCPeerConnection() |
| 166 { | 165 { |
| 167 stop(); | 166 stop(); |
| 168 } | 167 } |
| 169 | 168 |
| 170 void RTCPeerConnection::createOffer(PassRefPtr<RTCSessionDescriptionCallback> su
ccessCallback, PassRefPtr<RTCErrorCallback> errorCallback, const Dictionary& med
iaConstraints, ExceptionState& es) | 169 void RTCPeerConnection::createOffer(PassRefPtr<RTCSessionDescriptionCallback> su
ccessCallback, PassRefPtr<RTCErrorCallback> errorCallback, const Dictionary& med
iaConstraints, ExceptionCode& ec) |
| 171 { | 170 { |
| 172 if (m_signalingState == SignalingStateClosed) { | 171 if (m_signalingState == SignalingStateClosed) { |
| 173 es.throwDOMException(InvalidStateError); | 172 ec = InvalidStateError; |
| 174 return; | 173 return; |
| 175 } | 174 } |
| 176 | 175 |
| 177 if (!successCallback) { | 176 if (!successCallback) { |
| 178 es.throwDOMException(TypeMismatchError); | 177 ec = TypeMismatchError; |
| 179 return; | 178 return; |
| 180 } | 179 } |
| 181 | 180 |
| 182 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, es); | 181 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, ec); |
| 183 if (es.hadException()) | 182 if (ec) |
| 184 return; | 183 return; |
| 185 | 184 |
| 186 RefPtr<RTCSessionDescriptionRequestImpl> request = RTCSessionDescriptionRequ
estImpl::create(scriptExecutionContext(), successCallback, errorCallback); | 185 RefPtr<RTCSessionDescriptionRequestImpl> request = RTCSessionDescriptionRequ
estImpl::create(scriptExecutionContext(), successCallback, errorCallback); |
| 187 m_peerHandler->createOffer(request.release(), constraints); | 186 m_peerHandler->createOffer(request.release(), constraints); |
| 188 } | 187 } |
| 189 | 188 |
| 190 void RTCPeerConnection::createAnswer(PassRefPtr<RTCSessionDescriptionCallback> s
uccessCallback, PassRefPtr<RTCErrorCallback> errorCallback, const Dictionary& me
diaConstraints, ExceptionState& es) | 189 void RTCPeerConnection::createAnswer(PassRefPtr<RTCSessionDescriptionCallback> s
uccessCallback, PassRefPtr<RTCErrorCallback> errorCallback, const Dictionary& me
diaConstraints, ExceptionCode& ec) |
| 191 { | 190 { |
| 192 if (m_signalingState == SignalingStateClosed) { | 191 if (m_signalingState == SignalingStateClosed) { |
| 193 es.throwDOMException(InvalidStateError); | 192 ec = InvalidStateError; |
| 194 return; | 193 return; |
| 195 } | 194 } |
| 196 | 195 |
| 197 if (!successCallback) { | 196 if (!successCallback) { |
| 198 es.throwDOMException(TypeMismatchError); | 197 ec = TypeMismatchError; |
| 199 return; | 198 return; |
| 200 } | 199 } |
| 201 | 200 |
| 202 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, es); | 201 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, ec); |
| 203 if (es.hadException()) | 202 if (ec) |
| 204 return; | 203 return; |
| 205 | 204 |
| 206 RefPtr<RTCSessionDescriptionRequestImpl> request = RTCSessionDescriptionRequ
estImpl::create(scriptExecutionContext(), successCallback, errorCallback); | 205 RefPtr<RTCSessionDescriptionRequestImpl> request = RTCSessionDescriptionRequ
estImpl::create(scriptExecutionContext(), successCallback, errorCallback); |
| 207 m_peerHandler->createAnswer(request.release(), constraints.release()); | 206 m_peerHandler->createAnswer(request.release(), constraints.release()); |
| 208 } | 207 } |
| 209 | 208 |
| 210 void RTCPeerConnection::setLocalDescription(PassRefPtr<RTCSessionDescription> pr
pSessionDescription, PassRefPtr<VoidCallback> successCallback, PassRefPtr<RTCErr
orCallback> errorCallback, ExceptionState& es) | 209 void RTCPeerConnection::setLocalDescription(PassRefPtr<RTCSessionDescription> pr
pSessionDescription, PassRefPtr<VoidCallback> successCallback, PassRefPtr<RTCErr
orCallback> errorCallback, ExceptionCode& ec) |
| 211 { | 210 { |
| 212 if (m_signalingState == SignalingStateClosed) { | 211 if (m_signalingState == SignalingStateClosed) { |
| 213 es.throwDOMException(InvalidStateError); | 212 ec = InvalidStateError; |
| 214 return; | 213 return; |
| 215 } | 214 } |
| 216 | 215 |
| 217 RefPtr<RTCSessionDescription> sessionDescription = prpSessionDescription; | 216 RefPtr<RTCSessionDescription> sessionDescription = prpSessionDescription; |
| 218 if (!sessionDescription) { | 217 if (!sessionDescription) { |
| 219 es.throwDOMException(TypeMismatchError); | 218 ec = TypeMismatchError; |
| 220 return; | 219 return; |
| 221 } | 220 } |
| 222 | 221 |
| 223 RefPtr<RTCVoidRequestImpl> request = RTCVoidRequestImpl::create(scriptExecut
ionContext(), successCallback, errorCallback); | 222 RefPtr<RTCVoidRequestImpl> request = RTCVoidRequestImpl::create(scriptExecut
ionContext(), successCallback, errorCallback); |
| 224 m_peerHandler->setLocalDescription(request.release(), sessionDescription->we
bSessionDescription()); | 223 m_peerHandler->setLocalDescription(request.release(), sessionDescription->we
bSessionDescription()); |
| 225 } | 224 } |
| 226 | 225 |
| 227 PassRefPtr<RTCSessionDescription> RTCPeerConnection::localDescription(ExceptionS
tate& es) | 226 PassRefPtr<RTCSessionDescription> RTCPeerConnection::localDescription(ExceptionC
ode& ec) |
| 228 { | 227 { |
| 229 WebKit::WebRTCSessionDescription webSessionDescription = m_peerHandler->loca
lDescription(); | 228 WebKit::WebRTCSessionDescription webSessionDescription = m_peerHandler->loca
lDescription(); |
| 230 if (webSessionDescription.isNull()) | 229 if (webSessionDescription.isNull()) |
| 231 return 0; | 230 return 0; |
| 232 | 231 |
| 233 RefPtr<RTCSessionDescription> sessionDescription = RTCSessionDescription::cr
eate(webSessionDescription); | 232 RefPtr<RTCSessionDescription> sessionDescription = RTCSessionDescription::cr
eate(webSessionDescription); |
| 234 return sessionDescription.release(); | 233 return sessionDescription.release(); |
| 235 } | 234 } |
| 236 | 235 |
| 237 void RTCPeerConnection::setRemoteDescription(PassRefPtr<RTCSessionDescription> p
rpSessionDescription, PassRefPtr<VoidCallback> successCallback, PassRefPtr<RTCEr
rorCallback> errorCallback, ExceptionState& es) | 236 void RTCPeerConnection::setRemoteDescription(PassRefPtr<RTCSessionDescription> p
rpSessionDescription, PassRefPtr<VoidCallback> successCallback, PassRefPtr<RTCEr
rorCallback> errorCallback, ExceptionCode& ec) |
| 238 { | 237 { |
| 239 if (m_signalingState == SignalingStateClosed) { | 238 if (m_signalingState == SignalingStateClosed) { |
| 240 es.throwDOMException(InvalidStateError); | 239 ec = InvalidStateError; |
| 241 return; | 240 return; |
| 242 } | 241 } |
| 243 | 242 |
| 244 RefPtr<RTCSessionDescription> sessionDescription = prpSessionDescription; | 243 RefPtr<RTCSessionDescription> sessionDescription = prpSessionDescription; |
| 245 if (!sessionDescription) { | 244 if (!sessionDescription) { |
| 246 es.throwDOMException(TypeMismatchError); | 245 ec = TypeMismatchError; |
| 247 return; | 246 return; |
| 248 } | 247 } |
| 249 | 248 |
| 250 RefPtr<RTCVoidRequestImpl> request = RTCVoidRequestImpl::create(scriptExecut
ionContext(), successCallback, errorCallback); | 249 RefPtr<RTCVoidRequestImpl> request = RTCVoidRequestImpl::create(scriptExecut
ionContext(), successCallback, errorCallback); |
| 251 m_peerHandler->setRemoteDescription(request.release(), sessionDescription->w
ebSessionDescription()); | 250 m_peerHandler->setRemoteDescription(request.release(), sessionDescription->w
ebSessionDescription()); |
| 252 } | 251 } |
| 253 | 252 |
| 254 PassRefPtr<RTCSessionDescription> RTCPeerConnection::remoteDescription(Exception
State& es) | 253 PassRefPtr<RTCSessionDescription> RTCPeerConnection::remoteDescription(Exception
Code& ec) |
| 255 { | 254 { |
| 256 WebKit::WebRTCSessionDescription webSessionDescription = m_peerHandler->remo
teDescription(); | 255 WebKit::WebRTCSessionDescription webSessionDescription = m_peerHandler->remo
teDescription(); |
| 257 if (webSessionDescription.isNull()) | 256 if (webSessionDescription.isNull()) |
| 258 return 0; | 257 return 0; |
| 259 | 258 |
| 260 RefPtr<RTCSessionDescription> desc = RTCSessionDescription::create(webSessio
nDescription); | 259 RefPtr<RTCSessionDescription> desc = RTCSessionDescription::create(webSessio
nDescription); |
| 261 return desc.release(); | 260 return desc.release(); |
| 262 } | 261 } |
| 263 | 262 |
| 264 void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict
ionary& mediaConstraints, ExceptionState& es) | 263 void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict
ionary& mediaConstraints, ExceptionCode& ec) |
| 265 { | 264 { |
| 266 if (m_signalingState == SignalingStateClosed) { | 265 if (m_signalingState == SignalingStateClosed) { |
| 267 es.throwDOMException(InvalidStateError); | 266 ec = InvalidStateError; |
| 268 return; | 267 return; |
| 269 } | 268 } |
| 270 | 269 |
| 271 RefPtr<RTCConfiguration> configuration = parseConfiguration(rtcConfiguration
, es); | 270 RefPtr<RTCConfiguration> configuration = parseConfiguration(rtcConfiguration
, ec); |
| 272 if (es.hadException()) | 271 if (ec) |
| 273 return; | 272 return; |
| 274 | 273 |
| 275 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, es); | 274 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, ec); |
| 276 if (es.hadException()) | 275 if (ec) |
| 277 return; | 276 return; |
| 278 | 277 |
| 279 bool valid = m_peerHandler->updateIce(configuration, constraints); | 278 bool valid = m_peerHandler->updateIce(configuration, constraints); |
| 280 if (!valid) | 279 if (!valid) |
| 281 es.throwDOMException(SyntaxError); | 280 ec = SyntaxError; |
| 282 } | 281 } |
| 283 | 282 |
| 284 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception
State& es) | 283 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception
Code& ec) |
| 285 { | 284 { |
| 286 if (m_signalingState == SignalingStateClosed) { | 285 if (m_signalingState == SignalingStateClosed) { |
| 287 es.throwDOMException(InvalidStateError); | 286 ec = InvalidStateError; |
| 288 return; | 287 return; |
| 289 } | 288 } |
| 290 | 289 |
| 291 if (!iceCandidate) { | 290 if (!iceCandidate) { |
| 292 es.throwDOMException(TypeMismatchError); | 291 ec = TypeMismatchError; |
| 293 return; | 292 return; |
| 294 } | 293 } |
| 295 | 294 |
| 296 bool valid = m_peerHandler->addIceCandidate(iceCandidate->webCandidate()); | 295 bool valid = m_peerHandler->addIceCandidate(iceCandidate->webCandidate()); |
| 297 if (!valid) | 296 if (!valid) |
| 298 es.throwDOMException(SyntaxError); | 297 ec = SyntaxError; |
| 299 } | 298 } |
| 300 | 299 |
| 301 String RTCPeerConnection::signalingState() const | 300 String RTCPeerConnection::signalingState() const |
| 302 { | 301 { |
| 303 switch (m_signalingState) { | 302 switch (m_signalingState) { |
| 304 case SignalingStateStable: | 303 case SignalingStateStable: |
| 305 return ASCIILiteral("stable"); | 304 return ASCIILiteral("stable"); |
| 306 case SignalingStateHaveLocalOffer: | 305 case SignalingStateHaveLocalOffer: |
| 307 return ASCIILiteral("have-local-offer"); | 306 return ASCIILiteral("have-local-offer"); |
| 308 case SignalingStateHaveRemoteOffer: | 307 case SignalingStateHaveRemoteOffer: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 case IceConnectionStateDisconnected: | 349 case IceConnectionStateDisconnected: |
| 351 return ASCIILiteral("disconnected"); | 350 return ASCIILiteral("disconnected"); |
| 352 case IceConnectionStateClosed: | 351 case IceConnectionStateClosed: |
| 353 return ASCIILiteral("closed"); | 352 return ASCIILiteral("closed"); |
| 354 } | 353 } |
| 355 | 354 |
| 356 ASSERT_NOT_REACHED(); | 355 ASSERT_NOT_REACHED(); |
| 357 return String(); | 356 return String(); |
| 358 } | 357 } |
| 359 | 358 |
| 360 void RTCPeerConnection::addStream(PassRefPtr<MediaStream> prpStream, const Dicti
onary& mediaConstraints, ExceptionState& es) | 359 void RTCPeerConnection::addStream(PassRefPtr<MediaStream> prpStream, const Dicti
onary& mediaConstraints, ExceptionCode& ec) |
| 361 { | 360 { |
| 362 if (m_signalingState == SignalingStateClosed) { | 361 if (m_signalingState == SignalingStateClosed) { |
| 363 es.throwDOMException(InvalidStateError); | 362 ec = InvalidStateError; |
| 364 return; | 363 return; |
| 365 } | 364 } |
| 366 | 365 |
| 367 RefPtr<MediaStream> stream = prpStream; | 366 RefPtr<MediaStream> stream = prpStream; |
| 368 if (!stream) { | 367 if (!stream) { |
| 369 es.throwDOMException(TypeMismatchError); | 368 ec = TypeMismatchError; |
| 370 return; | 369 return; |
| 371 } | 370 } |
| 372 | 371 |
| 373 if (m_localStreams.contains(stream)) | 372 if (m_localStreams.contains(stream)) |
| 374 return; | 373 return; |
| 375 | 374 |
| 376 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, es); | 375 RefPtr<MediaConstraints> constraints = MediaConstraintsImpl::create(mediaCon
straints, ec); |
| 377 if (es.hadException()) | 376 if (ec) |
| 378 return; | 377 return; |
| 379 | 378 |
| 380 m_localStreams.append(stream); | 379 m_localStreams.append(stream); |
| 381 | 380 |
| 382 bool valid = m_peerHandler->addStream(stream->descriptor(), constraints); | 381 bool valid = m_peerHandler->addStream(stream->descriptor(), constraints); |
| 383 if (!valid) | 382 if (!valid) |
| 384 es.throwDOMException(SyntaxError); | 383 ec = SyntaxError; |
| 385 } | 384 } |
| 386 | 385 |
| 387 void RTCPeerConnection::removeStream(PassRefPtr<MediaStream> prpStream, Exceptio
nState& es) | 386 void RTCPeerConnection::removeStream(PassRefPtr<MediaStream> prpStream, Exceptio
nCode& ec) |
| 388 { | 387 { |
| 389 if (m_signalingState == SignalingStateClosed) { | 388 if (m_signalingState == SignalingStateClosed) { |
| 390 es.throwDOMException(InvalidStateError); | 389 ec = InvalidStateError; |
| 391 return; | 390 return; |
| 392 } | 391 } |
| 393 | 392 |
| 394 if (!prpStream) { | 393 if (!prpStream) { |
| 395 es.throwDOMException(TypeMismatchError); | 394 ec = TypeMismatchError; |
| 396 return; | 395 return; |
| 397 } | 396 } |
| 398 | 397 |
| 399 RefPtr<MediaStream> stream = prpStream; | 398 RefPtr<MediaStream> stream = prpStream; |
| 400 | 399 |
| 401 size_t pos = m_localStreams.find(stream); | 400 size_t pos = m_localStreams.find(stream); |
| 402 if (pos == notFound) | 401 if (pos == notFound) |
| 403 return; | 402 return; |
| 404 | 403 |
| 405 m_localStreams.remove(pos); | 404 m_localStreams.remove(pos); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 432 return 0; | 431 return 0; |
| 433 } | 432 } |
| 434 | 433 |
| 435 void RTCPeerConnection::getStats(PassRefPtr<RTCStatsCallback> successCallback, P
assRefPtr<MediaStreamTrack> selector) | 434 void RTCPeerConnection::getStats(PassRefPtr<RTCStatsCallback> successCallback, P
assRefPtr<MediaStreamTrack> selector) |
| 436 { | 435 { |
| 437 RefPtr<RTCStatsRequestImpl> statsRequest = RTCStatsRequestImpl::create(scrip
tExecutionContext(), successCallback, selector); | 436 RefPtr<RTCStatsRequestImpl> statsRequest = RTCStatsRequestImpl::create(scrip
tExecutionContext(), successCallback, selector); |
| 438 // FIXME: Add passing selector as part of the statsRequest. | 437 // FIXME: Add passing selector as part of the statsRequest. |
| 439 m_peerHandler->getStats(statsRequest.release()); | 438 m_peerHandler->getStats(statsRequest.release()); |
| 440 } | 439 } |
| 441 | 440 |
| 442 PassRefPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(String label, co
nst Dictionary& options, ExceptionState& es) | 441 PassRefPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(String label, co
nst Dictionary& options, ExceptionCode& ec) |
| 443 { | 442 { |
| 444 if (m_signalingState == SignalingStateClosed) { | 443 if (m_signalingState == SignalingStateClosed) { |
| 445 es.throwDOMException(InvalidStateError); | 444 ec = InvalidStateError; |
| 446 return 0; | 445 return 0; |
| 447 } | 446 } |
| 448 | 447 |
| 449 WebKit::WebRTCDataChannelInit init; | 448 WebKit::WebRTCDataChannelInit init; |
| 450 options.get("ordered", init.ordered); | 449 options.get("ordered", init.ordered); |
| 451 options.get("negotiated", init.negotiated); | 450 options.get("negotiated", init.negotiated); |
| 452 | 451 |
| 453 unsigned short value = 0; | 452 unsigned short value = 0; |
| 454 if (options.get("id", value)) | 453 if (options.get("id", value)) |
| 455 init.id = value; | 454 init.id = value; |
| 456 if (options.get("maxRetransmits", value)) | 455 if (options.get("maxRetransmits", value)) |
| 457 init.maxRetransmits = value; | 456 init.maxRetransmits = value; |
| 458 if (options.get("maxRetransmitTime", value)) | 457 if (options.get("maxRetransmitTime", value)) |
| 459 init.maxRetransmitTime = value; | 458 init.maxRetransmitTime = value; |
| 460 | 459 |
| 461 String protocolString; | 460 String protocolString; |
| 462 options.get("protocol", protocolString); | 461 options.get("protocol", protocolString); |
| 463 init.protocol = protocolString; | 462 init.protocol = protocolString; |
| 464 | 463 |
| 465 RefPtr<RTCDataChannel> channel = RTCDataChannel::create(scriptExecutionConte
xt(), m_peerHandler.get(), label, init, es); | 464 RefPtr<RTCDataChannel> channel = RTCDataChannel::create(scriptExecutionConte
xt(), m_peerHandler.get(), label, init, ec); |
| 466 if (es.hadException()) | 465 if (ec) |
| 467 return 0; | 466 return 0; |
| 468 m_dataChannels.append(channel); | 467 m_dataChannels.append(channel); |
| 469 return channel.release(); | 468 return channel.release(); |
| 470 } | 469 } |
| 471 | 470 |
| 472 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId) | 471 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId) |
| 473 { | 472 { |
| 474 for (MediaStreamVector::iterator iter = m_localStreams.begin(); iter != m_lo
calStreams.end(); ++iter) { | 473 for (MediaStreamVector::iterator iter = m_localStreams.begin(); iter != m_lo
calStreams.end(); ++iter) { |
| 475 if ((*iter)->getTrackById(trackId)) | 474 if ((*iter)->getTrackById(trackId)) |
| 476 return true; | 475 return true; |
| 477 } | 476 } |
| 478 return false; | 477 return false; |
| 479 } | 478 } |
| 480 | 479 |
| 481 PassRefPtr<RTCDTMFSender> RTCPeerConnection::createDTMFSender(PassRefPtr<MediaSt
reamTrack> prpTrack, ExceptionState& es) | 480 PassRefPtr<RTCDTMFSender> RTCPeerConnection::createDTMFSender(PassRefPtr<MediaSt
reamTrack> prpTrack, ExceptionCode& ec) |
| 482 { | 481 { |
| 483 if (m_signalingState == SignalingStateClosed) { | 482 if (m_signalingState == SignalingStateClosed) { |
| 484 es.throwDOMException(InvalidStateError); | 483 ec = InvalidStateError; |
| 485 return 0; | 484 return 0; |
| 486 } | 485 } |
| 487 | 486 |
| 488 if (!prpTrack) { | 487 if (!prpTrack) { |
| 489 es.throwDOMException(TypeError); | 488 ec = TypeError; |
| 490 return 0; | 489 return 0; |
| 491 } | 490 } |
| 492 | 491 |
| 493 RefPtr<MediaStreamTrack> track = prpTrack; | 492 RefPtr<MediaStreamTrack> track = prpTrack; |
| 494 | 493 |
| 495 if (!hasLocalStreamWithTrackId(track->id())) { | 494 if (!hasLocalStreamWithTrackId(track->id())) { |
| 496 es.throwDOMException(SyntaxError); | 495 ec = SyntaxError; |
| 497 return 0; | 496 return 0; |
| 498 } | 497 } |
| 499 | 498 |
| 500 RefPtr<RTCDTMFSender> dtmfSender = RTCDTMFSender::create(scriptExecutionCont
ext(), m_peerHandler.get(), track.release(), es); | 499 RefPtr<RTCDTMFSender> dtmfSender = RTCDTMFSender::create(scriptExecutionCont
ext(), m_peerHandler.get(), track.release(), ec); |
| 501 if (es.hadException()) | 500 if (ec) |
| 502 return 0; | 501 return 0; |
| 503 return dtmfSender.release(); | 502 return dtmfSender.release(); |
| 504 } | 503 } |
| 505 | 504 |
| 506 void RTCPeerConnection::close(ExceptionState& es) | 505 void RTCPeerConnection::close(ExceptionCode& ec) |
| 507 { | 506 { |
| 508 if (m_signalingState == SignalingStateClosed) { | 507 if (m_signalingState == SignalingStateClosed) { |
| 509 es.throwDOMException(InvalidStateError); | 508 ec = InvalidStateError; |
| 510 return; | 509 return; |
| 511 } | 510 } |
| 512 | 511 |
| 513 m_peerHandler->stop(); | 512 m_peerHandler->stop(); |
| 514 | 513 |
| 515 changeIceConnectionState(IceConnectionStateClosed); | 514 changeIceConnectionState(IceConnectionStateClosed); |
| 516 changeIceGatheringState(IceGatheringStateComplete); | 515 changeIceGatheringState(IceGatheringStateComplete); |
| 517 changeSignalingState(SignalingStateClosed); | 516 changeSignalingState(SignalingStateClosed); |
| 518 } | 517 } |
| 519 | 518 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 events.swap(m_scheduledEvents); | 666 events.swap(m_scheduledEvents); |
| 668 | 667 |
| 669 Vector<RefPtr<Event> >::iterator it = events.begin(); | 668 Vector<RefPtr<Event> >::iterator it = events.begin(); |
| 670 for (; it != events.end(); ++it) | 669 for (; it != events.end(); ++it) |
| 671 dispatchEvent((*it).release()); | 670 dispatchEvent((*it).release()); |
| 672 | 671 |
| 673 events.clear(); | 672 events.clear(); |
| 674 } | 673 } |
| 675 | 674 |
| 676 } // namespace WebCore | 675 } // namespace WebCore |
| OLD | NEW |