From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- netwerk/socket/nsSocketProviderService.cpp | 72 ++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 netwerk/socket/nsSocketProviderService.cpp (limited to 'netwerk/socket/nsSocketProviderService.cpp') diff --git a/netwerk/socket/nsSocketProviderService.cpp b/netwerk/socket/nsSocketProviderService.cpp new file mode 100644 index 0000000000..737820890e --- /dev/null +++ b/netwerk/socket/nsSocketProviderService.cpp @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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 "nsISocketProvider.h" +#include "nsError.h" +#include "nsNSSComponent.h" +#include "nsSOCKSSocketProvider.h" +#include "nsSocketProviderService.h" +#include "nsSSLSocketProvider.h" +#include "nsTLSSocketProvider.h" +#include "nsUDPSocketProvider.h" +#include "mozilla/ClearOnShutdown.h" +#include "nsThreadUtils.h" +#include "nsCRT.h" + +mozilla::StaticRefPtr + nsSocketProviderService::gSingleton; + +//////////////////////////////////////////////////////////////////////////////// + +already_AddRefed +nsSocketProviderService::GetOrCreate() { + RefPtr 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(); +} + +NS_IMPL_ISUPPORTS(nsSocketProviderService, nsISocketProviderService) + +//////////////////////////////////////////////////////////////////////////////// + +NS_IMETHODIMP +nsSocketProviderService::GetSocketProvider(const char* type, + nsISocketProvider** result) { + nsCOMPtr inst; + if (!nsCRT::strcmp(type, "ssl") && + (XRE_IsParentProcess() || XRE_IsSocketProcess()) && + EnsureNSSInitializedChromeOrContent()) { + inst = new nsSSLSocketProvider(); + } else if (!nsCRT::strcmp(type, "starttls") && + (XRE_IsParentProcess() || XRE_IsSocketProcess()) && + 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; +} + +//////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3