Handle MDNS resolution of candidates through libwebrtc directly
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Oct 2018 21:31:16 +0000 (21:31 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Oct 2018 21:31:16 +0000 (21:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190681

Reviewed by Eric Carlson.

Source/ThirdParty/libwebrtc:

* Configurations/libwebrtc.iOS.exp:
* Configurations/libwebrtc.iOSsim.exp:
* Configurations/libwebrtc.mac.exp:

Source/WebCore:

Remove the previous MDNS resolution mechanism.
Instead, add support for the AsyncResolver mechanism added to libwebrtc.
Covered by current mdns webrtc test that is unflaked.

* Modules/mediastream/PeerConnectionBackend.cpp:
(WebCore::PeerConnectionBackend::addIceCandidate):
* platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
(WebCore::LibWebRTCProvider::createPeerConnection):
* platform/mediastream/libwebrtc/LibWebRTCProvider.h:
* testing/MockLibWebRTCPeerConnection.cpp:
(WebCore::MockLibWebRTCPeerConnectionFactory::CreatePeerConnection):
* testing/MockLibWebRTCPeerConnection.h:

Source/WebKit:

Add support for AsyncResolver to resolve MDNS.
This basically reuse the code path used to resolve STUN server addresses.
Removed MDNS specific resolution.
Use existing CFHost resolution mechanism to do the actual resolution.

Make sure that a resolver is kept alive while iterating through its clients when signaling done.
Some of its clients may indeed call Destroy() on the resolver during that iteration.

* NetworkProcess/webrtc/NetworkMDNSRegister.cpp:
(WebKit::NetworkMDNSRegister::registerMDNSName):
* NetworkProcess/webrtc/NetworkMDNSRegister.messages.in:
* WebProcess/Network/webrtc/LibWebRTCProvider.cpp:
(WebKit::LibWebRTCResolver::Destroy):
(WebKit::LibWebRTCResolver::doDestroy):
(WebKit::LibWebRTCResolver::setResolvedAddress):
(WebKit::LibWebRTCResolver::setError):
(WebKit::LibWebRTCProvider::createPeerConnection):
* WebProcess/Network/webrtc/LibWebRTCProvider.h:
* WebProcess/Network/webrtc/LibWebRTCSocketFactory.h:
* WebProcess/Network/webrtc/WebMDNSRegister.cpp:
* WebProcess/Network/webrtc/WebMDNSRegister.h:
* WebProcess/Network/webrtc/WebMDNSRegister.messages.in:

LayoutTests:

* TestExpectations:
Test should no longer be flaky as we no longer enforce a timer for resolving MDNS candidates.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237568 268f45cc-cd09-0410-ab3c-d52691b4dbfc

23 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
Source/ThirdParty/libwebrtc/ChangeLog
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h
Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp
Source/WebCore/testing/MockLibWebRTCPeerConnection.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/webrtc/NetworkMDNSRegister.cpp
Source/WebKit/NetworkProcess/webrtc/NetworkMDNSRegister.messages.in
Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp
Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.h
Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.cpp
Source/WebKit/WebProcess/Network/webrtc/LibWebRTCResolver.h
Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h
Source/WebKit/WebProcess/Network/webrtc/WebMDNSRegister.cpp
Source/WebKit/WebProcess/Network/webrtc/WebMDNSRegister.h
Source/WebKit/WebProcess/Network/webrtc/WebMDNSRegister.messages.in

index 4988c09..e8362f1 100644 (file)
@@ -1,3 +1,13 @@
+2018-10-29  Youenn Fablet  <youenn@apple.com>
+
+        Handle MDNS resolution of candidates through libwebrtc directly
+        https://bugs.webkit.org/show_bug.cgi?id=190681
+
+        Reviewed by Eric Carlson.
+
+        * TestExpectations:
+        Test should no longer be flaky as we no longer enforce a timer for resolving MDNS candidates.
+
 2018-10-29  Tim Horton  <timothy_horton@apple.com>
 
         Modernize WebKit nibs and lprojs for localization's sake
index 3474578..21e8f69 100644 (file)
@@ -1216,7 +1216,6 @@ media/session [ Skip ]
 
 webrtc/simulcast-h264.html [ Slow ]
 webrtc/datachannel/multiple-connections.html [ Slow ]
-webkit.org/b/187180 webrtc/datachannel/mdns-ice-candidates.html [ Pass Failure ]
 webkit.org/b/171094 imported/w3c/web-platform-tests/webrtc/rtcpeerconnection/rtcpeerconnection-idl.html [ Failure ]
 webkit.org/b/172f21 imported/w3c/web-platform-tests/webrtc/getstats.html [ Failure ]
 imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-ontrack.https.html [ Skip ]
index 6462f39..209598f 100644 (file)
@@ -1,3 +1,14 @@
+2018-10-29  Youenn Fablet  <youenn@apple.com>
+
+        Handle MDNS resolution of candidates through libwebrtc directly
+        https://bugs.webkit.org/show_bug.cgi?id=190681
+
+        Reviewed by Eric Carlson.
+
+        * Configurations/libwebrtc.iOS.exp:
+        * Configurations/libwebrtc.iOSsim.exp:
+        * Configurations/libwebrtc.mac.exp:
+
 2018-10-23  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r237261.
index 4ee44b4..fdf9503 100644 (file)
@@ -229,3 +229,5 @@ __ZNK3rtc14RTCCertificate15ssl_certificateEv
 __ZNK3rtc14RTCCertificate5ToPEMEv
 __ZNK3rtc14SSLCertificate8GetStatsEv
 __ZN3rtc14RTCCertificate7FromPEMERKNS_17RTCCertificatePEME
+__ZN6webrtc26PeerConnectionDependenciesC1EPNS_22PeerConnectionObserverE
+__ZN6webrtc30PeerConnectionFactoryInterface20CreatePeerConnectionERKNS_23PeerConnectionInterface16RTCConfigurationENSt3__110unique_ptrIN7cricket13PortAllocatorENS5_14default_deleteIS8_EEEENS6_IN3rtc32RTCCertificateGeneratorInterfaceENS9_ISD_EEEEPNS_22PeerConnectionObserverE
index 2b4930c..0294607 100644 (file)
@@ -230,3 +230,5 @@ __ZNK3rtc14RTCCertificate15ssl_certificateEv
 __ZNK3rtc14RTCCertificate5ToPEMEv
 __ZNK3rtc14SSLCertificate8GetStatsEv
 __ZN3rtc14RTCCertificate7FromPEMERKNS_17RTCCertificatePEME
+__ZN6webrtc26PeerConnectionDependenciesC1EPNS_22PeerConnectionObserverE
+__ZN6webrtc30PeerConnectionFactoryInterface20CreatePeerConnectionERKNS_23PeerConnectionInterface16RTCConfigurationENSt3__110unique_ptrIN7cricket13PortAllocatorENS5_14default_deleteIS8_EEEENS6_IN3rtc32RTCCertificateGeneratorInterfaceENS9_ISD_EEEEPNS_22PeerConnectionObserverE
index 2b4930c..0294607 100644 (file)
@@ -230,3 +230,5 @@ __ZNK3rtc14RTCCertificate15ssl_certificateEv
 __ZNK3rtc14RTCCertificate5ToPEMEv
 __ZNK3rtc14SSLCertificate8GetStatsEv
 __ZN3rtc14RTCCertificate7FromPEMERKNS_17RTCCertificatePEME
+__ZN6webrtc26PeerConnectionDependenciesC1EPNS_22PeerConnectionObserverE
+__ZN6webrtc30PeerConnectionFactoryInterface20CreatePeerConnectionERKNS_23PeerConnectionInterface16RTCConfigurationENSt3__110unique_ptrIN7cricket13PortAllocatorENS5_14default_deleteIS8_EEEENS6_IN3rtc32RTCCertificateGeneratorInterfaceENS9_ISD_EEEEPNS_22PeerConnectionObserverE
index 718023c..8a4d6d9 100644 (file)
@@ -1,3 +1,23 @@
+2018-10-29  Youenn Fablet  <youenn@apple.com>
+
+        Handle MDNS resolution of candidates through libwebrtc directly
+        https://bugs.webkit.org/show_bug.cgi?id=190681
+
+        Reviewed by Eric Carlson.
+
+        Remove the previous MDNS resolution mechanism.
+        Instead, add support for the AsyncResolver mechanism added to libwebrtc.
+        Covered by current mdns webrtc test that is unflaked.
+
+        * Modules/mediastream/PeerConnectionBackend.cpp:
+        (WebCore::PeerConnectionBackend::addIceCandidate):
+        * platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
+        (WebCore::LibWebRTCProvider::createPeerConnection):
+        * platform/mediastream/libwebrtc/LibWebRTCProvider.h:
+        * testing/MockLibWebRTCPeerConnection.cpp:
+        (WebCore::MockLibWebRTCPeerConnectionFactory::CreatePeerConnection):
+        * testing/MockLibWebRTCPeerConnection.h:
+
 2018-10-29  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: increase size limits for NetworkResourceData
index 12aa9fa..60e3361 100644 (file)
@@ -274,42 +274,10 @@ void PeerConnectionBackend::addIceCandidate(RTCIceCandidate* iceCandidate, DOMPr
     ASSERT(!m_peerConnection.isClosed());
 
     if (!iceCandidate) {
-        if (m_waitingForMDNSResolution) {
-            m_finishedReceivingCandidates = true;
-            m_endOfIceCandidatePromise = WTFMove(promise);
-            return;
-        }
         endOfIceCandidates(WTFMove(promise));
         return;
     }
 
-    if (RuntimeEnabledFeatures::sharedFeatures().mdnsICECandidatesEnabled()) {
-        auto name = extractIPAddres(iceCandidate->candidate());
-        if (name.endsWith(".local")) {
-            ++m_waitingForMDNSResolution;
-            auto& document = downcast<Document>(*m_peerConnection.scriptExecutionContext());
-            auto& provider = document.page()->libWebRTCProvider();
-            provider.resolveMDNSName(document.sessionID(), name, [peerConnection = makeRef(m_peerConnection), this, name, iceCandidate = makeRef(*iceCandidate), promise = WTFMove(promise)] (LibWebRTCProvider::IPAddressOrError&& result) mutable {
-                if (peerConnection->isStopped())
-                    return;
-
-                --m_waitingForMDNSResolution;
-                if (!result.has_value()) {
-                    if (result.error() != MDNSRegisterError::Timeout)
-                        peerConnection->scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, makeString("MDNS resolution of a host candidate failed with error", (unsigned)result.error()));
-                    return;
-                }
-
-                auto candidate = iceCandidate->candidate();
-                candidate.replace(name, result.value());
-                iceCandidate->setCandidate(WTFMove(candidate));
-                m_addIceCandidatePromise = WTFMove(promise);
-                this->doAddIceCandidate(iceCandidate);
-            });
-            return;
-        }
-    }
-
     // FIXME: As per https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addicecandidate(), this check should be done before enqueuing the task.
     if (iceCandidate->sdpMid().isNull() && !iceCandidate->sdpMLineIndex()) {
         promise.reject(Exception { TypeError, "Trying to add a candidate that is missing both sdpMid and sdpMLineIndex"_s });
index 64e380e..e981196 100644 (file)
@@ -33,6 +33,7 @@
 
 ALLOW_UNUSED_PARAMETERS_BEGIN
 
+#include <webrtc/api/asyncresolverfactory.h>
 #include <webrtc/api/audio_codecs/builtin_audio_decoder_factory.h>
 #include <webrtc/api/audio_codecs/builtin_audio_encoder_factory.h>
 #include <webrtc/api/peerconnectionfactoryproxy.h>
@@ -244,10 +245,10 @@ rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPee
         factoryAndThreads.packetSocketFactory = std::make_unique<BasicPacketSocketFactory>(*factoryAndThreads.networkThread);
     factoryAndThreads.packetSocketFactory->setDisableNonLocalhostConnections(m_disableNonLocalhostConnections);
 
-    return createPeerConnection(observer, *factoryAndThreads.networkManager, *factoryAndThreads.packetSocketFactory, WTFMove(configuration));
+    return createPeerConnection(observer, *factoryAndThreads.networkManager, *factoryAndThreads.packetSocketFactory, WTFMove(configuration), nullptr);
 }
 
-rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, rtc::NetworkManager& networkManager, rtc::PacketSocketFactory& packetSocketFactory, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
+rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, rtc::NetworkManager& networkManager, rtc::PacketSocketFactory& packetSocketFactory, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration, std::unique_ptr<webrtc::AsyncResolverFactory>&& asyncResolveFactory)
 {
     auto& factoryAndThreads = getStaticFactoryAndThreads(m_useNetworkThreadWithSocketServer);
 
@@ -263,7 +264,11 @@ rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPee
     if (!factory)
         return nullptr;
 
-    return m_factory->CreatePeerConnection(configuration, WTFMove(portAllocator), nullptr, &observer);
+    webrtc::PeerConnectionDependencies dependencies { &observer };
+    dependencies.allocator = WTFMove(portAllocator);
+    dependencies.async_resolver_factory = WTFMove(asyncResolveFactory);
+
+    return m_factory->CreatePeerConnection(configuration, WTFMove(dependencies));
 }
 
 rtc::RTCCertificateGenerator& LibWebRTCProvider::certificateGenerator()
index d808c48..5d12e7b 100644 (file)
@@ -51,6 +51,7 @@ class RTCCertificateGenerator;
 }
 
 namespace webrtc {
+class AsyncResolverFactory;
 class PeerConnectionFactoryInterface;
 }
 #endif
