2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-08-22 18:40:41 +04:00
|
|
|
|
2000-03-31 14:13:22 +04:00
|
|
|
#include "nsString.h"
|
1999-08-22 18:40:41 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsISocketProvider.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2018-10-23 23:07:27 +03:00
|
|
|
#include "nsNSSComponent.h"
|
|
|
|
#include "nsSOCKSSocketProvider.h"
|
|
|
|
#include "nsSocketProviderService.h"
|
2018-10-23 23:07:25 +03:00
|
|
|
#include "nsSSLSocketProvider.h"
|
|
|
|
#include "nsTLSSocketProvider.h"
|
|
|
|
#include "nsUDPSocketProvider.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
|
|
|
|
|
|
mozilla::StaticRefPtr<nsSocketProviderService>
|
|
|
|
nsSocketProviderService::gSingleton;
|
1999-08-22 18:40:41 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-10-23 23:07:25 +03:00
|
|
|
already_AddRefed<nsISocketProviderService>
|
|
|
|
nsSocketProviderService::GetOrCreate() {
|
|
|
|
RefPtr<nsSocketProviderService> inst;
|
|
|
|
if (gSingleton) {
|
|
|
|
inst = gSingleton;
|
|
|
|
} else {
|
|
|
|
inst = new nsSocketProviderService();
|
|
|
|
gSingleton = inst;
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
mozilla::ClearOnShutdown(&gSingleton);
|
|
|
|
} else {
|
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
|
|
|
"net::nsSocketProviderService::GetOrCreate",
|
|
|
|
[]() -> void { mozilla::ClearOnShutdown(&gSingleton); }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return inst.forget();
|
1999-08-22 18:40:41 +04:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSocketProviderService, nsISocketProviderService)
|
1999-08-22 18:40:41 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSocketProviderService::GetSocketProvider(const char* type,
|
|
|
|
nsISocketProvider** result) {
|
2018-10-23 23:07:27 +03:00
|
|
|
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;
|
1999-08-22 18:40:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|