Changeset 229359 in webkit


Ignore:
Timestamp:
Mar 7, 2018 7:21:24 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Make NetworkRTCResolver port agnostic
https://bugs.webkit.org/show_bug.cgi?id=178855

Patch by Alejandro G. Castro <alex@igalia.com> on 2018-03-07
Reviewed by Youenn Fablet.

Source/WebCore:

Add new API in the DNSResolveQueue allowing to revolve hostnames and get the result. Add platform
specific code for soup platform and refactor the other platforms. Added new API to the DNS API header
and move the general code to the DNS.cpp file, that way we can reuse that code in all the platforms
and leave the ResolveQueue class of the platforms in a file.

No new tests because this is a refactor.

  • PlatformAppleWin.cmake: Move the DNSCFNet class to DNSResolveQueueCFNet.
  • PlatformMac.cmake: Ditto.
  • Sources.txt: Add the DNS.cpp for compilation.
  • SourcesCocoa.txt: Move the DNSCFNet class to DNSResolveQueueCFNet.
  • WebCore.xcodeproj/project.pbxproj: Move the DNSCFNet class to DNSResolveQueueCFNet, add the DNS.cpp

for compilation. Add the new DNSResolveQueueCFNet class.

  • platform/Curl.cmake: Move the DNSCFNet class to DNSResolveQueueCurl.
  • platform/network/DNS.cpp: Add this file with the default implementation of the DNS functions for

all the platforms.
(WebCore::prefetchDNS): Copied from every platform implementation.
(WebCore::resolveDNS): Add the function, resolves a hostname, receives the identifier of the operation
and the completion handler.
(WebCore::stopResolveDNS): Add the function, stops a resolution operation, receives the identifier
of the operation.

  • platform/network/DNS.h: Add the new APIs resolveDNS and stopResolveDNS with the classes used for the

implementation.
(WebCore::IPAddress::IPAddress): Add this class used to send the resolved address information, it does
not depend on libwebrtc rtc classes.
(WebCore::IPAddress::get): Get a reference to the struct sockaddr_in in the IPAddress class.
(WebCore::DNSCompletionHandler): Add this CompletionHandler type to be used when resolving the DNS
address.

  • platform/network/DNSResolveQueue.cpp: Add the DNSResolveQueue platform instantiation in the singleton.

(WebCore::DNSResolveQueue::singleton): Use DNSResolveQueue platform classes when creating the singleton..
(WebCore::DNSResolveQueue::resolve): Add this method to get the address of a hostname, it sends the
identifier and the completion handler to use when returning the result.
(WebCore::DNSResolveQueue::stopResolve): Add this method to stop the resolve operation when required.

  • platform/network/DNSResolveQueue.h: Add the new methods and make the class abstract, so that every

platform can implement the functions.

  • platform/network/cf/DNSResolveQueueCFNet.cpp: Renamed from Source/WebCore/platform/network/cf/DNSCFNet.cpp.

Add the methods to the new class DNSResolveQueueCFNet, move the prefetchDNS to the DNS.cpp general
implementation.

  • platform/network/cf/DNSResolveQueueCFNet.h: Add the new class inheriting from the DNSResolveQueue. Add the

new methods, we have to implement these methods and move the NetworkRTCResolver for COCOA code here.
(WebCore::DNSResolveQueueCF::resolve): Dummy method, not implemented.
(WebCore::DNSResolveQueueCF::stopResolve): Ditto.

  • platform/network/curl/DNSResolveQueueCurl.cpp: Renamed from Source/WebCore/platform/network/curl/DNSCurl.cpp.
  • platform/network/curl/DNSResolveQueueCurl.h: Add the new class inheriting from the DNSResolveQueue.

(WebCore::DNSResolveQueueCurl::resolve): Ditto.
(WebCore::DNSResolveQueueCurl::stopResolve): Ditto.

  • platform/network/soup/DNSResolveQueueSoup.h: New class inheriting from the DNSResolveQueue class, adding

a HasMap with the active operations, it allows stopping them.

  • platform/network/soup/DNSResolveQueueSoup.cpp: Renamed from Source/WebCore/platform/network/curl/DNSSoup.cpp.

(WebCore::resolvedWithObserverCallback): Called when the result address from the soup platform is ready,
sends the address to the completion handler.
(WebCore::DNSResolveQueueSoup::resolve): Launch the resolve operation with the soup library.
(WebCore::DNSResolveQueueSoup::stopResolve): Stop the resolve operation on process with a GCancellable.

Source/WebKit:

Create a specific Cocoa class to isolate the generic code in the base class, make the base implementation port
agnostic and dependent on DNS API in the platform directory which encapsulates the platform specific details.

  • NetworkProcess/webrtc/NetworkRTCProvider.cpp: Create an alias class name defined per platform to instantiate the resolver.

(WebKit::NetworkRTCProvider::createResolver): Used the alias class name and receive a new IPAddress class that is not
dependent on rtc libwebrtc library.

  • NetworkProcess/webrtc/NetworkRTCResolver.cpp: Remove the platform specific code. Use the DNS API to implement the

platform specific code in the default start and stop methods. Add the identifier of the resolve operation to the class.
(WebKit::NetworkRTCResolver::NetworkRTCResolver): Add the identifier in the initialization.
(WebKit::NetworkRTCResolver::~NetworkRTCResolver): Remove the platform specific code.
(WebKit::NetworkRTCResolver::completed): Ditto.
(WebKit::NetworkRTCResolver::start): Add a new implementation using the DNS API.
(WebKit::NetworkRTCResolver::stop): Ditto

  • NetworkProcess/webrtc/NetworkRTCResolver.h: Remove the platform specific code and use the DNSResolveQueue for a general

solution to implement the platform specific code. Avoid using the IPAddress class that depends on libwertc classes to make
it more general regarding DNS name resolution.
(WebKit::NetworkRTCResolver::start): Make this class virtual.
(WebKit::NetworkRTCResolver::stop): Ditto.

  • NetworkProcess/webrtc/NetworkRTCResolverCocoa.cpp: Copied Cocoa code from Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.cpp.

Now this class overrides the start and stop methods that use DNS, cocoa implementation should use the DNS methods in the future and
remove this class, making sure all the platform specific class is in the platform directory.

  • NetworkProcess/webrtc/NetworkRTCResolverCocoa.h: Copied Cocoa code from Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.h.
  • PlatformGTK.cmake: Add NetworkRTCResolver compilation for GTK.
  • WebKit.xcodeproj/project.pbxproj: Add the NetworkRTCResolverCocoa class to the compilation.

Tools:

Added new unit tests for he resolve and stopResolve functions. We need to compile them for the
other platforms when the APIs are supported.

  • TestWebKitAPI/PlatformGTK.cmake:
  • TestWebKitAPI/Tests/WebCore/DNS.cpp:
Location:
trunk
Files:
1 added
18 edited
6 copied
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r229353 r229359  
     12018-03-07  Alejandro G. Castro  <alex@igalia.com>
     2
     3        Make NetworkRTCResolver port agnostic
     4        https://bugs.webkit.org/show_bug.cgi?id=178855
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Add new API in the DNSResolveQueue allowing to revolve hostnames and get the result. Add platform
     9        specific code for soup platform and refactor the other platforms. Added new API to the DNS API header
     10        and move the general code to the DNS.cpp file, that way we can reuse that code in all the platforms
     11        and leave the ResolveQueue class of the platforms in a file.
     12
     13        No new tests because this is a refactor.
     14
     15        * PlatformAppleWin.cmake: Move the DNSCFNet class to DNSResolveQueueCFNet.
     16        * PlatformMac.cmake: Ditto.
     17        * Sources.txt: Add the DNS.cpp for compilation.
     18        * SourcesCocoa.txt: Move the DNSCFNet class to DNSResolveQueueCFNet.
     19        * WebCore.xcodeproj/project.pbxproj: Move the DNSCFNet class to DNSResolveQueueCFNet, add the DNS.cpp
     20        for compilation. Add the new DNSResolveQueueCFNet class.
     21        * platform/Curl.cmake: Move the DNSCFNet class to DNSResolveQueueCurl.
     22        * platform/network/DNS.cpp: Add this file with the default implementation of the DNS functions for
     23        all the platforms.
     24        (WebCore::prefetchDNS): Copied from every platform implementation.
     25        (WebCore::resolveDNS): Add the function, resolves a hostname, receives the identifier of the operation
     26        and the completion handler.
     27        (WebCore::stopResolveDNS): Add the function, stops a resolution operation, receives the identifier
     28        of the operation.
     29        * platform/network/DNS.h: Add the new APIs resolveDNS and stopResolveDNS with the classes used for the
     30        implementation.
     31        (WebCore::IPAddress::IPAddress): Add this class used to send the resolved address information, it does
     32        not depend on libwebrtc rtc classes.
     33        (WebCore::IPAddress::get): Get a reference to the struct sockaddr_in in the IPAddress class.
     34        (WebCore::DNSCompletionHandler): Add this CompletionHandler type to be used when resolving the DNS
     35        address.
     36        * platform/network/DNSResolveQueue.cpp: Add the DNSResolveQueue platform instantiation in the singleton.
     37        (WebCore::DNSResolveQueue::singleton): Use DNSResolveQueue platform classes when creating the singleton..
     38        (WebCore::DNSResolveQueue::resolve): Add this method to get the address of a hostname, it sends the
     39        identifier and the completion handler to use when returning the result.
     40        (WebCore::DNSResolveQueue::stopResolve): Add this method to stop the resolve operation when required.
     41        * platform/network/DNSResolveQueue.h: Add the new methods and make the class abstract, so that every
     42        platform can implement the functions.
     43        * platform/network/cf/DNSResolveQueueCFNet.cpp: Renamed from Source/WebCore/platform/network/cf/DNSCFNet.cpp.
     44        Add the methods to the new class DNSResolveQueueCFNet, move the prefetchDNS to the DNS.cpp general
     45        implementation.
     46        * platform/network/cf/DNSResolveQueueCFNet.h: Add the new class inheriting from the DNSResolveQueue. Add the
     47        new methods, we have to implement these methods and move the NetworkRTCResolver for COCOA code here.
     48        (WebCore::DNSResolveQueueCF::resolve): Dummy method, not implemented.
     49        (WebCore::DNSResolveQueueCF::stopResolve): Ditto.
     50        * platform/network/curl/DNSResolveQueueCurl.cpp: Renamed from Source/WebCore/platform/network/curl/DNSCurl.cpp.
     51        * platform/network/curl/DNSResolveQueueCurl.h: Add the new class inheriting from the DNSResolveQueue.
     52        (WebCore::DNSResolveQueueCurl::resolve): Ditto.
     53        (WebCore::DNSResolveQueueCurl::stopResolve): Ditto.
     54        * platform/network/soup/DNSResolveQueueSoup.h: New class inheriting from the DNSResolveQueue class, adding
     55        a HasMap with the active operations, it allows stopping them.
     56        * platform/network/soup/DNSResolveQueueSoup.cpp: Renamed from Source/WebCore/platform/network/curl/DNSSoup.cpp.
     57        (WebCore::resolvedWithObserverCallback): Called when the result address from the soup platform is ready,
     58        sends the address to the completion handler.
     59        (WebCore::DNSResolveQueueSoup::resolve): Launch the resolve operation with the soup library.
     60        (WebCore::DNSResolveQueueSoup::stopResolve): Stop the resolve operation on process with a GCancellable.
     61
    1622018-03-06  Brian Burg  <bburg@apple.com>
    263
  • trunk/Source/WebCore/PlatformAppleWin.cmake

    r228451 r229359  
    5151    platform/network/cf/CookieStorageCFNet.cpp
    5252    platform/network/cf/CredentialStorageCFNet.cpp
    53     platform/network/cf/DNSCFNet.cpp
     53    platform/network/cf/DNSResolveQueueCFNet.cpp
    5454    platform/network/cf/FormDataStreamCFNet.cpp
    5555    platform/network/cf/LoaderRunLoopCF.cpp
  • trunk/Source/WebCore/PlatformMac.cmake

    r228451 r229359  
    414414    platform/mediastream/mac/MockRealtimeVideoSourceMac.mm
    415415
    416     platform/network/cf/DNSCFNet.cpp
     416    platform/network/cf/DNSResolveQueueCFNet.cpp
    417417    platform/network/cf/FormDataStreamCFNet.cpp
    418418    platform/network/cf/NetworkStorageSessionCFNet.cpp
  • trunk/Source/WebCore/Sources.txt

    r229340 r229359  
    17101710platform/network/CredentialBase.cpp
    17111711platform/network/CredentialStorage.cpp
     1712platform/network/DNS.cpp
    17121713platform/network/DNSResolveQueue.cpp
    17131714platform/network/DataURLDecoder.cpp
  • trunk/Source/WebCore/SourcesCocoa.txt

    r228912 r229359  
    483483platform/mock/MediaPlaybackTargetMock.cpp
    484484
    485 platform/network/cf/DNSCFNet.cpp
     485platform/network/cf/DNSResolveQueueCFNet.cpp
    486486platform/network/cf/FormDataStreamCFNet.cpp
    487487platform/network/cf/NetworkStorageSessionCFNet.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r229353 r229359  
    22602260                7EE6846D12D26E3800E79415 /* ResourceRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6845A12D26E3800E79415 /* ResourceRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
    22612261                7EE6846F12D26E3800E79415 /* ResourceRequestCFNet.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6845C12D26E3800E79415 /* ResourceRequestCFNet.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2262                7EE6846F12D26E3800E73215 /* DNSResolveQueueCFNet.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6845C12D26E3800FF9415 /* DNSResolveQueueCFNet.h */; settings = {ATTRIBUTES = (Private, ); }; };
    22622263                7EE6847012D26E3800E79415 /* ResourceResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6845D12D26E3800E79415 /* ResourceResponse.h */; settings = {ATTRIBUTES = (Private, ); }; };
    22632264                7F4C96DD1AD4483500365A50 /* JSFetchBody.h in Headers */ = {isa = PBXBuildFile; fileRef = 7F4C96D91AD4483500365A50 /* JSFetchBody.h */; };
     
    96219622                7EE6845B12D26E3800E79415 /* ResourceRequestCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceRequestCFNet.cpp; sourceTree = "<group>"; };
    96229623                7EE6845C12D26E3800E79415 /* ResourceRequestCFNet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceRequestCFNet.h; sourceTree = "<group>"; };
     9624                7EE6845C12D26E3800FF9415 /* DNSResolveQueueCFNet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNSResolveQueueCFNet.h; sourceTree = "<group>"; };
    96239625                7EE6845D12D26E3800E79415 /* ResourceResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceResponse.h; sourceTree = "<group>"; };
    96249626                7F4C96D81AD4483500365A50 /* JSFetchBody.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchBody.cpp; sourceTree = "<group>"; };
     
    1214212144                B2E4EC960D00C22B00432643 /* SVGZoomEvent.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = SVGZoomEvent.idl; sourceTree = "<group>"; };
    1214312145                B2ED97700B1F55CE00257D0F /* GraphicsContextCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextCG.cpp; sourceTree = "<group>"; };
     12146                1AF8E13212565A4445230FF7 /* DNS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNS.cpp; sourceTree = "<group>"; };
    1214412147                B2F34FE50E82F81400F627CD /* DNS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNS.h; sourceTree = "<group>"; };
    12145                 B2F34FE80E82F82700F627CD /* DNSCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNSCFNet.cpp; sourceTree = "<group>"; };
     12148                B2F34FE80E82F82700F648CD /* DNSResolveQueueCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNSResolveQueueCFNet.cpp; sourceTree = "<group>"; };
    1214612149                B2FA3C4E0AB75A6E000E5AC4 /* JSSVGAnimateColorElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGAnimateColorElement.cpp; sourceTree = "<group>"; };
    1214712150                B2FA3C4F0AB75A6E000E5AC4 /* JSSVGAnimateColorElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSSVGAnimateColorElement.h; sourceTree = "<group>"; };
     
    1874218745                                E4A007841B820ED3002C5A6E /* DataURLDecoder.cpp */,
    1874318746                                E4A007821B820EC8002C5A6E /* DataURLDecoder.h */,
     18747                                1AF8E13212565A4445230FF7 /* DNS.cpp */,
    1874418748                                B2F34FE50E82F81400F627CD /* DNS.h */,
    1874518749                                7C60128060078BB70E367A95 /* DNSResolveQueue.cpp */,
     
    2347623480                                7EE6844E12D26E3800E79415 /* AuthenticationChallenge.h */,
    2347723481                                5F2DBBE8178E336900141486 /* CertificateInfo.h */,
    23478                                 B2F34FE80E82F82700F627CD /* DNSCFNet.cpp */,
     23482                                B2F34FE80E82F82700F648CD /* DNSResolveQueueCFNet.cpp */,
     23483                                7EE6845C12D26E3800FF9415 /* DNSResolveQueueCFNet.h */,
    2347923484                                7EE6845312D26E3800E79415 /* FormDataStreamCFNet.cpp */,
    2348023485                                7EE6845412D26E3800E79415 /* FormDataStreamCFNet.h */,
     
    2734127346                                84730D771248F0B300D3A9C9 /* DistantLightSource.h in Headers */,
    2734227347                                B2F34FE60E82F81400F627CD /* DNS.h in Headers */,
     27348                                7EE6846F12D26E3800E73215 /* DNSResolveQueueCFNet.h in Headers */,
    2734327349                                A8185F4009765766005826D9 /* Document.h in Headers */,
    2734427350                                A3BB59F41457A40D00AC56FE /* DocumentEventQueue.h in Headers */,
  • trunk/Source/WebCore/platform/Curl.cmake

    r228577 r229359  
    2222    platform/network/curl/CurlSSLHandle.cpp
    2323    platform/network/curl/CurlSSLVerifier.cpp
    24     platform/network/curl/DNSCurl.cpp
     24    platform/network/curl/DNSResolveQueueCurl.cpp
    2525    platform/network/curl/NetworkStorageSessionCurl.cpp
    2626    platform/network/curl/ProxyServerCurl.cpp
  • trunk/Source/WebCore/platform/SourcesSoup.txt

    r225054 r229359  
    2828platform/network/soup/CookieStorageSoup.cpp
    2929platform/network/soup/CredentialStorageSoup.cpp
    30 platform/network/soup/DNSSoup.cpp
     30platform/network/soup/DNSResolveQueueSoup.cpp
    3131platform/network/soup/GRefPtrSoup.cpp
    3232platform/network/soup/NetworkStorageSessionSoup.cpp
  • trunk/Source/WebCore/platform/network/DNS.cpp

    r229358 r229359  
    11/*
    2  * Copyright (C) 2008 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2009 Apple Inc. All Rights Reserved.
     3 * Copyright (C) 2012, 2018 Igalia S.L.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2122 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2223 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2425 */
    2526
    2627#include "config.h"
    2728#include "DNS.h"
     29
    2830#include "DNSResolveQueue.h"
    29 
    30 #if USE(CURL)
    31 
    32 #include "NotImplemented.h"
     31#include <wtf/MainThread.h>
    3332
    3433namespace WebCore {
    3534
    36 void DNSResolveQueue::updateIsUsingProxy()
     35void prefetchDNS(const String& hostname)
    3736{
    38     notImplemented();
     37    ASSERT(isMainThread());
     38    if (hostname.isEmpty())
     39        return;
     40
     41    DNSResolveQueue::singleton().add(hostname);
    3942}
    4043
    41 void DNSResolveQueue::platformResolve(const String& /* hostname */)
     44void resolveDNS(const String& hostname, uint64_t identifier, DNSCompletionHandler&& completionHandler)
    4245{
    43     notImplemented();
     46    ASSERT(isMainThread());
     47    if (hostname.isEmpty())
     48        return;
     49
     50    WebCore::DNSResolveQueue::singleton().resolve(hostname, identifier, WTFMove(completionHandler));
    4451}
    4552
    46 void prefetchDNS(const String& /* hostname */)
     53void stopResolveDNS(uint64_t identifier)
    4754{
    48     notImplemented();
     55    WebCore::DNSResolveQueue::singleton().stopResolve(identifier);
    4956}
    5057
    5158}
    52 
    53 #endif
  • trunk/Source/WebCore/platform/network/DNS.h

    r172849 r229359  
    2424 */
    2525
    26 #ifndef DNS_h
    27 #define DNS_h
     26#pragma once
     27
     28#if PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WPE)
     29#include <netinet/in.h>
     30#elif PLATFORM(WIN)
     31#include <winsock2.h>
     32#endif
    2833
    2934#include <wtf/Forward.h>
     
    3136namespace WebCore {
    3237
     38class WEBCORE_EXPORT IPAddress {
     39public:
     40    explicit IPAddress(const struct sockaddr_in& address)
     41    {
     42        memset(&m_address, 0, sizeof(struct sockaddr_in));
     43        m_address = address;
     44    }
     45
     46    const struct in_addr& getSinAddr() { return m_address.sin_addr; };
     47
     48private:
     49    struct sockaddr_in m_address;
     50};
     51
     52enum class DNSError { Unknown, CannotResolve, Cancelled };
     53
     54using DNSAddressesOrError = Expected<Vector<WebCore::IPAddress>, DNSError>;
     55using DNSCompletionHandler = WTF::CompletionHandler<void(DNSAddressesOrError&&)>;
     56
    3357WEBCORE_EXPORT void prefetchDNS(const String& hostname);
     58WEBCORE_EXPORT void resolveDNS(const String& hostname, uint64_t identifier, DNSCompletionHandler&&);
     59WEBCORE_EXPORT void stopResolveDNS(uint64_t identifier);
     60
    3461}
    35 
    36 #endif
  • trunk/Source/WebCore/platform/network/DNSResolveQueue.cpp

    r229209 r229359  
    2828#include "DNSResolveQueue.h"
    2929
     30#if USE(SOUP)
     31#include "DNSResolveQueueSoup.h"
     32#elif USE(CURL)
     33#include "DNSResolveQueueCurl.h"
     34#elif USE(CF)
     35#include "DNSResolveQueueCFNet.h"
     36#endif
     37
    3038#include <wtf/NeverDestroyed.h>
    3139
     
    5260DNSResolveQueue& DNSResolveQueue::singleton()
    5361{
    54     static NeverDestroyed<DNSResolveQueue> queue;
     62    static NeverDestroyed<DNSResolveQueuePlatform> queue;
    5563
    5664    return queue;
     
    6068    : m_timer(*this, &DNSResolveQueue::timerFired)
    6169    , m_requestsInFlight(0)
    62     , m_isUsingProxy(true)
    6370{
    6471    // isUsingProxy will return the initial value of m_isUsingProxy at first on
  • trunk/Source/WebCore/platform/network/DNSResolveQueue.h

    r229174 r229359  
    2828#define DNSResolveQueue_h
    2929
     30#include "DNS.h"
    3031#include "Timer.h"
    3132#include <atomic>
     
    4041
    4142public:
     43    DNSResolveQueue();
     44    virtual ~DNSResolveQueue() = default;
     45
    4246    static DNSResolveQueue& singleton();
    4347
     48    virtual void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) = 0;
     49    virtual void stopResolve(uint64_t identifier) = 0;
    4450    void add(const String& hostname);
    4551    void decrementRequestCount()
     
    4854    }
    4955
    50 private:
    51     DNSResolveQueue();
    52 
     56protected:
    5357    bool isUsingProxy();
    5458
    55     void updateIsUsingProxy();
    56     void platformResolve(const String&);
     59    bool m_isUsingProxy { true };
    5760
     61private:
     62    virtual void updateIsUsingProxy() = 0;
     63    virtual void platformResolve(const String&) = 0;
    5864    void timerFired();
    5965
     
    6268    HashSet<String> m_names;
    6369    std::atomic<int> m_requestsInFlight;
    64     bool m_isUsingProxy;
    6570    MonotonicTime m_lastProxyEnabledStatusCheckTime;
    6671};
  • trunk/Source/WebCore/platform/network/cf/DNSResolveQueueCFNet.cpp

    r229358 r229359  
    2727
    2828#include "config.h"
    29 #include "DNS.h"
    30 #include "DNSResolveQueue.h"
     29#include "DNSResolveQueueCFNet.h"
    3130
     31#include "NotImplemented.h"
     32#include "Timer.h"
    3233#include "URL.h"
    33 #include "Timer.h"
    3434#include <wtf/HashSet.h>
    3535#include <wtf/MainThread.h>
     
    3838#include <wtf/text/StringHash.h>
    3939
    40 #if PLATFORM(IOS)
    41 #include <CFNetwork/CFNetwork.h>
     40#if PLATFORM(WIN)
     41#include "LoaderRunLoopCF.h"
    4242#endif
    4343
    44 #if PLATFORM(WIN)
    45 #include "LoaderRunLoopCF.h"
     44#if PLATFORM(WIN) || PLATFORM(IOS)
    4645#include <CFNetwork/CFNetwork.h>
    4746#endif
     
    4948namespace WebCore {
    5049
    51 void DNSResolveQueue::updateIsUsingProxy()
     50void DNSResolveQueueCFNet::updateIsUsingProxy()
    5251{
    5352    RetainPtr<CFDictionaryRef> proxySettings = adoptCF(CFNetworkCopySystemProxySettings());
     
    7978}
    8079
    81 void DNSResolveQueue::platformResolve(const String& hostname)
     80void DNSResolveQueueCFNet::platformResolve(const String& hostname)
    8281{
    8382    ASSERT(isMainThread());
     
    102101}
    103102
    104 void prefetchDNS(const String& hostname)
     103void DNSResolveQueueCFNet::resolve(const String& /* hostname */, uint64_t /* identifier */, DNSCompletionHandler&& /* completionHandler */)
    105104{
    106     ASSERT(isMainThread());
    107     if (hostname.isEmpty())
    108         return;
    109     DNSResolveQueue::singleton().add(hostname);
     105    notImplemented();
     106}
     107
     108void DNSResolveQueueCFNet::stopResolve(uint64_t /* identifier */)
     109{
     110    notImplemented();
    110111}
    111112
  • trunk/Source/WebCore/platform/network/cf/DNSResolveQueueCFNet.h

    r229358 r229359  
    11/*
    2  * Copyright (C) 2008 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2018 Igalia S.L.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #include "config.h"
    27 #include "DNS.h"
     26#pragma once
     27
    2828#include "DNSResolveQueue.h"
    29 
    30 #if USE(CURL)
    31 
    32 #include "NotImplemented.h"
    3329
    3430namespace WebCore {
    3531
    36 void DNSResolveQueue::updateIsUsingProxy()
    37 {
    38     notImplemented();
    39 }
     32class DNSResolveQueueCFNet final : public DNSResolveQueue {
     33public:
     34    DNSResolveQueueCFNet() = default;
     35    void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) final;
     36    void stopResolve(uint64_t identifier) final;
    4037
    41 void DNSResolveQueue::platformResolve(const String& /* hostname */)
    42 {
    43     notImplemented();
    44 }
     38private:
     39    void updateIsUsingProxy() final;
     40    void platformResolve(const String&) final;
     41};
    4542
    46 void prefetchDNS(const String& /* hostname */)
    47 {
    48     notImplemented();
    49 }
     43using DNSResolveQueuePlatform = DNSResolveQueueCFNet;
    5044
    5145}
    52 
    53 #endif
  • trunk/Source/WebCore/platform/network/curl/DNSResolveQueueCurl.cpp

    r229358 r229359  
    2525
    2626#include "config.h"
    27 #include "DNS.h"
    28 #include "DNSResolveQueue.h"
     27#include "DNSResolveQueueCurl.h"
    2928
    3029#if USE(CURL)
     
    3433namespace WebCore {
    3534
    36 void DNSResolveQueue::updateIsUsingProxy()
     35void DNSResolveQueueCurl::updateIsUsingProxy()
    3736{
    3837    notImplemented();
    3938}
    4039
    41 void DNSResolveQueue::platformResolve(const String& /* hostname */)
     40void DNSResolveQueueCurl::platformResolve(const String& /* hostname */)
    4241{
    4342    notImplemented();
    4443}
    4544
    46 void prefetchDNS(const String& /* hostname */)
     45void DNSResolveQueueCurl::resolve(const String& /* hostname */, uint64_t /* identifier */, DNSCompletionHandler&& /* completionHandler */)
     46{
     47    notImplemented();
     48}
     49
     50void DNSResolveQueueCurl::stopResolve(uint64_t /* identifier */)
    4751{
    4852    notImplemented();
  • trunk/Source/WebCore/platform/network/curl/DNSResolveQueueCurl.h

    r229358 r229359  
    11/*
    2  * Copyright (C) 2008 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2018 Igalia S.L.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #include "config.h"
    27 #include "DNS.h"
     26#pragma once
     27
    2828#include "DNSResolveQueue.h"
    29 
    30 #if USE(CURL)
    31 
    32 #include "NotImplemented.h"
    3329
    3430namespace WebCore {
    3531
    36 void DNSResolveQueue::updateIsUsingProxy()
    37 {
    38     notImplemented();
    39 }
     32class DNSResolveQueueCurl final : public DNSResolveQueue {
     33public:
     34    DNSResolveQueueCurl() = default;
     35    void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) final;
     36    void stopResolve(uint64_t identifier) final;
    4037
    41 void DNSResolveQueue::platformResolve(const String& /* hostname */)
    42 {
    43     notImplemented();
    44 }
     38private:
     39    void updateIsUsingProxy() final;
     40    void platformResolve(const String&) final;
     41};
    4542
    46 void prefetchDNS(const String& /* hostname */)
    47 {
    48     notImplemented();
    49 }
     43using DNSResolveQueuePlatform = DNSResolveQueueCurl;
    5044
    5145}
    52 
    53 #endif
  • trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.cpp

    r229358 r229359  
    2626
    2727#include "config.h"
    28 #include "DNS.h"
    29 #include "DNSResolveQueue.h"
     28#include "DNSResolveQueueSoup.h"
    3029
    3130#if USE(SOUP)
     
    3433#include "SoupNetworkSession.h"
    3534#include <libsoup/soup.h>
     35#include <wtf/CompletionHandler.h>
    3636#include <wtf/MainThread.h>
    3737#include <wtf/glib/GUniquePtr.h>
     
    7777}
    7878
    79 void DNSResolveQueue::updateIsUsingProxy()
     79void DNSResolveQueueSoup::updateIsUsingProxy()
    8080{
    8181    GRefPtr<GProxyResolver> resolver;
     
    9292}
    9393
    94 void DNSResolveQueue::platformResolve(const String& hostname)
     94static void resolvedWithObserverCallback(SoupAddress* address, guint status, void* data)
     95{
     96    ASSERT(data);
     97    auto* resolveQueue = static_cast<DNSResolveQueueSoup*>(data);
     98
     99    uint64_t identifier = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(address), "identifier"));
     100
     101    auto completionAndCancelHandlers = resolveQueue->takeCompletionAndCancelHandlers(identifier);
     102
     103    if (!completionAndCancelHandlers)
     104        return;
     105
     106    auto completionHandler = WTFMove(completionAndCancelHandlers.get()->first);
     107
     108    if (status != SOUP_STATUS_OK) {
     109        DNSError error = DNSError::Unknown;
     110
     111        switch (status) {
     112        case SOUP_STATUS_CANT_RESOLVE:
     113            error = DNSError::CannotResolve;
     114            break;
     115        case SOUP_STATUS_CANCELLED:
     116            error = DNSError::Cancelled;
     117            break;
     118        case SOUP_STATUS_OK:
     119        default:
     120            ASSERT_NOT_REACHED();
     121        };
     122
     123        completionHandler(makeUnexpected(error));
     124        return;
     125    }
     126
     127    if (!soup_address_is_resolved(address)) {
     128        completionHandler(makeUnexpected(DNSError::Unknown));
     129        return;
     130    }
     131
     132    Vector<WebCore::IPAddress> addresses;
     133    addresses.reserveInitialCapacity(1);
     134    int len;
     135    auto* ipAddress = reinterpret_cast<const struct sockaddr_in*>(soup_address_get_sockaddr(address, &len));
     136    for (unsigned i = 0; i < sizeof(*ipAddress) / len; i++)
     137        addresses.uncheckedAppend(WebCore::IPAddress(ipAddress[i]));
     138
     139    completionHandler(addresses);
     140}
     141
     142std::unique_ptr<DNSResolveQueueSoup::CompletionAndCancelHandlers> DNSResolveQueueSoup::takeCompletionAndCancelHandlers(uint64_t identifier)
     143{
     144    ASSERT(isMainThread());
     145
     146    auto completionAndCancelHandlers = m_completionAndCancelHandlers.take(identifier);
     147
     148    if (!completionAndCancelHandlers)
     149        return nullptr;
     150
     151    return WTFMove(completionAndCancelHandlers);
     152}
     153
     154void DNSResolveQueueSoup::removeCancelAndCompletionHandler(uint64_t identifier)
     155{
     156    ASSERT(isMainThread());
     157
     158    m_completionAndCancelHandlers.remove(identifier);
     159}
     160
     161void DNSResolveQueueSoup::platformResolve(const String& hostname)
    95162{
    96163    ASSERT(isMainThread());
     
    99166}
    100167
    101 void prefetchDNS(const String& hostname)
     168void DNSResolveQueueSoup::resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&& completionHandler)
    102169{
    103170    ASSERT(isMainThread());
    104     if (hostname.isEmpty())
    105         return;
    106171
    107     DNSResolveQueue::singleton().add(hostname);
     172    auto address = adoptGRef(soup_address_new(hostname.utf8().data(), 0));
     173    auto cancellable = adoptGRef(g_cancellable_new());
     174    soup_address_resolve_async(address.get(), soup_session_get_async_context(WebCore::NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession()), cancellable.get(), resolvedWithObserverCallback, this);
     175
     176    g_object_set_data(G_OBJECT(address.get()), "identifier", GUINT_TO_POINTER(identifier));
     177
     178    m_completionAndCancelHandlers.add(identifier, std::make_unique<DNSResolveQueueSoup::CompletionAndCancelHandlers>(WTFMove(completionHandler), WTFMove(cancellable)));
     179}
     180
     181void DNSResolveQueueSoup::stopResolve(uint64_t identifier)
     182{
     183    ASSERT(isMainThread());
     184
     185    if (auto completionAndCancelHandler = m_completionAndCancelHandlers.take(identifier)) {
     186        g_cancellable_cancel(completionAndCancelHandler.get()->second.get());
     187        completionAndCancelHandler.get()->first(makeUnexpected(DNSError::Cancelled));
     188    }
    108189}
    109190
  • trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.h

    r229358 r229359  
    11/*
    2  * Copyright (C) 2009 Apple Inc. All Rights Reserved.
    3  * Copyright (C) 2012 Igalia S.L.
     2 * Copyright (C) 2018 Igalia S.L.
    43 *
    54 * Redistribution and use in source and binary forms, with or without
     
    2524 */
    2625
    27 #ifndef DNSResolveQueue_h
    28 #define DNSResolveQueue_h
     26#pragma once
    2927
    30 #include "Timer.h"
    31 #include <atomic>
    32 #include <wtf/Forward.h>
    33 #include <wtf/HashSet.h>
    34 #include <wtf/text/StringHash.h>
     28#include "DNSResolveQueue.h"
     29
     30#include <wtf/HashMap.h>
     31#include <wtf/glib/GRefPtr.h>
    3532
    3633namespace WebCore {
    3734
    38 class DNSResolveQueue {
    39     friend NeverDestroyed<DNSResolveQueue>;
     35class DNSResolveQueueSoup final : public DNSResolveQueue {
     36public:
     37    using CompletionAndCancelHandlers = std::pair<WebCore::DNSCompletionHandler, GRefPtr<GCancellable>>;
    4038
    41 public:
    42     static DNSResolveQueue& singleton();
     39    DNSResolveQueueSoup() = default;
     40    void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) final;
     41    void stopResolve(uint64_t identifier) final;
    4342
    44     void add(const String& hostname);
    45     void decrementRequestCount()
    46     {
    47         --m_requestsInFlight;
    48     }
     43    std::unique_ptr<CompletionAndCancelHandlers> takeCompletionAndCancelHandlers(uint64_t identifier);
     44    void removeCancelAndCompletionHandler(uint64_t identifier);
    4945
    5046private:
    51     DNSResolveQueue();
     47    void updateIsUsingProxy() final;
    5248
    53     bool isUsingProxy();
     49    HashMap<uint64_t, std::unique_ptr<CompletionAndCancelHandlers>> m_completionAndCancelHandlers;
    5450
    55     void updateIsUsingProxy();
    56     void platformResolve(const String&);
    57 
    58     void timerFired();
    59 
    60     Timer m_timer;
    61 
    62     HashSet<String> m_names;
    63     std::atomic<int> m_requestsInFlight;
    64     bool m_isUsingProxy;
    65     MonotonicTime m_lastProxyEnabledStatusCheckTime;
     51    void platformResolve(const String&) final;
    6652};
    6753
     54using DNSResolveQueuePlatform = DNSResolveQueueSoup;
     55
    6856}
    69 
    70 #endif // DNSResolveQueue_h
  • trunk/Source/WebKit/ChangeLog

    r229343 r229359  
     12018-03-07  Alejandro G. Castro  <alex@igalia.com>
     2
     3        Make NetworkRTCResolver port agnostic
     4        https://bugs.webkit.org/show_bug.cgi?id=178855
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Create a specific Cocoa class to isolate the generic code in the base class, make the base implementation port
     9        agnostic and dependent on DNS API in the platform directory which encapsulates the platform specific details.
     10
     11        * NetworkProcess/webrtc/NetworkRTCProvider.cpp: Create an alias class name defined per platform to instantiate the resolver.
     12        (WebKit::NetworkRTCProvider::createResolver): Used the alias class name and receive a new IPAddress class that is not
     13        dependent on rtc libwebrtc library.
     14        * NetworkProcess/webrtc/NetworkRTCResolver.cpp: Remove the platform specific code. Use the DNS API to implement the
     15        platform specific code in the default start and stop methods. Add the identifier of the resolve operation to the class.
     16        (WebKit::NetworkRTCResolver::NetworkRTCResolver): Add the identifier in the initialization.
     17        (WebKit::NetworkRTCResolver::~NetworkRTCResolver): Remove the platform specific code.
     18        (WebKit::NetworkRTCResolver::completed): Ditto.
     19        (WebKit::NetworkRTCResolver::start): Add a new implementation using the DNS API.
     20        (WebKit::NetworkRTCResolver::stop): Ditto
     21        * NetworkProcess/webrtc/NetworkRTCResolver.h: Remove the platform specific code and use the DNSResolveQueue for a general
     22        solution to implement the platform specific code. Avoid using the IPAddress class that depends on libwertc classes to make
     23        it more general regarding DNS name resolution.
     24        (WebKit::NetworkRTCResolver::start): Make this class virtual.
     25        (WebKit::NetworkRTCResolver::stop): Ditto.
     26        * NetworkProcess/webrtc/NetworkRTCResolverCocoa.cpp: Copied Cocoa code from Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.cpp.
     27        Now this class overrides the start and stop methods that use DNS, cocoa implementation should use the DNS methods in the future and
     28        remove this class, making sure all the platform specific class is in the platform directory.
     29        * NetworkProcess/webrtc/NetworkRTCResolverCocoa.h: Copied Cocoa code from Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.h.
     30        * PlatformGTK.cmake: Add NetworkRTCResolver compilation for GTK.
     31        * WebKit.xcodeproj/project.pbxproj: Add the NetworkRTCResolverCocoa class to the compilation.
     32
    1332018-03-06  Brent Fulgham  <bfulgham@apple.com>
    234
  • trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp

    r225499 r229359  
    4141#include <wtf/text/WTFString.h>
    4242
     43#if PLATFORM(COCOA)
     44#include "NetworkRTCResolverCocoa.h"
     45#endif
     46
    4347namespace WebKit {
    4448
     
    163167}
    164168
     169#if PLATFORM(COCOA)
     170
    165171void NetworkRTCProvider::createResolver(uint64_t identifier, const String& address)
    166172{
    167     auto resolver = std::make_unique<NetworkRTCResolver>([this, identifier](NetworkRTCResolver::AddressesOrError&& result) mutable {
     173    auto resolver = NetworkRTCResolver::create(identifier, [this, identifier](WebCore::DNSAddressesOrError&& result) mutable {
    168174        if (!result.has_value()) {
    169             if (result.error() != NetworkRTCResolver::Error::Cancelled)
     175            if (result.error() != WebCore::DNSError::Cancelled)
    170176                m_connection->connection().send(Messages::WebRTCResolver::ResolvedAddressError(1), identifier);
    171177            return;
    172178        }
    173         m_connection->connection().send(Messages::WebRTCResolver::SetResolvedAddress(result.value()), identifier);
     179
     180        auto addresses = WTF::map(result.value(), [] (auto& address) {
     181            return RTCNetwork::IPAddress { rtc::IPAddress { address.getSinAddr() } };
     182        });
     183
     184        m_connection->connection().send(Messages::WebRTCResolver::SetResolvedAddress(addresses), identifier);
    174185    });
    175186    resolver->start(address);
     
    182193        resolver->stop();
    183194}
     195
     196#else
     197
     198void NetworkRTCProvider::createResolver(uint64_t identifier, const String& address)
     199{
     200    auto completionHandler = [this, identifier](WebCore::DNSAddressesOrError&& result) mutable {
     201        if (!result.has_value()) {
     202            if (result.error() != WebCore::DNSError::Cancelled)
     203                m_connection->connection().send(Messages::WebRTCResolver::ResolvedAddressError(1), identifier);
     204            return;
     205        }
     206
     207        auto addresses = WTF::map(result.value(), [] (auto& address) {
     208            return RTCNetwork::IPAddress { rtc::IPAddress { address.getSinAddr() } };
     209        });
     210
     211        m_connection->connection().send(Messages::WebRTCResolver::SetResolvedAddress(addresses), identifier);
     212    };
     213
     214    WebCore::resolveDNS(address, identifier, WTFMove(completionHandler));
     215}
     216
     217void NetworkRTCProvider::stopResolver(uint64_t identifier)
     218{
     219    WebCore::stopResolveDNS(identifier);
     220}
     221
     222#endif
    184223
    185224void NetworkRTCProvider::closeListeningSockets(Function<void()>&& completionHandler)
  • trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.cpp

    r223990 r229359  
    3333namespace WebKit {
    3434
    35 static void resolvedName(CFHostRef hostRef, CFHostInfoType typeInfo, const CFStreamError *error, void *info)
     35// FIXME: Use the function after removing the NetworkRTCResolverCocoa.
     36#if !PLATFORM(COCOA)
     37std::unique_ptr<NetworkRTCResolver> NetworkRTCResolver::create(uint64_t identifier, WebCore::DNSCompletionHandler&& completionHandler)
    3638{
    37     ASSERT_UNUSED(typeInfo, !typeInfo);
     39    return std::unique_ptr<NetworkRTCResolver>(new NetworkRTCResolver(identifier, WTFMove(completionHandler)));
     40}
     41#endif
    3842
    39     if (error->domain) {
    40         // FIXME: Need to handle failure, but info is not provided in the callback.
    41         return;
    42     }
    43 
    44     ASSERT(info);
    45     auto* resolver = static_cast<NetworkRTCResolver*>(info);
    46 
    47     Boolean result;
    48     CFArrayRef resolvedAddresses = (CFArrayRef)CFHostGetAddressing(hostRef, &result);
    49     ASSERT_UNUSED(result, result);
    50 
    51     size_t count = CFArrayGetCount(resolvedAddresses);
    52     Vector<RTCNetwork::IPAddress> addresses;
    53     addresses.reserveInitialCapacity(count);
    54 
    55     for (size_t index = 0; index < count; ++index) {
    56         CFDataRef data = (CFDataRef)CFArrayGetValueAtIndex(resolvedAddresses, index);
    57         auto* address = reinterpret_cast<const struct sockaddr_in*>(CFDataGetBytePtr(data));
    58         addresses.uncheckedAppend(RTCNetwork::IPAddress(rtc::IPAddress(address->sin_addr)));
    59     }
    60     resolver->completed(addresses);
    61 }
    62 
    63 NetworkRTCResolver::NetworkRTCResolver(CompletionHandler&& completionHandler)
    64     : m_completionHandler(WTFMove(completionHandler))
     43NetworkRTCResolver::NetworkRTCResolver(uint64_t identifier, WebCore::DNSCompletionHandler&& completionHandler)
     44    : m_identifier(identifier)
     45    , m_completionHandler(WTFMove(completionHandler))
    6546{
    6647}
     
    6849NetworkRTCResolver::~NetworkRTCResolver()
    6950{
    70     CFHostUnscheduleFromRunLoop(m_host.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    71     CFHostSetClient(m_host.get(), nullptr, nullptr);
    7251    if (auto completionHandler = WTFMove(m_completionHandler))
    73         completionHandler(makeUnexpected(Error::Unknown));
     52        completionHandler(makeUnexpected(WebCore::DNSError::Unknown));
    7453}
    7554
    7655void NetworkRTCResolver::start(const String& address)
    7756{
    78     m_host = adoptCF(CFHostCreateWithName(kCFAllocatorDefault, address.createCFString().get()));
    79     CFHostClientContext context = { 0, this, nullptr, nullptr, nullptr };
    80     CFHostSetClient(m_host.get(), resolvedName, &context);
    81     CFHostScheduleWithRunLoop(m_host.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    82     Boolean result = CFHostStartInfoResolution(m_host.get(), kCFHostAddresses, nullptr);
    83     ASSERT_UNUSED(result, result);
     57    WebCore::resolveDNS(address, m_identifier, WTFMove(m_completionHandler));
    8458}
    8559
    8660void NetworkRTCResolver::stop()
    8761{
    88     CFHostCancelInfoResolution(m_host.get(), CFHostInfoType::kCFHostAddresses);
    89     if (auto completionHandler = WTFMove(m_completionHandler))
    90         completionHandler(makeUnexpected(Error::Cancelled));
    91 }
    92 
    93 void NetworkRTCResolver::completed(const Vector<RTCNetwork::IPAddress>& addresses)
    94 {
    95     if (auto completionHandler = WTFMove(m_completionHandler))
    96         completionHandler({ addresses });
     62    WebCore::stopResolveDNS(m_identifier);
    9763}
    9864
  • trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.h

    r223990 r229359  
    2929
    3030#include "RTCNetwork.h"
    31 #include <CFNetwork/CFHost.h>
     31#include <WebCore/DNS.h>
    3232#include <wtf/CompletionHandler.h>
    3333#include <wtf/text/WTFString.h>
     
    3737class NetworkRTCResolver {
    3838public:
    39     enum class Error { Unknown, Cancelled };
     39    static std::unique_ptr<NetworkRTCResolver> create(uint64_t identifier, WebCore::DNSCompletionHandler&&);
    4040
    41     using AddressesOrError = Expected<std::reference_wrapper<const Vector<RTCNetwork::IPAddress>>, Error>;
    42     using CompletionHandler = WTF::CompletionHandler<void(AddressesOrError&&)>;
     41    NetworkRTCResolver(uint64_t identifier, WebCore::DNSCompletionHandler&&);
     42    virtual ~NetworkRTCResolver();
    4343
    44     explicit NetworkRTCResolver(CompletionHandler&&);
    45     ~NetworkRTCResolver();
     44    virtual void start(const String& address);
     45    virtual void stop();
    4646
    47     void start(const String& address);
    48     void stop();
    49 
    50     void completed(const Vector<RTCNetwork::IPAddress>&);
    51 
    52 private:
    53     CompletionHandler m_completionHandler;
    54     RetainPtr<CFHostRef> m_host;
     47protected:
     48    uint64_t m_identifier;
     49    WebCore::DNSCompletionHandler m_completionHandler;
    5550};
    5651
  • trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolverCocoa.cpp

    r229358 r229359  
    2525
    2626#include "config.h"
    27 #include "NetworkRTCResolver.h"
     27#include "NetworkRTCResolverCocoa.h"
    2828
    2929#if USE(LIBWEBRTC)
     
    3737    ASSERT_UNUSED(typeInfo, !typeInfo);
    3838
     39    ASSERT(info);
     40    auto* resolver = static_cast<NetworkRTCResolverCocoa*>(info);
     41
    3942    if (error->domain) {
    4043        // FIXME: Need to handle failure, but info is not provided in the callback.
     44        resolver->completed(makeUnexpected(WebCore::DNSError::Unknown));
    4145        return;
    4246    }
    43 
    44     ASSERT(info);
    45     auto* resolver = static_cast<NetworkRTCResolver*>(info);
    4647
    4748    Boolean result;
     
    5051
    5152    size_t count = CFArrayGetCount(resolvedAddresses);
    52     Vector<RTCNetwork::IPAddress> addresses;
     53    Vector<WebCore::IPAddress> addresses;
    5354    addresses.reserveInitialCapacity(count);
    5455
     
    5657        CFDataRef data = (CFDataRef)CFArrayGetValueAtIndex(resolvedAddresses, index);
    5758        auto* address = reinterpret_cast<const struct sockaddr_in*>(CFDataGetBytePtr(data));
    58         addresses.uncheckedAppend(RTCNetwork::IPAddress(rtc::IPAddress(address->sin_addr)));
     59        addresses.uncheckedAppend(WebCore::IPAddress(*address));
    5960    }
    60     resolver->completed(addresses);
     61    resolver->completed(WTFMove(addresses));
    6162}
    6263
    63 NetworkRTCResolver::NetworkRTCResolver(CompletionHandler&& completionHandler)
    64     : m_completionHandler(WTFMove(completionHandler))
     64std::unique_ptr<NetworkRTCResolver> NetworkRTCResolver::create(uint64_t identifier, WebCore::DNSCompletionHandler&& completionHandler)
     65{
     66    return std::unique_ptr<NetworkRTCResolver>(new NetworkRTCResolverCocoa(identifier, WTFMove(completionHandler)));
     67}
     68
     69NetworkRTCResolverCocoa::NetworkRTCResolverCocoa(uint64_t identifier, WebCore::DNSCompletionHandler&& completionHandler)
     70    : NetworkRTCResolver(identifier, WTFMove(completionHandler))
    6571{
    6672}
    6773
    68 NetworkRTCResolver::~NetworkRTCResolver()
     74NetworkRTCResolverCocoa::~NetworkRTCResolverCocoa()
    6975{
    7076    CFHostUnscheduleFromRunLoop(m_host.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    7177    CFHostSetClient(m_host.get(), nullptr, nullptr);
    72     if (auto completionHandler = WTFMove(m_completionHandler))
    73         completionHandler(makeUnexpected(Error::Unknown));
    7478}
    7579
    76 void NetworkRTCResolver::start(const String& address)
     80void NetworkRTCResolverCocoa::start(const String& address)
    7781{
    7882    m_host = adoptCF(CFHostCreateWithName(kCFAllocatorDefault, address.createCFString().get()));
     
    8488}
    8589
    86 void NetworkRTCResolver::stop()
     90void NetworkRTCResolverCocoa::stop()
    8791{
    8892    CFHostCancelInfoResolution(m_host.get(), CFHostInfoType::kCFHostAddresses);
    8993    if (auto completionHandler = WTFMove(m_completionHandler))
    90         completionHandler(makeUnexpected(Error::Cancelled));
     94        completionHandler(makeUnexpected(WebCore::DNSError::Cancelled));
    9195}
    9296
    93 void NetworkRTCResolver::completed(const Vector<RTCNetwork::IPAddress>& addresses)
     97void NetworkRTCResolverCocoa::completed(WebCore::DNSAddressesOrError&& addressesOrError)
    9498{
    9599    if (auto completionHandler = WTFMove(m_completionHandler))
    96         completionHandler({ addresses });
     100        completionHandler(WTFMove(addressesOrError));
    97101}
    98102
  • trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolverCocoa.h

    r229358 r229359  
    2828#if USE(LIBWEBRTC)
    2929
    30 #include "RTCNetwork.h"
     30#include "NetworkRTCResolver.h"
     31
    3132#include <CFNetwork/CFHost.h>
    32 #include <wtf/CompletionHandler.h>
    33 #include <wtf/text/WTFString.h>
    3433
    3534namespace WebKit {
    3635
    37 class NetworkRTCResolver {
     36// FIXME: Remove this class when we complete the implementation of the DNSResolveQueueCFNet.
     37class NetworkRTCResolverCocoa final : public NetworkRTCResolver {
    3838public:
    39     enum class Error { Unknown, Cancelled };
     39    explicit NetworkRTCResolverCocoa(uint64_t identifier, WebCore::DNSCompletionHandler&&);
     40    ~NetworkRTCResolverCocoa() final;
    4041
    41     using AddressesOrError = Expected<std::reference_wrapper<const Vector<RTCNetwork::IPAddress>>, Error>;
    42     using CompletionHandler = WTF::CompletionHandler<void(AddressesOrError&&)>;
     42    void start(const String& address) final;
     43    void stop() final;
    4344
    44     explicit NetworkRTCResolver(CompletionHandler&&);
    45     ~NetworkRTCResolver();
    46 
    47     void start(const String& address);
    48     void stop();
    49 
    50     void completed(const Vector<RTCNetwork::IPAddress>&);
     45    void completed(WebCore::DNSAddressesOrError&&);
    5146
    5247private:
    53     CompletionHandler m_completionHandler;
    5448    RetainPtr<CFHostRef> m_host;
    5549};
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r229066 r229359  
    916916                410482CE1DDD324F00F006D0 /* RTCNetwork.h in Headers */ = {isa = PBXBuildFile; fileRef = 410482CC1DDD2FB500F006D0 /* RTCNetwork.h */; };
    917917                4112B5551FA0EA7A00E67875 /* NetworkRTCResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4112B5471F9FD3AB00E67875 /* NetworkRTCResolver.cpp */; };
     918                4112B5551FA0EA7A00E67986 /* NetworkRTCResolverCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4112B5471F9FD3AB00E67986 /* NetworkRTCResolverCocoa.cpp */; };
    918919                411B22641E371BA6004F7363 /* LibWebRTCNetwork.h in Headers */ = {isa = PBXBuildFile; fileRef = 411B22621E371244004F7363 /* LibWebRTCNetwork.h */; };
    919920                413075A91DE85F2C0039EC69 /* NetworkRTCSocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413075981DE84FB00039EC69 /* NetworkRTCSocket.cpp */; };
     
    32883289                4112B5471F9FD3AB00E67875 /* NetworkRTCResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkRTCResolver.cpp; path = NetworkProcess/webrtc/NetworkRTCResolver.cpp; sourceTree = "<group>"; };
    32893290                4112B5481F9FD3AC00E67875 /* NetworkRTCResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkRTCResolver.h; path = NetworkProcess/webrtc/NetworkRTCResolver.h; sourceTree = "<group>"; };
     3291                4112B5471F9FD3AB00E67986 /* NetworkRTCResolverCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkRTCResolverCocoa.cpp; path = NetworkProcess/webrtc/NetworkRTCResolverCocoa.cpp; sourceTree = "<group>"; };
     3292                4112B5481F9FD3AC00E67986 /* NetworkRTCResolverCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkRTCResolverCocoa.h; path = NetworkProcess/webrtc/NetworkRTCResolverCocoa.h; sourceTree = "<group>"; };
    32903293                411B22621E371244004F7363 /* LibWebRTCNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCNetwork.h; path = Network/webrtc/LibWebRTCNetwork.h; sourceTree = "<group>"; };
    32913294                413075981DE84FB00039EC69 /* NetworkRTCSocket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkRTCSocket.cpp; path = NetworkProcess/webrtc/NetworkRTCSocket.cpp; sourceTree = "<group>"; };
     
    62376240                                4112B5471F9FD3AB00E67875 /* NetworkRTCResolver.cpp */,
    62386241                                4112B5481F9FD3AC00E67875 /* NetworkRTCResolver.h */,
     6242                                4112B5471F9FD3AB00E67986 /* NetworkRTCResolverCocoa.cpp */,
     6243                                4112B5481F9FD3AC00E67986 /* NetworkRTCResolverCocoa.h */,
    62396244                                413075981DE84FB00039EC69 /* NetworkRTCSocket.cpp */,
    62406245                                413075991DE84FB00039EC69 /* NetworkRTCSocket.h */,
     
    1062210627                                51F060E11654318500F3282E /* NetworkRTCProviderMessageReceiver.cpp in Sources */,
    1062310628                                4112B5551FA0EA7A00E67875 /* NetworkRTCResolver.cpp in Sources */,
     10629                                4112B5551FA0EA7A00E67986 /* NetworkRTCResolverCocoa.cpp in Sources */,
    1062410630                                413075A91DE85F2C0039EC69 /* NetworkRTCSocket.cpp in Sources */,
    1062510631                                51F060E11654318500F3281D /* NetworkRTCSocketMessageReceiver.cpp in Sources */,
  • trunk/Tools/ChangeLog

    r229349 r229359  
     12018-03-07  Alejandro G. Castro  <alex@igalia.com>
     2
     3        Make NetworkRTCResolver port agnostic
     4        https://bugs.webkit.org/show_bug.cgi?id=178855
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Added new unit tests for he resolve and stopResolve functions. We need to compile them for the
     9        other platforms when the APIs are supported.
     10
     11        * TestWebKitAPI/PlatformGTK.cmake:
     12        * TestWebKitAPI/Tests/WebCore/DNS.cpp:
     13
    1142018-03-06  Youenn Fablet  <youenn@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/PlatformGTK.cmake

    r228451 r229359  
    8888    ${TESTWEBKITAPI_DIR}/Tests/WebCore/CSSParser.cpp
    8989    ${TESTWEBKITAPI_DIR}/Tests/WebCore/ComplexTextController.cpp
     90    ${TESTWEBKITAPI_DIR}/Tests/WebCore/DNS.cpp
    9091    ${TESTWEBKITAPI_DIR}/Tests/WebCore/FileMonitor.cpp
    9192    ${TESTWEBKITAPI_DIR}/Tests/WebCore/FileSystem.cpp
Note: See TracChangeset for help on using the changeset viewer.