@@ -88,12 +89,6 @@ public:
         callback(makeUnexpected(MDNSRegisterError::NotImplemented));
     }
 
-    virtual void resolveMDNSName(PAL::SessionID, const String& name, CompletionHandler<void(IPAddressOrError&&)>&& callback)
-    {
-        UNUSED_PARAM(name);
-        callback(makeUnexpected(MDNSRegisterError::NotImplemented));
-    }
-
 #if USE(LIBWEBRTC)
     virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&, webrtc::PeerConnectionInterface::RTCConfiguration&&);
 
@@ -117,7 +112,7 @@ public:
 protected:
     LibWebRTCProvider() = default;
 
-    rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&, rtc::NetworkManager&, rtc::PacketSocketFactory&, webrtc::PeerConnectionInterface::RTCConfiguration&&);
+    rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&, rtc::NetworkManager&, rtc::PacketSocketFactory&, webrtc::PeerConnectionInterface::RTCConfiguration&&, std::unique_ptr<webrtc::AsyncResolverFactory>&&);
 
     rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> createPeerConnectionFactory(rtc::Thread* networkThread, rtc::Thread* signalingThread, LibWebRTCAudioModule*);
     virtual std::unique_ptr<webrtc::VideoDecoderFactory> createDecoderFactory();
