Chromium Code Reviews| 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/ScriptPromiseResolver.h" | |
| 38 #include "bindings/modules/v8/V8RTCCertificate.h" | |
| 37 #include "core/dom/Document.h" | 39 #include "core/dom/Document.h" |
| 38 #include "core/dom/ExceptionCode.h" | 40 #include "core/dom/ExceptionCode.h" |
| 39 #include "core/dom/ExecutionContext.h" | 41 #include "core/dom/ExecutionContext.h" |
| 40 #include "core/frame/LocalFrame.h" | 42 #include "core/frame/LocalFrame.h" |
| 41 #include "core/html/VoidCallback.h" | 43 #include "core/html/VoidCallback.h" |
| 42 #include "core/loader/FrameLoader.h" | 44 #include "core/loader/FrameLoader.h" |
| 43 #include "core/loader/FrameLoaderClient.h" | 45 #include "core/loader/FrameLoaderClient.h" |
| 44 #include "modules/mediastream/MediaConstraintsImpl.h" | 46 #include "modules/mediastream/MediaConstraintsImpl.h" |
| 45 #include "modules/mediastream/MediaStreamEvent.h" | 47 #include "modules/mediastream/MediaStreamEvent.h" |
| 46 #include "modules/mediastream/RTCDTMFSender.h" | 48 #include "modules/mediastream/RTCDTMFSender.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 75 static bool throwExceptionIfSignalingStateClosed(RTCPeerConnection::SignalingSta te state, ExceptionState& exceptionState) | 77 static bool throwExceptionIfSignalingStateClosed(RTCPeerConnection::SignalingSta te state, ExceptionState& exceptionState) |
| 76 { | 78 { |
| 77 if (state == RTCPeerConnection::SignalingStateClosed) { | 79 if (state == RTCPeerConnection::SignalingStateClosed) { |
| 78 exceptionState.throwDOMException(InvalidStateError, "The RTCPeerConnecti on's signalingState is 'closed'."); | 80 exceptionState.throwDOMException(InvalidStateError, "The RTCPeerConnecti on's signalingState is 'closed'."); |
| 79 return true; | 81 return true; |
| 80 } | 82 } |
| 81 | 83 |
| 82 return false; | 84 return false; |
| 83 } | 85 } |
| 84 | 86 |
| 87 // Helper class for RTCPeerConnection::generateCertificate. | |
| 88 class WebRTCCertificateObserver : public WebCallbacks<WebRTCCertificate*, void> { | |
| 89 public: | |
| 90 // The created observer is responsible for deleting itself after onSuccess/o nError. To avoid memory | |
| 91 // leak the observer should therefore be used in a WebRTCCertificateGenerato r::generateCertificate call. | |
| 92 // which is ensured to invoke one of these. Takes ownership of |resolver|. | |
| 93 static WebRTCCertificateObserver* Create(ScriptPromiseResolver* resolver) | |
| 94 { | |
| 95 return new WebRTCCertificateObserver(resolver); | |
| 96 } | |
| 97 | |
| 98 DEFINE_INLINE_TRACE() { visitor->trace(m_resolver); } | |
| 99 | |
| 100 private: | |
| 101 WebRTCCertificateObserver(ScriptPromiseResolver* resolver) | |
| 102 : m_resolver(resolver) | |
| 103 { | |
| 104 } | |
| 105 | |
| 106 ~WebRTCCertificateObserver() override | |
| 107 { | |
| 108 } | |
| 109 | |
| 110 void onSuccess(WebRTCCertificate* certificate) override | |
| 111 { | |
| 112 m_resolver->resolve(new RTCCertificate(certificate)); | |
| 113 delete this; | |
| 114 } | |
| 115 | |
| 116 void onError() | |
| 117 { | |
| 118 m_resolver->resolve(static_cast<RTCCertificate*>(nullptr)); | |
| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 KURL url(KURL(), *iter); | 228 KURL url(KURL(), *iter); |
| 189 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) { | 229 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) { |
| 190 exceptionState.throwTypeError("Malformed URL"); | 230 exceptionState.throwTypeError("Malformed URL"); |
| 191 return 0; | 231 return 0; |
| 192 } | 232 } |
| 193 | 233 |
| 194 rtcConfiguration->appendServer(RTCIceServer::create(url, username, c redential)); | 234 rtcConfiguration->appendServer(RTCIceServer::create(url, username, c redential)); |
| 195 } | 235 } |
| 196 } | 236 } |
| 197 | 237 |
| 238 ArrayValue certificates; | |
| 239 if (DictionaryHelper::get(configuration, "certificates", certificates) | |
| 240 && !certificates.isUndefinedOrNull()) { | |
| 241 size_t numberOfCertificates; | |
| 242 certificates.length(numberOfCertificates); | |
| 243 for (size_t i = 0; i < numberOfCertificates; ++i) { | |
| 244 RTCCertificate* certificate = nullptr; | |
| 245 | |
| 246 Dictionary dictCert; | |
| 247 certificates.get(i, dictCert); | |
| 248 v8::Local<v8::Value> valCert = dictCert.v8Value(); | |
| 249 if (!valCert.IsEmpty()) { | |
| 250 certificate = V8RTCCertificate::toImplWithTypeCheck(configuratio n.isolate(), valCert); | |
| 251 } | |
| 252 if (!certificate) { | |
| 253 exceptionState.throwTypeError("Malformed sequence<RTCCertificate >"); | |
| 254 return 0; | |
| 255 } | |
| 256 | |
| 257 rtcConfiguration->appendCertificate(certificate->certificateShallowC opy()); | |
|
jochen (gone - plz use gerrit)
2015/09/15 08:04:19
why do you append a copy instead of just keeping t
hbos_chromium
2015/09/21 16:12:22
The WebRTCCertificate is owned by the JavaScript o
| |
| 258 } | |
| 259 } | |
| 260 | |
| 198 return rtcConfiguration; | 261 return rtcConfiguration; |
| 199 } | 262 } |
| 200 | 263 |
| 201 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState) | 264 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState) |
| 202 { | 265 { |
| 203 if (options.isUndefinedOrNull()) | 266 if (options.isUndefinedOrNull()) |
| 204 return 0; | 267 return 0; |
| 205 | 268 |
| 206 Vector<String> propertyNames; | 269 Vector<String> propertyNames; |
| 207 options.getPropertyNames(propertyNames); | 270 options.getPropertyNames(propertyNames); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 455 |
| 393 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); | 456 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); |
| 394 if (exceptionState.hadException()) | 457 if (exceptionState.hadException()) |
| 395 return; | 458 return; |
| 396 | 459 |
| 397 bool valid = m_peerHandler->updateICE(configuration, constraints); | 460 bool valid = m_peerHandler->updateICE(configuration, constraints); |
| 398 if (!valid) | 461 if (!valid) |
| 399 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); | 462 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); |
| 400 } | 463 } |
| 401 | 464 |
| 465 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c onst Dictionary& keygenAlgorithm, ExceptionState& exceptionState) | |
| 466 { | |
| 467 // Validate and interpret input |keygenAlgorithm|. | |
| 468 // The value |keyType| corresponds to the rtc::KeyType in libjingle. | |
| 469 int keyType = -1; | |
| 470 String name; | |
| 471 if (DictionaryHelper::get(keygenAlgorithm, "name", name)) { | |
| 472 if (name == "RSASSA-PKCS1-v1_5") { | |
| 473 // RSA - Supported |keygenAlgorithm|: | |
| 474 // { name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: 65537 } | |
| 475 // { name: "RSASSA-PKCS1-v1_5", modulusLength: 1024, publicExponent: 65537 } (not a MUST in specification, but the one actually being used) | |
| 476 // TODO(hbos): Use modulusLength and not the default (1024). | |
| 477 int modulusLength = -1; | |
| 478 DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusLengt h); | |
| 479 int publicExponent = -1; | |
| 480 DictionaryHelper::get(keygenAlgorithm, "publicExponent", publicExpon ent); | |
| 481 if ((modulusLength == 2048 || modulusLength == 1024) && publicExpone nt == 65537) { | |
| 482 keyType = 0; | |
| 483 } | |
| 484 } else if (name == "ECDSA") { | |
| 485 // ECDSA - Supported |keygenAlgorithm|: | |
| 486 // { name: "ECDSA", namedCurve: "P-256" } | |
| 487 String namedCurve; | |
| 488 DictionaryHelper::get(keygenAlgorithm, "namedCurve", namedCurve); | |
| 489 if (namedCurve == "P-256") { | |
| 490 keyType = 1; | |
| 491 } | |
| 492 } | |
| 493 } | |
| 494 if (keyType == -1) { | |
| 495 // Invalid argument. | |
| 496 return ScriptPromise::rejectWithDOMException( | |
| 497 scriptState, DOMException::create(InvalidAccessError, ExceptionMessa ges::argumentNullOrIncorrectType(1, "AlgorithmIdentifier"))); | |
| 498 } | |
| 499 | |
| 500 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 501 ScriptPromise promise = resolver->promise(); | |
| 502 | |
| 503 WebRTCCertificateObserver* certificateObserver = WebRTCCertificateObserver:: Create(resolver); | |
| 504 | |
| 505 // Generate certificate. The |certificateObserver| will resolve the promise asynchronously upon generate completion. | |
| 506 // The observer will manage its own and the resolver's destruction as well. | |
| 507 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr( | |
| 508 Platform::current()->createRTCCertificateGenerator()); | |
| 509 certificateGenerator->generateCertificate( | |
| 510 keyType, | |
| 511 toDocument(scriptState->executionContext())->url(), | |
| 512 toDocument(scriptState->executionContext())->firstPartyForCookies(), | |
| 513 certificateObserver); | |
| 514 | |
| 515 return promise; | |
| 516 } | |
| 517 | |
| 402 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) | 518 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) |
| 403 { | 519 { |
| 404 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 520 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 405 return; | 521 return; |
| 406 | 522 |
| 407 if (!iceCandidate) { | 523 if (!iceCandidate) { |
| 408 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); | 524 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); |
| 409 return; | 525 return; |
| 410 } | 526 } |
| 411 | 527 |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 { | 951 { |
| 836 visitor->trace(m_localStreams); | 952 visitor->trace(m_localStreams); |
| 837 visitor->trace(m_remoteStreams); | 953 visitor->trace(m_remoteStreams); |
| 838 visitor->trace(m_dataChannels); | 954 visitor->trace(m_dataChannels); |
| 839 visitor->trace(m_scheduledEvents); | 955 visitor->trace(m_scheduledEvents); |
| 840 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); | 956 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); |
| 841 ActiveDOMObject::trace(visitor); | 957 ActiveDOMObject::trace(visitor); |
| 842 } | 958 } |
| 843 | 959 |
| 844 } // namespace blink | 960 } // namespace blink |
| OLD | NEW |