From 4afedddb6b84a975a0c213292707147871ab4c49 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Mon, 22 Jul 2013 10:16:13 +0800 Subject: [PATCH] Bug 881761 - Part 3: Initialize NSS when initializing PeerConnection. r=ekr,bsmith --- .../src/peerconnection/PeerConnectionImpl.cpp | 59 +++++++++++++++++-- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp index f7abfc0536f..ac8a5c41e7a 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp @@ -45,6 +45,9 @@ #include "nsDOMDataChannel.h" #include "mozilla/TimeStamp.h" #include "mozilla/Telemetry.h" +#include "mozilla/PublicSSL.h" +#include "nsXULAppAPI.h" +#include "nsContentUtils.h" #include "nsDOMJSUtils.h" #include "nsIDocument.h" #include "nsIScriptError.h" @@ -81,9 +84,46 @@ using namespace mozilla::dom; typedef PCObserverString ObString; +static const char* logTag = "PeerConnectionImpl"; + +#ifdef MOZILLA_INTERNAL_API +static nsresult InitNSSInContent() +{ + NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_SAME_THREAD); + + if (XRE_GetProcessType() != GeckoProcessType_Content) { + MOZ_ASSUME_UNREACHABLE("Must be called in content process"); + } + + static bool nssStarted = false; + if (nssStarted) { + return NS_OK; + } + + if (NSS_NoDB_Init(nullptr) != SECSuccess) { + CSFLogError(logTag, "NSS_NoDB_Init failed."); + return NS_ERROR_FAILURE; + } + + if (NS_FAILED(mozilla::psm::InitializeCipherSuite())) { + CSFLogError(logTag, "Fail to set up nss cipher suite."); + return NS_ERROR_FAILURE; + } + + mozilla::psm::ConfigureMD5(false); + + nssStarted = true; + + return NS_OK; +} +#endif // MOZILLA_INTERNAL_API + +namespace mozilla { + class DataChannel; +} + class nsIDOMDataChannel; -static const char* logTag = "PeerConnectionImpl"; static const int DTLS_FINGERPRINT_LENGTH = 64; static const int MEDIA_STREAM_MUTE = 0x80; @@ -643,17 +683,24 @@ PeerConnectionImpl::Initialize(PeerConnectionObserver& aObserver, mSTSThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &res); MOZ_ASSERT(mSTSThread); - #ifdef MOZILLA_INTERNAL_API - // This code interferes with the C++ unit test startup code. - nsCOMPtr nssDummy = do_GetService("@mozilla.org/psm;1", &res); - NS_ENSURE_SUCCESS(res, res); + + // Initialize NSS if we are in content process. For chrome process, NSS should already + // been initialized. + if (XRE_GetProcessType() == GeckoProcessType_Default) { + // This code interferes with the C++ unit test startup code. + nsCOMPtr nssDummy = do_GetService("@mozilla.org/psm;1", &res); + NS_ENSURE_SUCCESS(res, res); + } else { + NS_ENSURE_SUCCESS(res = InitNSSInContent(), res); + } + // Currently no standalone unit tests for DataChannel, // which is the user of mWindow MOZ_ASSERT(aWindow); mWindow = aWindow; NS_ENSURE_STATE(mWindow); -#endif +#endif // MOZILLA_INTERNAL_API // Generate a random handle unsigned char handle_bin[8];