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

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

Issue 1373023002: RTCCertificate, RTCPeerConnection.generateCertificate (WebRTC JavaScript) added. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make trybots compile (WebRTCCertificate not including wtf/Noncopyable) Created 5 years, 2 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/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
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)
252 && !certificates.isUndefinedOrNull()) {
253 size_t numberOfCertificates;
254 certificates.length(numberOfCertificates);
255 for (size_t i = 0; i < numberOfCertificates; ++i) {
256 RTCCertificate* certificate = nullptr;
257
258 Dictionary dictCert;
259 certificates.get(i, dictCert);
260 v8::Local<v8::Value> valCert = dictCert.v8Value();
261 if (!valCert.IsEmpty()) {
262 certificate = V8RTCCertificate::toImplWithTypeCheck(configuratio n.isolate(), valCert);
263 }
264 if (!certificate) {
265 exceptionState.throwTypeError("Malformed sequence<RTCCertificate >");
266 return 0;
267 }
268
269 rtcConfiguration->appendCertificate(certificate->certificateShallowC opy());
270 }
271 }
272
210 return rtcConfiguration; 273 return rtcConfiguration;
211 } 274 }
212 275
213 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState) 276 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState)
214 { 277 {
215 if (options.isUndefinedOrNull()) 278 if (options.isUndefinedOrNull())
216 return 0; 279 return 0;
217 280
218 Vector<String> propertyNames; 281 Vector<String> propertyNames;
219 options.getPropertyNames(propertyNames); 282 options.getPropertyNames(propertyNames);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 467
405 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); 468 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState);
406 if (exceptionState.hadException()) 469 if (exceptionState.hadException())
407 return; 470 return;
408 471
409 bool valid = m_peerHandler->updateICE(configuration, constraints); 472 bool valid = m_peerHandler->updateICE(configuration, constraints);
410 if (!valid) 473 if (!valid)
411 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); 474 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration.");
412 } 475 }
413 476
477 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c onst Dictionary& keygenAlgorithm, ExceptionState& exceptionState)
478 {
479 // Validate and interpret input |keygenAlgorithm|.
480 Nullable<WebRTCKeyParams> keyParams;
481 String name;
482 if (DictionaryHelper::get(keygenAlgorithm, "name", name)) {
483 if (name == "RSASSA-PKCS1-v1_5") {
484 // RSA - Supported |keygenAlgorithm|:
485 // { name: "RSASSA-PKCS1-v1_5", modulusLength: <int>, publicExponent : 65537 }
486 int modulusLength = -1;
487 int publicExponent = -1;
488 if (DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusL ength)
489 && DictionaryHelper::get(keygenAlgorithm, "publicExponent", publ icExponent)) {
490 keyParams.set(blink::WebRTCKeyParams::createRSA(modulusLength, p ublicExponent));
491 }
492 } else if (name == "ECDSA") {
493 // ECDSA - Supported |keygenAlgorithm|:
494 // { name: "ECDSA", namedCurve: "P-256" }
495 String namedCurve;
496 DictionaryHelper::get(keygenAlgorithm, "namedCurve", namedCurve);
497 if (namedCurve == "P-256") {
498 keyParams.set(blink::WebRTCKeyParams::createECDSA(WebRTCECCurveN istP256));
499 }
500 }
501 }
Ryan Sleevi 2015/10/10 04:04:48 Eric can comment, but I'm fairly certain that the
hbos_chromium 2015/10/14 13:00:50 You're right. The proper way to address this is to
502 if (keyParams.isNull()) {
503 // Invalid argument.
504 return ScriptPromise::rejectWithDOMException(
505 scriptState, DOMException::create(InvalidAccessError, ExceptionMessa ges::argumentNullOrIncorrectType(1, "AlgorithmIdentifier")));
506 }
507
508 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr(
509 Platform::current()->createRTCCertificateGenerator());
510
511 // Check validity of |keyParams|.
512 if (!certificateGenerator->isValidKeyParams(keyParams.get())) {
513 return ScriptPromise::rejectWithDOMException(
514 scriptState, DOMException::create(NotSupportedError, "The 1st argume nt provided is an AlgorithmIdentifier, but it has unsupported parameter values." ));
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 certificateGenerator->generateCertificate(
525 keyParams.get(),
526 toDocument(scriptState->executionContext())->url(),
527 toDocument(scriptState->executionContext())->firstPartyForCookies(),
528 certificateObserver);
529
530 return promise;
531 }
532
414 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) 533 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState)
415 { 534 {
416 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 535 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
417 return; 536 return;
418 537
419 if (!iceCandidate) { 538 if (!iceCandidate) {
420 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); 539 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate"));
421 return; 540 return;
422 } 541 }
423 542
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 { 966 {
848 visitor->trace(m_localStreams); 967 visitor->trace(m_localStreams);
849 visitor->trace(m_remoteStreams); 968 visitor->trace(m_remoteStreams);
850 visitor->trace(m_dataChannels); 969 visitor->trace(m_dataChannels);
851 visitor->trace(m_scheduledEvents); 970 visitor->trace(m_scheduledEvents);
852 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); 971 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor);
853 ActiveDOMObject::trace(visitor); 972 ActiveDOMObject::trace(visitor);
854 } 973 }
855 974
856 } // namespace blink 975 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698