Bug 1097804 - Part 1 - Create a library containing nsISocketTransportService and nsIDNS that can be used to support standalone WebRTC. r=mcmanus

This commit is contained in:
Randall Barker 2015-04-03 15:54:00 +02:00
parent 5c28632032
commit ef733d24e8
11 changed files with 247 additions and 2 deletions

View File

@ -4,17 +4,20 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsSocketTransportService2.h" #include "nsSocketTransportService2.h"
#if !defined(MOZILLA_XPCOMRT_API)
#include "nsSocketTransport2.h" #include "nsSocketTransport2.h"
#include "NetworkActivityMonitor.h"
#include "mozilla/Preferences.h"
#endif // !defined(MOZILLA_XPCOMRT_API)
#include "nsASocketHandler.h"
#include "nsError.h" #include "nsError.h"
#include "prnetdb.h" #include "prnetdb.h"
#include "prerror.h" #include "prerror.h"
#include "nsIPrefService.h" #include "nsIPrefService.h"
#include "nsIPrefBranch.h" #include "nsIPrefBranch.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "NetworkActivityMonitor.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "mozilla/Preferences.h"
#include "mozilla/Likely.h" #include "mozilla/Likely.h"
#include "mozilla/PublicSSL.h" #include "mozilla/PublicSSL.h"
#include "mozilla/ChaosMode.h" #include "mozilla/ChaosMode.h"
@ -560,7 +563,9 @@ nsSocketTransportService::Shutdown()
obsSvc->RemoveObserver(this, "last-pb-context-exited"); obsSvc->RemoveObserver(this, "last-pb-context-exited");
} }
#if !defined(MOZILLA_XPCOMRT_API)
mozilla::net::NetworkActivityMonitor::Shutdown(); mozilla::net::NetworkActivityMonitor::Shutdown();
#endif // !defined(MOZILLA_XPCOMRT_API)
mInitialized = false; mInitialized = false;
mShuttingDown = false; mShuttingDown = false;
@ -634,6 +639,10 @@ nsSocketTransportService::CreateTransport(const char **types,
nsIProxyInfo *proxyInfo, nsIProxyInfo *proxyInfo,
nsISocketTransport **result) nsISocketTransport **result)
{ {
#if defined(MOZILLA_XPCOMRT_API)
NS_WARNING("nsSocketTransportService::CreateTransport not implemented");
return NS_ERROR_NOT_IMPLEMENTED;
#else
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
NS_ENSURE_TRUE(port >= 0 && port <= 0xFFFF, NS_ERROR_ILLEGAL_VALUE); NS_ENSURE_TRUE(port >= 0 && port <= 0xFFFF, NS_ERROR_ILLEGAL_VALUE);
@ -645,12 +654,17 @@ nsSocketTransportService::CreateTransport(const char **types,
trans.forget(result); trans.forget(result);
return NS_OK; return NS_OK;
#endif // defined(MOZILLA_XPCOMRT_API)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransportService::CreateUnixDomainTransport(nsIFile *aPath, nsSocketTransportService::CreateUnixDomainTransport(nsIFile *aPath,
nsISocketTransport **result) nsISocketTransport **result)
{ {
#if defined(MOZILLA_XPCOMRT_API)
NS_WARNING("nsSocketTransportService::CreateUnixDomainTransport not implemented");
return NS_ERROR_NOT_IMPLEMENTED;
#else
nsresult rv; nsresult rv;
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
@ -668,6 +682,7 @@ nsSocketTransportService::CreateUnixDomainTransport(nsIFile *aPath,
trans.forget(result); trans.forget(result);
return NS_OK; return NS_OK;
#endif // defined(MOZILLA_XPCOMRT_API)
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -732,7 +747,9 @@ nsSocketTransportService::Run()
SOCKET_LOG(("STS thread init\n")); SOCKET_LOG(("STS thread init\n"));
#if !defined(MOZILLA_XPCOMRT_API)
psm::InitializeSSLServerCertVerificationThreads(); psm::InitializeSSLServerCertVerificationThreads();
#endif // !defined(MOZILLA_XPCOMRT_API)
gSocketThread = PR_GetCurrentThread(); gSocketThread = PR_GetCurrentThread();
@ -901,7 +918,9 @@ nsSocketTransportService::Run()
gSocketThread = nullptr; gSocketThread = nullptr;
#if !defined(MOZILLA_XPCOMRT_API)
psm::StopSSLServerCertVerificationThreads(); psm::StopSSLServerCertVerificationThreads();
#endif // !defined(MOZILLA_XPCOMRT_API)
SOCKET_LOG(("STS thread exit\n")); SOCKET_LOG(("STS thread exit\n"));
return NS_OK; return NS_OK;
@ -1085,6 +1104,10 @@ nsSocketTransportService::DoPollIteration(bool wait, TimeDuration *pollDuration)
nsresult nsresult
nsSocketTransportService::UpdatePrefs() nsSocketTransportService::UpdatePrefs()
{ {
#if defined(MOZILLA_XPCOMRT_API)
NS_WARNING("nsSocketTransportService::UpdatePrefs not implemented");
return NS_ERROR_NOT_IMPLEMENTED;
#else
mSendBufferSize = 0; mSendBufferSize = 0;
nsCOMPtr<nsIPrefBranch> tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID); nsCOMPtr<nsIPrefBranch> tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
@ -1146,6 +1169,7 @@ nsSocketTransportService::UpdatePrefs()
} }
return NS_OK; return NS_OK;
#endif // defined(MOZILLA_XPCOMRT_API)
} }
void void
@ -1190,6 +1214,7 @@ nsSocketTransportService::Observe(nsISupports *subject,
const char *topic, const char *topic,
const char16_t *data) const char16_t *data)
{ {
#if !defined(MOZILLA_XPCOMRT_API)
if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
UpdatePrefs(); UpdatePrefs();
return NS_OK; return NS_OK;
@ -1203,6 +1228,7 @@ nsSocketTransportService::Observe(nsISupports *subject,
return net::NetworkActivityMonitor::Init(blipInterval); return net::NetworkActivityMonitor::Init(blipInterval);
} }
#endif // !defined(MOZILLA_XPCOMRT_API)
if (!strcmp(topic, "last-pb-context-exited")) { if (!strcmp(topic, "last-pb-context-exited")) {
nsCOMPtr<nsIRunnable> ev = nsCOMPtr<nsIRunnable> ev =
@ -1236,7 +1262,9 @@ nsSocketTransportService::ClosePrivateConnections()
} }
} }
#if !defined(MOZILLA_XPCOMRT_API)
mozilla::ClearPrivateSSLState(); mozilla::ClearPrivateSSLState();
#endif // !defined(MOZILLA_XPCOMRT_API)
} }
NS_IMETHODIMP NS_IMETHODIMP

