Chromium Code Reviews| 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) | |
| 244 , m_signalingState(SignalingStateStable) | 246 , m_signalingState(SignalingStateStable) |
| 245 , m_iceGatheringState(ICEGatheringStateNew) | 247 , m_iceGatheringState(ICEGatheringStateNew) |
| 246 , m_iceConnectionState(ICEConnectionStateNew) | 248 , m_iceConnectionState(ICEConnectionStateNew) |
| 247 , m_dispatchScheduledEventRunner(this, &RTCPeerConnection::dispatchScheduled Event) | 249 , m_dispatchScheduledEventRunner(this, &RTCPeerConnection::dispatchScheduled Event) |
| 248 , m_stopped(false) | 250 , m_stopped(false) |
| 249 , m_closed(false) | 251 , m_closed(false) |
| 250 { | 252 { |
| 251 Document* document = toDocument(executionContext()); | 253 Document* document = toDocument(executionContext()); |
| 252 | 254 |
| 253 // If we fail, set |m_closed| and |m_stopped| to true, to avoid hitting the assert in the destructor. | 255 // 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... | |
| 268 } | 270 } |
| 269 | 271 |
| 270 document->frame()->loader().client()->dispatchWillStartUsingPeerConnectionHa ndler(m_peerHandler.get()); | 272 document->frame()->loader().client()->dispatchWillStartUsingPeerConnectionHa ndler(m_peerHandler.get()); |
| 271 | 273 |
| 272 if (!m_peerHandler->initialize(configuration, constraints)) { | 274 if (!m_peerHandler->initialize(configuration, constraints)) { |
| 273 m_closed = true; | 275 m_closed = true; |
| 274 m_stopped = true; | 276 m_stopped = true; |
| 275 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ e native PeerConnection."); | 277 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ e native PeerConnection."); |
| 276 return; | 278 return; |
| 277 } | 279 } |
| 280 m_localDescription = RTCSessionDescription::create(m_peerHandler->localDescr iption()); | |
| 281 m_remoteDescription = RTCSessionDescription::create(m_peerHandler->remoteDes cription()); | |
| 278 } | 282 } |
| 279 | 283 |
| 280 RTCPeerConnection::~RTCPeerConnection() | 284 RTCPeerConnection::~RTCPeerConnection() |
| 281 { | 285 { |
| 282 // This checks that close() or stop() is called before the destructor. | 286 // This checks that close() or stop() is called before the destructor. |
| 283 // We are assuming that a wrapper is always created when RTCPeerConnection i s created. | 287 // We are assuming that a wrapper is always created when RTCPeerConnection i s created. |
| 284 ASSERT(m_closed || m_stopped); | 288 ASSERT(m_closed || m_stopped); |
| 285 } | 289 } |
| 286 | 290 |
| 287 void RTCPeerConnection::createOffer(RTCSessionDescriptionCallback* successCallba ck, RTCErrorCallback* errorCallback, const Dictionary& rtcOfferOptions, Exceptio nState& exceptionState) | 291 void RTCPeerConnection::createOffer(RTCSessionDescriptionCallback* successCallba ck, RTCErrorCallback* errorCallback, const Dictionary& rtcOfferOptions, Exceptio nState& exceptionState) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 332 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 329 return; | 333 return; |
| 330 | 334 |
| 331 if (!sessionDescription) { | 335 if (!sessionDescription) { |
| 332 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription")); | 336 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription")); |
| 333 return; | 337 return; |
| 334 } | 338 } |
| 335 | 339 |
| 336 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); | 340 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); |
| 337 m_peerHandler->setLocalDescription(request, sessionDescription->webSessionDe scription()); | 341 m_peerHandler->setLocalDescription(request, sessionDescription->webSessionDe scription()); |
| 342 m_pendingLocalDescription = sessionDescription; | |
| 338 } | 343 } |
| 339 | 344 |
| 340 RTCSessionDescription* RTCPeerConnection::localDescription(ExceptionState& excep tionState) | 345 RTCSessionDescription* RTCPeerConnection::localDescription() |
| 341 { | 346 { |
| 342 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip tion(); | 347 if (!m_peerHandler || m_peerHandler->localDescription().isNull()) |
| 343 if (webSessionDescription.isNull()) | |
| 344 return nullptr; | 348 return nullptr; |
| 345 | 349 |
| 346 return RTCSessionDescription::create(webSessionDescription); | 350 updateLocalSessionDescriptionIfNeeded(false); |
| 351 return m_localDescription; | |
| 347 } | 352 } |
| 348 | 353 |
| 349 void RTCPeerConnection::setRemoteDescription(RTCSessionDescription* sessionDescr iption, VoidCallback* successCallback, RTCErrorCallback* errorCallback, Exceptio nState& exceptionState) | 354 void RTCPeerConnection::setRemoteDescription(RTCSessionDescription* sessionDescr iption, VoidCallback* successCallback, RTCErrorCallback* errorCallback, Exceptio nState& exceptionState) |
| 350 { | 355 { |
| 351 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 356 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 352 return; | 357 return; |
| 353 | 358 |
| 354 if (!sessionDescription) { | 359 if (!sessionDescription) { |
| 355 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription")); | 360 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription")); |
| 356 return; | 361 return; |
| 357 } | 362 } |
| 358 | 363 |
| 359 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); | 364 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); |
| 360 m_peerHandler->setRemoteDescription(request, sessionDescription->webSessionD escription()); | 365 m_peerHandler->setRemoteDescription(request, sessionDescription->webSessionD escription()); |
| 366 m_pendingRemoteDescription = sessionDescription; | |
| 361 } | 367 } |
| 362 | 368 |
| 363 RTCSessionDescription* RTCPeerConnection::remoteDescription(ExceptionState& exce ptionState) | 369 RTCSessionDescription* RTCPeerConnection::remoteDescription() |
| 364 { | 370 { |
| 365 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri ption(); | 371 if (!m_peerHandler || m_peerHandler->remoteDescription().isNull()) |
| 366 if (webSessionDescription.isNull()) | |
| 367 return nullptr; | 372 return nullptr; |
| 368 | 373 |
| 369 return RTCSessionDescription::create(webSessionDescription); | 374 updateRemoteSessionDescriptionIfNeeded(false); |
| 375 return m_remoteDescription; | |
| 370 } | 376 } |
| 371 | 377 |
| 372 void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict ionary& mediaConstraints, ExceptionState& exceptionState) | 378 void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict ionary& mediaConstraints, ExceptionState& exceptionState) |
| 373 { | 379 { |
| 374 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 380 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 375 return; | 381 return; |
| 376 | 382 |
| 377 RTCConfiguration* configuration = parseConfiguration(rtcConfiguration, excep tionState); | 383 RTCConfiguration* configuration = parseConfiguration(rtcConfiguration, excep tionState); |
| 378 if (exceptionState.hadException()) | 384 if (exceptionState.hadException()) |
| 379 return; | 385 return; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 } | 626 } |
| 621 | 627 |
| 622 void RTCPeerConnection::close(ExceptionState& exceptionState) | 628 void RTCPeerConnection::close(ExceptionState& exceptionState) |
| 623 { | 629 { |
| 624 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 630 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 625 return; | 631 return; |
| 626 | 632 |
| 627 closeInternal(); | 633 closeInternal(); |
| 628 } | 634 } |
| 629 | 635 |
| 636 void RTCPeerConnection::updateLocalSessionDescriptionIfNeeded(bool pending) | |
| 637 { | |
| 638 if (!m_peerHandler) | |
| 639 return; | |
| 640 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip tion(); | |
| 641 if (webSessionDescription.isNull()) | |
| 642 return; | |
| 643 | |
| 644 if (pending) { | |
|
Jens Widell
2015/05/05 06:31:20
This code path has essentially nothing in common w
changbin
2015/05/05 07:02:29
Therefore, your proposal would be,
1. Move out 'if
Jens Widell
2015/05/05 07:17:21
Correct.
Though 2 is somewhat optional. Keeping t
| |
| 645 m_localDescription = m_pendingLocalDescription; | |
| 646 return; | |
| 647 } | |
| 648 | |
| 649 if (!m_localDescription || m_localDescription->webSessionDescription().isNul l() | |
| 650 || m_localDescription->webSessionDescription() != webSessionDescription) { | |
| 651 m_localDescription = RTCSessionDescription::create(webSessionDescription ); | |
| 652 } | |
| 653 } | |
| 654 | |
| 655 void RTCPeerConnection::updateRemoteSessionDescriptionIfNeeded(bool pending) | |
| 656 { | |
| 657 if (!m_peerHandler) | |
| 658 return; | |
| 659 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri ption(); | |
| 660 if (webSessionDescription.isNull()) | |
| 661 return; | |
| 662 | |
| 663 if (pending) { | |
| 664 m_remoteDescription = m_pendingRemoteDescription; | |
| 665 return; | |
| 666 } | |
| 667 | |
| 668 if (!m_remoteDescription || m_remoteDescription->webSessionDescription().isN ull() | |
| 669 || m_remoteDescription->webSessionDescription() != webSessionDescription ) { | |
| 670 m_remoteDescription = RTCSessionDescription::create(webSessionDescriptio n); | |
| 671 } | |
| 672 } | |
| 673 | |
| 630 void RTCPeerConnection::negotiationNeeded() | 674 void RTCPeerConnection::negotiationNeeded() |
| 631 { | 675 { |
| 632 ASSERT(!m_closed); | 676 ASSERT(!m_closed); |
| 633 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded)); | 677 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded)); |
| 634 } | 678 } |
| 635 | 679 |
| 636 void RTCPeerConnection::didGenerateICECandidate(const WebRTCICECandidate& webCan didate) | 680 void RTCPeerConnection::didGenerateICECandidate(const WebRTCICECandidate& webCan didate) |
| 637 { | 681 { |
| 638 ASSERT(!m_closed); | 682 ASSERT(!m_closed); |
| 639 ASSERT(executionContext()->isContextThread()); | 683 ASSERT(executionContext()->isContextThread()); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 dispatchEvent((*it).release()); | 861 dispatchEvent((*it).release()); |
| 818 | 862 |
| 819 events.clear(); | 863 events.clear(); |
| 820 } | 864 } |
| 821 | 865 |
| 822 DEFINE_TRACE(RTCPeerConnection) | 866 DEFINE_TRACE(RTCPeerConnection) |
| 823 { | 867 { |
| 824 visitor->trace(m_localStreams); | 868 visitor->trace(m_localStreams); |
| 825 visitor->trace(m_remoteStreams); | 869 visitor->trace(m_remoteStreams); |
| 826 visitor->trace(m_dataChannels); | 870 visitor->trace(m_dataChannels); |
| 871 visitor->trace(m_localDescription); | |
| 872 visitor->trace(m_remoteDescription); | |
| 873 visitor->trace(m_pendingLocalDescription); | |
| 874 visitor->trace(m_pendingRemoteDescription); | |
| 827 #if ENABLE(OILPAN) | 875 #if ENABLE(OILPAN) |
| 828 visitor->trace(m_scheduledEvents); | 876 visitor->trace(m_scheduledEvents); |
| 829 #endif | 877 #endif |
| 830 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); | 878 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); |
| 831 ActiveDOMObject::trace(visitor); | 879 ActiveDOMObject::trace(visitor); |
| 832 } | 880 } |
| 833 | 881 |
| 834 } // namespace blink | 882 } // namespace blink |
| OLD | NEW |