Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp

Issue 2007923003: Use Init dictionaries in RTCPeerConnection legacy methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 28 matching lines...) Expand all
39 #include "bindings/core/v8/ScriptState.h" 39 #include "bindings/core/v8/ScriptState.h"
40 #include "bindings/core/v8/ScriptValue.h" 40 #include "bindings/core/v8/ScriptValue.h"
41 #include "bindings/core/v8/V8ThrowException.h" 41 #include "bindings/core/v8/V8ThrowException.h"
42 #include "bindings/modules/v8/RTCIceCandidateInitOrRTCIceCandidate.h" 42 #include "bindings/modules/v8/RTCIceCandidateInitOrRTCIceCandidate.h"
43 #include "bindings/modules/v8/V8RTCCertificate.h" 43 #include "bindings/modules/v8/V8RTCCertificate.h"
44 #include "core/dom/DOMException.h" 44 #include "core/dom/DOMException.h"
45 #include "core/dom/DOMTimeStamp.h" 45 #include "core/dom/DOMTimeStamp.h"
46 #include "core/dom/Document.h" 46 #include "core/dom/Document.h"
47 #include "core/dom/ExceptionCode.h" 47 #include "core/dom/ExceptionCode.h"
48 #include "core/dom/ExecutionContext.h" 48 #include "core/dom/ExecutionContext.h"
49 #include "core/frame/Deprecation.h"
50 #include "core/frame/LocalFrame.h" 49 #include "core/frame/LocalFrame.h"
50 #include "core/frame/UseCounter.h"
51 #include "core/html/VoidCallback.h" 51 #include "core/html/VoidCallback.h"
52 #include "core/loader/FrameLoader.h" 52 #include "core/loader/FrameLoader.h"
53 #include "core/loader/FrameLoaderClient.h" 53 #include "core/loader/FrameLoaderClient.h"
54 #include "modules/crypto/CryptoResultImpl.h" 54 #include "modules/crypto/CryptoResultImpl.h"
55 #include "modules/mediastream/MediaConstraintsImpl.h" 55 #include "modules/mediastream/MediaConstraintsImpl.h"
56 #include "modules/mediastream/MediaStreamEvent.h" 56 #include "modules/mediastream/MediaStreamEvent.h"
57 #include "modules/mediastream/RTCAnswerOptions.h" 57 #include "modules/mediastream/RTCAnswerOptions.h"
58 #include "modules/mediastream/RTCDTMFSender.h" 58 #include "modules/mediastream/RTCDTMFSender.h"
59 #include "modules/mediastream/RTCDataChannel.h" 59 #include "modules/mediastream/RTCDataChannel.h"
60 #include "modules/mediastream/RTCDataChannelEvent.h" 60 #include "modules/mediastream/RTCDataChannelEvent.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 options.hasVoiceActivityDetection() ? options.voiceActivityDetection() : true, 145 options.hasVoiceActivityDetection() ? options.voiceActivityDetection() : true,
146 options.hasIceRestart() ? options.iceRestart() : false)); 146 options.hasIceRestart() ? options.iceRestart() : false));
147 } 147 }
148 148
149 WebRTCAnswerOptions convertToWebRTCAnswerOptions(const RTCAnswerOptions& options ) 149 WebRTCAnswerOptions convertToWebRTCAnswerOptions(const RTCAnswerOptions& options )
150 { 150 {
151 return WebRTCAnswerOptions(RTCAnswerOptionsPlatform::create( 151 return WebRTCAnswerOptions(RTCAnswerOptionsPlatform::create(
152 options.hasVoiceActivityDetection() ? options.voiceActivityDetection() : true)); 152 options.hasVoiceActivityDetection() ? options.voiceActivityDetection() : true));
153 } 153 }
154 154
155 WebRTCICECandidate convertToWebRTCIceCandidate(const RTCIceCandidateInitOrRTCIce Candidate& candidate) 155 WebRTCICECandidate convertToWebRTCIceCandidate(ExecutionContext* context, const RTCIceCandidateInitOrRTCIceCandidate& candidate)
156 { 156 {
157 DCHECK(!candidate.isNull());
157 if (candidate.isRTCIceCandidateInit()) { 158 if (candidate.isRTCIceCandidateInit()) {
158 const RTCIceCandidateInit& iceCandidateInit = candidate.getAsRTCIceCandi dateInit(); 159 const RTCIceCandidateInit& iceCandidateInit = candidate.getAsRTCIceCandi dateInit();
159 return WebRTCICECandidate(iceCandidateInit.candidate(), iceCandidateInit .sdpMid(), iceCandidateInit.sdpMLineIndex()); 160 // TODO(guidou): Change default value to -1. crbug.com/614958.
161 unsigned short sdpMLineIndex = 0;
162 if (iceCandidateInit.hasSdpMLineIndex())
163 sdpMLineIndex = iceCandidateInit.sdpMLineIndex();
164 else
165 UseCounter::count(context, UseCounter::RTCIceCandidateDefaultSdpMLin eIndex);
166 return WebRTCICECandidate(iceCandidateInit.candidate(), iceCandidateInit .sdpMid(), sdpMLineIndex);
160 } 167 }
161 168
162 DCHECK(candidate.isRTCIceCandidate()); 169 DCHECK(candidate.isRTCIceCandidate());
163 return candidate.getAsRTCIceCandidate()->webCandidate(); 170 return candidate.getAsRTCIceCandidate()->webCandidate();
164 } 171 }
165 172
166 // Helper class for RTCPeerConnection::generateCertificate. 173 // Helper class for RTCPeerConnection::generateCertificate.
167 class WebRTCCertificateObserver : public WebRTCCertificateCallback { 174 class WebRTCCertificateObserver : public WebRTCCertificateCallback {
168 public: 175 public:
169 // Takes ownership of |resolver|. 176 // Takes ownership of |resolver|.
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 if (m_signalingState == SignalingStateClosed) 576 if (m_signalingState == SignalingStateClosed)
570 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, kSignalingStateClosedMessage)); 577 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, kSignalingStateClosedMessage));
571 578
572 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 579 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
573 ScriptPromise promise = resolver->promise(); 580 ScriptPromise promise = resolver->promise();
574 RTCVoidRequest* request = RTCVoidRequestPromiseImpl::create(this, resolver); 581 RTCVoidRequest* request = RTCVoidRequestPromiseImpl::create(this, resolver);
575 m_peerHandler->setLocalDescription(request, WebRTCSessionDescription(session DescriptionInit.type(), sessionDescriptionInit.sdp())); 582 m_peerHandler->setLocalDescription(request, WebRTCSessionDescription(session DescriptionInit.type(), sessionDescriptionInit.sdp()));
576 return promise; 583 return promise;
577 } 584 }
578 585
579 ScriptPromise RTCPeerConnection::setLocalDescription(ScriptState* scriptState, R TCSessionDescription* sessionDescription, VoidCallback* successCallback, RTCPeer ConnectionErrorCallback* errorCallback) 586 ScriptPromise RTCPeerConnection::setLocalDescription(ScriptState* scriptState, c onst RTCSessionDescriptionInit& sessionDescriptionInit, VoidCallback* successCal lback, RTCPeerConnectionErrorCallback* errorCallback)
580 { 587 {
581 ExecutionContext* context = scriptState->getExecutionContext(); 588 ExecutionContext* context = scriptState->getExecutionContext();
582 if (successCallback && errorCallback) { 589 if (successCallback && errorCallback) {
583 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDescript ionLegacyCompliant); 590 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDescript ionLegacyCompliant);
584 } else { 591 } else {
585 if (!successCallback) 592 if (!successCallback)
586 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc riptionLegacyNoSuccessCallback); 593 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc riptionLegacyNoSuccessCallback);
587 if (!errorCallback) 594 if (!errorCallback)
588 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc riptionLegacyNoFailureCallback); 595 UseCounter::count(context, UseCounter::RTCPeerConnectionSetLocalDesc riptionLegacyNoFailureCallback);
589 } 596 }
590 597
591 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) ) 598 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) )
592 return ScriptPromise::castUndefined(scriptState); 599 return ScriptPromise::castUndefined(scriptState);
593 600
594 DCHECK(sessionDescription);
595
596 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(), this, successCallback, errorCallback); 601 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(), this, successCallback, errorCallback);
597 m_peerHandler->setLocalDescription(request, sessionDescription->webSessionDe scription()); 602 m_peerHandler->setLocalDescription(request, WebRTCSessionDescription(session DescriptionInit.type(), sessionDescriptionInit.sdp()));
598 return ScriptPromise::castUndefined(scriptState); 603 return ScriptPromise::castUndefined(scriptState);
599 } 604 }
600 605
601 RTCSessionDescription* RTCPeerConnection::localDescription() 606 RTCSessionDescription* RTCPeerConnection::localDescription()
602 { 607 {
603 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip tion(); 608 WebRTCSessionDescription webSessionDescription = m_peerHandler->localDescrip tion();
604 if (webSessionDescription.isNull()) 609 if (webSessionDescription.isNull())
605 return nullptr; 610 return nullptr;
606 611
607 return RTCSessionDescription::create(webSessionDescription); 612 return RTCSessionDescription::create(webSessionDescription);
608 } 613 }
609 614
610 ScriptPromise RTCPeerConnection::setRemoteDescription(ScriptState* scriptState, const RTCSessionDescriptionInit& sessionDescriptionInit) 615 ScriptPromise RTCPeerConnection::setRemoteDescription(ScriptState* scriptState, const RTCSessionDescriptionInit& sessionDescriptionInit)
611 { 616 {
612 if (m_signalingState == SignalingStateClosed) 617 if (m_signalingState == SignalingStateClosed)
613 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, kSignalingStateClosedMessage)); 618 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, kSignalingStateClosedMessage));
614 619
615 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 620 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
616 ScriptPromise promise = resolver->promise(); 621 ScriptPromise promise = resolver->promise();
617 RTCVoidRequest* request = RTCVoidRequestPromiseImpl::create(this, resolver); 622 RTCVoidRequest* request = RTCVoidRequestPromiseImpl::create(this, resolver);
618 m_peerHandler->setRemoteDescription(request, WebRTCSessionDescription(sessio nDescriptionInit.type(), sessionDescriptionInit.sdp())); 623 m_peerHandler->setRemoteDescription(request, WebRTCSessionDescription(sessio nDescriptionInit.type(), sessionDescriptionInit.sdp()));
619 return promise; 624 return promise;
620 } 625 }
621 626
622 ScriptPromise RTCPeerConnection::setRemoteDescription(ScriptState* scriptState, RTCSessionDescription* sessionDescription, VoidCallback* successCallback, RTCPee rConnectionErrorCallback* errorCallback) 627 ScriptPromise RTCPeerConnection::setRemoteDescription(ScriptState* scriptState, const RTCSessionDescriptionInit& sessionDescriptionInit, VoidCallback* successCa llback, RTCPeerConnectionErrorCallback* errorCallback)
623 { 628 {
624 ExecutionContext* context = scriptState->getExecutionContext(); 629 ExecutionContext* context = scriptState->getExecutionContext();
625 if (successCallback && errorCallback) { 630 if (successCallback && errorCallback) {
626 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDescrip tionLegacyCompliant); 631 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDescrip tionLegacyCompliant);
627 } else { 632 } else {
628 if (!successCallback) 633 if (!successCallback)
629 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes criptionLegacyNoSuccessCallback); 634 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes criptionLegacyNoSuccessCallback);
630 if (!errorCallback) 635 if (!errorCallback)
631 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes criptionLegacyNoFailureCallback); 636 UseCounter::count(context, UseCounter::RTCPeerConnectionSetRemoteDes criptionLegacyNoFailureCallback);
632 } 637 }
633 638
634 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) ) 639 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) )
635 return ScriptPromise::castUndefined(scriptState); 640 return ScriptPromise::castUndefined(scriptState);
636 641
637 DCHECK(sessionDescription);
638
639 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(), this, successCallback, errorCallback); 642 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(), this, successCallback, errorCallback);
640 m_peerHandler->setRemoteDescription(request, sessionDescription->webSessionD escription()); 643 m_peerHandler->setRemoteDescription(request, WebRTCSessionDescription(sessio nDescriptionInit.type(), sessionDescriptionInit.sdp()));
641 return ScriptPromise::castUndefined(scriptState); 644 return ScriptPromise::castUndefined(scriptState);
642 } 645 }
643 646
644 RTCSessionDescription* RTCPeerConnection::remoteDescription() 647 RTCSessionDescription* RTCPeerConnection::remoteDescription()
645 { 648 {
646 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri ption(); 649 WebRTCSessionDescription webSessionDescription = m_peerHandler->remoteDescri ption();
647 if (webSessionDescription.isNull()) 650 if (webSessionDescription.isNull())
648 return nullptr; 651 return nullptr;
649 652
650 return RTCSessionDescription::create(webSessionDescription); 653 return RTCSessionDescription::create(webSessionDescription);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 { 772 {
770 if (m_signalingState == SignalingStateClosed) 773 if (m_signalingState == SignalingStateClosed)
771 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, kSignalingStateClosedMessage)); 774 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, kSignalingStateClosedMessage));
772 775
773 if (isIceCandidateMissingSdp(candidate)) 776 if (isIceCandidateMissingSdp(candidate))
774 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Candidate missing values for both sdpMid and sdpMLi neIndex")); 777 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Candidate missing values for both sdpMid and sdpMLi neIndex"));
775 778
776 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 779 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
777 ScriptPromise promise = resolver->promise(); 780 ScriptPromise promise = resolver->promise();
778 RTCVoidRequest* request = RTCVoidRequestPromiseImpl::create(this, resolver); 781 RTCVoidRequest* request = RTCVoidRequestPromiseImpl::create(this, resolver);
779 WebRTCICECandidate webCandidate = convertToWebRTCIceCandidate(candidate); 782 WebRTCICECandidate webCandidate = convertToWebRTCIceCandidate(scriptState->g etExecutionContext(), candidate);
780 bool implemented = m_peerHandler->addICECandidate(request, webCandidate); 783 bool implemented = m_peerHandler->addICECandidate(request, webCandidate);
781 if (!implemented) 784 if (!implemented)
782 resolver->reject(DOMException::create(OperationError, "This operation co uld not be completed.")); 785 resolver->reject(DOMException::create(OperationError, "This operation co uld not be completed."));
783 786
784 return promise; 787 return promise;
785 } 788 }
786 789
787 ScriptPromise RTCPeerConnection::addIceCandidate(ScriptState* scriptState, RTCIc eCandidate* iceCandidate, VoidCallback* successCallback, RTCPeerConnectionErrorC allback* errorCallback) 790 ScriptPromise RTCPeerConnection::addIceCandidate(ScriptState* scriptState, const RTCIceCandidateInitOrRTCIceCandidate& candidate, VoidCallback* successCallback, RTCPeerConnectionErrorCallback* errorCallback)
788 { 791 {
789 DCHECK(iceCandidate);
790 DCHECK(successCallback); 792 DCHECK(successCallback);
791 DCHECK(errorCallback); 793 DCHECK(errorCallback);
792 794
793 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) ) 795 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) )
794 return ScriptPromise::castUndefined(scriptState); 796 return ScriptPromise::castUndefined(scriptState);
795 797
798 if (isIceCandidateMissingSdp(candidate))
799 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Candidate missing values for both sdpMid and sdpMLi neIndex"));
800
796 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(), this, successCallback, errorCallback); 801 RTCVoidRequest* request = RTCVoidRequestImpl::create(getExecutionContext(), this, successCallback, errorCallback);
797 bool implemented = m_peerHandler->addICECandidate(request, iceCandidate->web Candidate()); 802 WebRTCICECandidate webCandidate = convertToWebRTCIceCandidate(scriptState->g etExecutionContext(), candidate);
803 bool implemented = m_peerHandler->addICECandidate(request, webCandidate);
798 if (!implemented) 804 if (!implemented)
799 asyncCallErrorCallback(errorCallback, DOMException::create(OperationErro r, "This operation could not be completed.")); 805 asyncCallErrorCallback(errorCallback, DOMException::create(OperationErro r, "This operation could not be completed."));
800 806
801 return ScriptPromise::castUndefined(scriptState); 807 return ScriptPromise::castUndefined(scriptState);
802 } 808 }
803 809
804 String RTCPeerConnection::signalingState() const 810 String RTCPeerConnection::signalingState() const
805 { 811 {
806 switch (m_signalingState) { 812 switch (m_signalingState) {
807 case SignalingStateStable: 813 case SignalingStateStable:
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 { 1219 {
1214 visitor->trace(m_localStreams); 1220 visitor->trace(m_localStreams);
1215 visitor->trace(m_remoteStreams); 1221 visitor->trace(m_remoteStreams);
1216 visitor->trace(m_dispatchScheduledEventRunner); 1222 visitor->trace(m_dispatchScheduledEventRunner);
1217 visitor->trace(m_scheduledEvents); 1223 visitor->trace(m_scheduledEvents);
1218 EventTargetWithInlineData::trace(visitor); 1224 EventTargetWithInlineData::trace(visitor);
1219 ActiveDOMObject::trace(visitor); 1225 ActiveDOMObject::trace(visitor);
1220 } 1226 }
1221 1227
1222 } // namespace blink 1228 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698