| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if (state == RTCPeerConnection::SignalingStateClosed) { | 99 if (state == RTCPeerConnection::SignalingStateClosed) { |
| 100 exceptionState.throwDOMException(InvalidStateError, kSignalingStateClose
dMessage); | 100 exceptionState.throwDOMException(InvalidStateError, kSignalingStateClose
dMessage); |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 | 103 |
| 104 return false; | 104 return false; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void asyncCallErrorCallback(RTCPeerConnectionErrorCallback* errorCallback, DOMEx
ception* exception) | 107 void asyncCallErrorCallback(RTCPeerConnectionErrorCallback* errorCallback, DOMEx
ception* exception) |
| 108 { | 108 { |
| 109 ASSERT(errorCallback); | 109 DCHECK(errorCallback); |
| 110 Microtask::enqueueMicrotask(bind(&RTCPeerConnectionErrorCallback::handleEven
t, errorCallback, exception)); | 110 Microtask::enqueueMicrotask(bind(&RTCPeerConnectionErrorCallback::handleEven
t, errorCallback, exception)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool callErrorCallbackIfSignalingStateClosed(RTCPeerConnection::SignalingState s
tate, RTCPeerConnectionErrorCallback* errorCallback) | 113 bool callErrorCallbackIfSignalingStateClosed(RTCPeerConnection::SignalingState s
tate, RTCPeerConnectionErrorCallback* errorCallback) |
| 114 { | 114 { |
| 115 if (state == RTCPeerConnection::SignalingStateClosed) { | 115 if (state == RTCPeerConnection::SignalingStateClosed) { |
| 116 if (errorCallback) | 116 if (errorCallback) |
| 117 asyncCallErrorCallback(errorCallback, DOMException::create(InvalidSt
ateError, kSignalingStateClosedMessage)); | 117 asyncCallErrorCallback(errorCallback, DOMException::create(InvalidSt
ateError, kSignalingStateClosedMessage)); |
| 118 | 118 |
| 119 return true; | 119 return true; |
| 120 } | 120 } |
| 121 | 121 |
| 122 return false; | 122 return false; |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool isIceCandidateMissingSdp(const RTCIceCandidateInitOrRTCIceCandidate& candid
ate) | 125 bool isIceCandidateMissingSdp(const RTCIceCandidateInitOrRTCIceCandidate& candid
ate) |
| 126 { | 126 { |
| 127 if (candidate.isRTCIceCandidateInit()) { | 127 if (candidate.isRTCIceCandidateInit()) { |
| 128 const RTCIceCandidateInit& iceCandidateInit = candidate.getAsRTCIceCandi
dateInit(); | 128 const RTCIceCandidateInit& iceCandidateInit = candidate.getAsRTCIceCandi
dateInit(); |
| 129 return !iceCandidateInit.hasSdpMid() && !iceCandidateInit.hasSdpMLineInd
ex(); | 129 return !iceCandidateInit.hasSdpMid() && !iceCandidateInit.hasSdpMLineInd
ex(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 ASSERT(candidate.isRTCIceCandidate()); | 132 DCHECK(candidate.isRTCIceCandidate()); |
| 133 return false; | 133 return false; |
| 134 } | 134 } |
| 135 | 135 |
| 136 WebRTCOfferOptions convertToWebRTCOfferOptions(const RTCOfferOptions& options) | 136 WebRTCOfferOptions convertToWebRTCOfferOptions(const RTCOfferOptions& options) |
| 137 { | 137 { |
| 138 return WebRTCOfferOptions(RTCOfferOptionsPlatform::create( | 138 return WebRTCOfferOptions(RTCOfferOptionsPlatform::create( |
| 139 -1, -1, | 139 -1, -1, |
| 140 options.hasVoiceActivityDetection() ? options.voiceActivityDetection() :
true, | 140 options.hasVoiceActivityDetection() ? options.voiceActivityDetection() :
true, |
| 141 options.hasIceRestart() ? options.iceRestart() : false)); | 141 options.hasIceRestart() ? options.iceRestart() : false)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 WebRTCAnswerOptions convertToWebRTCAnswerOptions(const RTCAnswerOptions& options
) | 144 WebRTCAnswerOptions convertToWebRTCAnswerOptions(const RTCAnswerOptions& options
) |
| 145 { | 145 { |
| 146 return WebRTCAnswerOptions(RTCAnswerOptionsPlatform::create( | 146 return WebRTCAnswerOptions(RTCAnswerOptionsPlatform::create( |
| 147 options.hasVoiceActivityDetection() ? options.voiceActivityDetection() :
true)); | 147 options.hasVoiceActivityDetection() ? options.voiceActivityDetection() :
true)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 WebRTCICECandidate convertToWebRTCIceCandidate(const RTCIceCandidateInitOrRTCIce
Candidate& candidate) | 150 WebRTCICECandidate convertToWebRTCIceCandidate(const RTCIceCandidateInitOrRTCIce
Candidate& candidate) |
| 151 { | 151 { |
| 152 if (candidate.isRTCIceCandidateInit()) { | 152 if (candidate.isRTCIceCandidateInit()) { |
| 153 const RTCIceCandidateInit& iceCandidateInit = candidate.getAsRTCIceCandi
dateInit(); | 153 const RTCIceCandidateInit& iceCandidateInit = candidate.getAsRTCIceCandi
dateInit(); |
| 154 return WebRTCICECandidate(iceCandidateInit.candidate(), iceCandidateInit
.sdpMid(), iceCandidateInit.sdpMLineIndex()); | 154 return WebRTCICECandidate(iceCandidateInit.candidate(), iceCandidateInit
.sdpMid(), iceCandidateInit.sdpMLineIndex()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 ASSERT(candidate.isRTCIceCandidate()); | 157 DCHECK(candidate.isRTCIceCandidate()); |
| 158 return candidate.getAsRTCIceCandidate()->webCandidate(); | 158 return candidate.getAsRTCIceCandidate()->webCandidate(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // Helper class for RTCPeerConnection::generateCertificate. | 161 // Helper class for RTCPeerConnection::generateCertificate. |
| 162 class WebRTCCertificateObserver : public WebRTCCertificateCallback { | 162 class WebRTCCertificateObserver : public WebRTCCertificateCallback { |
| 163 public: | 163 public: |
| 164 // Takes ownership of |resolver|. | 164 // Takes ownership of |resolver|. |
| 165 static WebRTCCertificateObserver* create(ScriptPromiseResolver* resolver) | 165 static WebRTCCertificateObserver* create(ScriptPromiseResolver* resolver) |
| 166 { | 166 { |
| 167 return new WebRTCCertificateObserver(resolver); | 167 return new WebRTCCertificateObserver(resolver); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 m_stopped = true; | 438 m_stopped = true; |
| 439 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ
e native PeerConnection."); | 439 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ
e native PeerConnection."); |
| 440 return; | 440 return; |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 RTCPeerConnection::~RTCPeerConnection() | 444 RTCPeerConnection::~RTCPeerConnection() |
| 445 { | 445 { |
| 446 // This checks that close() or stop() is called before the destructor. | 446 // This checks that close() or stop() is called before the destructor. |
| 447 // We are assuming that a wrapper is always created when RTCPeerConnection i
s created. | 447 // We are assuming that a wrapper is always created when RTCPeerConnection i
s created. |
| 448 ASSERT(m_closed || m_stopped); | 448 DCHECK(m_closed || m_stopped); |
| 449 } | 449 } |
| 450 | 450 |
| 451 ScriptPromise RTCPeerConnection::createOffer(ScriptState* scriptState, const RTC
OfferOptions& options) | 451 ScriptPromise RTCPeerConnection::createOffer(ScriptState* scriptState, const RTC
OfferOptions& options) |
| 452 { | 452 { |
| 453 if (m_signalingState == SignalingStateClosed) | 453 if (m_signalingState == SignalingStateClosed) |
| 454 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, kSignalingStateClosedMessage)); | 454 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, kSignalingStateClosedMessage)); |
| 455 | 455 |
| 456 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 456 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 457 ScriptPromise promise = resolver->promise(); | 457 ScriptPromise promise = resolver->promise(); |
| 458 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestPromiseI
mpl::create(this, resolver); | 458 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestPromiseI
mpl::create(this, resolver); |
| 459 m_peerHandler->createOffer(request, convertToWebRTCOfferOptions(options)); | 459 m_peerHandler->createOffer(request, convertToWebRTCOfferOptions(options)); |
| 460 return promise; | 460 return promise; |
| 461 } | 461 } |
| 462 | 462 |
| 463 ScriptPromise RTCPeerConnection::createOffer(ScriptState* scriptState, RTCSessio
nDescriptionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCall
back, const Dictionary& rtcOfferOptions) | 463 ScriptPromise RTCPeerConnection::createOffer(ScriptState* scriptState, RTCSessio
nDescriptionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCall
back, const Dictionary& rtcOfferOptions) |
| 464 { | 464 { |
| 465 ASSERT(successCallback); | 465 DCHECK(successCallback); |
| 466 ASSERT(errorCallback); | 466 DCHECK(errorCallback); |
| 467 ExecutionContext* context = scriptState->getExecutionContext(); | 467 ExecutionContext* context = scriptState->getExecutionContext(); |
| 468 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferLegacyFai
lureCallback); | 468 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferLegacyFai
lureCallback); |
| 469 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) | 469 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) |
| 470 return ScriptPromise::castUndefined(scriptState); | 470 return ScriptPromise::castUndefined(scriptState); |
| 471 | 471 |
| 472 RTCOfferOptionsPlatform* offerOptions = parseOfferOptions(rtcOfferOptions); | 472 RTCOfferOptionsPlatform* offerOptions = parseOfferOptions(rtcOfferOptions); |
| 473 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr
eate(getExecutionContext(), this, successCallback, errorCallback); | 473 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr
eate(getExecutionContext(), this, successCallback, errorCallback); |
| 474 | 474 |
| 475 if (offerOptions) { | 475 if (offerOptions) { |
| 476 if (offerOptions->offerToReceiveAudio() != -1 || offerOptions->offerToRe
ceiveVideo() != -1) | 476 if (offerOptions->offerToReceiveAudio() != -1 || offerOptions->offerToRe
ceiveVideo() != -1) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 508 |
| 509 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 509 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 510 ScriptPromise promise = resolver->promise(); | 510 ScriptPromise promise = resolver->promise(); |
| 511 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestPromiseI
mpl::create(this, resolver); | 511 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestPromiseI
mpl::create(this, resolver); |
| 512 m_peerHandler->createAnswer(request, convertToWebRTCAnswerOptions(options)); | 512 m_peerHandler->createAnswer(request, convertToWebRTCAnswerOptions(options)); |
| 513 return promise; | 513 return promise; |
| 514 } | 514 } |
| 515 | 515 |
| 516 ScriptPromise RTCPeerConnection::createAnswer(ScriptState* scriptState, RTCSessi
onDescriptionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCal
lback, const Dictionary& mediaConstraints) | 516 ScriptPromise RTCPeerConnection::createAnswer(ScriptState* scriptState, RTCSessi
onDescriptionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCal
lback, const Dictionary& mediaConstraints) |
| 517 { | 517 { |
| 518 ASSERT(successCallback); | 518 DCHECK(successCallback); |
| 519 ASSERT(errorCallback); | 519 DCHECK(errorCallback); |
| 520 ExecutionContext* context = scriptState->getExecutionContext(); | 520 ExecutionContext* context = scriptState->getExecutionContext(); |
| 521 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLegacyFa
ilureCallback); | 521 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLegacyFa
ilureCallback); |
| 522 if (mediaConstraints.isObject()) | 522 if (mediaConstraints.isObject()) |
| 523 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega
cyConstraints); | 523 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega
cyConstraints); |
| 524 else | 524 else |
| 525 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega
cyCompliant); | 525 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega
cyCompliant); |
| 526 | 526 |
| 527 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) | 527 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) |
| 528 return ScriptPromise::castUndefined(scriptState); | 528 return ScriptPromise::castUndefined(scriptState); |
| 529 | 529 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 } else { | 562 } else { |
| 563 if (!successCallback) | 563 if (!successCallback) |
| 564 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc
riptionLegacyNoSuccessCallback); | 564 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc
riptionLegacyNoSuccessCallback); |
| 565 if (!errorCallback) | 565 if (!errorCallback) |
| 566 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc
riptionLegacyNoFailureCallback); | 566 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc
riptionLegacyNoFailureCallback); |
| 567 } | 567 } |
| 568 | 568 |
| 569 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) | 569 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) |
| 570 return ScriptPromise::castUndefined(scriptState); | 570 return ScriptPromise::castUndefined(scriptState); |
| 571 | 571 |
| 572 ASSERT(sessionDescription); | 572 DCHECK(sessionDescription); |
| 573 | 573 |
| 574 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(),
this, successCallback, errorCallback); | 574 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(),
this, successCallback, errorCallback); |
| 575 m_peerHandler->setLocalDescription(request, sessionDescription->webSessionDe
scription()); | 575 m_peerHandler->setLocalDescription(request, sessionDescription->webSessionDe
scription()); |
| 576 return ScriptPromise::castUndefined(scriptState); | 576 return ScriptPromise::castUndefined(scriptState); |
| 577 } | 577 } |
| 578 | 578 |
| 579 RTCSessionDescription* RTCPeerConnection::localDescription() | 579 RTCSessionDescription* RTCPeerConnection::localDescription() |
| 580 { | 580 { |
| 581 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip
tion(); | 581 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip
tion(); |
| 582 if (webSessionDescription.isNull()) | 582 if (webSessionDescription.isNull()) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 605 } else { | 605 } else { |
| 606 if (!successCallback) | 606 if (!successCallback) |
| 607 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes
criptionLegacyNoSuccessCallback); | 607 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes
criptionLegacyNoSuccessCallback); |
| 608 if (!errorCallback) | 608 if (!errorCallback) |
| 609 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes
criptionLegacyNoFailureCallback); | 609 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes
criptionLegacyNoFailureCallback); |
| 610 } | 610 } |
| 611 | 611 |
| 612 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) | 612 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) |
| 613 return ScriptPromise::castUndefined(scriptState); | 613 return ScriptPromise::castUndefined(scriptState); |
| 614 | 614 |
| 615 ASSERT(sessionDescription); | 615 DCHECK(sessionDescription); |
| 616 | 616 |
| 617 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(),
this, successCallback, errorCallback); | 617 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(),
this, successCallback, errorCallback); |
| 618 m_peerHandler->setRemoteDescription(request, sessionDescription->webSessionD
escription()); | 618 m_peerHandler->setRemoteDescription(request, sessionDescription->webSessionD
escription()); |
| 619 return ScriptPromise::castUndefined(scriptState); | 619 return ScriptPromise::castUndefined(scriptState); |
| 620 } | 620 } |
| 621 | 621 |
| 622 RTCSessionDescription* RTCPeerConnection::remoteDescription() | 622 RTCSessionDescription* RTCPeerConnection::remoteDescription() |
| 623 { | 623 { |
| 624 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri
ption(); | 624 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri
ption(); |
| 625 if (webSessionDescription.isNull()) | 625 if (webSessionDescription.isNull()) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 if (cryptoAlgorithm.ecKeyGenParams()->namedCurve() == WebCryptoNamedCurv
eP256) { | 685 if (cryptoAlgorithm.ecKeyGenParams()->namedCurve() == WebCryptoNamedCurv
eP256) { |
| 686 keyParams.set(WebRTCKeyParams::createECDSA(WebRTCECCurveNistP256)); | 686 keyParams.set(WebRTCKeyParams::createECDSA(WebRTCECCurveNistP256)); |
| 687 } else { | 687 } else { |
| 688 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(NotSupportedError, unsupportedParamsString)); | 688 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(NotSupportedError, unsupportedParamsString)); |
| 689 } | 689 } |
| 690 break; | 690 break; |
| 691 default: | 691 default: |
| 692 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, "The 1st argument provided is an AlgorithmIdentifier,
but the algorithm is not supported.")); | 692 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, "The 1st argument provided is an AlgorithmIdentifier,
but the algorithm is not supported.")); |
| 693 break; | 693 break; |
| 694 } | 694 } |
| 695 ASSERT(!keyParams.isNull()); | 695 DCHECK(!keyParams.isNull()); |
| 696 | 696 |
| 697 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr( | 697 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr( |
| 698 Platform::current()->createRTCCertificateGenerator()); | 698 Platform::current()->createRTCCertificateGenerator()); |
| 699 | 699 |
| 700 // |keyParams| was successfully constructed, but does the certificate genera
tor support these parameters? | 700 // |keyParams| was successfully constructed, but does the certificate genera
tor support these parameters? |
| 701 if (!certificateGenerator->isSupportedKeyParams(keyParams.get())) { | 701 if (!certificateGenerator->isSupportedKeyParams(keyParams.get())) { |
| 702 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, unsupportedParamsString)); | 702 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, unsupportedParamsString)); |
| 703 } | 703 } |
| 704 | 704 |
| 705 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 705 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 732 WebRTCICECandidate webCandidate = convertToWebRTCIceCandidate(candidate); | 732 WebRTCICECandidate webCandidate = convertToWebRTCIceCandidate(candidate); |
| 733 bool implemented = m_peerHandler->addICECandidate(request, webCandidate); | 733 bool implemented = m_peerHandler->addICECandidate(request, webCandidate); |
| 734 if (!implemented) | 734 if (!implemented) |
| 735 resolver->reject(DOMException::create(OperationError, "This operation co
uld not be completed.")); | 735 resolver->reject(DOMException::create(OperationError, "This operation co
uld not be completed.")); |
| 736 | 736 |
| 737 return promise; | 737 return promise; |
| 738 } | 738 } |
| 739 | 739 |
| 740 ScriptPromise RTCPeerConnection::addIceCandidate(ScriptState* scriptState, RTCIc
eCandidate* iceCandidate, VoidCallback* successCallback, RTCPeerConnectionErrorC
allback* errorCallback) | 740 ScriptPromise RTCPeerConnection::addIceCandidate(ScriptState* scriptState, RTCIc
eCandidate* iceCandidate, VoidCallback* successCallback, RTCPeerConnectionErrorC
allback* errorCallback) |
| 741 { | 741 { |
| 742 ASSERT(iceCandidate); | 742 DCHECK(iceCandidate); |
| 743 ASSERT(successCallback); | 743 DCHECK(successCallback); |
| 744 ASSERT(errorCallback); | 744 DCHECK(errorCallback); |
| 745 | 745 |
| 746 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) | 746 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) |
| 747 return ScriptPromise::castUndefined(scriptState); | 747 return ScriptPromise::castUndefined(scriptState); |
| 748 | 748 |
| 749 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(),
this, successCallback, errorCallback); | 749 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(),
this, successCallback, errorCallback); |
| 750 bool implemented = m_peerHandler->addICECandidate(request, iceCandidate->web
Candidate()); | 750 bool implemented = m_peerHandler->addICECandidate(request, iceCandidate->web
Candidate()); |
| 751 if (!implemented) | 751 if (!implemented) |
| 752 asyncCallErrorCallback(errorCallback, DOMException::create(OperationErro
r, "This operation could not be completed.")); | 752 asyncCallErrorCallback(errorCallback, DOMException::create(OperationErro
r, "This operation could not be completed.")); |
| 753 | 753 |
| 754 return ScriptPromise::castUndefined(scriptState); | 754 return ScriptPromise::castUndefined(scriptState); |
| 755 } | 755 } |
| 756 | 756 |
| 757 String RTCPeerConnection::signalingState() const | 757 String RTCPeerConnection::signalingState() const |
| 758 { | 758 { |
| 759 switch (m_signalingState) { | 759 switch (m_signalingState) { |
| 760 case SignalingStateStable: | 760 case SignalingStateStable: |
| 761 return "stable"; | 761 return "stable"; |
| 762 case SignalingStateHaveLocalOffer: | 762 case SignalingStateHaveLocalOffer: |
| 763 return "have-local-offer"; | 763 return "have-local-offer"; |
| 764 case SignalingStateHaveRemoteOffer: | 764 case SignalingStateHaveRemoteOffer: |
| 765 return "have-remote-offer"; | 765 return "have-remote-offer"; |
| 766 case SignalingStateHaveLocalPrAnswer: | 766 case SignalingStateHaveLocalPrAnswer: |
| 767 return "have-local-pranswer"; | 767 return "have-local-pranswer"; |
| 768 case SignalingStateHaveRemotePrAnswer: | 768 case SignalingStateHaveRemotePrAnswer: |
| 769 return "have-remote-pranswer"; | 769 return "have-remote-pranswer"; |
| 770 case SignalingStateClosed: | 770 case SignalingStateClosed: |
| 771 return "closed"; | 771 return "closed"; |
| 772 } | 772 } |
| 773 | 773 |
| 774 ASSERT_NOT_REACHED(); | 774 NOTREACHED(); |
| 775 return String(); | 775 return String(); |
| 776 } | 776 } |
| 777 | 777 |
| 778 String RTCPeerConnection::iceGatheringState() const | 778 String RTCPeerConnection::iceGatheringState() const |
| 779 { | 779 { |
| 780 switch (m_iceGatheringState) { | 780 switch (m_iceGatheringState) { |
| 781 case ICEGatheringStateNew: | 781 case ICEGatheringStateNew: |
| 782 return "new"; | 782 return "new"; |
| 783 case ICEGatheringStateGathering: | 783 case ICEGatheringStateGathering: |
| 784 return "gathering"; | 784 return "gathering"; |
| 785 case ICEGatheringStateComplete: | 785 case ICEGatheringStateComplete: |
| 786 return "complete"; | 786 return "complete"; |
| 787 } | 787 } |
| 788 | 788 |
| 789 ASSERT_NOT_REACHED(); | 789 NOTREACHED(); |
| 790 return String(); | 790 return String(); |
| 791 } | 791 } |
| 792 | 792 |
| 793 String RTCPeerConnection::iceConnectionState() const | 793 String RTCPeerConnection::iceConnectionState() const |
| 794 { | 794 { |
| 795 switch (m_iceConnectionState) { | 795 switch (m_iceConnectionState) { |
| 796 case ICEConnectionStateNew: | 796 case ICEConnectionStateNew: |
| 797 return "new"; | 797 return "new"; |
| 798 case ICEConnectionStateChecking: | 798 case ICEConnectionStateChecking: |
| 799 return "checking"; | 799 return "checking"; |
| 800 case ICEConnectionStateConnected: | 800 case ICEConnectionStateConnected: |
| 801 return "connected"; | 801 return "connected"; |
| 802 case ICEConnectionStateCompleted: | 802 case ICEConnectionStateCompleted: |
| 803 return "completed"; | 803 return "completed"; |
| 804 case ICEConnectionStateFailed: | 804 case ICEConnectionStateFailed: |
| 805 return "failed"; | 805 return "failed"; |
| 806 case ICEConnectionStateDisconnected: | 806 case ICEConnectionStateDisconnected: |
| 807 return "disconnected"; | 807 return "disconnected"; |
| 808 case ICEConnectionStateClosed: | 808 case ICEConnectionStateClosed: |
| 809 return "closed"; | 809 return "closed"; |
| 810 } | 810 } |
| 811 | 811 |
| 812 ASSERT_NOT_REACHED(); | 812 NOTREACHED(); |
| 813 return String(); | 813 return String(); |
| 814 } | 814 } |
| 815 | 815 |
| 816 void RTCPeerConnection::addStream(ExecutionContext* context, MediaStream* stream
, const Dictionary& mediaConstraints, ExceptionState& exceptionState) | 816 void RTCPeerConnection::addStream(ExecutionContext* context, MediaStream* stream
, const Dictionary& mediaConstraints, ExceptionState& exceptionState) |
| 817 { | 817 { |
| 818 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 818 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 819 return; | 819 return; |
| 820 | 820 |
| 821 if (!stream) { | 821 if (!stream) { |
| 822 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "MediaStream")); | 822 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "MediaStream")); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 return true; | 931 return true; |
| 932 } | 932 } |
| 933 return false; | 933 return false; |
| 934 } | 934 } |
| 935 | 935 |
| 936 RTCDTMFSender* RTCPeerConnection::createDTMFSender(MediaStreamTrack* track, Exce
ptionState& exceptionState) | 936 RTCDTMFSender* RTCPeerConnection::createDTMFSender(MediaStreamTrack* track, Exce
ptionState& exceptionState) |
| 937 { | 937 { |
| 938 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 938 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 939 return nullptr; | 939 return nullptr; |
| 940 | 940 |
| 941 ASSERT(track); | 941 DCHECK(track); |
| 942 | 942 |
| 943 if (!hasLocalStreamWithTrackId(track->id())) { | 943 if (!hasLocalStreamWithTrackId(track->id())) { |
| 944 exceptionState.throwDOMException(SyntaxError, "No local stream is availa
ble for the track provided."); | 944 exceptionState.throwDOMException(SyntaxError, "No local stream is availa
ble for the track provided."); |
| 945 return nullptr; | 945 return nullptr; |
| 946 } | 946 } |
| 947 | 947 |
| 948 RTCDTMFSender* dtmfSender = RTCDTMFSender::create(getExecutionContext(), m_p
eerHandler.get(), track, exceptionState); | 948 RTCDTMFSender* dtmfSender = RTCDTMFSender::create(getExecutionContext(), m_p
eerHandler.get(), track, exceptionState); |
| 949 if (exceptionState.hadException()) | 949 if (exceptionState.hadException()) |
| 950 return nullptr; | 950 return nullptr; |
| 951 return dtmfSender; | 951 return dtmfSender; |
| 952 } | 952 } |
| 953 | 953 |
| 954 void RTCPeerConnection::close(ExceptionState& exceptionState) | 954 void RTCPeerConnection::close(ExceptionState& exceptionState) |
| 955 { | 955 { |
| 956 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 956 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 957 return; | 957 return; |
| 958 | 958 |
| 959 closeInternal(); | 959 closeInternal(); |
| 960 } | 960 } |
| 961 | 961 |
| 962 void RTCPeerConnection::negotiationNeeded() | 962 void RTCPeerConnection::negotiationNeeded() |
| 963 { | 963 { |
| 964 ASSERT(!m_closed); | 964 DCHECK(!m_closed); |
| 965 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded)); | 965 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded)); |
| 966 } | 966 } |
| 967 | 967 |
| 968 void RTCPeerConnection::didGenerateICECandidate(const WebRTCICECandidate& webCan
didate) | 968 void RTCPeerConnection::didGenerateICECandidate(const WebRTCICECandidate& webCan
didate) |
| 969 { | 969 { |
| 970 ASSERT(!m_closed); | 970 DCHECK(!m_closed); |
| 971 ASSERT(getExecutionContext()->isContextThread()); | 971 DCHECK(getExecutionContext()->isContextThread()); |
| 972 if (webCandidate.isNull()) | 972 if (webCandidate.isNull()) |
| 973 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, nullptr
)); | 973 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, nullptr
)); |
| 974 else { | 974 else { |
| 975 RTCIceCandidate* iceCandidate = RTCIceCandidate::create(webCandidate); | 975 RTCIceCandidate* iceCandidate = RTCIceCandidate::create(webCandidate); |
| 976 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCand
idate)); | 976 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCand
idate)); |
| 977 } | 977 } |
| 978 } | 978 } |
| 979 | 979 |
| 980 void RTCPeerConnection::didChangeSignalingState(SignalingState newState) | 980 void RTCPeerConnection::didChangeSignalingState(SignalingState newState) |
| 981 { | 981 { |
| 982 ASSERT(!m_closed); | 982 DCHECK(!m_closed); |
| 983 ASSERT(getExecutionContext()->isContextThread()); | 983 DCHECK(getExecutionContext()->isContextThread()); |
| 984 changeSignalingState(newState); | 984 changeSignalingState(newState); |
| 985 } | 985 } |
| 986 | 986 |
| 987 void RTCPeerConnection::didChangeICEGatheringState(ICEGatheringState newState) | 987 void RTCPeerConnection::didChangeICEGatheringState(ICEGatheringState newState) |
| 988 { | 988 { |
| 989 ASSERT(!m_closed); | 989 DCHECK(!m_closed); |
| 990 ASSERT(getExecutionContext()->isContextThread()); | 990 DCHECK(getExecutionContext()->isContextThread()); |
| 991 changeIceGatheringState(newState); | 991 changeIceGatheringState(newState); |
| 992 } | 992 } |
| 993 | 993 |
| 994 void RTCPeerConnection::didChangeICEConnectionState(ICEConnectionState newState) | 994 void RTCPeerConnection::didChangeICEConnectionState(ICEConnectionState newState) |
| 995 { | 995 { |
| 996 ASSERT(!m_closed); | 996 DCHECK(!m_closed); |
| 997 ASSERT(getExecutionContext()->isContextThread()); | 997 DCHECK(getExecutionContext()->isContextThread()); |
| 998 changeIceConnectionState(newState); | 998 changeIceConnectionState(newState); |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 void RTCPeerConnection::didAddRemoteStream(const WebMediaStream& remoteStream) | 1001 void RTCPeerConnection::didAddRemoteStream(const WebMediaStream& remoteStream) |
| 1002 { | 1002 { |
| 1003 ASSERT(!m_closed); | 1003 DCHECK(!m_closed); |
| 1004 ASSERT(getExecutionContext()->isContextThread()); | 1004 DCHECK(getExecutionContext()->isContextThread()); |
| 1005 | 1005 |
| 1006 if (m_signalingState == SignalingStateClosed) | 1006 if (m_signalingState == SignalingStateClosed) |
| 1007 return; | 1007 return; |
| 1008 | 1008 |
| 1009 MediaStream* stream = MediaStream::create(getExecutionContext(), remoteStrea
m); | 1009 MediaStream* stream = MediaStream::create(getExecutionContext(), remoteStrea
m); |
| 1010 m_remoteStreams.append(stream); | 1010 m_remoteStreams.append(stream); |
| 1011 | 1011 |
| 1012 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::addstream, fa
lse, false, stream)); | 1012 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::addstream, fa
lse, false, stream)); |
| 1013 } | 1013 } |
| 1014 | 1014 |
| 1015 void RTCPeerConnection::didRemoveRemoteStream(const WebMediaStream& remoteStream
) | 1015 void RTCPeerConnection::didRemoveRemoteStream(const WebMediaStream& remoteStream
) |
| 1016 { | 1016 { |
| 1017 ASSERT(!m_closed); | 1017 DCHECK(!m_closed); |
| 1018 ASSERT(getExecutionContext()->isContextThread()); | 1018 DCHECK(getExecutionContext()->isContextThread()); |
| 1019 | 1019 |
| 1020 MediaStreamDescriptor* streamDescriptor = remoteStream; | 1020 MediaStreamDescriptor* streamDescriptor = remoteStream; |
| 1021 ASSERT(streamDescriptor->client()); | 1021 DCHECK(streamDescriptor->client()); |
| 1022 | 1022 |
| 1023 MediaStream* stream = static_cast<MediaStream*>(streamDescriptor->client()); | 1023 MediaStream* stream = static_cast<MediaStream*>(streamDescriptor->client()); |
| 1024 stream->streamEnded(); | 1024 stream->streamEnded(); |
| 1025 | 1025 |
| 1026 if (m_signalingState == SignalingStateClosed) | 1026 if (m_signalingState == SignalingStateClosed) |
| 1027 return; | 1027 return; |
| 1028 | 1028 |
| 1029 size_t pos = m_remoteStreams.find(stream); | 1029 size_t pos = m_remoteStreams.find(stream); |
| 1030 ASSERT(pos != kNotFound); | 1030 DCHECK(pos != kNotFound); |
| 1031 m_remoteStreams.remove(pos); | 1031 m_remoteStreams.remove(pos); |
| 1032 | 1032 |
| 1033 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::removestream,
false, false, stream)); | 1033 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::removestream,
false, false, stream)); |
| 1034 } | 1034 } |
| 1035 | 1035 |
| 1036 void RTCPeerConnection::didAddRemoteDataChannel(WebRTCDataChannelHandler* handle
r) | 1036 void RTCPeerConnection::didAddRemoteDataChannel(WebRTCDataChannelHandler* handle
r) |
| 1037 { | 1037 { |
| 1038 ASSERT(!m_closed); | 1038 DCHECK(!m_closed); |
| 1039 ASSERT(getExecutionContext()->isContextThread()); | 1039 DCHECK(getExecutionContext()->isContextThread()); |
| 1040 | 1040 |
| 1041 if (m_signalingState == SignalingStateClosed) | 1041 if (m_signalingState == SignalingStateClosed) |
| 1042 return; | 1042 return; |
| 1043 | 1043 |
| 1044 RTCDataChannel* channel = RTCDataChannel::create(getExecutionContext(), adop
tPtr(handler)); | 1044 RTCDataChannel* channel = RTCDataChannel::create(getExecutionContext(), adop
tPtr(handler)); |
| 1045 scheduleDispatchEvent(RTCDataChannelEvent::create(EventTypeNames::datachanne
l, false, false, channel)); | 1045 scheduleDispatchEvent(RTCDataChannelEvent::create(EventTypeNames::datachanne
l, false, false, channel)); |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 void RTCPeerConnection::releasePeerConnectionHandler() | 1048 void RTCPeerConnection::releasePeerConnectionHandler() |
| 1049 { | 1049 { |
| 1050 stop(); | 1050 stop(); |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 void RTCPeerConnection::closePeerConnection() | 1053 void RTCPeerConnection::closePeerConnection() |
| 1054 { | 1054 { |
| 1055 ASSERT(m_signalingState != RTCPeerConnection::SignalingStateClosed); | 1055 DCHECK(m_signalingState != RTCPeerConnection::SignalingStateClosed); |
| 1056 closeInternal(); | 1056 closeInternal(); |
| 1057 } | 1057 } |
| 1058 | 1058 |
| 1059 const AtomicString& RTCPeerConnection::interfaceName() const | 1059 const AtomicString& RTCPeerConnection::interfaceName() const |
| 1060 { | 1060 { |
| 1061 return EventTargetNames::RTCPeerConnection; | 1061 return EventTargetNames::RTCPeerConnection; |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 ExecutionContext* RTCPeerConnection::getExecutionContext() const | 1064 ExecutionContext* RTCPeerConnection::getExecutionContext() const |
| 1065 { | 1065 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 void RTCPeerConnection::changeIceConnectionState(ICEConnectionState iceConnectio
nState) | 1115 void RTCPeerConnection::changeIceConnectionState(ICEConnectionState iceConnectio
nState) |
| 1116 { | 1116 { |
| 1117 if (m_iceConnectionState != ICEConnectionStateClosed) { | 1117 if (m_iceConnectionState != ICEConnectionStateClosed) { |
| 1118 scheduleDispatchEvent(Event::create(EventTypeNames::iceconnectionstatech
ange), | 1118 scheduleDispatchEvent(Event::create(EventTypeNames::iceconnectionstatech
ange), |
| 1119 WTF::bind(&RTCPeerConnection::setIceConnectionState, this, iceConnec
tionState)); | 1119 WTF::bind(&RTCPeerConnection::setIceConnectionState, this, iceConnec
tionState)); |
| 1120 } | 1120 } |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 void RTCPeerConnection::closeInternal() | 1123 void RTCPeerConnection::closeInternal() |
| 1124 { | 1124 { |
| 1125 ASSERT(m_signalingState != RTCPeerConnection::SignalingStateClosed); | 1125 DCHECK(m_signalingState != RTCPeerConnection::SignalingStateClosed); |
| 1126 m_peerHandler->stop(); | 1126 m_peerHandler->stop(); |
| 1127 m_closed = true; | 1127 m_closed = true; |
| 1128 | 1128 |
| 1129 changeIceConnectionState(ICEConnectionStateClosed); | 1129 changeIceConnectionState(ICEConnectionStateClosed); |
| 1130 changeIceGatheringState(ICEGatheringStateComplete); | 1130 changeIceGatheringState(ICEGatheringStateComplete); |
| 1131 changeSignalingState(SignalingStateClosed); | 1131 changeSignalingState(SignalingStateClosed); |
| 1132 } | 1132 } |
| 1133 | 1133 |
| 1134 void RTCPeerConnection::scheduleDispatchEvent(RawPtr<Event> event) | 1134 void RTCPeerConnection::scheduleDispatchEvent(RawPtr<Event> event) |
| 1135 { | 1135 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1166 { | 1166 { |
| 1167 visitor->trace(m_localStreams); | 1167 visitor->trace(m_localStreams); |
| 1168 visitor->trace(m_remoteStreams); | 1168 visitor->trace(m_remoteStreams); |
| 1169 visitor->trace(m_dispatchScheduledEventRunner); | 1169 visitor->trace(m_dispatchScheduledEventRunner); |
| 1170 visitor->trace(m_scheduledEvents); | 1170 visitor->trace(m_scheduledEvents); |
| 1171 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac
e(visitor); | 1171 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac
e(visitor); |
| 1172 ActiveDOMObject::trace(visitor); | 1172 ActiveDOMObject::trace(visitor); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 } // namespace blink | 1175 } // namespace blink |
| OLD | NEW |