View File

@ -53,8 +53,10 @@ InitGlobals()
} }
gInitialized = true; gInitialized = true;
#if !defined(MOZILLA_XPCOMRT_API)
Preferences::AddIntVarCache(&gMaxLength, Preferences::AddIntVarCache(&gMaxLength,
"network.standard-url.max-length", 1048576); "network.standard-url.max-length", 1048576);
#endif
} }
void void
@ -107,6 +109,10 @@ net_GetStdURLParser()
nsresult nsresult
net_GetURLSpecFromDir(nsIFile *aFile, nsACString &result) net_GetURLSpecFromDir(nsIFile *aFile, nsACString &result)
{ {
#if defined(MOZILLA_XPCOMRT_API)
NS_WARNING("net_GetURLSpecFromDir not implemented");
return NS_ERROR_NOT_IMPLEMENTED;
#else
nsAutoCString escPath; nsAutoCString escPath;
nsresult rv = net_GetURLSpecFromActualFile(aFile, escPath); nsresult rv = net_GetURLSpecFromActualFile(aFile, escPath);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
@ -118,11 +124,16 @@ net_GetURLSpecFromDir(nsIFile *aFile, nsACString &result)
result = escPath; result = escPath;
return NS_OK; return NS_OK;
#endif // defined(MOZILLA_XPCOMRT_API)
} }
nsresult nsresult
net_GetURLSpecFromFile(nsIFile *aFile, nsACString &result) net_GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
{ {
#if defined(MOZILLA_XPCOMRT_API)
NS_WARNING("net_GetURLSpecFromFile not implemented");
return NS_ERROR_NOT_IMPLEMENTED;
#else
nsAutoCString escPath; nsAutoCString escPath;
nsresult rv = net_GetURLSpecFromActualFile(aFile, escPath); nsresult rv = net_GetURLSpecFromActualFile(aFile, escPath);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
@ -142,6 +153,7 @@ net_GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
result = escPath; result = escPath;
return NS_OK; return NS_OK;
#endif // defined(MOZILLA_XPCOMRT_API)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -36,7 +36,9 @@
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/VisualEventTracer.h" #include "mozilla/VisualEventTracer.h"
#include "mozilla/net/NeckoCommon.h" #include "mozilla/net/NeckoCommon.h"
#if !defined(MOZILLA_XPCOMRT_API)
#include "mozilla/net/ChildDNSService.h" #include "mozilla/net/ChildDNSService.h"
#endif // !defined(MOZILLA_XPCOMRT_API)
#include "mozilla/net/DNSListenerProxy.h" #include "mozilla/net/DNSListenerProxy.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
@ -502,9 +504,11 @@ static nsDNSService *gDNSService;
nsIDNSService* nsIDNSService*
nsDNSService::GetXPCOMSingleton() nsDNSService::GetXPCOMSingleton()
{ {
#if !defined(MOZILLA_XPCOMRT_API)
if (IsNeckoChild()) { if (IsNeckoChild()) {
return ChildDNSService::GetSingleton(); return ChildDNSService::GetSingleton();
} }
#endif // !defined(MOZILLA_XPCOMRT_API)
return GetSingleton(); return GetSingleton();
} }
@ -640,7 +644,9 @@ nsDNSService::Init()
} }
} }
#if !defined(MOZILLA_XPCOMRT_API)
RegisterWeakMemoryReporter(this); RegisterWeakMemoryReporter(this);
#endif // !defined(MOZILLA_XPCOMRT_API)
return rv; return rv;
} }
@ -648,7 +654,9 @@ nsDNSService::Init()
NS_IMETHODIMP NS_IMETHODIMP
nsDNSService::Shutdown() nsDNSService::Shutdown()
{ {
#if !defined(MOZILLA_XPCOMRT_API)
UnregisterWeakMemoryReporter(this); UnregisterWeakMemoryReporter(this);
#endif // !defined(MOZILLA_XPCOMRT_API)
nsRefPtr<nsHostResolver> res; nsRefPtr<nsHostResolver> res;
{ {

View File

@ -16,6 +16,7 @@ DIRS += [
'protocol', 'protocol',
'system', 'system',
'ipc', 'ipc',
'standalone',
] ]
if CONFIG['MOZ_SRTP']: if CONFIG['MOZ_SRTP']:

View File

@ -0,0 +1,53 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
if CONFIG['OS_TARGET'] != 'WINNT' and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
Library('necko_standalone')
src_list = [
'nsNetModuleStandalone.cpp',
]
netwerk_base_src = [
'nsDNSPrefetch.cpp',
'nsNetAddr.cpp',
'nsSocketTransportService2.cpp',
'nsURLHelper.cpp',
]
src_list += [
'%s/netwerk/base/%s' % (TOPSRCDIR, s) for s in netwerk_base_src
]
netwerk_dns_src = [
'nsHostResolver.cpp',
'DNS.cpp',
'DNSListenerProxy.cpp',
'GetAddrInfo.cpp',
'nameprep.c',
'nsDNSService2.cpp',
'nsIDNService.cpp',
'punycode.c',
'race.c',
]
src_list += [
'%s/netwerk/dns/%s' % (TOPSRCDIR, s) for s in netwerk_dns_src
]
SOURCES += sorted(src_list)
FAIL_ON_WARNINGS = True
LOCAL_INCLUDES = [
'../base',
'../build',
'../dns',
]
DEFINES['MOZILLA_INTERNAL_API'] = True
DEFINES['MOZILLA_XPCOMRT_API'] = True
DEFINES['MOZILLA_EXTERNAL_LINKAGE'] = True
include('/ipc/chromium/chromium-config.mozbuild')

View File

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "necko-config.h"
#include "mozilla/ModuleUtils.h"
#include "mozilla/DebugOnly.h"
#include "nsCOMPtr.h"
#include "nsICategoryManager.h"
#include "nsIClassInfoImpl.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsNetCID.h"
#include "nsPIDNSService.h"
#include "nsPISocketTransportService.h"
#include "nscore.h"
extern const mozilla::Module kNeckoStandaloneModule;
namespace mozilla {
nsresult
InitNetModuleStandalone()
{
nsresult rv;
nsCOMPtr<nsPIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
mozilla::DebugOnly<nsresult> rv = dns->Init();
NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service init failed");
} else {
NS_WARNING("failed to get dns service");
}
nsCOMPtr<nsPISocketTransportService> sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
mozilla::DebugOnly<nsresult> rv = sts->Init();
NS_ASSERTION(NS_SUCCEEDED(rv), "Socket transport service init failed");
} else {
NS_WARNING("failed to get socket transport service");
}
return NS_OK;
}
nsresult
ShutdownNetModuleStandalone()
{
nsresult rv;
nsCOMPtr<nsPIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
mozilla::DebugOnly<nsresult> rv = dns->Shutdown();
NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service shutdown failed");
} else {
NS_WARNING("failed to get dns service");
}
nsCOMPtr<nsPISocketTransportService> sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
mozilla::DebugOnly<nsresult> rv = sts->Shutdown();
NS_ASSERTION(NS_SUCCEEDED(rv), "Socket transport service shutdown failed");
} else {
NS_WARNING("failed to get socket transport service");
}
return NS_OK;
}
} // namespace mozilla
#include "nsDNSService2.h"
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDNSService,
nsDNSService::GetXPCOMSingleton)
#include "nsSocketTransportService2.h"
#undef LOG
#undef LOG_ENABLED
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSocketTransportService, Init)
// Net module startup hook
static nsresult nsNetStartup()
{
return NS_OK;
}
// Net module shutdown hook
static void nsNetShutdown()
{
}
NS_DEFINE_NAMED_CID(NS_SOCKETTRANSPORTSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_DNSSERVICE_CID);
static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_SOCKETTRANSPORTSERVICE_CID, false, nullptr, nsSocketTransportServiceConstructor },
{ &kNS_DNSSERVICE_CID, false, nullptr, nsIDNSServiceConstructor },
{ nullptr }
};
static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
{ NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &kNS_SOCKETTRANSPORTSERVICE_CID },
{ NS_DNSSERVICE_CONTRACTID, &kNS_DNSSERVICE_CID },
{ nullptr }
};
const mozilla::Module kNeckoStandaloneModule = {
mozilla::Module::kVersion,
kNeckoCIDs,
kNeckoContracts,
nullptr,
nullptr,
nsNetStartup,
nsNetShutdown
};

