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 16 matching lines...) Expand all Loading... | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
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 "config.h" | 31 #include "config.h" |
32 #include "modules/mediastream/RTCPeerConnection.h" | 32 #include "modules/mediastream/RTCPeerConnection.h" |
33 | 33 |
34 #include "bindings/core/v8/ArrayValue.h" | 34 #include "bindings/core/v8/ArrayValue.h" |
35 #include "bindings/core/v8/ExceptionMessages.h" | 35 #include "bindings/core/v8/ExceptionMessages.h" |
36 #include "bindings/core/v8/ExceptionState.h" | 36 #include "bindings/core/v8/ExceptionState.h" |
37 #include "bindings/core/v8/Nullable.h" | |
38 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
39 #include "bindings/modules/v8/V8RTCCertificate.h" | |
37 #include "core/dom/Document.h" | 40 #include "core/dom/Document.h" |
38 #include "core/dom/ExceptionCode.h" | 41 #include "core/dom/ExceptionCode.h" |
39 #include "core/dom/ExecutionContext.h" | 42 #include "core/dom/ExecutionContext.h" |
40 #include "core/frame/LocalFrame.h" | 43 #include "core/frame/LocalFrame.h" |
41 #include "core/html/VoidCallback.h" | 44 #include "core/html/VoidCallback.h" |
42 #include "core/loader/FrameLoader.h" | 45 #include "core/loader/FrameLoader.h" |
43 #include "core/loader/FrameLoaderClient.h" | 46 #include "core/loader/FrameLoaderClient.h" |
44 #include "modules/mediastream/MediaConstraintsImpl.h" | 47 #include "modules/mediastream/MediaConstraintsImpl.h" |
45 #include "modules/mediastream/MediaStreamEvent.h" | 48 #include "modules/mediastream/MediaStreamEvent.h" |
46 #include "modules/mediastream/RTCDTMFSender.h" | 49 #include "modules/mediastream/RTCDTMFSender.h" |
47 #include "modules/mediastream/RTCDataChannel.h" | 50 #include "modules/mediastream/RTCDataChannel.h" |
48 #include "modules/mediastream/RTCDataChannelEvent.h" | 51 #include "modules/mediastream/RTCDataChannelEvent.h" |
49 #include "modules/mediastream/RTCErrorCallback.h" | 52 #include "modules/mediastream/RTCErrorCallback.h" |
50 #include "modules/mediastream/RTCIceCandidateEvent.h" | 53 #include "modules/mediastream/RTCIceCandidateEvent.h" |
51 #include "modules/mediastream/RTCSessionDescription.h" | 54 #include "modules/mediastream/RTCSessionDescription.h" |
52 #include "modules/mediastream/RTCSessionDescriptionCallback.h" | 55 #include "modules/mediastream/RTCSessionDescriptionCallback.h" |
53 #include "modules/mediastream/RTCSessionDescriptionRequestImpl.h" | 56 #include "modules/mediastream/RTCSessionDescriptionRequestImpl.h" |
54 #include "modules/mediastream/RTCStatsCallback.h" | 57 #include "modules/mediastream/RTCStatsCallback.h" |
55 #include "modules/mediastream/RTCStatsRequestImpl.h" | 58 #include "modules/mediastream/RTCStatsRequestImpl.h" |
56 #include "modules/mediastream/RTCVoidRequestImpl.h" | 59 #include "modules/mediastream/RTCVoidRequestImpl.h" |
57 #include "platform/mediastream/RTCConfiguration.h" | 60 #include "platform/mediastream/RTCConfiguration.h" |
58 #include "platform/mediastream/RTCOfferOptions.h" | 61 #include "platform/mediastream/RTCOfferOptions.h" |
59 #include "public/platform/Platform.h" | 62 #include "public/platform/Platform.h" |
60 #include "public/platform/WebMediaStream.h" | 63 #include "public/platform/WebMediaStream.h" |
64 #include "public/platform/WebRTCCertificate.h" | |
65 #include "public/platform/WebRTCCertificateGenerator.h" | |
61 #include "public/platform/WebRTCConfiguration.h" | 66 #include "public/platform/WebRTCConfiguration.h" |
62 #include "public/platform/WebRTCDataChannelHandler.h" | 67 #include "public/platform/WebRTCDataChannelHandler.h" |
63 #include "public/platform/WebRTCDataChannelInit.h" | 68 #include "public/platform/WebRTCDataChannelInit.h" |
64 #include "public/platform/WebRTCICECandidate.h" | 69 #include "public/platform/WebRTCICECandidate.h" |
70 #include "public/platform/WebRTCKeyParams.h" | |
65 #include "public/platform/WebRTCOfferOptions.h" | 71 #include "public/platform/WebRTCOfferOptions.h" |
66 #include "public/platform/WebRTCSessionDescription.h" | 72 #include "public/platform/WebRTCSessionDescription.h" |
67 #include "public/platform/WebRTCSessionDescriptionRequest.h" | 73 #include "public/platform/WebRTCSessionDescriptionRequest.h" |
68 #include "public/platform/WebRTCStatsRequest.h" | 74 #include "public/platform/WebRTCStatsRequest.h" |
69 #include "public/platform/WebRTCVoidRequest.h" | 75 #include "public/platform/WebRTCVoidRequest.h" |
70 | 76 |
71 namespace blink { | 77 namespace blink { |
72 | 78 |
73 namespace { | 79 namespace { |
74 | 80 |
75 static bool throwExceptionIfSignalingStateClosed(RTCPeerConnection::SignalingSta te state, ExceptionState& exceptionState) | 81 static bool throwExceptionIfSignalingStateClosed(RTCPeerConnection::SignalingSta te state, ExceptionState& exceptionState) |
76 { | 82 { |
77 if (state == RTCPeerConnection::SignalingStateClosed) { | 83 if (state == RTCPeerConnection::SignalingStateClosed) { |
78 exceptionState.throwDOMException(InvalidStateError, "The RTCPeerConnecti on's signalingState is 'closed'."); | 84 exceptionState.throwDOMException(InvalidStateError, "The RTCPeerConnecti on's signalingState is 'closed'."); |
79 return true; | 85 return true; |
80 } | 86 } |
81 | 87 |
82 return false; | 88 return false; |
83 } | 89 } |
84 | 90 |
91 // Helper class for RTCPeerConnection::generateCertificate. | |
92 class WebRTCCertificateObserver : public WebCallbacks<WebRTCCertificate*, void> { | |
93 public: | |
94 // The created observer is responsible for deleting itself after onSuccess/o nError. To avoid memory | |
95 // leak the observer should therefore be used in a WebRTCCertificateGenerato r::generateCertificate call | |
96 // which is ensured to invoke one of these. Takes ownership of |resolver|. | |
97 static WebRTCCertificateObserver* create(ScriptPromiseResolver* resolver) | |
98 { | |
99 return new WebRTCCertificateObserver(resolver); | |
100 } | |
101 | |
102 DEFINE_INLINE_TRACE() { visitor->trace(m_resolver); } | |
103 | |
104 private: | |
105 WebRTCCertificateObserver(ScriptPromiseResolver* resolver) | |
106 : m_resolver(resolver) {} | |
107 | |
108 ~WebRTCCertificateObserver() override {} | |
109 | |
110 void onSuccess(WebRTCCertificate* certificate) override | |
111 { | |
112 m_resolver->resolve(new RTCCertificate(certificate)); | |
113 delete this; | |
114 } | |
115 | |
116 void onError() override | |
117 { | |
118 m_resolver->reject(); | |
119 delete this; | |
120 } | |
121 | |
122 Persistent<ScriptPromiseResolver> m_resolver; | |
123 }; | |
124 | |
85 } // namespace | 125 } // namespace |
86 | 126 |
87 RTCConfiguration* RTCPeerConnection::parseConfiguration(const Dictionary& config uration, ExceptionState& exceptionState) | 127 RTCConfiguration* RTCPeerConnection::parseConfiguration(const Dictionary& config uration, ExceptionState& exceptionState) |
88 { | 128 { |
89 if (configuration.isUndefinedOrNull()) | 129 if (configuration.isUndefinedOrNull()) |
90 return 0; | 130 return 0; |
91 | 131 |
92 RTCIceTransports iceTransports = RTCIceTransportsAll; | 132 RTCIceTransports iceTransports = RTCIceTransportsAll; |
93 String iceTransportsString; | 133 String iceTransportsString; |
94 if (DictionaryHelper::get(configuration, "iceTransports", iceTransportsStrin g)) { | 134 if (DictionaryHelper::get(configuration, "iceTransports", iceTransportsStrin g)) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 KURL url(KURL(), *iter); | 240 KURL url(KURL(), *iter); |
201 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) { | 241 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) { |
202 exceptionState.throwTypeError("Malformed URL"); | 242 exceptionState.throwTypeError("Malformed URL"); |
203 return 0; | 243 return 0; |
204 } | 244 } |
205 | 245 |
206 rtcConfiguration->iceServers()->appendServer(RTCIceServer::create(ur l, username, credential)); | 246 rtcConfiguration->iceServers()->appendServer(RTCIceServer::create(ur l, username, credential)); |
207 } | 247 } |
208 } | 248 } |
209 | 249 |
250 ArrayValue certificates; | |
251 if (DictionaryHelper::get(configuration, "certificates", certificates) && !c ertificates.isUndefinedOrNull()) { | |
252 size_t numberOfCertificates; | |
253 certificates.length(numberOfCertificates); | |
254 for (size_t i = 0; i < numberOfCertificates; ++i) { | |
255 RTCCertificate* certificate = nullptr; | |
256 | |
257 Dictionary dictCert; | |
258 certificates.get(i, dictCert); | |
259 v8::Local<v8::Value> valCert = dictCert.v8Value(); | |
260 if (!valCert.IsEmpty()) { | |
261 certificate = V8RTCCertificate::toImplWithTypeCheck(configuratio n.isolate(), valCert); | |
262 } | |
263 if (!certificate) { | |
264 exceptionState.throwTypeError("Malformed sequence<RTCCertificate >"); | |
265 return 0; | |
266 } | |
267 | |
268 rtcConfiguration->appendCertificate(certificate->certificateShallowC opy()); | |
269 } | |
270 } | |
271 | |
210 return rtcConfiguration; | 272 return rtcConfiguration; |
211 } | 273 } |
212 | 274 |
213 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState) | 275 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState) |
214 { | 276 { |
215 if (options.isUndefinedOrNull()) | 277 if (options.isUndefinedOrNull()) |
216 return 0; | 278 return 0; |
217 | 279 |
218 Vector<String> propertyNames; | 280 Vector<String> propertyNames; |
219 options.getPropertyNames(propertyNames); | 281 options.getPropertyNames(propertyNames); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 | 466 |
405 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); | 467 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); |
406 if (exceptionState.hadException()) | 468 if (exceptionState.hadException()) |
407 return; | 469 return; |
408 | 470 |
409 bool valid = m_peerHandler->updateICE(configuration, constraints); | 471 bool valid = m_peerHandler->updateICE(configuration, constraints); |
410 if (!valid) | 472 if (!valid) |
411 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); | 473 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); |
412 } | 474 } |
413 | 475 |
476 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c onst Dictionary& keygenAlgorithm, ExceptionState& exceptionState) | |
477 { | |
478 // Validate and interpret input |keygenAlgorithm|. | |
479 // TODO(hbos): Use WebCrypto normalization process to validate and interpret |keygenAlgorithm|. | |
480 // This may create a dependency between the Blink and WebCrypto modules? crb ug.com/544917 | |
eroman
2015/10/21 22:55:50
As discussed over email, depending on NormalizeAlg
hbos_chromium
2015/10/22 09:40:56
Acknowledged.
| |
481 Nullable<WebRTCKeyParams> keyParams; | |
482 String name; | |
483 if (DictionaryHelper::get(keygenAlgorithm, "name", name)) { | |
eroman
2015/10/21 22:55:50
As-written the AlgorithmIdentifier parsing code he
hbos_chromium
2015/10/22 09:40:56
That's what I'll do :) Btw there is a third proble
eroman
2015/10/22 17:49:49
Oh right, that too ... Yuck!
| |
484 if (name == "RSASSA-PKCS1-v1_5") { | |
485 // RSA - Supported |keygenAlgorithm|: | |
486 // { name: "RSASSA-PKCS1-v1_5", modulusLength: <int>, publicExponent : 65537 } | |
487 int modulusLength = -1; | |
488 int publicExponent = -1; | |
489 if (DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusL ength) | |
490 && modulusLength >= 0 | |
491 && DictionaryHelper::get(keygenAlgorithm, "publicExponent", publ icExponent) | |
492 && publicExponent >= 0) { | |
493 keyParams.set(blink::WebRTCKeyParams::createRSA(modulusLength, p ublicExponent)); | |
494 } | |
495 } else if (name == "ECDSA") { | |
496 // ECDSA - Supported |keygenAlgorithm|: | |
497 // { name: "ECDSA", namedCurve: "P-256" } | |
498 String namedCurve; | |
499 DictionaryHelper::get(keygenAlgorithm, "namedCurve", namedCurve); | |
500 if (namedCurve == "P-256") { | |
501 keyParams.set(blink::WebRTCKeyParams::createECDSA(WebRTCECCurveN istP256)); | |
502 } | |
503 } | |
504 } | |
505 if (keyParams.isNull()) { | |
506 // Invalid argument. | |
507 return ScriptPromise::rejectWithDOMException( | |
508 scriptState, DOMException::create(InvalidAccessError, ExceptionMessa ges::argumentNullOrIncorrectType(1, "AlgorithmIdentifier"))); | |
eroman
2015/10/21 22:55:51
According to the WebRTC spec you should be failing
hbos_chromium
2015/10/22 09:40:56
Acknowledged. To be addressed in follow-up.
| |
509 } | |
510 | |
511 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr( | |
512 Platform::current()->createRTCCertificateGenerator()); | |
513 | |
514 // Check validity of |keyParams|. | |
515 if (!certificateGenerator->isValidKeyParams(keyParams.get())) { | |
516 return ScriptPromise::rejectWithDOMException( | |
517 scriptState, DOMException::create(NotSupportedError, "The 1st argume nt provided is an AlgorithmIdentifier, but it has unsupported parameter values." )); | |
518 } | |
519 | |
520 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
521 ScriptPromise promise = resolver->promise(); | |
522 | |
523 WebRTCCertificateObserver* certificateObserver = WebRTCCertificateObserver:: create(resolver); | |
524 | |
525 // Generate certificate. The |certificateObserver| will resolve the promise asynchronously upon completion. | |
526 // The observer will manage its own destruction as well as the resolver's de struction. | |
527 certificateGenerator->generateCertificate( | |
528 keyParams.get(), | |
529 toDocument(scriptState->executionContext())->url(), | |
530 toDocument(scriptState->executionContext())->firstPartyForCookies(), | |
531 certificateObserver); | |
532 | |
533 return promise; | |
534 } | |
535 | |
414 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) | 536 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) |
415 { | 537 { |
416 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 538 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
417 return; | 539 return; |
418 | 540 |
419 if (!iceCandidate) { | 541 if (!iceCandidate) { |
420 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); | 542 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); |
421 return; | 543 return; |
422 } | 544 } |
423 | 545 |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 { | 969 { |
848 visitor->trace(m_localStreams); | 970 visitor->trace(m_localStreams); |
849 visitor->trace(m_remoteStreams); | 971 visitor->trace(m_remoteStreams); |
850 visitor->trace(m_dataChannels); | 972 visitor->trace(m_dataChannels); |
851 visitor->trace(m_scheduledEvents); | 973 visitor->trace(m_scheduledEvents); |
852 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); | 974 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); |
853 ActiveDOMObject::trace(visitor); | 975 ActiveDOMObject::trace(visitor); |
854 } | 976 } |
855 | 977 |
856 } // namespace blink | 978 } // namespace blink |
OLD | NEW |