diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 4761ab697f2..0c2911450d9 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -4,17 +4,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsSocketTransportService2.h" +#if !defined(MOZILLA_XPCOMRT_API) #include "nsSocketTransport2.h" +#include "NetworkActivityMonitor.h" +#include "mozilla/Preferences.h" +#endif // !defined(MOZILLA_XPCOMRT_API) +#include "nsASocketHandler.h" #include "nsError.h" #include "prnetdb.h" #include "prerror.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" #include "nsServiceManagerUtils.h" -#include "NetworkActivityMonitor.h" #include "nsIObserverService.h" #include "mozilla/Services.h" -#include "mozilla/Preferences.h" #include "mozilla/Likely.h" #include "mozilla/PublicSSL.h" #include "mozilla/ChaosMode.h" @@ -560,7 +563,9 @@ nsSocketTransportService::Shutdown() obsSvc->RemoveObserver(this, "last-pb-context-exited"); } +#if !defined(MOZILLA_XPCOMRT_API) mozilla::net::NetworkActivityMonitor::Shutdown(); +#endif // !defined(MOZILLA_XPCOMRT_API) mInitialized = false; mShuttingDown = false; @@ -634,6 +639,10 @@ nsSocketTransportService::CreateTransport(const char **types, nsIProxyInfo *proxyInfo, 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(port >= 0 && port <= 0xFFFF, NS_ERROR_ILLEGAL_VALUE); @@ -645,12 +654,17 @@ nsSocketTransportService::CreateTransport(const char **types, trans.forget(result); return NS_OK; +#endif // defined(MOZILLA_XPCOMRT_API) } NS_IMETHODIMP nsSocketTransportService::CreateUnixDomainTransport(nsIFile *aPath, nsISocketTransport **result) { +#if defined(MOZILLA_XPCOMRT_API) + NS_WARNING("nsSocketTransportService::CreateUnixDomainTransport not implemented"); + return NS_ERROR_NOT_IMPLEMENTED; +#else nsresult rv; NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED); @@ -668,6 +682,7 @@ nsSocketTransportService::CreateUnixDomainTransport(nsIFile *aPath, trans.forget(result); return NS_OK; +#endif // defined(MOZILLA_XPCOMRT_API) } NS_IMETHODIMP @@ -732,7 +747,9 @@ nsSocketTransportService::Run() SOCKET_LOG(("STS thread init\n")); +#if !defined(MOZILLA_XPCOMRT_API) psm::InitializeSSLServerCertVerificationThreads(); +#endif // !defined(MOZILLA_XPCOMRT_API) gSocketThread = PR_GetCurrentThread(); @@ -901,7 +918,9 @@ nsSocketTransportService::Run() gSocketThread = nullptr; +#if !defined(MOZILLA_XPCOMRT_API) psm::StopSSLServerCertVerificationThreads(); +#endif // !defined(MOZILLA_XPCOMRT_API) SOCKET_LOG(("STS thread exit\n")); return NS_OK; @@ -1085,6 +1104,10 @@ nsSocketTransportService::DoPollIteration(bool wait, TimeDuration *pollDuration) nsresult nsSocketTransportService::UpdatePrefs() { +#if defined(MOZILLA_XPCOMRT_API) + NS_WARNING("nsSocketTransportService::UpdatePrefs not implemented"); + return NS_ERROR_NOT_IMPLEMENTED; +#else mSendBufferSize = 0; nsCOMPtr tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID); @@ -1146,6 +1169,7 @@ nsSocketTransportService::UpdatePrefs() } return NS_OK; +#endif // defined(MOZILLA_XPCOMRT_API) } void @@ -1190,6 +1214,7 @@ nsSocketTransportService::Observe(nsISupports *subject, const char *topic, const char16_t *data) { +#if !defined(MOZILLA_XPCOMRT_API) if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { UpdatePrefs(); return NS_OK; @@ -1203,6 +1228,7 @@ nsSocketTransportService::Observe(nsISupports *subject, return net::NetworkActivityMonitor::Init(blipInterval); } +#endif // !defined(MOZILLA_XPCOMRT_API) if (!strcmp(topic, "last-pb-context-exited")) { nsCOMPtr ev = @@ -1236,7 +1262,9 @@ nsSocketTransportService::ClosePrivateConnections() } } +#if !defined(MOZILLA_XPCOMRT_API) mozilla::ClearPrivateSSLState(); +#endif // !defined(MOZILLA_XPCOMRT_API) } NS_IMETHODIMP diff --git a/netwerk/base/nsURLHelper.cpp b/netwerk/base/nsURLHelper.cpp index ea88126b7f0..7692a26a5c6 100644 --- a/netwerk/base/nsURLHelper.cpp +++ b/netwerk/base/nsURLHelper.cpp @@ -53,8 +53,10 @@ InitGlobals() } gInitialized = true; +#if !defined(MOZILLA_XPCOMRT_API) Preferences::AddIntVarCache(&gMaxLength, "network.standard-url.max-length", 1048576); +#endif } void @@ -107,6 +109,10 @@ net_GetStdURLParser() nsresult 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; nsresult rv = net_GetURLSpecFromActualFile(aFile, escPath); if (NS_FAILED(rv)) @@ -118,11 +124,16 @@ net_GetURLSpecFromDir(nsIFile *aFile, nsACString &result) result = escPath; return NS_OK; +#endif // defined(MOZILLA_XPCOMRT_API) } nsresult 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; nsresult rv = net_GetURLSpecFromActualFile(aFile, escPath); if (NS_FAILED(rv)) @@ -142,6 +153,7 @@ net_GetURLSpecFromFile(nsIFile *aFile, nsACString &result) result = escPath; return NS_OK; +#endif // defined(MOZILLA_XPCOMRT_API) } //---------------------------------------------------------------------------- diff --git a/netwerk/dns/nsDNSService2.cpp b/netwerk/dns/nsDNSService2.cpp index 1990567b3d4..21a181206bc 100644 --- a/netwerk/dns/nsDNSService2.cpp +++ b/netwerk/dns/nsDNSService2.cpp @@ -36,7 +36,9 @@ #include "mozilla/Attributes.h" #include "mozilla/VisualEventTracer.h" #include "mozilla/net/NeckoCommon.h" +#if !defined(MOZILLA_XPCOMRT_API) #include "mozilla/net/ChildDNSService.h" +#endif // !defined(MOZILLA_XPCOMRT_API) #include "mozilla/net/DNSListenerProxy.h" #include "mozilla/Services.h" @@ -502,9 +504,11 @@ static nsDNSService *gDNSService; nsIDNSService* nsDNSService::GetXPCOMSingleton() { +#if !defined(MOZILLA_XPCOMRT_API) if (IsNeckoChild()) { return ChildDNSService::GetSingleton(); } +#endif // !defined(MOZILLA_XPCOMRT_API) return GetSingleton(); } @@ -640,7 +644,9 @@ nsDNSService::Init() } } +#if !defined(MOZILLA_XPCOMRT_API) RegisterWeakMemoryReporter(this); +#endif // !defined(MOZILLA_XPCOMRT_API) return rv; } @@ -648,7 +654,9 @@ nsDNSService::Init() NS_IMETHODIMP nsDNSService::Shutdown() { +#if !defined(MOZILLA_XPCOMRT_API) UnregisterWeakMemoryReporter(this); +#endif // !defined(MOZILLA_XPCOMRT_API) nsRefPtr res; { diff --git a/netwerk/moz.build b/netwerk/moz.build index a5e732bcd47..3cf12a5a9d6 100644 --- a/netwerk/moz.build +++ b/netwerk/moz.build @@ -16,6 +16,7 @@ DIRS += [ 'protocol', 'system', 'ipc', + 'standalone', ] if CONFIG['MOZ_SRTP']: diff --git a/netwerk/standalone/moz.build b/netwerk/standalone/moz.build new file mode 100644 index 00000000000..112a07ded90 --- /dev/null +++ b/netwerk/standalone/moz.build @@ -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') diff --git a/netwerk/standalone/nsNetModuleStandalone.cpp b/netwerk/standalone/nsNetModuleStandalone.cpp new file mode 100644 index 00000000000..82dfe61840d --- /dev/null +++ b/netwerk/standalone/nsNetModuleStandalone.cpp @@ -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 dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + mozilla::DebugOnly rv = dns->Init(); + NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service init failed"); + } else { + NS_WARNING("failed to get dns service"); + } + + nsCOMPtr sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + mozilla::DebugOnly 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 dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + mozilla::DebugOnly rv = dns->Shutdown(); + NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service shutdown failed"); + } else { + NS_WARNING("failed to get dns service"); + } + + nsCOMPtr sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + mozilla::DebugOnly 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 +}; diff --git a/netwerk/standalone/nsNetModuleStandalone.h b/netwerk/standalone/nsNetModuleStandalone.h new file mode 100644 index 00000000000..6e59cef4eae --- /dev/null +++ b/netwerk/standalone/nsNetModuleStandalone.h @@ -0,0 +1,13 @@ +#ifndef ns_net_module_standalone_h_ +#define ns_net_module_standalone_h_ + +#include + +namespace mozilla { + +nsresult InitNetModuleStandalone(); +nsresult ShutdownNetModuleStandalone(); + +} + +#endif // ns_net_module_standalone_h_ diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index 0589a1b7e6f..558aedb4747 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -396,6 +396,7 @@ nsComponentManagerImpl::Init() #if defined(MOZILLA_XPCOMRT_API) RegisterModule(&kXPCOMRTModule, nullptr); + RegisterModule(&kNeckoStandaloneModule, nullptr); #else RegisterModule(&kXPCOMModule, nullptr); #endif // defined(MOZILLA_XPCOMRT_API) diff --git a/xpcom/components/nsComponentManager.h b/xpcom/components/nsComponentManager.h index 35d3d26b043..55ae55751db 100644 --- a/xpcom/components/nsComponentManager.h +++ b/xpcom/components/nsComponentManager.h @@ -69,6 +69,7 @@ extern const char staticComponentType[]; #if defined(MOZILLA_XPCOMRT_API) extern const mozilla::Module kXPCOMRTModule; +extern const mozilla::Module kNeckoStandaloneModule; #else extern const mozilla::Module kXPCOMModule; #endif diff --git a/xpcom/libxpcomrt/XPCOMRTInit.cpp b/xpcom/libxpcomrt/XPCOMRTInit.cpp index 5bdb8bb8052..53c15634e20 100644 --- a/xpcom/libxpcomrt/XPCOMRTInit.cpp +++ b/xpcom/libxpcomrt/XPCOMRTInit.cpp @@ -13,6 +13,8 @@ #include "nsDebugImpl.h" #include "nsIErrorService.h" #include "nsMemoryImpl.h" +#include "nsNetCID.h" +#include "nsNetModuleStandalone.h" #include "nsObserverService.h" #include "nsThreadManager.h" #include "nsThreadPool.h" @@ -98,6 +100,8 @@ NS_InitXPCOMRT() return rv; } + mozilla::InitNetModuleStandalone(); + return NS_OK; } @@ -152,6 +156,11 @@ NS_ShutdownXPCOMRT() 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 // all threads created using the thread manager (with the exception of // the main thread) have exited. diff --git a/xpcom/libxpcomrt/moz.build b/xpcom/libxpcomrt/moz.build index 2ad8dfea607..48c784727ed 100644 --- a/xpcom/libxpcomrt/moz.build +++ b/xpcom/libxpcomrt/moz.build @@ -141,6 +141,7 @@ LOCAL_INCLUDES = [ '../ds', '../glue', '../threads', + '/netwerk/standalone/', '/xpcom/reflect/xptinfo/', ]