index 8c26858..1597eb7 100644 (file)
@@ -172,24 +172,24 @@ MockLibWebRTCPeerConnectionFactory::MockLibWebRTCPeerConnectionFactory(String&&
 {
 }
 
-rtc::scoped_refptr<webrtc::PeerConnectionInterface> MockLibWebRTCPeerConnectionFactory::CreatePeerConnection(const webrtc::PeerConnectionInterface::RTCConfiguration&, std::unique_ptr<cricket::PortAllocator>, std::unique_ptr<rtc::RTCCertificateGeneratorInterface>, webrtc::PeerConnectionObserver* observer)
+rtc::scoped_refptr<webrtc::PeerConnectionInterface> MockLibWebRTCPeerConnectionFactory::CreatePeerConnection(const webrtc::PeerConnectionInterface::RTCConfiguration&, webrtc::PeerConnectionDependencies dependencies)
 {
     if (m_testCase == "ICECandidates")
-        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionForIceCandidates>(*observer);
+        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionForIceCandidates>(*dependencies.observer);
 
     if (m_testCase == "ICEConnectionState")
-        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionForIceConnectionState>(*observer);
+        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionForIceConnectionState>(*dependencies.observer);
 
     if (m_testCase == "LibWebRTCReleasingWhileCreatingOffer")
-        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionReleasedInNetworkThreadWhileCreatingOffer>(*observer);
+        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionReleasedInNetworkThreadWhileCreatingOffer>(*dependencies.observer);
 
     if (m_testCase == "LibWebRTCReleasingWhileGettingStats")
-        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionReleasedInNetworkThreadWhileGettingStats>(*observer);
+        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionReleasedInNetworkThreadWhileGettingStats>(*dependencies.observer);
 
     if (m_testCase == "LibWebRTCReleasingWhileSettingDescription")
-        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionReleasedInNetworkThreadWhileSettingDescription>(*observer);
+        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionReleasedInNetworkThreadWhileSettingDescription>(*dependencies.observer);
 
-    return new rtc::RefCountedObject<MockLibWebRTCPeerConnection>(*observer);
+    return new rtc::RefCountedObject<MockLibWebRTCPeerConnection>(*dependencies.observer);
 }
 
 rtc::scoped_refptr<webrtc::VideoTrackInterface> MockLibWebRTCPeerConnectionFactory::CreateVideoTrack(const std::string& id, webrtc::VideoTrackSourceInterface* source)
index 0876129..77a2170 100644 (file)
@@ -241,7 +241,7 @@ protected:
     MockLibWebRTCPeerConnectionFactory(String&&);
 
 private:
-    rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(const webrtc::PeerConnectionInterface::RTCConfiguration&, std::unique_ptr<cricket::PortAllocator>, std::unique_ptr<rtc::RTCCertificateGeneratorInterface>, webrtc::PeerConnectionObserver*) final;
+    rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(const webrtc::PeerConnectionInterface::RTCConfiguration&, webrtc::PeerConnectionDependencies) final;
 
     rtc::scoped_refptr<webrtc::MediaStreamInterface> CreateLocalMediaStream(const std::string&) final;
 
index 16a6653..bc8f24b 100644 (file)
@@ -1,3 +1,33 @@
+2018-10-29  Youenn Fablet  <youenn@apple.com>
+
+        Handle MDNS resolution of candidates through libwebrtc directly
+        https://bugs.webkit.org/show_bug.cgi?id=190681
+
+        Reviewed by Eric Carlson.
+
+        Add support for AsyncResolver to resolve MDNS.
+        This basically reuse the code path used to resolve STUN server addresses.
+        Removed MDNS specific resolution.
+        Use existing CFHost resolution mechanism to do the actual resolution.
+
+        Make sure that a resolver is kept alive while iterating through its clients when signaling done.
+        Some of its clients may indeed call Destroy() on the resolver during that iteration.
+
+        * NetworkProcess/webrtc/NetworkMDNSRegister.cpp:
+        (WebKit::NetworkMDNSRegister::registerMDNSName):
+        * NetworkProcess/webrtc/NetworkMDNSRegister.messages.in:
+        * WebProcess/Network/webrtc/LibWebRTCProvider.cpp:
+        (WebKit::LibWebRTCResolver::Destroy):
+        (WebKit::LibWebRTCResolver::doDestroy):
+        (WebKit::LibWebRTCResolver::setResolvedAddress):
+        (WebKit::LibWebRTCResolver::setError):
+        (WebKit::LibWebRTCProvider::createPeerConnection):
+        * WebProcess/Network/webrtc/LibWebRTCProvider.h:
+        * WebProcess/Network/webrtc/LibWebRTCSocketFactory.h:
+        * WebProcess/Network/webrtc/WebMDNSRegister.cpp:
+        * WebProcess/Network/webrtc/WebMDNSRegister.h:
+        * WebProcess/Network/webrtc/WebMDNSRegister.messages.in:
+
 2018-10-29  Tim Horton  <timothy_horton@apple.com>
 
         Modernize WebKit nibs and lprojs for localization's sake
index 5e092d5..5c19b81 100644 (file)
@@ -156,97 +156,6 @@ void NetworkMDNSRegister::registerMDNSName(uint64_t requestIdentifier, PAL::Sess
     }
     pendingRegistrationRequests().add(pendingRegistrationRequestCount++, WTFMove(pendingRequest));
 }
