| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 RTCPeerConnection* peerConnection = new RTCPeerConnection(context, configura
tion, constraints, exceptionState); | 234 RTCPeerConnection* peerConnection = new RTCPeerConnection(context, configura
tion, constraints, exceptionState); |
| 235 peerConnection->suspendIfNeeded(); | 235 peerConnection->suspendIfNeeded(); |
| 236 if (exceptionState.hadException()) | 236 if (exceptionState.hadException()) |
| 237 return 0; | 237 return 0; |
| 238 | 238 |
| 239 return peerConnection; | 239 return peerConnection; |
| 240 } | 240 } |
| 241 | 241 |
| 242 RTCPeerConnection::RTCPeerConnection(ExecutionContext* context, RTCConfiguration
* configuration, WebMediaConstraints constraints, ExceptionState& exceptionState
) | 242 RTCPeerConnection::RTCPeerConnection(ExecutionContext* context, RTCConfiguration
* configuration, WebMediaConstraints constraints, ExceptionState& exceptionState
) |
| 243 : ActiveDOMObject(context) | 243 : ActiveDOMObject(context) |
| 244 , m_pendingLocalDescription(nullptr) | |
| 245 , m_pendingRemoteDescription(nullptr) | |
| 246 , m_signalingState(SignalingStateStable) | 244 , m_signalingState(SignalingStateStable) |
| 247 , m_iceGatheringState(ICEGatheringStateNew) | 245 , m_iceGatheringState(ICEGatheringStateNew) |
| 248 , m_iceConnectionState(ICEConnectionStateNew) | 246 , m_iceConnectionState(ICEConnectionStateNew) |
| 249 , m_dispatchScheduledEventRunner(this, &RTCPeerConnection::dispatchScheduled
Event) | 247 , m_dispatchScheduledEventRunner(this, &RTCPeerConnection::dispatchScheduled
Event) |
| 250 , m_stopped(false) | 248 , m_stopped(false) |
| 251 , m_closed(false) | 249 , m_closed(false) |
| 252 { | 250 { |
| 253 Document* document = toDocument(executionContext()); | 251 Document* document = toDocument(executionContext()); |
| 254 | 252 |
| 255 // If we fail, set |m_closed| and |m_stopped| to true, to avoid hitting the
assert in the destructor. | 253 // If we fail, set |m_closed| and |m_stopped| to true, to avoid hitting the
assert in the destructor. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 270 } | 268 } |
| 271 | 269 |
| 272 document->frame()->loader().client()->dispatchWillStartUsingPeerConnectionHa
ndler(m_peerHandler.get()); | 270 document->frame()->loader().client()->dispatchWillStartUsingPeerConnectionHa
ndler(m_peerHandler.get()); |
| 273 | 271 |
| 274 if (!m_peerHandler->initialize(configuration, constraints)) { | 272 if (!m_peerHandler->initialize(configuration, constraints)) { |
| 275 m_closed = true; | 273 m_closed = true; |
| 276 m_stopped = true; | 274 m_stopped = true; |
| 277 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ
e native PeerConnection."); | 275 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ
e native PeerConnection."); |
| 278 return; | 276 return; |
| 279 } | 277 } |
| 280 m_localDescription = RTCSessionDescription::create(m_peerHandler->localDescr
iption()); | |
| 281 m_remoteDescription = RTCSessionDescription::create(m_peerHandler->remoteDes
cription()); | |
| 282 } | 278 } |
| 283 | 279 |
| 284 RTCPeerConnection::~RTCPeerConnection() | 280 RTCPeerConnection::~RTCPeerConnection() |
| 285 { | 281 { |
| 286 // This checks that close() or stop() is called before the destructor. | 282 // This checks that close() or stop() is called before the destructor. |
| 287 // We are assuming that a wrapper is always created when RTCPeerConnection i
s created. | 283 // We are assuming that a wrapper is always created when RTCPeerConnection i
s created. |
| 288 ASSERT(m_closed || m_stopped); | 284 ASSERT(m_closed || m_stopped); |
| 289 } | 285 } |
| 290 | 286 |
| 291 void RTCPeerConnection::createOffer(RTCSessionDescriptionCallback* successCallba
ck, RTCErrorCallback* errorCallback, const Dictionary& rtcOfferOptions, Exceptio
nState& exceptionState) | 287 void RTCPeerConnection::createOffer(RTCSessionDescriptionCallback* successCallba
ck, RTCErrorCallback* errorCallback, const Dictionary& rtcOfferOptions, Exceptio
nState& exceptionState) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 void RTCPeerConnection::setLocalDescription(RTCSessionDescription* sessionDescri
ption, VoidCallback* successCallback, RTCErrorCallback* errorCallback, Exception
State& exceptionState) | 326 void RTCPeerConnection::setLocalDescription(RTCSessionDescription* sessionDescri
ption, VoidCallback* successCallback, RTCErrorCallback* errorCallback, Exception
State& exceptionState) |
| 331 { | 327 { |
| 332 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 328 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 333 return; | 329 return; |
| 334 | 330 |
| 335 if (!sessionDescription) { | 331 if (!sessionDescription) { |
| 336 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "RTCSessionDescription")); | 332 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "RTCSessionDescription")); |
| 337 return; | 333 return; |
| 338 } | 334 } |
| 339 | 335 |
| 340 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi
s, successCallback, errorCallback, RTCVoidRequestImpl::RequestTypeLocal); | 336 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi
s, successCallback, errorCallback); |
| 341 m_peerHandler->setLocalDescription(request, sessionDescription->webSessionDe
scription()); | 337 m_peerHandler->setLocalDescription(request, sessionDescription->webSessionDe
scription()); |
| 342 m_pendingLocalDescription = sessionDescription; | |
| 343 } | 338 } |
| 344 | 339 |
| 345 RTCSessionDescription* RTCPeerConnection::localDescription() | 340 RTCSessionDescription* RTCPeerConnection::localDescription(ExceptionState& excep
tionState) |
| 346 { | 341 { |
| 347 if (!m_peerHandler) | |
| 348 return nullptr; | |
| 349 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip
tion(); | 342 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip
tion(); |
| 350 if (webSessionDescription.isNull()) | 343 if (webSessionDescription.isNull()) |
| 351 return nullptr; | 344 return nullptr; |
| 352 | 345 |
| 353 if (!m_localDescription || m_localDescription->webSessionDescription().isNul
l() | 346 return RTCSessionDescription::create(webSessionDescription); |
| 354 || m_localDescription->webSessionDescription() != webSessionDescription)
{ | |
| 355 m_localDescription = RTCSessionDescription::create(webSessionDescription
); | |
| 356 } | |
| 357 | |
| 358 return m_localDescription; | |
| 359 } | 347 } |
| 360 | 348 |
| 361 void RTCPeerConnection::setRemoteDescription(RTCSessionDescription* sessionDescr
iption, VoidCallback* successCallback, RTCErrorCallback* errorCallback, Exceptio
nState& exceptionState) | 349 void RTCPeerConnection::setRemoteDescription(RTCSessionDescription* sessionDescr
iption, VoidCallback* successCallback, RTCErrorCallback* errorCallback, Exceptio
nState& exceptionState) |
| 362 { | 350 { |
| 363 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 351 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 364 return; | 352 return; |
| 365 | 353 |
| 366 if (!sessionDescription) { | 354 if (!sessionDescription) { |
| 367 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "RTCSessionDescription")); | 355 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "RTCSessionDescription")); |
| 368 return; | 356 return; |
| 369 } | 357 } |
| 370 | 358 |
| 371 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi
s, successCallback, errorCallback, RTCVoidRequestImpl::RequestTypeRemote); | 359 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi
s, successCallback, errorCallback); |
| 372 m_peerHandler->setRemoteDescription(request, sessionDescription->webSessionD
escription()); | 360 m_peerHandler->setRemoteDescription(request, sessionDescription->webSessionD
escription()); |
| 373 m_pendingRemoteDescription = sessionDescription; | |
| 374 } | 361 } |
| 375 | 362 |
| 376 RTCSessionDescription* RTCPeerConnection::remoteDescription() | 363 RTCSessionDescription* RTCPeerConnection::remoteDescription(ExceptionState& exce
ptionState) |
| 377 { | 364 { |
| 378 if (!m_peerHandler) | |
| 379 return nullptr; | |
| 380 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri
ption(); | 365 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri
ption(); |
| 381 if (webSessionDescription.isNull()) | 366 if (webSessionDescription.isNull()) |
| 382 return nullptr; | 367 return nullptr; |
| 383 | 368 |
| 384 if (!m_remoteDescription || m_remoteDescription->webSessionDescription().isN
ull() | 369 return RTCSessionDescription::create(webSessionDescription); |
| 385 || m_remoteDescription->webSessionDescription() != webSessionDescription
) { | |
| 386 m_remoteDescription = RTCSessionDescription::create(webSessionDescriptio
n); | |
| 387 } | |
| 388 | |
| 389 return m_remoteDescription; | |
| 390 } | 370 } |
| 391 | 371 |
| 392 void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict
ionary& mediaConstraints, ExceptionState& exceptionState) | 372 void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict
ionary& mediaConstraints, ExceptionState& exceptionState) |
| 393 { | 373 { |
| 394 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 374 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 395 return; | 375 return; |
| 396 | 376 |
| 397 RTCConfiguration* configuration = parseConfiguration(rtcConfiguration, excep
tionState); | 377 RTCConfiguration* configuration = parseConfiguration(rtcConfiguration, excep
tionState); |
| 398 if (exceptionState.hadException()) | 378 if (exceptionState.hadException()) |
| 399 return; | 379 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 427 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 407 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 428 return; | 408 return; |
| 429 | 409 |
| 430 if (!iceCandidate) { | 410 if (!iceCandidate) { |
| 431 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "RTCIceCandidate")); | 411 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "RTCIceCandidate")); |
| 432 return; | 412 return; |
| 433 } | 413 } |
| 434 ASSERT(successCallback); | 414 ASSERT(successCallback); |
| 435 ASSERT(errorCallback); | 415 ASSERT(errorCallback); |
| 436 | 416 |
| 437 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi
s, successCallback, errorCallback, RTCVoidRequestImpl::RequestTypeNone); | 417 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi
s, successCallback, errorCallback); |
| 438 | 418 |
| 439 bool implemented = m_peerHandler->addICECandidate(request, iceCandidate->web
Candidate()); | 419 bool implemented = m_peerHandler->addICECandidate(request, iceCandidate->web
Candidate()); |
| 440 if (!implemented) { | 420 if (!implemented) { |
| 441 exceptionState.throwDOMException(NotSupportedError, "This method is not
yet implemented."); | 421 exceptionState.throwDOMException(NotSupportedError, "This method is not
yet implemented."); |
| 442 } | 422 } |
| 443 } | 423 } |
| 444 | 424 |
| 445 String RTCPeerConnection::signalingState() const | 425 String RTCPeerConnection::signalingState() const |
| 446 { | 426 { |
| 447 switch (m_signalingState) { | 427 switch (m_signalingState) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 } | 620 } |
| 641 | 621 |
| 642 void RTCPeerConnection::close(ExceptionState& exceptionState) | 622 void RTCPeerConnection::close(ExceptionState& exceptionState) |
| 643 { | 623 { |
| 644 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 624 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 645 return; | 625 return; |
| 646 | 626 |
| 647 closeInternal(); | 627 closeInternal(); |
| 648 } | 628 } |
| 649 | 629 |
| 650 void RTCPeerConnection::requestSucceeded(RTCVoidRequestImpl::RequestType request
Type) | |
| 651 { | |
| 652 if (requestType == RTCVoidRequestImpl::RequestTypeLocal) { | |
| 653 commitPendingLocalSessionDescription(); | |
| 654 } else if (requestType == RTCVoidRequestImpl::RequestTypeRemote) { | |
| 655 commitPendingRemoteSessionDescription(); | |
| 656 } | |
| 657 } | |
| 658 | |
| 659 void RTCPeerConnection::negotiationNeeded() | 630 void RTCPeerConnection::negotiationNeeded() |
| 660 { | 631 { |
| 661 ASSERT(!m_closed); | 632 ASSERT(!m_closed); |
| 662 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded)); | 633 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded)); |
| 663 } | 634 } |
| 664 | 635 |
| 665 void RTCPeerConnection::didGenerateICECandidate(const WebRTCICECandidate& webCan
didate) | 636 void RTCPeerConnection::didGenerateICECandidate(const WebRTCICECandidate& webCan
didate) |
| 666 { | 637 { |
| 667 ASSERT(!m_closed); | 638 ASSERT(!m_closed); |
| 668 ASSERT(executionContext()->isContextThread()); | 639 ASSERT(executionContext()->isContextThread()); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 { | 790 { |
| 820 ASSERT(m_signalingState != RTCPeerConnection::SignalingStateClosed); | 791 ASSERT(m_signalingState != RTCPeerConnection::SignalingStateClosed); |
| 821 m_peerHandler->stop(); | 792 m_peerHandler->stop(); |
| 822 m_closed = true; | 793 m_closed = true; |
| 823 | 794 |
| 824 changeIceConnectionState(ICEConnectionStateClosed); | 795 changeIceConnectionState(ICEConnectionStateClosed); |
| 825 changeIceGatheringState(ICEGatheringStateComplete); | 796 changeIceGatheringState(ICEGatheringStateComplete); |
| 826 changeSignalingState(SignalingStateClosed); | 797 changeSignalingState(SignalingStateClosed); |
| 827 } | 798 } |
| 828 | 799 |
| 829 void RTCPeerConnection::commitPendingLocalSessionDescription() | |
| 830 { | |
| 831 m_localDescription = m_pendingLocalDescription; | |
| 832 } | |
| 833 | |
| 834 void RTCPeerConnection::commitPendingRemoteSessionDescription() | |
| 835 { | |
| 836 m_remoteDescription = m_pendingRemoteDescription; | |
| 837 } | |
| 838 | |
| 839 void RTCPeerConnection::scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event> even
t) | 800 void RTCPeerConnection::scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event> even
t) |
| 840 { | 801 { |
| 841 m_scheduledEvents.append(event); | 802 m_scheduledEvents.append(event); |
| 842 | 803 |
| 843 m_dispatchScheduledEventRunner.runAsync(); | 804 m_dispatchScheduledEventRunner.runAsync(); |
| 844 } | 805 } |
| 845 | 806 |
| 846 void RTCPeerConnection::dispatchScheduledEvent() | 807 void RTCPeerConnection::dispatchScheduledEvent() |
| 847 { | 808 { |
| 848 if (m_stopped) | 809 if (m_stopped) |
| 849 return; | 810 return; |
| 850 | 811 |
| 851 WillBeHeapVector<RefPtrWillBeMember<Event>> events; | 812 WillBeHeapVector<RefPtrWillBeMember<Event>> events; |
| 852 events.swap(m_scheduledEvents); | 813 events.swap(m_scheduledEvents); |
| 853 | 814 |
| 854 WillBeHeapVector<RefPtrWillBeMember<Event>>::iterator it = events.begin(); | 815 WillBeHeapVector<RefPtrWillBeMember<Event>>::iterator it = events.begin(); |
| 855 for (; it != events.end(); ++it) | 816 for (; it != events.end(); ++it) |
| 856 dispatchEvent((*it).release()); | 817 dispatchEvent((*it).release()); |
| 857 | 818 |
| 858 events.clear(); | 819 events.clear(); |
| 859 } | 820 } |
| 860 | 821 |
| 861 DEFINE_TRACE(RTCPeerConnection) | 822 DEFINE_TRACE(RTCPeerConnection) |
| 862 { | 823 { |
| 863 visitor->trace(m_localStreams); | 824 visitor->trace(m_localStreams); |
| 864 visitor->trace(m_remoteStreams); | 825 visitor->trace(m_remoteStreams); |
| 865 visitor->trace(m_dataChannels); | 826 visitor->trace(m_dataChannels); |
| 866 visitor->trace(m_localDescription); | |
| 867 visitor->trace(m_remoteDescription); | |
| 868 visitor->trace(m_pendingLocalDescription); | |
| 869 visitor->trace(m_pendingRemoteDescription); | |
| 870 #if ENABLE(OILPAN) | 827 #if ENABLE(OILPAN) |
| 871 visitor->trace(m_scheduledEvents); | 828 visitor->trace(m_scheduledEvents); |
| 872 #endif | 829 #endif |
| 873 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac
e(visitor); | 830 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac
e(visitor); |
| 874 ActiveDOMObject::trace(visitor); | 831 ActiveDOMObject::trace(visitor); |
| 875 } | 832 } |
| 876 | 833 |
| 877 } // namespace blink | 834 } // namespace blink |
| OLD | NEW |