Bug 1501404 - Part 6: Remove the XPCOM registrations for socket provider classes r=valentin
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 23 Oct 2018 20:07:27 +0000
changeset 442629 1766ed669623dd83d791586c65a65a5a7d1097c0
parent 442628 79795a6721ccdafcaf4f68898240568047cdd18f
child 442630 89474459aeb8d21854d18c26822069d94625ea16
push id34916
push useraiakab@mozilla.com
push dateWed, 24 Oct 2018 04:14:42 +0000
treeherdermozilla-central@e61ca916da32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1501404
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1501404 - Part 6: Remove the XPCOM registrations for socket provider classes r=valentin Depends on D9574 Differential Revision: https://phabricator.services.mozilla.com/D9575
netwerk/build/nsNetCID.h
netwerk/build/nsNetModule.cpp
netwerk/socket/nsISocketProvider.idl
netwerk/socket/nsSocketProviderService.cpp
security/manager/ssl/moz.build
security/manager/ssl/nsNSSModule.cpp
--- a/netwerk/build/nsNetCID.h
+++ b/netwerk/build/nsNetCID.h
@@ -772,26 +772,16 @@
 #define NS_UDPSOCKETPROVIDER_CID                       \
 { /* 320706D2-2E81-42c6-89C3-8D83B17D3FB4 */           \
     0x320706d2,                                        \
     0x2e81,                                            \
     0x42c6,                                            \
     { 0x89, 0xc3, 0x8d, 0x83, 0xb1, 0x7d, 0x3f, 0xb4 } \
 }
 
-#define NS_SSLSOCKETPROVIDER_CONTRACTID \
-    NS_NETWORK_SOCKET_CONTRACTID_PREFIX "ssl"
-
-/* This code produces a normal socket which can be used to initiate the
- * STARTTLS protocol by calling its nsISSLSocketControl->StartTLS()
- */
-#define NS_STARTTLSSOCKETPROVIDER_CONTRACTID \
-    NS_NETWORK_SOCKET_CONTRACTID_PREFIX "starttls"
-
-
 #define NS_DASHBOARD_CONTRACTID \
     "@mozilla.org/network/dashboard;1"
 #define NS_DASHBOARD_CID                               \
 {   /*c79eb3c6-091a-45a6-8544-5a8d1ab79537 */          \
     0xc79eb3c6,                                        \
     0x091a,                                            \
     0x45a6,                                            \
     { 0x85, 0x44, 0x5a, 0x8d, 0x1a, 0xb7, 0x95, 0x37 } \
--- a/netwerk/build/nsNetModule.cpp
+++ b/netwerk/build/nsNetModule.cpp
@@ -81,19 +81,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsServerS
 #include "TLSServerSocket.h"
 typedef mozilla::net::TLSServerSocket TLSServerSocket;
 NS_GENERIC_FACTORY_CONSTRUCTOR(TLSServerSocket)
 
 #include "nsUDPSocket.h"
 typedef mozilla::net::nsUDPSocket nsUDPSocket;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsUDPSocket)
 
-#include "nsUDPSocketProvider.h"
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsUDPSocketProvider)
-
 #include "nsAsyncStreamCopier.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAsyncStreamCopier)
 
 #include "nsInputStreamPump.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsInputStreamPump)
 
 #include "nsInputStreamChannel.h"
 typedef mozilla::net::nsInputStreamChannel nsInputStreamChannel;