-
-struct PendingResolutionRequest {
-    PendingResolutionRequest(Ref<IPC::Connection> connection, uint64_t requestIdentifier, PAL::SessionID sessionID)
-        : connection(WTFMove(connection))
-        , requestIdentifier(requestIdentifier)
-        , timeoutTimer(*this, &PendingResolutionRequest::timeout)
-        , sessionID(sessionID)
-    {
-        timeoutTimer.startOneShot(500_ms);
-    }
-
-    ~PendingResolutionRequest()
-    {
-        if (service)
-            DNSServiceRefDeallocate(service);
-        if (operationService)
-            DNSServiceRefDeallocate(operationService);
-    }
-
-    void timeout()
-    {
-        connection->send(Messages::WebMDNSRegister::FinishedResolvingMDNSName { requestIdentifier, makeUnexpected(MDNSRegisterError::Timeout) }, 0);
-        requestIdentifier = 0;
-    }
-
-    Ref<IPC::Connection> connection;
-    uint64_t requestIdentifier { 0 };
-    DNSServiceRef service { nullptr };
-    DNSServiceRef operationService { nullptr };
-    Timer timeoutTimer;
-    PAL::SessionID sessionID;
-};
-
-static void resolveMDNSNameCallback(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType errorCode, const char *hostname, const struct sockaddr *socketAddress, uint32_t ttl, void *context)
-{
-    std::unique_ptr<PendingResolutionRequest> request { static_cast<PendingResolutionRequest*>(context) };
-
-    if (!request->requestIdentifier)
-        return;
-
-    if (errorCode) {
-        RELEASE_LOG_IF_ALLOWED_IN_CALLBACK(request->sessionID, "resolveMDNSNameCallback MDNS error %d", errorCode);
-        request->connection->send(Messages::WebMDNSRegister::FinishedResolvingMDNSName { request->requestIdentifier, makeUnexpected(MDNSRegisterError::DNSSD) }, 0);
-        return;
-    }
-
-    const void* address = socketAddress->sa_family == AF_INET6 ? (const void*) &((const struct sockaddr_in6*)socketAddress)->sin6_addr : (const void*)&((const struct sockaddr_in*)socketAddress)->sin_addr;
-
-    char buffer[INET6_ADDRSTRLEN] = { 0 };
-    if (!inet_ntop(socketAddress->sa_family, address, buffer, sizeof(buffer))) {
-        RELEASE_LOG_IF_ALLOWED_IN_CALLBACK(request->sessionID, "resolveMDNSNameCallback inet_ntop error");
-        request->connection->send(Messages::WebMDNSRegister::FinishedResolvingMDNSName { request->requestIdentifier, makeUnexpected(MDNSRegisterError::DNSSD) }, 0);
-        return;
-    }
-
-    request->connection->send(Messages::WebMDNSRegister::FinishedResolvingMDNSName { request->requestIdentifier, String { buffer } }, 0);
-}
-
-void NetworkMDNSRegister::resolveMDNSName(uint64_t requestIdentifier, PAL::SessionID sessionID, const String& name)
-{
-    UNUSED_PARAM(sessionID);
-    auto pendingRequest = std::make_unique<PendingResolutionRequest>(makeRef(m_connection.connection()), requestIdentifier, sessionID);
-
-    if (auto error = DNSServiceCreateConnection(&pendingRequest->service)) {
-        RELEASE_LOG_IF_ALLOWED(sessionID, "resolveMDNSName DNSServiceCreateConnection error %d", error);
-        m_connection.connection().send(Messages::WebMDNSRegister::FinishedResolvingMDNSName { requestIdentifier, makeUnexpected(MDNSRegisterError::DNSSD) }, 0);
-        return;
-    }
-
-    DNSServiceRef service;
-    auto error = DNSServiceGetAddrInfo(&service,
-        kDNSServiceFlagsUnique,
-        0,
-        kDNSServiceProtocol_IPv4,
-        name.utf8().data(),
-        resolveMDNSNameCallback,
-        pendingRequest.get());
-    pendingRequest->operationService = service;
-    if (error) {
-        RELEASE_LOG_IF_ALLOWED(sessionID, "resolveMDNSName DNSServiceGetAddrInfo error %d", error);
-        m_connection.connection().send(Messages::WebMDNSRegister::FinishedResolvingMDNSName { requestIdentifier, makeUnexpected(MDNSRegisterError::DNSSD) }, 0);
-        return;
-    }
-    pendingRequest.release();
-
-    error = DNSServiceSetDispatchQueue(service, dispatch_get_main_queue());
-    if (error) {
-        RELEASE_LOG_IF_ALLOWED(sessionID, "resolveMDNSName DNSServiceSetDispatchQueue error %d", error);
-        m_connection.connection().send(Messages::WebMDNSRegister::FinishedResolvingMDNSName { requestIdentifier, makeUnexpected(MDNSRegisterError::DNSSD) }, 0);
-    }
-}
 #else
 void NetworkMDNSRegister::unregisterMDNSNames(WebCore::DocumentIdentifier)
 {
@@ -258,12 +167,6 @@ void NetworkMDNSRegister::registerMDNSName(uint64_t requestIdentifier, PAL::Sess
     m_connection.connection().send(Messages::WebMDNSRegister::FinishedRegisteringMDNSName { requestIdentifier, makeUnexpected(MDNSRegisterError::NotImplemented) }, 0);
 }
 
-void NetworkMDNSRegister::resolveMDNSName(uint64_t requestIdentifier, PAL::SessionID sessionID, const String& name)
-{
-    RELEASE_LOG_IF_ALLOWED(sessionID, "resolveMDNSName not implemented");
-    m_connection.connection().send(Messages::WebMDNSRegister::FinishedResolvingMDNSName { requestIdentifier, makeUnexpected(MDNSRegisterError::NotImplemented) }, 0);
-}
-
 #endif
 
 } // namespace WebKit
