From fb5c6b1cd67e74114df904d35df8bfcfba6c144c Mon Sep 17 00:00:00 2001 From: Youenn Fablet Date: Thu, 14 Dec 2023 04:17:30 -0800 Subject: [PATCH] Switch to libwebrtc new DNS resolver interface https://bugs.webkit.org/show_bug.cgi?id=265791 rdar://119133276 Reviewed by Eric Carlson. Migrate code from deprecated webrtc::AsyncResolverFactory to webrtc::AsyncDnsResolverFactory. This in particular simplifies how we do memory management, since the peer connection factory is now owned by the peer connection. We keep using a map of WeakPtr to allow to handle IPC responses from network process. We work around a header conflict between SDK and libwebrtc by isolating absl::InvokeCall in LibWebRTCDnsResolverFactory.cpp. * Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp: (WebCore::LibWebRTCProvider::createPeerConnection): * Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h: * Source/WebKit/Sources.txt: * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.cpp: Added. (WebKit::LibWebRTCDnsResolverFactory::CreateAndResolve): (WebKit::LibWebRTCDnsResolverFactory::Create): (WebKit::LibWebRTCDnsResolverFactory::Resolver::Start): * Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.h: Added. * Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp: (WebKit::LibWebRTCProvider::createPeerConnection): (WebKit::RTCSocketFactory::CreateAsyncDnsResolver): (WebKit::RTCSocketFactory::CreateAsyncResolver): Deleted. * Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.cpp: (WebKit::LibWebRTCResolver::~LibWebRTCResolver): (WebKit::LibWebRTCResolver::start): (WebKit::LibWebRTCResolver::result const): (WebKit::LibWebRTCResolver::setResolvedAddress): (WebKit::LibWebRTCResolver::setError): (WebKit::LibWebRTCResolver::Start): Deleted. (WebKit::LibWebRTCResolver::Destroy): Deleted. (WebKit::LibWebRTCResolver::doDestroy): Deleted. * Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.h: * Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp: (WebKit::LibWebRTCSocketFactory::createAsyncDnsResolver): (WebKit::LibWebRTCSocketFactory::createAsyncResolver): Deleted. * Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h: (WebKit::LibWebRTCSocketFactory::resolver): (WebKit::LibWebRTCSocketFactory::removeResolver): (WebKit::LibWebRTCSocketFactory::takeResolver): Deleted. * Source/WebKit/WebProcess/Network/webrtc/WebRTCResolver.cpp: (WebKit::WebRTCResolver::setResolvedAddress): (WebKit::WebRTCResolver::resolvedAddressError): Canonical link: https://commits.webkit.org/272029@main --- .../libwebrtc/LibWebRTCProvider.cpp | 7 +- .../mediastream/libwebrtc/LibWebRTCProvider.h | 7 +- .../WebKit/WebKit.xcodeproj/project.pbxproj | 24 +++--- .../webrtc/LibWebRTCDnsResolverFactory.cpp | 77 +++++++++++++++++++ .../webrtc/LibWebRTCDnsResolverFactory.h | 62 +++++++++++++++ .../Network/webrtc/LibWebRTCProvider.cpp | 28 ++----- .../Network/webrtc/LibWebRTCResolver.cpp | 60 +++++---------- .../Network/webrtc/LibWebRTCResolver.h | 37 ++++----- .../Network/webrtc/LibWebRTCSocketFactory.cpp | 13 ++-- .../Network/webrtc/LibWebRTCSocketFactory.h | 14 ++-- .../Network/webrtc/WebRTCResolver.cpp | 18 ++--- 11 files changed, 211 insertions(+), 136 deletions(-) create mode 100644 Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.cpp create mode 100644 Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.h diff --git a/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp b/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp index e43d35ff82852..61bf436d1a066 100644 --- a/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp +++ b/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp @@ -388,9 +388,7 @@ void LibWebRTCProvider::setUseDTLS10(bool useDTLS10) m_factory->SetOptions(options); } -ALLOW_DEPRECATED_DECLARATIONS_BEGIN -// FIXME: https://bugs.webkit.org/show_bug.cgi?id=265791 -rtc::scoped_refptr LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, rtc::NetworkManager& networkManager, rtc::PacketSocketFactory& packetSocketFactory, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration, std::unique_ptr&& asyncResolveFactory) +rtc::scoped_refptr LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, rtc::NetworkManager& networkManager, rtc::PacketSocketFactory& packetSocketFactory, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration, std::unique_ptr&& asyncDnsResolverFactory) { auto& factoryAndThreads = getStaticFactoryAndThreads(m_useNetworkThreadWithSocketServer); @@ -408,7 +406,7 @@ rtc::scoped_refptr LibWebRTCProvider::createPee webrtc::PeerConnectionDependencies dependencies { &observer }; dependencies.allocator = WTFMove(portAllocator); - dependencies.async_resolver_factory = WTFMove(asyncResolveFactory); + dependencies.async_dns_resolver_factory = WTFMove(asyncDnsResolverFactory); auto peerConnectionOrError = m_factory->CreatePeerConnectionOrError(configuration, WTFMove(dependencies)); if (!peerConnectionOrError.ok()) @@ -416,7 +414,6 @@ rtc::scoped_refptr LibWebRTCProvider::createPee return peerConnectionOrError.MoveValue(); } -ALLOW_DEPRECATED_DECLARATIONS_END void LibWebRTCProvider::prepareCertificateGenerator(Function&& callback) { diff --git a/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h b/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h index f9c1e07476c63..514885e08ca16 100644 --- a/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h +++ b/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h @@ -52,7 +52,7 @@ class RTCCertificateGenerator; } namespace webrtc { -class AsyncResolverFactory; +class AsyncDnsResolverFactory; class PeerConnectionFactoryInterface; } @@ -122,10 +122,7 @@ class WEBCORE_EXPORT LibWebRTCProvider : public WebRTCProvider { protected: LibWebRTCProvider(); -ALLOW_DEPRECATED_DECLARATIONS_BEGIN - // FIXME: https://bugs.webkit.org/show_bug.cgi?id=265791 - rtc::scoped_refptr createPeerConnection(webrtc::PeerConnectionObserver&, rtc::NetworkManager&, rtc::PacketSocketFactory&, webrtc::PeerConnectionInterface::RTCConfiguration&&, std::unique_ptr&&); -ALLOW_DEPRECATED_DECLARATIONS_END + rtc::scoped_refptr createPeerConnection(webrtc::PeerConnectionObserver&, rtc::NetworkManager&, rtc::PacketSocketFactory&, webrtc::PeerConnectionInterface::RTCConfiguration&&, std::unique_ptr&&); rtc::scoped_refptr createPeerConnectionFactory(rtc::Thread* networkThread, rtc::Thread* signalingThread); virtual std::unique_ptr createDecoderFactory(); diff --git a/Source/WebKit/WebKit.xcodeproj/project.pbxproj b/Source/WebKit/WebKit.xcodeproj/project.pbxproj index 1d1bf7f6634cc..59a71c46f46d4 100644 --- a/Source/WebKit/WebKit.xcodeproj/project.pbxproj +++ b/Source/WebKit/WebKit.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 55; + objectVersion = 54; objects = { /* Begin PBXAggregateTarget section */ @@ -1020,6 +1020,7 @@ 417915B92257046F00D6F97E /* NetworkSocketChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 417915B62257046E00D6F97E /* NetworkSocketChannel.h */; }; 41897ED11F415D680016FA42 /* WebCacheStorageConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 41897ECD1F415D5C0016FA42 /* WebCacheStorageConnection.h */; }; 4193927828BE41C000162139 /* LSApplicationWorkspaceSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 4193927728BE41C000162139 /* LSApplicationWorkspaceSPI.h */; }; + 419E200F2B286E8900BB13A6 /* LibWebRTCDnsResolverFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 419E200D2B286CF700BB13A6 /* LibWebRTCDnsResolverFactory.cpp */; }; 41A0EB142641714900794471 /* LibWebRTCCodecsProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41E0A7C823B6397900561060 /* LibWebRTCCodecsProxy.mm */; }; 41C5379021F15B55008B1FAD /* _WKWebsiteDataStoreDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C5378F21F1362D008B1FAD /* _WKWebsiteDataStoreDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; }; 41D129DA1F3D101800D15E47 /* WebCacheStorageProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D129D91F3D101400D15E47 /* WebCacheStorageProvider.h */; }; @@ -4937,6 +4938,8 @@ 4193927728BE41C000162139 /* LSApplicationWorkspaceSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSApplicationWorkspaceSPI.h; sourceTree = ""; }; 419ACF9B1F981D26009F1A83 /* WebServiceWorkerFetchTaskClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebServiceWorkerFetchTaskClient.h; sourceTree = ""; }; 419BD18F28E1A86C0089D7B7 /* VideoCodecType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VideoCodecType.h; sourceTree = ""; }; + 419E200D2B286CF700BB13A6 /* LibWebRTCDnsResolverFactory.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCDnsResolverFactory.cpp; path = Network/webrtc/LibWebRTCDnsResolverFactory.cpp; sourceTree = ""; }; + 419E200E2B286CF700BB13A6 /* LibWebRTCDnsResolverFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = LibWebRTCDnsResolverFactory.h; path = Network/webrtc/LibWebRTCDnsResolverFactory.h; sourceTree = ""; }; 41A5F7B9226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AuthenticationChallengeDispositionCocoa.h; sourceTree = ""; }; 41A5F7BA226ECF7C00671764 /* AuthenticationChallengeDispositionCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AuthenticationChallengeDispositionCocoa.mm; sourceTree = ""; }; 41AC86811E042E5300303074 /* WebRTCResolver.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; lineEnding = 0; name = WebRTCResolver.messages.in; path = Network/webrtc/WebRTCResolver.messages.in; sourceTree = ""; xcLanguageSpecificationIdentifier = ""; }; @@ -11216,6 +11219,8 @@ 4130759E1DE85E650039EC69 /* webrtc */ = { isa = PBXGroup; children = ( + 419E200D2B286CF700BB13A6 /* LibWebRTCDnsResolverFactory.cpp */, + 419E200E2B286CF700BB13A6 /* LibWebRTCDnsResolverFactory.h */, 416F8089245C7FF500B68F02 /* LibWebRTCNetwork.cpp */, 411B22621E371244004F7363 /* LibWebRTCNetwork.h */, 416F8086245B397400B68F02 /* LibWebRTCNetwork.messages.in */, @@ -18306,6 +18311,7 @@ 2984F588164BA095004BC0C6 /* LegacyCustomProtocolManagerMessageReceiver.cpp in Sources */, 2984F57C164B915F004BC0C6 /* LegacyCustomProtocolManagerProxyMessageReceiver.cpp in Sources */, 41A0EB142641714900794471 /* LibWebRTCCodecsProxy.mm in Sources */, + 419E200F2B286E8900BB13A6 /* LibWebRTCDnsResolverFactory.cpp in Sources */, 51F060E11654318500F3281C /* LibWebRTCNetworkMessageReceiver.cpp in Sources */, 449D90DA21FDC30B00F677C0 /* LocalAuthenticationSoftLink.mm in Sources */, A141DF502B06ED0F00E80B2D /* MediaCapability.mm in Sources */, @@ -18853,9 +18859,7 @@ }; 5C400E6A29DB8AB500446F6F /* PBXTargetDependency */ = { isa = PBXTargetDependency; - platformFilters = ( - ios, - ); + platformFilter = ios; target = 5C139DA129DB82E500D5117B /* WebContentCaptivePortalExtension */; targetProxy = 5C400E6929DB8AB500446F6F /* PBXContainerItemProxy */; }; @@ -18871,25 +18875,19 @@ }; 5CE4B60729CEBB760038F565 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - platformFilters = ( - ios, - ); + platformFilter = ios; target = 5CA5A2C929CBBA1A000F1046 /* WebContentExtension */; targetProxy = 5CE4B60629CEBB760038F565 /* PBXContainerItemProxy */; }; 5CE4B62329CF880B0038F565 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - platformFilters = ( - ios, - ); + platformFilter = ios; target = 5CE4B61529CF877F0038F565 /* GPUExtension */; targetProxy = 5CE4B62229CF880B0038F565 /* PBXContainerItemProxy */; }; 5CE4B62529CF880B0038F565 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - platformFilters = ( - ios, - ); + platformFilter = ios; target = 5CE4B60829CF87680038F565 /* NetworkingExtension */; targetProxy = 5CE4B62429CF880B0038F565 /* PBXContainerItemProxy */; }; diff --git a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.cpp b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.cpp new file mode 100644 index 0000000000000..3af8d651351e5 --- /dev/null +++ b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2023 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "LibWebRTCDnsResolverFactory.h" + +#if USE(LIBWEBRTC) + +#include "LibWebRTCNetwork.h" +#include "WebProcess.h" + +namespace WebKit { + +std::unique_ptr LibWebRTCDnsResolverFactory::CreateAndResolve(const rtc::SocketAddress& address, absl::AnyInvocable callback) +{ + auto resolver = WebProcess::singleton().libWebRTCNetwork().socketFactory().createAsyncDnsResolver(); + resolver->start(address, [callback = absl::move(callback)] () mutable { + callback(); + }); + return resolver; +} + +std::unique_ptr LibWebRTCDnsResolverFactory::CreateAndResolve(const rtc::SocketAddress& address, int /* family */, absl::AnyInvocable callback) +{ + auto resolver = WebProcess::singleton().libWebRTCNetwork().socketFactory().createAsyncDnsResolver(); + // FIXME: Make use of family. + resolver->start(address, [callback = absl::move(callback)] () mutable { + callback(); + }); + return resolver; +} + +std::unique_ptr LibWebRTCDnsResolverFactory::Create() +{ + return WebProcess::singleton().libWebRTCNetwork().socketFactory().createAsyncDnsResolver(); +} + +void LibWebRTCDnsResolverFactory::Resolver::Start(const rtc::SocketAddress& address, absl::AnyInvocable callback) +{ + start(address, [callback = absl::move(callback)] () mutable { + callback(); + }); +} + +void LibWebRTCDnsResolverFactory::Resolver::Start(const rtc::SocketAddress& address, int /* family */, absl::AnyInvocable callback) +{ + // FIXME: Make use of family. + start(address, [callback = absl::move(callback)] () mutable { + callback(); + }); +} + +} // namespace WebKit + +#endif // USE(LIBWEBRTC) diff --git a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.h b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.h new file mode 100644 index 0000000000000..b3e36b28c9bf9 --- /dev/null +++ b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCDnsResolverFactory.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2023 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#if USE(LIBWEBRTC) + +#include + +ALLOW_COMMA_BEGIN +#include +ALLOW_COMMA_END + +#include +#include + +namespace WebKit { + +class LibWebRTCDnsResolverFactory final : public webrtc::AsyncDnsResolverFactoryInterface { + WTF_MAKE_FAST_ALLOCATED; +public: + class Resolver : public webrtc::AsyncDnsResolverInterface { + public: + virtual void start(const rtc::SocketAddress&, Function&&) = 0; + + private: + // webrtc::AsyncDnsResolverInterface + void Start(const rtc::SocketAddress&, absl::AnyInvocable) final; + void Start(const rtc::SocketAddress&, int family, absl::AnyInvocable) final; + }; + +private: + std::unique_ptr CreateAndResolve(const rtc::SocketAddress&, absl::AnyInvocable) final; + std::unique_ptr CreateAndResolve(const rtc::SocketAddress&, int family, absl::AnyInvocable) final; + std::unique_ptr Create() final; +}; + +} // namespace WebKit + +#endif // USE(LIBWEBRTC) diff --git a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp index d50e4b57735e0..be6d8b4838f9d 100644 --- a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp +++ b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp @@ -32,6 +32,7 @@ #include "LibWebRTCCodecs.h" #endif +#include "LibWebRTCDnsResolverFactory.h" #include "LibWebRTCNetwork.h" #include "LibWebRTCNetworkManager.h" #include "RTCDataChannelRemoteManager.h" @@ -43,7 +44,6 @@ ALLOW_COMMA_BEGIN -#include #include ALLOW_COMMA_END @@ -51,18 +51,6 @@ ALLOW_COMMA_END namespace WebKit { using namespace WebCore; -ALLOW_DEPRECATED_DECLARATIONS_BEGIN -// FIXME: https://bugs.webkit.org/show_bug.cgi?id=265791 -class AsyncResolverFactory : public webrtc::AsyncResolverFactory { - WTF_MAKE_FAST_ALLOCATED; -private: - rtc::AsyncResolverInterface* Create() final - { - return WebProcess::singleton().libWebRTCNetwork().socketFactory().createAsyncResolver(); - } -}; -ALLOW_DEPRECATED_DECLARATIONS_END - LibWebRTCProvider::LibWebRTCProvider(WebPage& webPage) : m_webPage(webPage) { @@ -85,7 +73,7 @@ rtc::scoped_refptr LibWebRTCProvider::createPee networkManager->setEnumeratingAllNetworkInterfacesEnabled(isEnumeratingAllNetworkInterfacesEnabled()); networkManager->setEnumeratingVisibleNetworkInterfacesEnabled(isEnumeratingVisibleNetworkInterfacesEnabled()); - return WebCore::LibWebRTCProvider::createPeerConnection(observer, *networkManager, *socketFactory, WTFMove(configuration), makeUnique()); + return WebCore::LibWebRTCProvider::createPeerConnection(observer, *networkManager, *socketFactory, WTFMove(configuration), makeUnique()); } void LibWebRTCProvider::disableNonLocalhostConnections() @@ -105,10 +93,7 @@ class RTCSocketFactory final : public LibWebRTCProvider::SuspendableSocketFactor rtc::AsyncPacketSocket* CreateUdpSocket(const rtc::SocketAddress&, uint16_t minPort, uint16_t maxPort) final; rtc::AsyncListenSocket* CreateServerTcpSocket(const rtc::SocketAddress&, uint16_t minPort, uint16_t maxPort, int options) final { return nullptr; } rtc::AsyncPacketSocket* CreateClientTcpSocket(const rtc::SocketAddress& localAddress, const rtc::SocketAddress& remoteAddress, const rtc::ProxyInfo&, const std::string&, const rtc::PacketSocketTcpOptions&) final; -ALLOW_DEPRECATED_DECLARATIONS_BEGIN - // FIXME: https://bugs.webkit.org/show_bug.cgi?id=265791 - rtc::AsyncResolverInterface* CreateAsyncResolver() final; -ALLOW_DEPRECATED_DECLARATIONS_END + std::unique_ptr CreateAsyncDnsResolver() final; void suspend() final; void resume() final; @@ -140,13 +125,10 @@ rtc::AsyncPacketSocket* RTCSocketFactory::CreateClientTcpSocket(const rtc::Socke return WebProcess::singleton().libWebRTCNetwork().socketFactory().createClientTcpSocket(m_contextIdentifier, localAddress, remoteAddress, String { m_userAgent }, options, m_pageIdentifier, m_isFirstParty, m_isRelayDisabled, m_domain); } -ALLOW_DEPRECATED_DECLARATIONS_BEGIN -// FIXME: https://bugs.webkit.org/show_bug.cgi?id=265791 -rtc::AsyncResolverInterface* RTCSocketFactory::CreateAsyncResolver() +std::unique_ptr RTCSocketFactory::CreateAsyncDnsResolver() { - return WebProcess::singleton().libWebRTCNetwork().socketFactory().createAsyncResolver(); + return WebProcess::singleton().libWebRTCNetwork().socketFactory().createAsyncDnsResolver(); } -ALLOW_DEPRECATED_DECLARATIONS_END void RTCSocketFactory::suspend() { diff --git a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.cpp b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.cpp index 3747e3c3308e9..87a666d8e1ce7 100644 --- a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.cpp +++ b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.cpp @@ -45,10 +45,19 @@ void LibWebRTCResolver::sendOnMainThread(Function&& call }); } -void LibWebRTCResolver::Start(const rtc::SocketAddress& address, int /* family */) +LibWebRTCResolver::~LibWebRTCResolver() { - // FIXME: Make use of family parameter. - m_isResolving = true; + WebProcess::singleton().libWebRTCNetwork().socketFactory().removeResolver(m_identifier); + sendOnMainThread([identifier = m_identifier](IPC::Connection& connection) { + connection.send(Messages::NetworkRTCProvider::StopResolver(identifier), 0); + }); +} + +void LibWebRTCResolver::start(const rtc::SocketAddress& address, Function&& callback) +{ + ASSERT(!m_callback); + + m_callback = WTFMove(callback); m_addressToResolve = address; m_port = address.port(); @@ -66,6 +75,11 @@ void LibWebRTCResolver::Start(const rtc::SocketAddress& address, int /* family * }); } +const webrtc::AsyncDnsResolverResult& LibWebRTCResolver::result() const +{ + return *this; +} + bool LibWebRTCResolver::GetResolvedAddress(int family, rtc::SocketAddress* address) const { ASSERT(address); @@ -83,48 +97,16 @@ bool LibWebRTCResolver::GetResolvedAddress(int family, rtc::SocketAddress* addre return false; } -void LibWebRTCResolver::Destroy(bool) -{ - if (!isResolving()) - return; - - if (m_isProvidingResults) { - m_shouldDestroy = true; - return; - } - - sendOnMainThread([identifier = m_identifier](IPC::Connection& connection) { - connection.send(Messages::NetworkRTCProvider::StopResolver(identifier), 0); - }); - - doDestroy(); -} - -void LibWebRTCResolver::doDestroy() -{ - // Let's take the resolver so that it gets destroyed at the end of this function. - auto resolver = WebProcess::singleton().libWebRTCNetwork().socketFactory().takeResolver(m_identifier); - ASSERT(resolver); -} - -void LibWebRTCResolver::setResolvedAddress(const Vector& addresses) +void LibWebRTCResolver::setResolvedAddress(Vector&& addresses) { - m_addresses = addresses; - m_isProvidingResults = true; - SignalDone(this); - m_isProvidingResults = false; - if (m_shouldDestroy) - doDestroy(); + m_addresses = WTFMove(addresses); + m_callback(); } void LibWebRTCResolver::setError(int error) { m_error = error; - m_isProvidingResults = true; - SignalDone(this); - m_isProvidingResults = false; - if (m_shouldDestroy) - doDestroy(); + m_callback(); } } // namespace WebKit diff --git a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.h b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.h index 8fce19f108964..ec7a04c4aebca 100644 --- a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.h +++ b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.h @@ -27,16 +27,11 @@ #if USE(LIBWEBRTC) +#include "LibWebRTCDnsResolverFactory.h" #include "LibWebRTCResolverIdentifier.h" #include #include - -ALLOW_COMMA_BEGIN - -#include -#include - -ALLOW_COMMA_END +#include namespace IPC { class Connection; @@ -45,41 +40,37 @@ class Connection; namespace WebKit { class LibWebRTCSocketFactory; -ALLOW_DEPRECATED_DECLARATIONS_BEGIN -// FIXME: https://bugs.webkit.org/show_bug.cgi?id=265791 -class LibWebRTCResolver final : public rtc::AsyncResolverInterface { -ALLOW_DEPRECATED_DECLARATIONS_END +class LibWebRTCResolver final : public LibWebRTCDnsResolverFactory::Resolver, private webrtc::AsyncDnsResolverResult, public CanMakeWeakPtr { WTF_MAKE_FAST_ALLOCATED; public: LibWebRTCResolver() : m_identifier(LibWebRTCResolverIdentifier::generate()) { } + ~LibWebRTCResolver(); - bool isResolving() const { return m_isResolving; } LibWebRTCResolverIdentifier identifier() const { return m_identifier; } + void start(const rtc::SocketAddress&, Function&&) final; + private: friend class WebRTCResolver; - // AsyncResolverInterface API. - void Start(const rtc::SocketAddress& address) final { Start(address, address.family()); } - void Start(const rtc::SocketAddress&, int) final; - bool GetResolvedAddress(int, rtc::SocketAddress*) const final; - int GetError() const final { return m_error; } - void Destroy(bool) final; + // webrtc::AsyncDnsResolverInterface + const webrtc::AsyncDnsResolverResult& result() const final; + + // webrtc::AsyncDnsResolverResult + bool GetResolvedAddress(int family, rtc::SocketAddress*) const final; + int GetError() const { return m_error; } - void doDestroy(); void setError(int); - void setResolvedAddress(const Vector&); + void setResolvedAddress(Vector&&); static void sendOnMainThread(Function&&); LibWebRTCResolverIdentifier m_identifier; Vector m_addresses; rtc::SocketAddress m_addressToResolve; + Function m_callback; int m_error { 0 }; uint16_t m_port { 0 }; - bool m_isResolving { false }; - bool m_isProvidingResults { false }; - bool m_shouldDestroy { false }; }; } // namespace WebKit diff --git a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp index df0dddf892bf7..94b604f6a47fe 100644 --- a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp +++ b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp @@ -148,16 +148,15 @@ void LibWebRTCSocketFactory::forSocketInGroup(ScriptExecutionContextIdentifier c } } -ALLOW_DEPRECATED_DECLARATIONS_BEGIN -// FIXME: https://bugs.webkit.org/show_bug.cgi?id=265791 -rtc::AsyncResolverInterface* LibWebRTCSocketFactory::createAsyncResolver() +std::unique_ptr LibWebRTCSocketFactory::createAsyncDnsResolver() { auto resolver = makeUnique(); - auto* resolverPointer = resolver.get(); - m_resolvers.set(resolverPointer->identifier(), WTFMove(resolver)); - return resolverPointer; + + ASSERT(!m_resolvers.contains(resolver->identifier())); + m_resolvers.add(resolver->identifier(), resolver.get()); + + return resolver; } -ALLOW_DEPRECATED_DECLARATIONS_END } // namespace WebKit diff --git a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h index 740454a7d33f0..a35bf5f422de8 100644 --- a/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h +++ b/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h @@ -62,13 +62,10 @@ class LibWebRTCSocketFactory { rtc::AsyncPacketSocket* createClientTcpSocket(WebCore::ScriptExecutionContextIdentifier, const rtc::SocketAddress& localAddress, const rtc::SocketAddress& remoteAddress, String&& userAgent, const rtc::PacketSocketTcpOptions&, WebPageProxyIdentifier, bool isFirstParty, bool isRelayDisabled, const WebCore::RegistrableDomain&); rtc::AsyncPacketSocket* createNewConnectionSocket(LibWebRTCSocket&, WebCore::LibWebRTCSocketIdentifier newConnectionSocketIdentifier, const rtc::SocketAddress&); - LibWebRTCResolver* resolver(LibWebRTCResolverIdentifier identifier) { return m_resolvers.get(identifier); } - std::unique_ptr takeResolver(LibWebRTCResolverIdentifier identifier) { return m_resolvers.take(identifier); } + WeakPtr resolver(LibWebRTCResolverIdentifier identifier) { return m_resolvers.get(identifier); } + void removeResolver(LibWebRTCResolverIdentifier identifier) { m_resolvers.remove(identifier); } -ALLOW_DEPRECATED_DECLARATIONS_BEGIN - // FIXME: https://bugs.webkit.org/show_bug.cgi?id=265791 - rtc::AsyncResolverInterface* createAsyncResolver(); -ALLOW_DEPRECATED_DECLARATIONS_END + std::unique_ptr createAsyncDnsResolver(); void disableNonLocalhostConnections() { m_disableNonLocalhostConnections = true; } @@ -78,9 +75,8 @@ ALLOW_DEPRECATED_DECLARATIONS_END private: // We cannot own sockets, clients of the factory are responsible to free them. HashMap> m_sockets; - - // We can own resolvers as we control their Destroy method. - HashMap> m_resolvers; + + HashMap> m_resolvers; bool m_disableNonLocalhostConnections { false }; RefPtr m_connection; diff --git a/Source/WebKit/WebProcess/Network/webrtc/WebRTCResolver.cpp b/Source/WebKit/WebProcess/Network/webrtc/WebRTCResolver.cpp index e5b4fa53a0177..7da3dd0d4a7e1 100644 --- a/Source/WebKit/WebProcess/Network/webrtc/WebRTCResolver.cpp +++ b/Source/WebKit/WebProcess/Network/webrtc/WebRTCResolver.cpp @@ -43,29 +43,23 @@ WebRTCResolver::WebRTCResolver(LibWebRTCSocketFactory& socketFactory, LibWebRTCR void WebRTCResolver::setResolvedAddress(const Vector& addresses) { - auto identifier = m_identifier; auto& factory = m_socketFactory; auto rtcAddresses = addresses.map([](auto& address) { return address.rtcAddress(); }); - WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([&factory, identifier, rtcAddresses = WTFMove(rtcAddresses)]() { - auto* resolver = factory.resolver(identifier); - if (!resolver) - return; - resolver->setResolvedAddress(rtcAddresses); + WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([&factory, identifier = m_identifier, rtcAddresses = WTFMove(rtcAddresses)] () mutable { + if (auto resolver = factory.resolver(identifier)) + resolver->setResolvedAddress(WTFMove(rtcAddresses)); }); } void WebRTCResolver::resolvedAddressError(int error) { - auto identifier = m_identifier; auto& factory = m_socketFactory; - WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([&factory, identifier, error]() { - auto* resolver = factory.resolver(identifier); - if (!resolver) - return; - resolver->setError(error); + WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([&factory, identifier = m_identifier, error]() { + if (auto resolver = factory.resolver(identifier)) + resolver->setError(error); }); }