View File

@ -0,0 +1,13 @@
#ifndef ns_net_module_standalone_h_
#define ns_net_module_standalone_h_
#include <nsError.h>
namespace mozilla {
nsresult InitNetModuleStandalone();
nsresult ShutdownNetModuleStandalone();
}
#endif // ns_net_module_standalone_h_

View File

@ -396,6 +396,7 @@ nsComponentManagerImpl::Init()
#if defined(MOZILLA_XPCOMRT_API) #if defined(MOZILLA_XPCOMRT_API)
RegisterModule(&kXPCOMRTModule, nullptr); RegisterModule(&kXPCOMRTModule, nullptr);
RegisterModule(&kNeckoStandaloneModule, nullptr);
#else #else
RegisterModule(&kXPCOMModule, nullptr); RegisterModule(&kXPCOMModule, nullptr);
#endif // defined(MOZILLA_XPCOMRT_API) #endif // defined(MOZILLA_XPCOMRT_API)

View File

@ -69,6 +69,7 @@ extern const char staticComponentType[];
#if defined(MOZILLA_XPCOMRT_API) #if defined(MOZILLA_XPCOMRT_API)
extern const mozilla::Module kXPCOMRTModule; extern const mozilla::Module kXPCOMRTModule;
extern const mozilla::Module kNeckoStandaloneModule;
#else #else
extern const mozilla::Module kXPCOMModule; extern const mozilla::Module kXPCOMModule;
#endif #endif