index a88f770..62bed7e 100644 (file)
@@ -25,7 +25,6 @@
 messages -> NetworkMDNSRegister {
     UnregisterMDNSNames(WebCore::DocumentIdentifier documentIdentifier)
     RegisterMDNSName(uint64_t requestIdentifier, PAL::SessionID sessionID, WebCore::DocumentIdentifier documentIdentifier, String ipAddress)
-    ResolveMDNSName(uint64_t requestIdentifier, PAL::SessionID sessionID, String name)
 }
 
 #endif // ENABLE(WEB_RTC)
index fdcb7d4..afe2408 100644 (file)
 
 #include "LibWebRTCNetwork.h"
 #include "WebProcess.h"
+#include <webrtc/api/asyncresolverfactory.h>
 #include <webrtc/pc/peerconnectionfactory.h>
 
 namespace WebKit {
 using namespace WebCore;
 
+class AsyncResolverFactory : public webrtc::AsyncResolverFactory {
+private:
+    rtc::AsyncResolverInterface* Create() final
+    {
+        return WebProcess::singleton().libWebRTCNetwork().socketFactory().createAsyncResolver();
+    }
+};
+
 rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
 {
-    return WebCore::LibWebRTCProvider::createPeerConnection(observer, WebProcess::singleton().libWebRTCNetwork().monitor(), WebProcess::singleton().libWebRTCNetwork().socketFactory(), WTFMove(configuration));
+    return WebCore::LibWebRTCProvider::createPeerConnection(observer, WebProcess::singleton().libWebRTCNetwork().monitor(), WebProcess::singleton().libWebRTCNetwork().socketFactory(), WTFMove(configuration), std::make_unique<AsyncResolverFactory>());
 }
 
 void LibWebRTCProvider::disableNonLocalhostConnections()
@@ -55,11 +64,6 @@ void LibWebRTCProvider::registerMDNSName(PAL::SessionID sessionID, uint64_t docu
     WebProcess::singleton().libWebRTCNetwork().mdnsRegister().registerMDNSName(sessionID, documentIdentifier, ipAddress, WTFMove(callback));
 }
 
-void LibWebRTCProvider::resolveMDNSName(PAL::SessionID sessionID, const String& name, CompletionHandler<void(IPAddressOrError&&)>&& callback)
-{
-    WebProcess::singleton().libWebRTCNetwork().mdnsRegister().resolveMDNSName(sessionID, name, WTFMove(callback));
-}
-
 } // namespace WebKit
 
 #endif // USE(LIBWEBRTC)
