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 17 matching lines...) Expand all Loading... | |
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 "modules/mediastream/RTCPeerConnection.h" | 31 #include "modules/mediastream/RTCPeerConnection.h" |
32 | 32 |
33 #include "bindings/core/v8/ArrayValue.h" | 33 #include "bindings/core/v8/ArrayValue.h" |
34 #include "bindings/core/v8/ExceptionMessages.h" | 34 #include "bindings/core/v8/ExceptionMessages.h" |
35 #include "bindings/core/v8/ExceptionState.h" | 35 #include "bindings/core/v8/ExceptionState.h" |
36 #include "bindings/core/v8/Nullable.h" | 36 #include "bindings/core/v8/Nullable.h" |
37 #include "bindings/core/v8/ScriptPromiseResolver.h" | 37 #include "bindings/core/v8/ScriptPromiseResolver.h" |
38 #include "bindings/core/v8/ScriptState.h" | |
39 #include "bindings/core/v8/ScriptValue.h" | |
40 #include "bindings/core/v8/V8ThrowException.h" | |
41 #include "bindings/modules/v8/UnionTypesModules.h" | |
38 #include "bindings/modules/v8/V8RTCCertificate.h" | 42 #include "bindings/modules/v8/V8RTCCertificate.h" |
39 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
40 #include "core/dom/ExceptionCode.h" | 44 #include "core/dom/ExceptionCode.h" |
41 #include "core/dom/ExecutionContext.h" | 45 #include "core/dom/ExecutionContext.h" |
46 #include "core/dom/Microtask.h" | |
42 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
43 #include "core/frame/UseCounter.h" | 48 #include "core/frame/UseCounter.h" |
44 #include "core/html/VoidCallback.h" | 49 #include "core/html/VoidCallback.h" |
45 #include "core/loader/FrameLoader.h" | 50 #include "core/loader/FrameLoader.h" |
46 #include "core/loader/FrameLoaderClient.h" | 51 #include "core/loader/FrameLoaderClient.h" |
47 #include "modules/crypto/CryptoResultImpl.h" | 52 #include "modules/crypto/CryptoResultImpl.h" |
48 #include "modules/mediastream/MediaConstraintsImpl.h" | 53 #include "modules/mediastream/MediaConstraintsImpl.h" |
49 #include "modules/mediastream/MediaStreamEvent.h" | 54 #include "modules/mediastream/MediaStreamEvent.h" |
50 #include "modules/mediastream/RTCDTMFSender.h" | 55 #include "modules/mediastream/RTCDTMFSender.h" |
51 #include "modules/mediastream/RTCDataChannel.h" | 56 #include "modules/mediastream/RTCDataChannel.h" |
52 #include "modules/mediastream/RTCDataChannelEvent.h" | 57 #include "modules/mediastream/RTCDataChannelEvent.h" |
53 #include "modules/mediastream/RTCErrorCallback.h" | 58 #include "modules/mediastream/RTCErrorCallback.h" |
54 #include "modules/mediastream/RTCIceCandidateEvent.h" | 59 #include "modules/mediastream/RTCIceCandidateEvent.h" |
55 #include "modules/mediastream/RTCSessionDescription.h" | 60 #include "modules/mediastream/RTCSessionDescription.h" |
56 #include "modules/mediastream/RTCSessionDescriptionCallback.h" | 61 #include "modules/mediastream/RTCSessionDescriptionCallback.h" |
62 #include "modules/mediastream/RTCSessionDescriptionInit.h" | |
57 #include "modules/mediastream/RTCSessionDescriptionRequestImpl.h" | 63 #include "modules/mediastream/RTCSessionDescriptionRequestImpl.h" |
58 #include "modules/mediastream/RTCStatsCallback.h" | 64 #include "modules/mediastream/RTCStatsCallback.h" |
59 #include "modules/mediastream/RTCStatsRequestImpl.h" | 65 #include "modules/mediastream/RTCStatsRequestImpl.h" |
60 #include "modules/mediastream/RTCVoidRequestImpl.h" | 66 #include "modules/mediastream/RTCVoidRequestImpl.h" |
67 #include "modules/mediastream/RTCVoidRequestPromiseImpl.h" | |
61 #include "platform/mediastream/RTCConfiguration.h" | 68 #include "platform/mediastream/RTCConfiguration.h" |
62 #include "platform/mediastream/RTCOfferOptions.h" | 69 #include "platform/mediastream/RTCOfferOptions.h" |
63 #include "public/platform/Platform.h" | 70 #include "public/platform/Platform.h" |
64 #include "public/platform/WebCryptoAlgorithmParams.h" | 71 #include "public/platform/WebCryptoAlgorithmParams.h" |
65 #include "public/platform/WebCryptoUtil.h" | 72 #include "public/platform/WebCryptoUtil.h" |
66 #include "public/platform/WebMediaStream.h" | 73 #include "public/platform/WebMediaStream.h" |
67 #include "public/platform/WebRTCCertificate.h" | 74 #include "public/platform/WebRTCCertificate.h" |
68 #include "public/platform/WebRTCCertificateGenerator.h" | 75 #include "public/platform/WebRTCCertificateGenerator.h" |
69 #include "public/platform/WebRTCConfiguration.h" | 76 #include "public/platform/WebRTCConfiguration.h" |
70 #include "public/platform/WebRTCDataChannelHandler.h" | 77 #include "public/platform/WebRTCDataChannelHandler.h" |
71 #include "public/platform/WebRTCDataChannelInit.h" | 78 #include "public/platform/WebRTCDataChannelInit.h" |
72 #include "public/platform/WebRTCICECandidate.h" | 79 #include "public/platform/WebRTCICECandidate.h" |
73 #include "public/platform/WebRTCKeyParams.h" | 80 #include "public/platform/WebRTCKeyParams.h" |
74 #include "public/platform/WebRTCOfferOptions.h" | 81 #include "public/platform/WebRTCOfferOptions.h" |
75 #include "public/platform/WebRTCSessionDescription.h" | 82 #include "public/platform/WebRTCSessionDescription.h" |
76 #include "public/platform/WebRTCSessionDescriptionRequest.h" | 83 #include "public/platform/WebRTCSessionDescriptionRequest.h" |
77 #include "public/platform/WebRTCStatsRequest.h" | 84 #include "public/platform/WebRTCStatsRequest.h" |
78 #include "public/platform/WebRTCVoidRequest.h" | 85 #include "public/platform/WebRTCVoidRequest.h" |
79 | 86 |
80 namespace blink { | 87 namespace blink { |
81 | 88 |
82 namespace { | 89 namespace { |
83 | 90 |
84 static bool throwExceptionIfSignalingStateClosed(RTCPeerConnection::SignalingSta te state, ExceptionState& exceptionState) | 91 const char kSignalingStateClosedMsg[] = "The RTCPeerConnection's signalingState is 'closed'."; |
haraken
2016/02/13 15:07:18
Msg => Message (Blink prefers a fully qualified na
Guido Urdaneta
2016/02/15 16:56:51
Done.
| |
92 | |
93 // TODO(guidou): Update exception codes once the error-handling aspects of the s pec are finalized. crbug.com/585621 | |
philipj_slow
2016/02/15 10:00:44
AFAICT the spec now uses only existing DOMExceptio
Guido Urdaneta
2016/02/15 16:56:51
Done.
| |
94 const ExceptionCode kDefaultErrorName = AbortError; | |
95 const ExceptionCode kSessionDescriptionErrorName = AbortError; | |
96 | |
97 bool throwExceptionIfSignalingStateClosed(RTCPeerConnection::SignalingState stat e, ExceptionState& exceptionState) | |
85 { | 98 { |
86 if (state == RTCPeerConnection::SignalingStateClosed) { | 99 if (state == RTCPeerConnection::SignalingStateClosed) { |
87 exceptionState.throwDOMException(InvalidStateError, "The RTCPeerConnecti on's signalingState is 'closed'."); | 100 exceptionState.throwDOMException(InvalidStateError, kSignalingStateClose dMsg); |
88 return true; | 101 return true; |
89 } | 102 } |
90 | 103 |
91 return false; | 104 return false; |
92 } | 105 } |
93 | 106 |
107 // Helper class for running error callbacks asynchronously | |
108 class ErrorCallbackTask : public WebTaskRunner::Task { | |
109 public: | |
110 static PassOwnPtr<ErrorCallbackTask> create(RTCErrorCallback* errorCallback, const String& errorMsg) | |
haraken
2016/02/13 15:07:18
Msg => Message
The same comment for other parts i
Guido Urdaneta
2016/02/15 16:56:51
Done.
| |
111 { | |
112 return adoptPtr(new ErrorCallbackTask(errorCallback, errorMsg)); | |
113 } | |
114 | |
115 ~ErrorCallbackTask() override = default; | |
116 | |
117 void run() override | |
118 { | |
119 m_errorCallback->handleEvent(m_errorMsg); | |
120 } | |
121 | |
122 private: | |
123 ErrorCallbackTask(RTCErrorCallback* errorCallback, const String& errorMsg) | |
124 : m_errorCallback(errorCallback) | |
125 , m_errorMsg(errorMsg) {} | |
haraken
2016/02/13 15:07:18
Shall we add ASSERT(m_errorCallback)?
Guido Urdaneta
2016/02/15 16:56:51
Done.
| |
126 | |
127 Persistent<RTCErrorCallback> m_errorCallback; | |
128 String m_errorMsg; | |
129 }; | |
130 | |
131 void asyncCallErrorCallback(RTCErrorCallback* errorCallback, const String& error Msg) | |
132 { | |
133 Microtask::enqueueMicrotask(ErrorCallbackTask::create(errorCallback, errorMs g)); | |
134 } | |
135 | |
136 bool callErrorCallbackIfSignalingStateClosed(RTCPeerConnection::SignalingState s tate, RTCErrorCallback* errorCallback) | |
137 { | |
138 if (state == RTCPeerConnection::SignalingStateClosed) { | |
139 if (errorCallback) | |
140 asyncCallErrorCallback(errorCallback, kSignalingStateClosedMsg); | |
141 | |
142 return true; | |
143 } | |
144 | |
145 return false; | |
146 } | |
147 | |
148 bool isIceCandidateMissingSdp(const RTCIceCandidateInitOrRTCIceCandidate& candid ate) | |
149 { | |
150 if (candidate.isRTCIceCandidateInit()) { | |
151 const RTCIceCandidateInit& iceCandidateInit = candidate.getAsRTCIceCandi dateInit(); | |
152 return !iceCandidateInit.hasSdpMid() && !iceCandidateInit.hasSdpMLineInd ex(); | |
153 } | |
154 | |
155 ASSERT(candidate.isRTCIceCandidate()); | |
156 return false; | |
157 } | |
158 | |
159 WebRTCICECandidate convertToWebRTCIceCandidate(const RTCIceCandidateInitOrRTCIce Candidate& candidate) | |
160 { | |
161 if (candidate.isRTCIceCandidateInit()) { | |
162 const RTCIceCandidateInit& iceCandidateInit = candidate.getAsRTCIceCandi dateInit(); | |
163 return WebRTCICECandidate(iceCandidateInit.candidate(), iceCandidateInit .sdpMid(), iceCandidateInit.sdpMLineIndex()); | |
164 } | |
165 | |
166 ASSERT(candidate.isRTCIceCandidate()); | |
167 return candidate.getAsRTCIceCandidate()->webCandidate(); | |
168 } | |
169 | |
94 // Helper class for RTCPeerConnection::generateCertificate. | 170 // Helper class for RTCPeerConnection::generateCertificate. |
95 class WebRTCCertificateObserver : public WebCallbacks<WebRTCCertificate*, void> { | 171 class WebRTCCertificateObserver : public WebCallbacks<WebRTCCertificate*, void> { |
96 public: | 172 public: |
97 // The created observer is responsible for deleting itself after onSuccess/o nError. To avoid memory | 173 // The created observer is responsible for deleting itself after onSuccess/o nError. To avoid memory |
98 // leak the observer should therefore be used in a WebRTCCertificateGenerato r::generateCertificate call | 174 // leak the observer should therefore be used in a WebRTCCertificateGenerato r::generateCertificate call |
99 // which is ensured to invoke one of these. Takes ownership of |resolver|. | 175 // which is ensured to invoke one of these. Takes ownership of |resolver|. |
100 static WebRTCCertificateObserver* create(ScriptPromiseResolver* resolver) | 176 static WebRTCCertificateObserver* create(ScriptPromiseResolver* resolver) |
101 { | 177 { |
102 return new WebRTCCertificateObserver(resolver); | 178 return new WebRTCCertificateObserver(resolver); |
103 } | 179 } |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 WebMediaConstraints constraints = MediaConstraintsImpl::create(context, medi aConstraints, mediaErrorState); | 529 WebMediaConstraints constraints = MediaConstraintsImpl::create(context, medi aConstraints, mediaErrorState); |
454 if (mediaErrorState.hadException()) { | 530 if (mediaErrorState.hadException()) { |
455 mediaErrorState.raiseException(exceptionState); | 531 mediaErrorState.raiseException(exceptionState); |
456 return; | 532 return; |
457 } | 533 } |
458 | 534 |
459 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr eate(executionContext(), this, successCallback, errorCallback); | 535 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr eate(executionContext(), this, successCallback, errorCallback); |
460 m_peerHandler->createAnswer(request, constraints); | 536 m_peerHandler->createAnswer(request, constraints); |
461 } | 537 } |
462 | 538 |
463 void RTCPeerConnection::setLocalDescription(ExecutionContext* context, RTCSessio nDescription* sessionDescription, VoidCallback* successCallback, RTCErrorCallbac k* errorCallback, ExceptionState& exceptionState) | 539 ScriptPromise RTCPeerConnection::setLocalDescription(ScriptState* scriptState, c onst RTCSessionDescriptionInit& sessionDescriptionInit) |
464 { | 540 { |
541 if (m_signalingState == SignalingStateClosed) | |
542 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, kSignalingStateClosedMsg)); | |
543 | |
544 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
545 ScriptPromise promise = resolver->promise(); | |
546 RTCVoidRequest* request = RTCVoidRequestPromiseImpl::create(this, resolver, kSessionDescriptionErrorName); | |
547 m_peerHandler->setLocalDescription(request, WebRTCSessionDescription(session DescriptionInit.type(), sessionDescriptionInit.sdp())); | |
548 return promise; | |
549 } | |
550 | |
551 ScriptPromise RTCPeerConnection::setLocalDescription(ScriptState* scriptState, R TCSessionDescription* sessionDescription, VoidCallback* successCallback, RTCErro rCallback* errorCallback) | |
haraken
2016/02/13 15:07:18
This method always returns an undefined ScriptProm
philipj_slow
2016/02/15 10:00:44
That is expected. The methods that take success/er
Guido Urdaneta
2016/02/15 16:56:51
To further clarify, the reason all methods with th
| |
552 { | |
553 ExecutionContext* context = scriptState->executionContext(); | |
465 if (successCallback && errorCallback) { | 554 if (successCallback && errorCallback) { |
466 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDescript ionLegacyCompliant); | 555 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDescript ionLegacyCompliant); |
467 } else { | 556 } else { |
468 if (!successCallback) | 557 if (!successCallback) |
469 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc riptionLegacyNoSuccessCallback); | 558 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc riptionLegacyNoSuccessCallback); |
470 if (!errorCallback) | 559 if (!errorCallback) |
471 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc riptionLegacyNoFailureCallback); | 560 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc riptionLegacyNoFailureCallback); |
472 } | 561 } |
473 | 562 |
474 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 563 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) ) |
475 return; | 564 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola te())); |
haraken
2016/02/13 15:07:18
Can we just use ScriptPromise()?
Guido Urdaneta
2016/02/15 16:56:51
Done. That is what the CL had originally.
| |
476 | 565 |
477 ASSERT(sessionDescription); | 566 ASSERT(sessionDescription); |
478 | 567 |
479 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); | 568 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); |
480 m_peerHandler->setLocalDescription(request, sessionDescription->webSessionDe scription()); | 569 m_peerHandler->setLocalDescription(request, sessionDescription->webSessionDe scription()); |
570 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate() )); | |
481 } | 571 } |
482 | 572 |
483 RTCSessionDescription* RTCPeerConnection::localDescription() | 573 RTCSessionDescription* RTCPeerConnection::localDescription() |
484 { | 574 { |
485 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip tion(); | 575 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip tion(); |
486 if (webSessionDescription.isNull()) | 576 if (webSessionDescription.isNull()) |
487 return nullptr; | 577 return nullptr; |
488 | 578 |
489 return RTCSessionDescription::create(webSessionDescription); | 579 return RTCSessionDescription::create(webSessionDescription); |
490 } | 580 } |
491 | 581 |
492 void RTCPeerConnection::setRemoteDescription(ExecutionContext* context, RTCSessi onDescription* sessionDescription, VoidCallback* successCallback, RTCErrorCallba ck* errorCallback, ExceptionState& exceptionState) | 582 ScriptPromise RTCPeerConnection::setRemoteDescription(ScriptState* scriptState, const RTCSessionDescriptionInit& sessionDescriptionInit) |
493 { | 583 { |
584 if (m_signalingState == SignalingStateClosed) | |
585 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, kSignalingStateClosedMsg)); | |
586 | |
587 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
588 ScriptPromise promise = resolver->promise(); | |
589 RTCVoidRequest* request = RTCVoidRequestPromiseImpl::create(this, resolver, kSessionDescriptionErrorName); | |
590 m_peerHandler->setRemoteDescription(request, WebRTCSessionDescription(sessio nDescriptionInit.type(), sessionDescriptionInit.sdp())); | |
591 return promise; | |
592 } | |
593 | |
594 ScriptPromise RTCPeerConnection::setRemoteDescription(ScriptState* scriptState, RTCSessionDescription* sessionDescription, VoidCallback* successCallback, RTCErr orCallback* errorCallback) | |
595 { | |
596 ExecutionContext* context = scriptState->executionContext(); | |
494 if (successCallback && errorCallback) { | 597 if (successCallback && errorCallback) { |
495 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDescrip tionLegacyCompliant); | 598 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDescrip tionLegacyCompliant); |
496 } else { | 599 } else { |
497 if (!successCallback) | 600 if (!successCallback) |
498 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes criptionLegacyNoSuccessCallback); | 601 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes criptionLegacyNoSuccessCallback); |
499 if (!errorCallback) | 602 if (!errorCallback) |
500 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes criptionLegacyNoFailureCallback); | 603 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes criptionLegacyNoFailureCallback); |
501 } | 604 } |
502 | 605 |
503 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 606 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) ) |
504 return; | 607 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola te())); |
505 | 608 |
506 ASSERT(sessionDescription); | 609 ASSERT(sessionDescription); |
507 | 610 |
508 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); | 611 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); |
509 m_peerHandler->setRemoteDescription(request, sessionDescription->webSessionD escription()); | 612 m_peerHandler->setRemoteDescription(request, sessionDescription->webSessionD escription()); |
613 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate() )); | |
510 } | 614 } |
511 | 615 |
512 RTCSessionDescription* RTCPeerConnection::remoteDescription() | 616 RTCSessionDescription* RTCPeerConnection::remoteDescription() |
513 { | 617 { |
514 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri ption(); | 618 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri ption(); |
515 if (webSessionDescription.isNull()) | 619 if (webSessionDescription.isNull()) |
516 return nullptr; | 620 return nullptr; |
517 | 621 |
518 return RTCSessionDescription::create(webSessionDescription); | 622 return RTCSessionDescription::create(webSessionDescription); |
519 } | 623 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 // The observer will manage its own destruction as well as the resolver's de struction. | 705 // The observer will manage its own destruction as well as the resolver's de struction. |
602 certificateGenerator->generateCertificate( | 706 certificateGenerator->generateCertificate( |
603 keyParams.get(), | 707 keyParams.get(), |
604 toDocument(scriptState->executionContext())->url(), | 708 toDocument(scriptState->executionContext())->url(), |
605 toDocument(scriptState->executionContext())->firstPartyForCookies(), | 709 toDocument(scriptState->executionContext())->firstPartyForCookies(), |
606 certificateObserver); | 710 certificateObserver); |
607 | 711 |
608 return promise; | 712 return promise; |
609 } | 713 } |
610 | 714 |
611 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) | 715 ScriptPromise RTCPeerConnection::addIceCandidate(ScriptState* scriptState, const RTCIceCandidateInitOrRTCIceCandidate& candidate) |
612 { | 716 { |
613 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 717 if (m_signalingState == SignalingStateClosed) |
614 return; | 718 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, kSignalingStateClosedMsg)); |
615 | 719 |
616 ASSERT(iceCandidate); | 720 if (isIceCandidateMissingSdp(candidate)) |
721 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Candidate missing values for both sdpMid and sdpMLi neIndex")); | |
617 | 722 |
618 bool valid = m_peerHandler->addICECandidate(iceCandidate->webCandidate()); | 723 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
619 if (!valid) | 724 ScriptPromise promise = resolver->promise(); |
620 exceptionState.throwDOMException(SyntaxError, "The ICE candidate could n ot be added."); | 725 RTCVoidRequest* request = RTCVoidRequestPromiseImpl::create(this, resolver, kDefaultErrorName); |
726 WebRTCICECandidate webCandidate = convertToWebRTCIceCandidate(candidate); | |
727 bool implemented = m_peerHandler->addICECandidate(request, webCandidate); | |
728 // TODO(guidou): replace NotSupportedError when error handling in the spec i s finalized. crbug.com/585621 | |
729 if (!implemented) | |
730 resolver->reject(DOMException::create(NotSupportedError, "This method is not yet implemented.")); | |
731 | |
732 return promise; | |
621 } | 733 } |
622 | 734 |
623 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, VoidCallb ack* successCallback, RTCErrorCallback* errorCallback, ExceptionState& exception State) | 735 ScriptPromise RTCPeerConnection::addIceCandidate(ScriptState* scriptState, RTCIc eCandidate* iceCandidate, VoidCallback* successCallback, RTCErrorCallback* error Callback) |
624 { | 736 { |
625 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | |
626 return; | |
627 | |
628 ASSERT(iceCandidate); | 737 ASSERT(iceCandidate); |
629 ASSERT(successCallback); | 738 ASSERT(successCallback); |
630 ASSERT(errorCallback); | 739 ASSERT(errorCallback); |
631 | 740 |
741 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) ) | |
742 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola te())); | |
743 | |
632 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); | 744 RTCVoidRequest* request = RTCVoidRequestImpl::create(executionContext(), thi s, successCallback, errorCallback); |
745 bool implemented = m_peerHandler->addICECandidate(request, iceCandidate->web Candidate()); | |
746 if (!implemented) | |
747 asyncCallErrorCallback(errorCallback, "This method is not yet implemente d."); | |
633 | 748 |
634 bool implemented = m_peerHandler->addICECandidate(request, iceCandidate->web Candidate()); | 749 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate() )); |
635 if (!implemented) { | |
636 exceptionState.throwDOMException(NotSupportedError, "This method is not yet implemented."); | |
637 } | |
638 } | 750 } |
639 | 751 |
640 String RTCPeerConnection::signalingState() const | 752 String RTCPeerConnection::signalingState() const |
641 { | 753 { |
642 switch (m_signalingState) { | 754 switch (m_signalingState) { |
643 case SignalingStateStable: | 755 case SignalingStateStable: |
644 return "stable"; | 756 return "stable"; |
645 case SignalingStateHaveLocalOffer: | 757 case SignalingStateHaveLocalOffer: |
646 return "have-local-offer"; | 758 return "have-local-offer"; |
647 case SignalingStateHaveRemoteOffer: | 759 case SignalingStateHaveRemoteOffer: |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1049 { | 1161 { |
1050 visitor->trace(m_localStreams); | 1162 visitor->trace(m_localStreams); |
1051 visitor->trace(m_remoteStreams); | 1163 visitor->trace(m_remoteStreams); |
1052 visitor->trace(m_dispatchScheduledEventRunner); | 1164 visitor->trace(m_dispatchScheduledEventRunner); |
1053 visitor->trace(m_scheduledEvents); | 1165 visitor->trace(m_scheduledEvents); |
1054 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); | 1166 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); |
1055 ActiveDOMObject::trace(visitor); | 1167 ActiveDOMObject::trace(visitor); |
1056 } | 1168 } |
1057 | 1169 |
1058 } // namespace blink | 1170 } // namespace blink |
OLD | NEW |