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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 KURL url(KURL(), *iter); | 190 KURL url(KURL(), *iter); |
| 189 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) { | 191 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) { |
| 190 exceptionState.throwTypeError("Malformed URL"); | 192 exceptionState.throwTypeError("Malformed URL"); |
| 191 return 0; | 193 return 0; |
| 192 } | 194 } |
| 193 | 195 |
| 194 rtcConfiguration->appendServer(RTCIceServer::create(url, username, c redential)); | 196 rtcConfiguration->appendServer(RTCIceServer::create(url, username, c redential)); |
| 195 } | 197 } |
| 196 } | 198 } |
| 197 | 199 |
| 200 ArrayValue certificates; | |
| 201 if (DictionaryHelper::get(configuration, "certificates", certificates) | |
| 202 && !certificates.isUndefinedOrNull()) { | |
| 203 size_t numberOfCertificates; | |
| 204 certificates.length(numberOfCertificates); | |
| 205 for (size_t i = 0; i < numberOfCertificates; ++i) { | |
| 206 RTCCertificate* certificate = nullptr; | |
| 207 | |
| 208 Dictionary dictCert; | |
| 209 certificates.get(i, dictCert); | |
| 210 v8::Local<v8::Value> valCert = dictCert.v8Value(); | |
| 211 if (!valCert.IsEmpty()) { | |
| 212 certificate = V8RTCCertificate::toImplWithTypeCheck(configuratio n.isolate(), valCert); | |
| 213 } | |
| 214 if (!certificate) { | |
| 215 exceptionState.throwTypeError("Malformed sequence<RTCCertificate >"); | |
| 216 return 0; | |
| 217 } | |
| 218 | |
| 219 rtcConfiguration->appendCertificate(certificate->certificate()->shal lowCopy()); | |
| 220 } | |
| 221 } | |
| 222 | |
| 198 return rtcConfiguration; | 223 return rtcConfiguration; |
| 199 } | 224 } |
| 200 | 225 |
| 201 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState) | 226 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState) |
| 202 { | 227 { |
| 203 if (options.isUndefinedOrNull()) | 228 if (options.isUndefinedOrNull()) |
| 204 return 0; | 229 return 0; |
| 205 | 230 |
| 206 Vector<String> propertyNames; | 231 Vector<String> propertyNames; |
| 207 options.getPropertyNames(propertyNames); | 232 options.getPropertyNames(propertyNames); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 417 |
| 393 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); | 418 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); |
| 394 if (exceptionState.hadException()) | 419 if (exceptionState.hadException()) |
| 395 return; | 420 return; |
| 396 | 421 |
| 397 bool valid = m_peerHandler->updateICE(configuration, constraints); | 422 bool valid = m_peerHandler->updateICE(configuration, constraints); |
| 398 if (!valid) | 423 if (!valid) |
| 399 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); | 424 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); |
| 400 } | 425 } |
| 401 | 426 |
| 427 // The observer deletes itself upon generation complete. Keeps |m_resolver| aliv e until destruction. | |
| 428 static class GenerateRTCCertificateObserver : public WebRTCCertificateObserver { | |
| 429 public: | |
| 430 GenerateRTCCertificateObserver(ScriptPromiseResolver* resolver) | |
|
Guido Urdaneta
2015/09/03 11:07:49
Constructor should be private and you should have
hbos_chromium
2015/09/03 16:01:37
Done.
| |
| 431 : m_resolver(resolver) | |
| 432 { | |
| 433 } | |
| 434 | |
| 435 ~GenerateRTCCertificateObserver() override | |
| 436 { | |
| 437 } | |
| 438 | |
| 439 DEFINE_INLINE_TRACE() { visitor->trace(m_resolver); } | |
| 440 | |
| 441 private: | |
| 442 void onGenerateComplete(WebRTCCertificate* certificate) override | |
| 443 { | |
| 444 m_resolver->resolve(certificate ? new RTCCertificate(certificate) : null ptr); | |
| 445 delete this; | |
| 446 } | |
| 447 | |
| 448 Persistent<ScriptPromiseResolver> m_resolver; | |
| 449 }; | |
| 450 | |
| 451 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c onst Dictionary& keygenAlgorithm, ExceptionState& exceptionState) | |
| 452 { | |
| 453 // Validate and interpret input |keygenAlgorithm|. | |
| 454 // The value |keyType| corresponds to the rtc::KeyType in libjingle. | |
| 455 int keyType = -1; | |
| 456 String name; | |
| 457 if (DictionaryHelper::get(keygenAlgorithm, "name", name)) { | |
| 458 if (name == "RSASSA-PKCS1-v1_5") { | |
| 459 // RSA - Supported |keygenAlgorithm|: | |
| 460 // { name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: 65537 } | |
| 461 // { name: "RSASSA-PKCS1-v1_5", modulusLength: 1024, publicExponent: 65537 } (not a MUST in specification, but the one actually being used) | |
| 462 // TODO(hbos): Use modulusLength and not the default (1024). | |
| 463 int modulusLength = -1; | |
| 464 DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusLengt h); | |
| 465 int publicExponent = -1; | |
| 466 DictionaryHelper::get(keygenAlgorithm, "publicExponent", publicExpon ent); | |
| 467 if ((modulusLength == 2048 || modulusLength == 1024) && publicExpone nt == 65537) { | |
| 468 keyType = 0; | |
| 469 } | |
| 470 } else if (name == "ECDSA") { | |
| 471 // ECDSA - Supported |keygenAlgorithm|: | |
| 472 // { name: "ECDSA", namedCurve: "P-256" } | |
| 473 String namedCurve; | |
| 474 DictionaryHelper::get(keygenAlgorithm, "namedCurve", namedCurve); | |
| 475 if (namedCurve == "P-256") { | |
| 476 keyType = 1; | |
| 477 } | |
| 478 } | |
| 479 } | |
| 480 if (keyType == -1) { | |
| 481 // Invalid argument. | |
| 482 return ScriptPromise::rejectWithDOMException( | |
| 483 scriptState, DOMException::create(InvalidAccessError, ExceptionMessa ges::argumentNullOrIncorrectType(1, "AlgorithmIdentifier"))); | |
| 484 } | |
| 485 | |
| 486 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 487 ScriptPromise promise = resolver->promise(); | |
| 488 | |
| 489 GenerateRTCCertificateObserver* certificateObserver = new GenerateRTCCertifi cateObserver(resolver); | |
| 490 | |
| 491 // Generate certificate. The |certificateObserver| will resolve the promise asynchronously upon generate completion. | |
| 492 // The observer will manage its own and the resolver's destruction as well. | |
| 493 WebRTCCertificateGenerator* certificateGenerator = Platform::current()->crea teRTCCertificateGenerator(); | |
| 494 certificateGenerator->generateCertificate( | |
| 495 keyType, | |
| 496 toDocument(scriptState->executionContext())->url(), | |
| 497 toDocument(scriptState->executionContext())->firstPartyForCookies(), | |
| 498 certificateObserver); | |
| 499 delete certificateGenerator; | |
|
Guido Urdaneta
2015/09/03 11:07:49
Is it safe to delete |certificateGenerator| here?
hbos_chromium
2015/09/03 16:01:37
Yes the object need only live for the generateCert
| |
| 500 | |
| 501 return promise; | |
| 502 } | |
| 503 | |
| 402 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) | 504 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) |
| 403 { | 505 { |
| 404 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 506 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
| 405 return; | 507 return; |
| 406 | 508 |
| 407 if (!iceCandidate) { | 509 if (!iceCandidate) { |
| 408 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); | 510 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); |
| 409 return; | 511 return; |
| 410 } | 512 } |
| 411 | 513 |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 { | 937 { |
| 836 visitor->trace(m_localStreams); | 938 visitor->trace(m_localStreams); |
| 837 visitor->trace(m_remoteStreams); | 939 visitor->trace(m_remoteStreams); |
| 838 visitor->trace(m_dataChannels); | 940 visitor->trace(m_dataChannels); |
| 839 visitor->trace(m_scheduledEvents); | 941 visitor->trace(m_scheduledEvents); |
| 840 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); | 942 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); |
| 841 ActiveDOMObject::trace(visitor); | 943 ActiveDOMObject::trace(visitor); |
| 842 } | 944 } |
| 843 | 945 |
| 844 } // namespace blink | 946 } // namespace blink |
| OLD | NEW |