@@ -708,19 +705,16 @@ NS_DEFINE_NAMED_CID(NS_SUBSTITUTINGURL_C
 NS_DEFINE_NAMED_CID(NS_SUBSTITUTINGURLMUTATOR_CID);
 NS_DEFINE_NAMED_CID(NS_ABOUTPROTOCOLHANDLER_CID);
 NS_DEFINE_NAMED_CID(NS_SAFEABOUTPROTOCOLHANDLER_CID);
 NS_DEFINE_NAMED_CID(NS_ABOUT_BLANK_MODULE_CID);
 NS_DEFINE_NAMED_CID(NS_NESTEDABOUTURI_CID);
 NS_DEFINE_NAMED_CID(NS_NESTEDABOUTURIMUTATOR_CID);
 NS_DEFINE_NAMED_CID(NS_ABOUT_CACHE_MODULE_CID);
 NS_DEFINE_NAMED_CID(NS_ABOUT_CACHE_ENTRY_MODULE_CID);
-NS_DEFINE_NAMED_CID(NS_SOCKSSOCKETPROVIDER_CID);
-NS_DEFINE_NAMED_CID(NS_SOCKS4SOCKETPROVIDER_CID);
-NS_DEFINE_NAMED_CID(NS_UDPSOCKETPROVIDER_CID);
 NS_DEFINE_NAMED_CID(NS_CACHESERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_APPLICATIONCACHESERVICE_CID);
 #ifdef NECKO_COOKIES
 NS_DEFINE_NAMED_CID(NS_COOKIEMANAGER_CID);
 NS_DEFINE_NAMED_CID(NS_COOKIESERVICE_CID);
 #endif
 #ifdef NECKO_WIFI
 NS_DEFINE_NAMED_CID(NS_WIFI_MONITOR_COMPONENT_CID);
@@ -821,19 +815,16 @@ static const mozilla::Module::CIDEntry k
     { &kNS_SUBSTITUTINGURLMUTATOR_CID, false, nullptr, mozilla::SubstitutingURLMutatorConstructor },
     { &kNS_ABOUTPROTOCOLHANDLER_CID, false, nullptr, nsAboutProtocolHandlerConstructor },
     { &kNS_SAFEABOUTPROTOCOLHANDLER_CID, false, nullptr, nsSafeAboutProtocolHandlerConstructor },
     { &kNS_ABOUT_BLANK_MODULE_CID, false, nullptr, nsAboutBlank::Create },
     { &kNS_NESTEDABOUTURI_CID, false, nullptr, nsNestedAboutURIMutatorConstructor }, // do_CreateInstance returns mutator
     { &kNS_NESTEDABOUTURIMUTATOR_CID, false, nullptr, nsNestedAboutURIMutatorConstructor },
     { &kNS_ABOUT_CACHE_MODULE_CID, false, nullptr, nsAboutCache::Create },
     { &kNS_ABOUT_CACHE_ENTRY_MODULE_CID, false, nullptr, nsAboutCacheEntryConstructor },
-    { &kNS_SOCKSSOCKETPROVIDER_CID, false, nullptr, nsSOCKSSocketProvider::CreateV5 },
-    { &kNS_SOCKS4SOCKETPROVIDER_CID, false, nullptr, nsSOCKSSocketProvider::CreateV4 },
-    { &kNS_UDPSOCKETPROVIDER_CID, false, nullptr, nsUDPSocketProviderConstructor },
     { &kNS_CACHESERVICE_CID, false, nullptr, nsCacheService::Create },
     { &kNS_APPLICATIONCACHESERVICE_CID, false, nullptr, nsApplicationCacheServiceConstructor },
 #ifdef NECKO_COOKIES
     { &kNS_COOKIEMANAGER_CID, false, nullptr, nsICookieServiceConstructor },
     { &kNS_COOKIESERVICE_CID, false, nullptr, nsICookieServiceConstructor },
 #endif
 #ifdef NECKO_WIFI
     { &kNS_WIFI_MONITOR_COMPONENT_CID, false, nullptr, nsWifiMonitorConstructor },
@@ -937,19 +928,16 @@ static const mozilla::Module::ContractID
     { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "ftp", &kNS_FTPPROTOCOLHANDLER_CID },
     { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "resource", &kNS_RESPROTOCOLHANDLER_CID },
     { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "moz-extension", &kNS_EXTENSIONPROTOCOLHANDLER_CID },
     { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "about", &kNS_ABOUTPROTOCOLHANDLER_CID },
     { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "moz-safe-about", &kNS_SAFEABOUTPROTOCOLHANDLER_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "blank", &kNS_ABOUT_BLANK_MODULE_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "cache", &kNS_ABOUT_CACHE_MODULE_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "cache-entry", &kNS_ABOUT_CACHE_ENTRY_MODULE_CID },
-    { NS_NETWORK_SOCKET_CONTRACTID_PREFIX "socks", &kNS_SOCKSSOCKETPROVIDER_CID },
-    { NS_NETWORK_SOCKET_CONTRACTID_PREFIX "socks4", &kNS_SOCKS4SOCKETPROVIDER_CID },
-    { NS_NETWORK_SOCKET_CONTRACTID_PREFIX "udp", &kNS_UDPSOCKETPROVIDER_CID },
     { NS_CACHESERVICE_CONTRACTID, &kNS_CACHESERVICE_CID },
     { NS_APPLICATIONCACHESERVICE_CONTRACTID, &kNS_APPLICATIONCACHESERVICE_CID },
 #ifdef NECKO_COOKIES
     { NS_COOKIEMANAGER_CONTRACTID, &kNS_COOKIEMANAGER_CID },
     { NS_COOKIESERVICE_CONTRACTID, &kNS_COOKIESERVICE_CID },
 #endif
 #ifdef NECKO_WIFI
     { NS_WIFI_MONITOR_CONTRACTID, &kNS_WIFI_MONITOR_COMPONENT_CID },
--- a/netwerk/socket/nsISocketProvider.idl
+++ b/netwerk/socket/nsISocketProvider.idl
@@ -114,17 +114,8 @@ interface nsISocketProvider : nsISupport
 
     /**
      * If set, do not use newer protocol features that might have interop problems
      * on the Internet. Intended only for use with critical infra like the updater.
      * default is false.
      */
     const unsigned long BE_CONSERVATIVE = 1 << 4;
 };
