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/WebRTCKeyType.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 } |
| 109 |
| 110 ~WebRTCCertificateObserver() override |
| 111 { |
| 112 } |
| 113 |
| 114 void onSuccess(WebRTCCertificate* certificate) override |
| 115 { |
| 116 m_resolver->resolve(new RTCCertificate(certificate)); |
| 117 delete this; |
| 118 } |
| 119 |
| 120 void onError() |
| 121 { |
| 122 m_resolver->resolve(static_cast<RTCCertificate*>(nullptr)); |
| 123 delete this; |
| 124 } |
| 125 |
| 126 Persistent<ScriptPromiseResolver> m_resolver; |
| 127 }; |
| 128 |
85 } // namespace | 129 } // namespace |
86 | 130 |
87 RTCConfiguration* RTCPeerConnection::parseConfiguration(const Dictionary& config
uration, ExceptionState& exceptionState) | 131 RTCConfiguration* RTCPeerConnection::parseConfiguration(const Dictionary& config
uration, ExceptionState& exceptionState) |
88 { | 132 { |
89 if (configuration.isUndefinedOrNull()) | 133 if (configuration.isUndefinedOrNull()) |
90 return 0; | 134 return 0; |
91 | 135 |
92 RTCIceTransports iceTransports = RTCIceTransportsAll; | 136 RTCIceTransports iceTransports = RTCIceTransportsAll; |
93 String iceTransportsString; | 137 String iceTransportsString; |
94 if (DictionaryHelper::get(configuration, "iceTransports", iceTransportsStrin
g)) { | 138 if (DictionaryHelper::get(configuration, "iceTransports", iceTransportsStrin
g)) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 KURL url(KURL(), *iter); | 232 KURL url(KURL(), *iter); |
189 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu
rns") || url.protocolIs("stun"))) { | 233 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu
rns") || url.protocolIs("stun"))) { |
190 exceptionState.throwTypeError("Malformed URL"); | 234 exceptionState.throwTypeError("Malformed URL"); |
191 return 0; | 235 return 0; |
192 } | 236 } |
193 | 237 |
194 rtcConfiguration->appendServer(RTCIceServer::create(url, username, c
redential)); | 238 rtcConfiguration->appendServer(RTCIceServer::create(url, username, c
redential)); |
195 } | 239 } |
196 } | 240 } |
197 | 241 |
| 242 ArrayValue certificates; |
| 243 if (DictionaryHelper::get(configuration, "certificates", certificates) |
| 244 && !certificates.isUndefinedOrNull()) { |
| 245 size_t numberOfCertificates; |
| 246 certificates.length(numberOfCertificates); |
| 247 for (size_t i = 0; i < numberOfCertificates; ++i) { |
| 248 RTCCertificate* certificate = nullptr; |
| 249 |
| 250 Dictionary dictCert; |
| 251 certificates.get(i, dictCert); |
| 252 v8::Local<v8::Value> valCert = dictCert.v8Value(); |
| 253 if (!valCert.IsEmpty()) { |
| 254 certificate = V8RTCCertificate::toImplWithTypeCheck(configuratio
n.isolate(), valCert); |
| 255 } |
| 256 if (!certificate) { |
| 257 exceptionState.throwTypeError("Malformed sequence<RTCCertificate
>"); |
| 258 return 0; |
| 259 } |
| 260 |
| 261 rtcConfiguration->appendCertificate(certificate->certificateShallowC
opy()); |
| 262 } |
| 263 } |
| 264 |
198 return rtcConfiguration; | 265 return rtcConfiguration; |
199 } | 266 } |
200 | 267 |
201 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options,
ExceptionState& exceptionState) | 268 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options,
ExceptionState& exceptionState) |
202 { | 269 { |
203 if (options.isUndefinedOrNull()) | 270 if (options.isUndefinedOrNull()) |
204 return 0; | 271 return 0; |
205 | 272 |
206 Vector<String> propertyNames; | 273 Vector<String> propertyNames; |
207 options.getPropertyNames(propertyNames); | 274 options.getPropertyNames(propertyNames); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 459 |
393 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai
nts, exceptionState); | 460 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai
nts, exceptionState); |
394 if (exceptionState.hadException()) | 461 if (exceptionState.hadException()) |
395 return; | 462 return; |
396 | 463 |
397 bool valid = m_peerHandler->updateICE(configuration, constraints); | 464 bool valid = m_peerHandler->updateICE(configuration, constraints); |
398 if (!valid) | 465 if (!valid) |
399 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE
Agent with the given configuration."); | 466 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE
Agent with the given configuration."); |
400 } | 467 } |
401 | 468 |
| 469 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c
onst Dictionary& keygenAlgorithm, ExceptionState& exceptionState) |
| 470 { |
| 471 // Validate and interpret input |keygenAlgorithm|. |
| 472 // The value |keyType| corresponds to the rtc::KeyType in libjingle. |
| 473 blink::Nullable<blink::WebRTCKeyType> keyType; |
| 474 String name; |
| 475 if (DictionaryHelper::get(keygenAlgorithm, "name", name)) { |
| 476 if (name == "RSASSA-PKCS1-v1_5") { |
| 477 // RSA - Supported |keygenAlgorithm|: |
| 478 // { name: "RSASSA-PKCS1-v1_5", modulusLength: <int>, publicExponent
: 65537 } |
| 479 // Where 1024 <= modulusLength <= 8192. This is a somewhat arbitrary |
| 480 // restriction. The idea is that less than 1024 is unsafe and |
| 481 // greater than 8192 is unreasonably large and slow. |
| 482 int modulusLength = -1; |
| 483 DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusLengt
h); |
| 484 int publicExponent = -1; |
| 485 DictionaryHelper::get(keygenAlgorithm, "publicExponent", publicExpon
ent); |
| 486 if (modulusLength >= 1024 && modulusLength <= 8192 && publicExponent
== 65537) { |
| 487 keyType.set(blink::WebRTCKeyType::createRSA(modulusLength)); |
| 488 } |
| 489 } else if (name == "ECDSA") { |
| 490 // ECDSA - Supported |keygenAlgorithm|: |
| 491 // { name: "ECDSA", namedCurve: "P-256" } |
| 492 String namedCurve; |
| 493 DictionaryHelper::get(keygenAlgorithm, "namedCurve", namedCurve); |
| 494 if (namedCurve == "P-256") { |
| 495 keyType.set(blink::WebRTCKeyType::createECDSA()); |
| 496 } |
| 497 } |
| 498 } |
| 499 if (keyType.isNull()) { |
| 500 // Invalid argument. |
| 501 return ScriptPromise::rejectWithDOMException( |
| 502 scriptState, DOMException::create(InvalidAccessError, ExceptionMessa
ges::argumentNullOrIncorrectType(1, "AlgorithmIdentifier"))); |
| 503 } |
| 504 |
| 505 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 506 ScriptPromise promise = resolver->promise(); |
| 507 |
| 508 WebRTCCertificateObserver* certificateObserver = WebRTCCertificateObserver::
Create(resolver); |
| 509 |
| 510 // Generate certificate. The |certificateObserver| will resolve the promise
asynchronously upon generate completion. |
| 511 // The observer will manage its own and the resolver's destruction as well. |
| 512 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr( |
| 513 Platform::current()->createRTCCertificateGenerator()); |
| 514 certificateGenerator->generateCertificate( |
| 515 keyType.get(), |
| 516 toDocument(scriptState->executionContext())->url(), |
| 517 toDocument(scriptState->executionContext())->firstPartyForCookies(), |
| 518 certificateObserver); |
| 519 |
| 520 return promise; |
| 521 } |
| 522 |
402 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception
State& exceptionState) | 523 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception
State& exceptionState) |
403 { | 524 { |
404 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 525 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
405 return; | 526 return; |
406 | 527 |
407 if (!iceCandidate) { | 528 if (!iceCandidate) { |
408 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "RTCIceCandidate")); | 529 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a
rgumentNullOrIncorrectType(1, "RTCIceCandidate")); |
409 return; | 530 return; |
410 } | 531 } |
411 | 532 |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 { | 956 { |
836 visitor->trace(m_localStreams); | 957 visitor->trace(m_localStreams); |
837 visitor->trace(m_remoteStreams); | 958 visitor->trace(m_remoteStreams); |
838 visitor->trace(m_dataChannels); | 959 visitor->trace(m_dataChannels); |
839 visitor->trace(m_scheduledEvents); | 960 visitor->trace(m_scheduledEvents); |
840 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac
e(visitor); | 961 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac
e(visitor); |
841 ActiveDOMObject::trace(visitor); | 962 ActiveDOMObject::trace(visitor); |
842 } | 963 } |
843 | 964 |
844 } // namespace blink | 965 } // namespace blink |
OLD | NEW |