index e708a55..0bba25a 100644 (file)
@@ -54,7 +54,6 @@ private:
 
     void unregisterMDNSNames(uint64_t documentIdentifier) final;
     void registerMDNSName(PAL::SessionID, uint64_t documentIdentifier, const String& ipAddress, CompletionHandler<void(MDNSNameOrError&&)>&&) final;
-    void resolveMDNSName(PAL::SessionID, const String& name, CompletionHandler<void(IPAddressOrError&&)>&&) final;
     void disableNonLocalhostConnections() final;
 };
 #else
index e5addbc..fbd2beb 100644 (file)
@@ -77,11 +77,21 @@ void LibWebRTCResolver::Destroy(bool)
     if (!isResolving())
         return;
 
+    if (m_isProvidingResults) {
+        m_shouldDestroy = true;
+        return;
+    }
+
     auto identifier = m_identifier;
     sendOnMainThread([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);
@@ -90,13 +100,21 @@ void LibWebRTCResolver::Destroy(bool)
 void LibWebRTCResolver::setResolvedAddress(const Vector<rtc::IPAddress>& addresses)
 {
     m_addresses = addresses;
+    m_isProvidingResults = true;
     SignalDone(this);
+    m_isProvidingResults = false;
+    if (m_shouldDestroy)
+        doDestroy();
 }
 
 void LibWebRTCResolver::setError(int error)
 {
     m_error = error;
+    m_isProvidingResults = true;
     SignalDone(this);
+    m_isProvidingResults = false;
+    if (m_shouldDestroy)
+        doDestroy();
 }
 
 } // namespace WebKit