View File

@ -13,6 +13,8 @@
#include "nsDebugImpl.h" #include "nsDebugImpl.h"
#include "nsIErrorService.h" #include "nsIErrorService.h"
#include "nsMemoryImpl.h" #include "nsMemoryImpl.h"
#include "nsNetCID.h"
#include "nsNetModuleStandalone.h"
#include "nsObserverService.h" #include "nsObserverService.h"
#include "nsThreadManager.h" #include "nsThreadManager.h"
#include "nsThreadPool.h" #include "nsThreadPool.h"
@ -98,6 +100,8 @@ NS_InitXPCOMRT()
return rv; return rv;
} }
mozilla::InitNetModuleStandalone();
return NS_OK; return NS_OK;
} }
@ -152,6 +156,11 @@ NS_ShutdownXPCOMRT()
NS_ProcessPendingEvents(thread); NS_ProcessPendingEvents(thread);
// Net module needs to be shutdown before the thread manager or else
// the thread manager will hang waiting for the socket transport
// service to shutdown.
mozilla::ShutdownNetModuleStandalone();
// Shutdown all remaining threads. This method does not return until // Shutdown all remaining threads. This method does not return until
// all threads created using the thread manager (with the exception of // all threads created using the thread manager (with the exception of
// the main thread) have exited. // the main thread) have exited.

View File

@ -141,6 +141,7 @@ LOCAL_INCLUDES = [
'../ds', '../ds',
'../glue', '../glue',
'../threads', '../threads',
'/netwerk/standalone/',
'/xpcom/reflect/xptinfo/', '/xpcom/reflect/xptinfo/',
] ]