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

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

Issue 1311853005: RTCCertificate and RTCPeerConnection.generateCertificate added to JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Merge with master Created 5 years, 3 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 16 matching lines...) Expand all
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()
jochen (gone - plz use gerrit) 2015/09/22 15:48:53 should this also be marked as override?
hbos_chromium 2015/09/28 08:10:16 Done.
121 {
122 m_resolver->resolve(static_cast<RTCCertificate*>(nullptr));
jochen (gone - plz use gerrit) 2015/09/22 15:48:53 why not reject?
hbos_chromium 2015/09/28 08:10:16 Spec does not say what happens if we fail to gener
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 KURL url(KURL(), *iter); 244 KURL url(KURL(), *iter);
201 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) { 245 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) {
202 exceptionState.throwTypeError("Malformed URL"); 246 exceptionState.throwTypeError("Malformed URL");
203 return 0; 247 return 0;
204 } 248 }
205 249
206 rtcConfiguration->iceServers()->appendServer(RTCIceServer::create(ur l, username, credential)); 250 rtcConfiguration->iceServers()->appendServer(RTCIceServer::create(ur l, username, credential));
207 } 251 }
208 } 252 }
209 253
254 ArrayValue certificates;
255 if (DictionaryHelper::get(configuration, "certificates", certificates)
256 && !certificates.isUndefinedOrNull()) {
257 size_t numberOfCertificates;
258 certificates.length(numberOfCertificates);
259 for (size_t i = 0; i < numberOfCertificates; ++i) {
260 RTCCertificate* certificate = nullptr;
261
262 Dictionary dictCert;
263 certificates.get(i, dictCert);
264 v8::Local<v8::Value> valCert = dictCert.v8Value();
265 if (!valCert.IsEmpty()) {
266 certificate = V8RTCCertificate::toImplWithTypeCheck(configuratio n.isolate(), valCert);
267 }
268 if (!certificate) {
269 exceptionState.throwTypeError("Malformed sequence<RTCCertificate >");
270 return 0;
271 }
272
273 rtcConfiguration->appendCertificate(certificate->certificateShallowC opy());
274 }
275 }
276
210 return rtcConfiguration; 277 return rtcConfiguration;
211 } 278 }
212 279
213 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState) 280 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState)
214 { 281 {
215 if (options.isUndefinedOrNull()) 282 if (options.isUndefinedOrNull())
216 return 0; 283 return 0;
217 284
218 Vector<String> propertyNames; 285 Vector<String> propertyNames;
219 options.getPropertyNames(propertyNames); 286 options.getPropertyNames(propertyNames);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 471
405 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); 472 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState);
406 if (exceptionState.hadException()) 473 if (exceptionState.hadException())
407 return; 474 return;
408 475
409 bool valid = m_peerHandler->updateICE(configuration, constraints); 476 bool valid = m_peerHandler->updateICE(configuration, constraints);
410 if (!valid) 477 if (!valid)
411 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); 478 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration.");
412 } 479 }
413 480
481 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c onst Dictionary& keygenAlgorithm, ExceptionState& exceptionState)
482 {
483 // Validate and interpret input |keygenAlgorithm|.
484 // The value |keyType| corresponds to the rtc::KeyType in libjingle.
485 blink::Nullable<blink::WebRTCKeyType> keyType;
486 String name;
487 if (DictionaryHelper::get(keygenAlgorithm, "name", name)) {
488 if (name == "RSASSA-PKCS1-v1_5") {
489 // RSA - Supported |keygenAlgorithm|:
490 // { name: "RSASSA-PKCS1-v1_5", modulusLength: <int>, publicExponent : 65537 }
491 // Where 1024 <= modulusLength <= 8192. This is a somewhat arbitrary
492 // restriction. The idea is that less than 1024 is unsafe and
493 // greater than 8192 is unreasonably large and slow.
494 int modulusLength = -1;
495 DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusLengt h);
496 int publicExponent = -1;
497 DictionaryHelper::get(keygenAlgorithm, "publicExponent", publicExpon ent);
498 if (modulusLength >= 1024 && modulusLength <= 8192 && publicExponent == 65537) {
499 keyType.set(blink::WebRTCKeyType::createRSA(modulusLength));
500 }
501 } else if (name == "ECDSA") {
502 // ECDSA - Supported |keygenAlgorithm|:
503 // { name: "ECDSA", namedCurve: "P-256" }
504 String namedCurve;
505 DictionaryHelper::get(keygenAlgorithm, "namedCurve", namedCurve);
506 if (namedCurve == "P-256") {
507 keyType.set(blink::WebRTCKeyType::createECDSA());
508 }
509 }
510 }
511 if (keyType.isNull()) {
512 // Invalid argument.
513 return ScriptPromise::rejectWithDOMException(
514 scriptState, DOMException::create(InvalidAccessError, ExceptionMessa ges::argumentNullOrIncorrectType(1, "AlgorithmIdentifier")));
515 }
516
517 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
518 ScriptPromise promise = resolver->promise();
519
520 WebRTCCertificateObserver* certificateObserver = WebRTCCertificateObserver:: Create(resolver);
521
522 // Generate certificate. The |certificateObserver| will resolve the promise asynchronously upon generate completion.
523 // The observer will manage its own and the resolver's destruction as well.
524 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr(
525 Platform::current()->createRTCCertificateGenerator());
526 certificateGenerator->generateCertificate(
527 keyType.get(),
528 toDocument(scriptState->executionContext())->url(),
529 toDocument(scriptState->executionContext())->firstPartyForCookies(),
530 certificateObserver);
531
532 return promise;
533 }
534
414 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) 535 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState)
415 { 536 {
416 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 537 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
417 return; 538 return;
418 539
419 if (!iceCandidate) { 540 if (!iceCandidate) {
420 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); 541 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate"));
421 return; 542 return;
422 } 543 }
423 544
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 { 968 {
848 visitor->trace(m_localStreams); 969 visitor->trace(m_localStreams);
849 visitor->trace(m_remoteStreams); 970 visitor->trace(m_remoteStreams);
850 visitor->trace(m_dataChannels); 971 visitor->trace(m_dataChannels);
851 visitor->trace(m_scheduledEvents); 972 visitor->trace(m_scheduledEvents);
852 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); 973 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor);
853 ActiveDOMObject::trace(visitor); 974 ActiveDOMObject::trace(visitor);
854 } 975 }
855 976
856 } // namespace blink 977 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698