index 7a465d3..5d6383f 100644 (file)
@@ -55,6 +55,7 @@ private:
     int GetError() const final { return m_error; }
     void Destroy(bool) final;
 
+    void doDestroy();
     void setError(int);
     void setResolvedAddress(const Vector<rtc::IPAddress>&);
 
@@ -66,6 +67,8 @@ private:
     int m_error { 0 };
     uint16_t m_port { 0 };
     bool m_isResolving { false };
+    bool m_isProvidingResults { false };
+    bool m_shouldDestroy { false };
 };
 
 } // namespace WebKit
index 8da49a3..f0b4195 100644 (file)
@@ -51,6 +51,8 @@ public:
 
     void disableNonLocalhostConnections() { m_disableNonLocalhostConnections = true; }
 
+    rtc::AsyncResolverInterface* createAsyncResolver() { return CreateAsyncResolver(); }
+
 private:
     rtc::AsyncPacketSocket* CreateUdpSocket(const rtc::SocketAddress&, uint16_t minPort, uint16_t maxPort) final;
     rtc::AsyncPacketSocket* CreateServerTcpSocket(const rtc::SocketAddress&, uint16_t min_port, uint16_t max_port, int options) final;
index f19c744..f227008 100644 (file)
@@ -52,13 +52,6 @@ void WebMDNSRegister::finishedRegisteringMDNSName(uint64_t identifier, LibWebRTC
     pendingRegistration.callback(WTFMove(result));
 }
 
