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

Unified 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: Addressed nits + Pass webkit_tests (updated global-interface-listing-expected.txt) 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp
diff --git a/third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp b/third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp
index 8fcfb151c7501c01ccecb154045756c3262678ec..c9af5f09d2d08270715fce5f89b8b66431ec07f0 100644
--- a/third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp
+++ b/third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp
@@ -34,6 +34,9 @@
#include "bindings/core/v8/ArrayValue.h"
#include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/Nullable.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "bindings/modules/v8/V8RTCCertificate.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
@@ -58,10 +61,13 @@
#include "platform/mediastream/RTCOfferOptions.h"
#include "public/platform/Platform.h"
#include "public/platform/WebMediaStream.h"
+#include "public/platform/WebRTCCertificate.h"
+#include "public/platform/WebRTCCertificateGenerator.h"
#include "public/platform/WebRTCConfiguration.h"
#include "public/platform/WebRTCDataChannelHandler.h"
#include "public/platform/WebRTCDataChannelInit.h"
#include "public/platform/WebRTCICECandidate.h"
+#include "public/platform/WebRTCKeyParams.h"
#include "public/platform/WebRTCOfferOptions.h"
#include "public/platform/WebRTCSessionDescription.h"
#include "public/platform/WebRTCSessionDescriptionRequest.h"
@@ -82,6 +88,40 @@ static bool throwExceptionIfSignalingStateClosed(RTCPeerConnection::SignalingSta
return false;
}
+// Helper class for RTCPeerConnection::generateCertificate.
+class WebRTCCertificateObserver : public WebCallbacks<WebRTCCertificate*, void> {
+public:
+ // The created observer is responsible for deleting itself after onSuccess/onError. To avoid memory
+ // leak the observer should therefore be used in a WebRTCCertificateGenerator::generateCertificate call
+ // which is ensured to invoke one of these. Takes ownership of |resolver|.
+ static WebRTCCertificateObserver* Create(ScriptPromiseResolver* resolver)
jochen (gone - plz use gerrit) 2015/10/20 12:27:35 blink coding style would be "create"
hbos_chromium 2015/10/20 15:42:23 Done.
+ {
+ return new WebRTCCertificateObserver(resolver);
+ }
+
+ DEFINE_INLINE_TRACE() { visitor->trace(m_resolver); }
+
+private:
+ WebRTCCertificateObserver(ScriptPromiseResolver* resolver)
+ : m_resolver(resolver) {}
+
+ ~WebRTCCertificateObserver() override {}
+
+ void onSuccess(WebRTCCertificate* certificate) override
+ {
+ m_resolver->resolve(new RTCCertificate(certificate));
+ delete this;
+ }
+
+ void onError() override
+ {
+ m_resolver->reject();
+ delete this;
+ }
+
+ Persistent<ScriptPromiseResolver> m_resolver;
+};
+
} // namespace
RTCConfiguration* RTCPeerConnection::parseConfiguration(const Dictionary& configuration, ExceptionState& exceptionState)
@@ -207,6 +247,29 @@ RTCConfiguration* RTCPeerConnection::parseConfiguration(const Dictionary& config
}
}
+ ArrayValue certificates;
+ if (DictionaryHelper::get(configuration, "certificates", certificates)
+ && !certificates.isUndefinedOrNull()) {
jochen (gone - plz use gerrit) 2015/10/20 12:27:35 no 80c line length limit in blink
hbos_chromium 2015/10/20 15:42:24 Done.
+ size_t numberOfCertificates;
+ certificates.length(numberOfCertificates);
+ for (size_t i = 0; i < numberOfCertificates; ++i) {
+ RTCCertificate* certificate = nullptr;
+
+ Dictionary dictCert;
+ certificates.get(i, dictCert);
+ v8::Local<v8::Value> valCert = dictCert.v8Value();
+ if (!valCert.IsEmpty()) {
+ certificate = V8RTCCertificate::toImplWithTypeCheck(configuration.isolate(), valCert);
+ }
+ if (!certificate) {
+ exceptionState.throwTypeError("Malformed sequence<RTCCertificate>");
+ return 0;
+ }
+
+ rtcConfiguration->appendCertificate(certificate->certificateShallowCopy());
+ }
+ }
+
return rtcConfiguration;
}
@@ -411,6 +474,66 @@ void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict
exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration.");
}
+ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, const Dictionary& keygenAlgorithm, ExceptionState& exceptionState)
+{
+ // Validate and interpret input |keygenAlgorithm|.
+ // TODO(hbos): Use WebCrypto normalization process to validate and interpret |keygenAlgorithm|.
+ // This may create a dependency between the Blink and WebCrypto modules? crbug.com/544917
+ Nullable<WebRTCKeyParams> keyParams;
+ String name;
+ if (DictionaryHelper::get(keygenAlgorithm, "name", name)) {
+ if (name == "RSASSA-PKCS1-v1_5") {
+ // RSA - Supported |keygenAlgorithm|:
+ // { name: "RSASSA-PKCS1-v1_5", modulusLength: <int>, publicExponent: 65537 }
+ int modulusLength = -1;
+ int publicExponent = -1;
+ if (DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusLength)
+ && modulusLength >= 0
+ && DictionaryHelper::get(keygenAlgorithm, "publicExponent", publicExponent)
+ && publicExponent >= 0) {
+ keyParams.set(blink::WebRTCKeyParams::createRSA(modulusLength, publicExponent));
+ }
+ } else if (name == "ECDSA") {
+ // ECDSA - Supported |keygenAlgorithm|:
+ // { name: "ECDSA", namedCurve: "P-256" }
+ String namedCurve;
+ DictionaryHelper::get(keygenAlgorithm, "namedCurve", namedCurve);
+ if (namedCurve == "P-256") {
+ keyParams.set(blink::WebRTCKeyParams::createECDSA(WebRTCECCurveNistP256));
+ }
+ }
+ }
+ if (keyParams.isNull()) {
+ // Invalid argument.
+ return ScriptPromise::rejectWithDOMException(
+ scriptState, DOMException::create(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "AlgorithmIdentifier")));
+ }
+
+ OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr(
+ Platform::current()->createRTCCertificateGenerator());
+
+ // Check validity of |keyParams|.
+ if (!certificateGenerator->isValidKeyParams(keyParams.get())) {
+ return ScriptPromise::rejectWithDOMException(
+ scriptState, DOMException::create(NotSupportedError, "The 1st argument provided is an AlgorithmIdentifier, but it has unsupported parameter values."));
+ }
+
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ WebRTCCertificateObserver* certificateObserver = WebRTCCertificateObserver::Create(resolver);
+
+ // Generate certificate. The |certificateObserver| will resolve the promise asynchronously upon completion.
+ // The observer will manage its own destruction as well as the resolver's destruction.
+ certificateGenerator->generateCertificate(
+ keyParams.get(),
+ toDocument(scriptState->executionContext())->url(),
+ toDocument(scriptState->executionContext())->firstPartyForCookies(),
+ certificateObserver);
+
+ return promise;
+}
+
void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, ExceptionState& exceptionState)
{
if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))

Powered by Google App Engine
This is Rietveld 408576698