-
-%{C++
-/**
- * nsISocketProvider implementations should be registered with XPCOM under a
- * contract ID of the form: "@mozilla.org/network/socket;2?type=foo"
- */
-#define NS_NETWORK_SOCKET_CONTRACTID_PREFIX \
-    "@mozilla.org/network/socket;2?type="
-%}
--- a/netwerk/socket/nsSocketProviderService.cpp
+++ b/netwerk/socket/nsSocketProviderService.cpp
@@ -1,18 +1,20 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* 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 "nsString.h"
 #include "nsIServiceManager.h"
 #include "nsISocketProvider.h"
+#include "nsError.h"
+#include "nsNSSComponent.h"
+#include "nsSOCKSSocketProvider.h"
 #include "nsSocketProviderService.h"
-#include "nsError.h"
 #include "nsSSLSocketProvider.h"
 #include "nsTLSSocketProvider.h"
 #include "nsUDPSocketProvider.h"
 #include "mozilla/ClearOnShutdown.h"
 
 mozilla::StaticRefPtr<nsSocketProviderService> nsSocketProviderService::gSingleton;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -40,20 +42,31 @@ nsSocketProviderService::GetOrCreate()
 NS_IMPL_ISUPPORTS(nsSocketProviderService, nsISocketProviderService)
 
 ////////////////////////////////////////////////////////////////////////////////
 
 NS_IMETHODIMP
 nsSocketProviderService::GetSocketProvider(const char         *type,
                                            nsISocketProvider **result)
 {
-  nsresult rv;
-  nsAutoCString contractID(
-          NS_LITERAL_CSTRING(NS_NETWORK_SOCKET_CONTRACTID_PREFIX) +
-          nsDependentCString(type));
-
-  rv = CallGetService(contractID.get(), result);
-  if (NS_FAILED(rv))
-      rv = NS_ERROR_UNKNOWN_SOCKET_TYPE;
-  return rv;
+  nsCOMPtr<nsISocketProvider> inst;
+  if (!nsCRT::strcmp(type, "ssl") &&
+      XRE_IsParentProcess() &&
+      EnsureNSSInitializedChromeOrContent()) {
+    inst = new nsSSLSocketProvider();
+  } else if (!nsCRT::strcmp(type, "starttls") &&
+             XRE_IsParentProcess() &&
+             EnsureNSSInitializedChromeOrContent()) {
+    inst = new nsTLSSocketProvider();
+  } else if (!nsCRT::strcmp(type, "socks")) {
+    inst = new nsSOCKSSocketProvider(NS_SOCKS_VERSION_5);
+  } else if (!nsCRT::strcmp(type, "socks4")) {
+    inst = new nsSOCKSSocketProvider(NS_SOCKS_VERSION_4);
+  } else if (!nsCRT::strcmp(type, "udp")) {
+    inst = new nsUDPSocketProvider();
+  } else {
+    return NS_ERROR_UNKNOWN_SOCKET_TYPE;
+  }
+  inst.forget(result);
+  return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/security/manager/ssl/moz.build
+++ b/security/manager/ssl/moz.build
@@ -63,16 +63,18 @@ EXPORTS += [
     'nsClientAuthRemember.h',
     'nsNSSCallbacks.h',
     'nsNSSCertificate.h',
     'nsNSSComponent.h',
     'nsNSSHelper.h',
     'nsRandomGenerator.h',
     'nsSecurityHeaderParser.h',
     'NSSErrorsService.h',
+    'nsSSLSocketProvider.h',
+    'nsTLSSocketProvider.h',
     'RootCertificateTelemetryUtils.h',
     'ScopedNSSTypes.h',
     'SharedCertVerifier.h',
 ]
 
 EXPORTS.mozilla += [
     'DataStorage.h',
     'DataStorageList.h',
--- a/security/manager/ssl/nsNSSModule.cpp
+++ b/security/manager/ssl/nsNSSModule.cpp
@@ -23,20 +23,18 @@
 #include "nsNSSCertificateDB.h"
 #include "nsNSSComponent.h"
 #include "nsNSSVersion.h"
 #include "nsNTLMAuthModule.h"
 #include "nsNetCID.h"
 #include "nsPK11TokenDB.h"
 #include "nsPKCS11Slot.h"
 #include "nsRandomGenerator.h"
-#include "nsSSLSocketProvider.h"
 #include "nsSecureBrowserUIImpl.h"
 #include "nsSiteSecurityService.h"
-#include "nsTLSSocketProvider.h"
 #include "nsXULAppAPI.h"
 #include "OSKeyStore.h"
 #include "OSReauthenticator.h"
 
 #ifdef MOZ_XUL
 #include "nsCertTree.h"
 #endif
 
@@ -128,18 +126,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(PSMC
 
 typedef mozilla::psm::NSSErrorsService NSSErrorsService;
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NSSErrorsService, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsNSSVersion)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecureBrowserUIImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNSSComponent, Init)
 
 NS_DEFINE_NAMED_CID(NS_NSSCOMPONENT_CID);
-NS_DEFINE_NAMED_CID(NS_SSLSOCKETPROVIDER_CID);
-NS_DEFINE_NAMED_CID(NS_STARTTLSSOCKETPROVIDER_CID);
 NS_DEFINE_NAMED_CID(NS_SECRETDECODERRING_CID);
 NS_DEFINE_NAMED_CID(NS_PK11TOKENDB_CID);
 NS_DEFINE_NAMED_CID(NS_PKCS11MODULEDB_CID);
 NS_DEFINE_NAMED_CID(NS_PSMCONTENTLISTEN_CID);
 NS_DEFINE_NAMED_CID(NS_X509CERT_CID);
 NS_DEFINE_NAMED_CID(NS_X509CERTDB_CID);
 NS_DEFINE_NAMED_CID(NS_X509CERTLIST_CID);
 NS_DEFINE_NAMED_CID(NS_FORMPROCESSOR_CID);
@@ -164,20 +160,16 @@ NS_DEFINE_NAMED_CID(NS_OSKEYSTORE_CID);
 NS_DEFINE_NAMED_CID(NS_OSREAUTHENTICATOR_CID);
 
 // Components that require main thread initialization could cause a deadlock
 // in necko code (bug 1418752). To prevent it we initialize all such components
 // on main thread in advance in net_EnsurePSMInit(). Update that function when
 // new component with ThreadRestriction::MainThreadOnly is added.
 static const mozilla::Module::CIDEntry kNSSCIDs[] = {
   { &kNS_NSSCOMPONENT_CID, false, nullptr, nsNSSComponentConstructor },
-  { &kNS_SSLSOCKETPROVIDER_CID, false, nullptr,
-    Constructor<nsSSLSocketProvider> },
-  { &kNS_STARTTLSSOCKETPROVIDER_CID, false, nullptr,
-    Constructor<nsTLSSocketProvider> },
   { &kNS_SECRETDECODERRING_CID, false, nullptr,
     Constructor<SecretDecoderRing> },
   { &kNS_PK11TOKENDB_CID, false, nullptr, Constructor<nsPK11TokenDB> },
   { &kNS_PKCS11MODULEDB_CID, false, nullptr, Constructor<PKCS11ModuleDB> },
   { &kNS_PSMCONTENTLISTEN_CID, false, nullptr, PSMContentListenerConstructor },
   { &kNS_X509CERT_CID, false, nullptr,
     Constructor<nsNSSCertificate, nullptr, ProcessRestriction::AnyProcess> },
   { &kNS_X509CERTDB_CID, false, nullptr, Constructor<nsNSSCertificateDB> },
@@ -229,18 +221,16 @@ static const mozilla::Module::CIDEntry k
                 ThreadRestriction::MainThreadOnly> },
   { nullptr }
 };
 
 static const mozilla::Module::ContractIDEntry kNSSContracts[] = {
   { PSM_COMPONENT_CONTRACTID, &kNS_NSSCOMPONENT_CID },
   { NS_NSS_ERRORS_SERVICE_CONTRACTID, &kNS_NSSERRORSSERVICE_CID },
   { NS_NSSVERSION_CONTRACTID, &kNS_NSSVERSION_CID },
-  { NS_SSLSOCKETPROVIDER_CONTRACTID, &kNS_SSLSOCKETPROVIDER_CID },
-  { NS_STARTTLSSOCKETPROVIDER_CONTRACTID, &kNS_STARTTLSSOCKETPROVIDER_CID },
   { NS_SECRETDECODERRING_CONTRACTID, &kNS_SECRETDECODERRING_CID },
   { NS_PK11TOKENDB_CONTRACTID, &kNS_PK11TOKENDB_CID },
   { NS_PKCS11MODULEDB_CONTRACTID, &kNS_PKCS11MODULEDB_CID },
   { NS_PSMCONTENTLISTEN_CONTRACTID, &kNS_PSMCONTENTLISTEN_CID },
   { NS_X509CERTDB_CONTRACTID, &kNS_X509CERTDB_CID },
   { NS_X509CERTLIST_CONTRACTID, &kNS_X509CERTLIST_CID },
   { NS_FORMPROCESSOR_CONTRACTID, &kNS_FORMPROCESSOR_CID },
 #ifdef MOZ_XUL