-void WebMDNSRegister::finishedResolvingMDNSName(uint64_t identifier, LibWebRTCProvider::IPAddressOrError&& result)
-{
-    auto callback = m_pendingResolutions.take(identifier);
-    if (callback)
-        callback(WTFMove(result));
-}
-
 void WebMDNSRegister::unregisterMDNSNames(uint64_t documentIdentifier)
 {
     auto identifier = makeObjectIdentifier<DocumentIdentifierType>(documentIdentifier);
@@ -89,15 +82,6 @@ void WebMDNSRegister::registerMDNSName(PAL::SessionID sessionID, uint64_t docume
         finishedRegisteringMDNSName(m_pendingRequestsIdentifier, makeUnexpected(MDNSRegisterError::Internal));
 }
 
-void WebMDNSRegister::resolveMDNSName(PAL::SessionID sessionID, const String& name, CompletionHandler<void(LibWebRTCProvider::IPAddressOrError&&)>&& callback)
-{
-    m_pendingResolutions.add(++m_pendingRequestsIdentifier, WTFMove(callback));
-
-    auto& connection = WebProcess::singleton().ensureNetworkProcessConnection().connection();
-    if (!connection.send(Messages::NetworkMDNSRegister::ResolveMDNSName { m_pendingRequestsIdentifier, sessionID, name }, 0))
-        finishedResolvingMDNSName(m_pendingRequestsIdentifier, makeUnexpected(MDNSRegisterError::Internal));
-}
-
 } // namespace WebKit
 
 #endif // ENABLE(WEB_RTC)
index bd6e9d1..c1bbcac 100644 (file)
@@ -46,13 +46,11 @@ public:
 
     void unregisterMDNSNames(uint64_t documentIdentifier);
     void registerMDNSName(PAL::SessionID, uint64_t documentIdentifier, const String& ipAddress, CompletionHandler<void(WebCore::LibWebRTCProvider::MDNSNameOrError&&)>&&);
-    void resolveMDNSName(PAL::SessionID, const String& name, CompletionHandler<void(WebCore::LibWebRTCProvider::IPAddressOrError&&)>&&);
 
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
 
 private:
     void finishedRegisteringMDNSName(uint64_t, WebCore::LibWebRTCProvider::MDNSNameOrError&&);
-    void finishedResolvingMDNSName(uint64_t, WebCore::LibWebRTCProvider::IPAddressOrError&&);
 
     struct PendingRegistration {
         CompletionHandler<void(WebCore::LibWebRTCProvider::MDNSNameOrError&&)> callback;
index e943e99..6e521cc 100644 (file)
@@ -24,7 +24,6 @@
 
 messages -> WebMDNSRegister {
     void FinishedRegisteringMDNSName(uint64_t identifier, WebCore::LibWebRTCProvider::MDNSNameOrError result)
-    void FinishedResolvingMDNSName(uint64_t identifier, WebCore::LibWebRTCProvider::IPAddressOrError result)
 }
 
 #endif // ENABLE(WEB_RTC)