Diff
Modified: trunk/Source/WebCore/ChangeLog (229358 => 229359)
--- trunk/Source/WebCore/ChangeLog 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/ChangeLog 2018-03-07 15:21:24 UTC (rev 229359)
@@ -1,3 +1,64 @@
+2018-03-07 Alejandro G. Castro <a...@igalia.com>
+
+ Make NetworkRTCResolver port agnostic
+ https://bugs.webkit.org/show_bug.cgi?id=178855
+
+ Reviewed by Youenn Fablet.
+
+ 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.
+
2018-03-06 Brian Burg <bb...@apple.com>
[Cocoa] Stop copying ForwardingHeaders directory that no longer exists
Modified: trunk/Source/WebCore/PlatformAppleWin.cmake (229358 => 229359)
--- trunk/Source/WebCore/PlatformAppleWin.cmake 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/PlatformAppleWin.cmake 2018-03-07 15:21:24 UTC (rev 229359)
@@ -50,7 +50,7 @@
platform/network/cf/CookieJarCFNet.cpp
platform/network/cf/CookieStorageCFNet.cpp
platform/network/cf/CredentialStorageCFNet.cpp
- platform/network/cf/DNSCFNet.cpp
+ platform/network/cf/DNSResolveQueueCFNet.cpp
platform/network/cf/FormDataStreamCFNet.cpp
platform/network/cf/LoaderRunLoopCF.cpp
platform/network/cf/NetworkStorageSessionCFNet.cpp
Modified: trunk/Source/WebCore/PlatformMac.cmake (229358 => 229359)
--- trunk/Source/WebCore/PlatformMac.cmake 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/PlatformMac.cmake 2018-03-07 15:21:24 UTC (rev 229359)
@@ -413,7 +413,7 @@
platform/mediastream/mac/MockRealtimeVideoSourceMac.mm
- platform/network/cf/DNSCFNet.cpp
+ platform/network/cf/DNSResolveQueueCFNet.cpp
platform/network/cf/FormDataStreamCFNet.cpp
platform/network/cf/NetworkStorageSessionCFNet.cpp
platform/network/cf/ProxyServerCFNet.cpp
Modified: trunk/Source/WebCore/Sources.txt (229358 => 229359)
--- trunk/Source/WebCore/Sources.txt 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/Sources.txt 2018-03-07 15:21:24 UTC (rev 229359)
@@ -1709,6 +1709,7 @@
platform/network/Cookie.cpp
platform/network/CredentialBase.cpp
platform/network/CredentialStorage.cpp
+platform/network/DNS.cpp
platform/network/DNSResolveQueue.cpp
platform/network/DataURLDecoder.cpp
platform/network/FormData.cpp
Modified: trunk/Source/WebCore/SourcesCocoa.txt (229358 => 229359)
--- trunk/Source/WebCore/SourcesCocoa.txt 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2018-03-07 15:21:24 UTC (rev 229359)
@@ -482,7 +482,7 @@
platform/mock/MediaPlaybackTargetPickerMock.cpp
platform/mock/MediaPlaybackTargetMock.cpp
-platform/network/cf/DNSCFNet.cpp
+platform/network/cf/DNSResolveQueueCFNet.cpp
platform/network/cf/FormDataStreamCFNet.cpp
platform/network/cf/NetworkStorageSessionCFNet.cpp
platform/network/cf/ProxyServerCFNet.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (229358 => 229359)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-03-07 15:21:24 UTC (rev 229359)
@@ -2259,6 +2259,7 @@
7EE6846A12D26E3800E79415 /* ResourceError.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6845712D26E3800E79415 /* ResourceError.h */; settings = {ATTRIBUTES = (Private, ); }; };
7EE6846D12D26E3800E79415 /* ResourceRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6845A12D26E3800E79415 /* ResourceRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
7EE6846F12D26E3800E79415 /* ResourceRequestCFNet.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6845C12D26E3800E79415 /* ResourceRequestCFNet.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 7EE6846F12D26E3800E73215 /* DNSResolveQueueCFNet.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6845C12D26E3800FF9415 /* DNSResolveQueueCFNet.h */; settings = {ATTRIBUTES = (Private, ); }; };
7EE6847012D26E3800E79415 /* ResourceResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6845D12D26E3800E79415 /* ResourceResponse.h */; settings = {ATTRIBUTES = (Private, ); }; };
7F4C96DD1AD4483500365A50 /* JSFetchBody.h in Headers */ = {isa = PBXBuildFile; fileRef = 7F4C96D91AD4483500365A50 /* JSFetchBody.h */; };
7F4C96DD1AD4483500365A51 /* JSReadableStreamSink.h in Headers */ = {isa = PBXBuildFile; fileRef = 7F4C96D91AD4483500365A51 /* JSReadableStreamSink.h */; };
@@ -9620,6 +9621,7 @@
7EE6845A12D26E3800E79415 /* ResourceRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceRequest.h; sourceTree = "<group>"; };
7EE6845B12D26E3800E79415 /* ResourceRequestCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceRequestCFNet.cpp; sourceTree = "<group>"; };
7EE6845C12D26E3800E79415 /* ResourceRequestCFNet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceRequestCFNet.h; sourceTree = "<group>"; };
+ 7EE6845C12D26E3800FF9415 /* DNSResolveQueueCFNet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNSResolveQueueCFNet.h; sourceTree = "<group>"; };
7EE6845D12D26E3800E79415 /* ResourceResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceResponse.h; sourceTree = "<group>"; };
7F4C96D81AD4483500365A50 /* JSFetchBody.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchBody.cpp; sourceTree = "<group>"; };
7F4C96D81AD4483500365A51 /* JSReadableStreamSink.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamSink.cpp; sourceTree = "<group>"; };
@@ -12141,8 +12143,9 @@
B2E4EC950D00C22B00432643 /* SVGZoomEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGZoomEvent.h; sourceTree = "<group>"; };
B2E4EC960D00C22B00432643 /* SVGZoomEvent.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = SVGZoomEvent.idl; sourceTree = "<group>"; };
B2ED97700B1F55CE00257D0F /* GraphicsContextCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextCG.cpp; sourceTree = "<group>"; };
+ 1AF8E13212565A4445230FF7 /* DNS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNS.cpp; sourceTree = "<group>"; };
B2F34FE50E82F81400F627CD /* DNS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNS.h; sourceTree = "<group>"; };
- B2F34FE80E82F82700F627CD /* DNSCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNSCFNet.cpp; sourceTree = "<group>"; };
+ B2F34FE80E82F82700F648CD /* DNSResolveQueueCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNSResolveQueueCFNet.cpp; sourceTree = "<group>"; };
B2FA3C4E0AB75A6E000E5AC4 /* JSSVGAnimateColorElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGAnimateColorElement.cpp; sourceTree = "<group>"; };
B2FA3C4F0AB75A6E000E5AC4 /* JSSVGAnimateColorElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSSVGAnimateColorElement.h; sourceTree = "<group>"; };
B2FA3C500AB75A6E000E5AC4 /* JSSVGAnimatedAngle.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGAnimatedAngle.cpp; sourceTree = "<group>"; };
@@ -18741,6 +18744,7 @@
51A052311058774F00CC9E95 /* CredentialStorage.h */,
E4A007841B820ED3002C5A6E /* DataURLDecoder.cpp */,
E4A007821B820EC8002C5A6E /* DataURLDecoder.h */,
+ 1AF8E13212565A4445230FF7 /* DNS.cpp */,
B2F34FE50E82F81400F627CD /* DNS.h */,
7C60128060078BB70E367A95 /* DNSResolveQueue.cpp */,
FA6E466FCD0418A9966A5B60 /* DNSResolveQueue.h */,
@@ -23475,7 +23479,8 @@
children = (
7EE6844E12D26E3800E79415 /* AuthenticationChallenge.h */,
5F2DBBE8178E336900141486 /* CertificateInfo.h */,
- B2F34FE80E82F82700F627CD /* DNSCFNet.cpp */,
+ B2F34FE80E82F82700F648CD /* DNSResolveQueueCFNet.cpp */,
+ 7EE6845C12D26E3800FF9415 /* DNSResolveQueueCFNet.h */,
7EE6845312D26E3800E79415 /* FormDataStreamCFNet.cpp */,
7EE6845412D26E3800E79415 /* FormDataStreamCFNet.h */,
E13EF34716850C470034C83F /* NetworkStorageSessionCFNet.cpp */,
@@ -27340,6 +27345,7 @@
FD31609112B026F700C1A359 /* Distance.h in Headers */,
84730D771248F0B300D3A9C9 /* DistantLightSource.h in Headers */,
B2F34FE60E82F81400F627CD /* DNS.h in Headers */,
+ 7EE6846F12D26E3800E73215 /* DNSResolveQueueCFNet.h in Headers */,
A8185F4009765766005826D9 /* Document.h in Headers */,
A3BB59F41457A40D00AC56FE /* DocumentEventQueue.h in Headers */,
A8185F3D09765766005826D9 /* DocumentFragment.h in Headers */,
Modified: trunk/Source/WebCore/platform/Curl.cmake (229358 => 229359)
--- trunk/Source/WebCore/platform/Curl.cmake 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/platform/Curl.cmake 2018-03-07 15:21:24 UTC (rev 229359)
@@ -21,7 +21,7 @@
platform/network/curl/CurlResourceHandleDelegate.cpp
platform/network/curl/CurlSSLHandle.cpp
platform/network/curl/CurlSSLVerifier.cpp
- platform/network/curl/DNSCurl.cpp
+ platform/network/curl/DNSResolveQueueCurl.cpp
platform/network/curl/NetworkStorageSessionCurl.cpp
platform/network/curl/ProxyServerCurl.cpp
platform/network/curl/ResourceErrorCurl.cpp
Modified: trunk/Source/WebCore/platform/SourcesSoup.txt (229358 => 229359)
--- trunk/Source/WebCore/platform/SourcesSoup.txt 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/platform/SourcesSoup.txt 2018-03-07 15:21:24 UTC (rev 229359)
@@ -27,7 +27,7 @@
platform/network/soup/CookieSoup.cpp
platform/network/soup/CookieStorageSoup.cpp
platform/network/soup/CredentialStorageSoup.cpp
-platform/network/soup/DNSSoup.cpp
+platform/network/soup/DNSResolveQueueSoup.cpp
platform/network/soup/GRefPtrSoup.cpp
platform/network/soup/NetworkStorageSessionSoup.cpp
platform/network/soup/ProxyServerSoup.cpp
Copied: trunk/Source/WebCore/platform/network/DNS.cpp (from rev 229358, trunk/Source/WebCore/platform/network/curl/DNSCurl.cpp) (0 => 229359)
--- trunk/Source/WebCore/platform/network/DNS.cpp (rev 0)
+++ trunk/Source/WebCore/platform/network/DNS.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2012, 2018 Igalia S.L.
+ *
+ * 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 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
+ * 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 "DNS.h"
+
+#include "DNSResolveQueue.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+void prefetchDNS(const String& hostname)
+{
+ ASSERT(isMainThread());
+ if (hostname.isEmpty())
+ return;
+
+ DNSResolveQueue::singleton().add(hostname);
+}
+
+void resolveDNS(const String& hostname, uint64_t identifier, DNSCompletionHandler&& completionHandler)
+{
+ ASSERT(isMainThread());
+ if (hostname.isEmpty())
+ return;
+
+ WebCore::DNSResolveQueue::singleton().resolve(hostname, identifier, WTFMove(completionHandler));
+}
+
+void stopResolveDNS(uint64_t identifier)
+{
+ WebCore::DNSResolveQueue::singleton().stopResolve(identifier);
+}
+
+}
Modified: trunk/Source/WebCore/platform/network/DNS.h (229358 => 229359)
--- trunk/Source/WebCore/platform/network/DNS.h 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/platform/network/DNS.h 2018-03-07 15:21:24 UTC (rev 229359)
@@ -23,14 +23,39 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef DNS_h
-#define DNS_h
+#pragma once
+#if PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WPE)
+#include <netinet/in.h>
+#elif PLATFORM(WIN)
+#include <winsock2.h>
+#endif
+
#include <wtf/Forward.h>
namespace WebCore {
+class WEBCORE_EXPORT IPAddress {
+public:
+ explicit IPAddress(const struct sockaddr_in& address)
+ {
+ memset(&m_address, 0, sizeof(struct sockaddr_in));
+ m_address = address;
+ }
+
+ const struct in_addr& getSinAddr() { return m_address.sin_addr; };
+
+private:
+ struct sockaddr_in m_address;
+};
+
+enum class DNSError { Unknown, CannotResolve, Cancelled };
+
+using DNSAddressesOrError = Expected<Vector<WebCore::IPAddress>, DNSError>;
+using DNSCompletionHandler = WTF::CompletionHandler<void(DNSAddressesOrError&&)>;
+
WEBCORE_EXPORT void prefetchDNS(const String& hostname);
+WEBCORE_EXPORT void resolveDNS(const String& hostname, uint64_t identifier, DNSCompletionHandler&&);
+WEBCORE_EXPORT void stopResolveDNS(uint64_t identifier);
+
}
-
-#endif
Modified: trunk/Source/WebCore/platform/network/DNSResolveQueue.cpp (229358 => 229359)
--- trunk/Source/WebCore/platform/network/DNSResolveQueue.cpp 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/platform/network/DNSResolveQueue.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -27,6 +27,14 @@
#include "config.h"
#include "DNSResolveQueue.h"
+#if USE(SOUP)
+#include "DNSResolveQueueSoup.h"
+#elif USE(CURL)
+#include "DNSResolveQueueCurl.h"
+#elif USE(CF)
+#include "DNSResolveQueueCFNet.h"
+#endif
+
#include <wtf/NeverDestroyed.h>
namespace WebCore {
@@ -51,7 +59,7 @@
DNSResolveQueue& DNSResolveQueue::singleton()
{
- static NeverDestroyed<DNSResolveQueue> queue;
+ static NeverDestroyed<DNSResolveQueuePlatform> queue;
return queue;
}
@@ -59,7 +67,6 @@
DNSResolveQueue::DNSResolveQueue()
: m_timer(*this, &DNSResolveQueue::timerFired)
, m_requestsInFlight(0)
- , m_isUsingProxy(true)
{
// isUsingProxy will return the initial value of m_isUsingProxy at first on
// platforms that have an asynchronous implementation of updateIsUsingProxy,
Modified: trunk/Source/WebCore/platform/network/DNSResolveQueue.h (229358 => 229359)
--- trunk/Source/WebCore/platform/network/DNSResolveQueue.h 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/platform/network/DNSResolveQueue.h 2018-03-07 15:21:24 UTC (rev 229359)
@@ -27,6 +27,7 @@
#ifndef DNSResolveQueue_h
#define DNSResolveQueue_h
+#include "DNS.h"
#include "Timer.h"
#include <atomic>
#include <wtf/Forward.h>
@@ -39,8 +40,13 @@
friend NeverDestroyed<DNSResolveQueue>;
public:
+ DNSResolveQueue();
+ virtual ~DNSResolveQueue() = default;
+
static DNSResolveQueue& singleton();
+ virtual void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) = 0;
+ virtual void stopResolve(uint64_t identifier) = 0;
void add(const String& hostname);
void decrementRequestCount()
{
@@ -47,14 +53,14 @@
--m_requestsInFlight;
}
-private:
- DNSResolveQueue();
-
+protected:
bool isUsingProxy();
- void updateIsUsingProxy();
- void platformResolve(const String&);
+ bool m_isUsingProxy { true };
+private:
+ virtual void updateIsUsingProxy() = 0;
+ virtual void platformResolve(const String&) = 0;
void timerFired();
Timer m_timer;
@@ -61,7 +67,6 @@
HashSet<String> m_names;
std::atomic<int> m_requestsInFlight;
- bool m_isUsingProxy;
MonotonicTime m_lastProxyEnabledStatusCheckTime;
};
Deleted: trunk/Source/WebCore/platform/network/cf/DNSCFNet.cpp (229358 => 229359)
--- trunk/Source/WebCore/platform/network/cf/DNSCFNet.cpp 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/platform/network/cf/DNSCFNet.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2008 Collin Jackson <coll...@webkit.org>
- * Copyright (C) 2009 Apple Inc. All Rights Reserved.
- * Copyright (C) 2012 Igalia S.L.
- *
- * 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 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
- * 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 "DNS.h"
-#include "DNSResolveQueue.h"
-
-#include "URL.h"
-#include "Timer.h"
-#include <wtf/HashSet.h>
-#include <wtf/MainThread.h>
-#include <wtf/RetainPtr.h>
-#include <wtf/StdLibExtras.h>
-#include <wtf/text/StringHash.h>
-
-#if PLATFORM(IOS)
-#include <CFNetwork/CFNetwork.h>
-#endif
-
-#if PLATFORM(WIN)
-#include "LoaderRunLoopCF.h"
-#include <CFNetwork/CFNetwork.h>
-#endif
-
-namespace WebCore {
-
-void DNSResolveQueue::updateIsUsingProxy()
-{
- RetainPtr<CFDictionaryRef> proxySettings = adoptCF(CFNetworkCopySystemProxySettings());
- if (!proxySettings) {
- m_isUsingProxy = false;
- return;
- }
-
- RetainPtr<CFURLRef> httpCFURL = URL(ParsedURLString, "http://example.com/").createCFURL();
- RetainPtr<CFURLRef> httpsCFURL = URL(ParsedURLString, "https://example.com/").createCFURL();
-
- RetainPtr<CFArrayRef> httpProxyArray = adoptCF(CFNetworkCopyProxiesForURL(httpCFURL.get(), proxySettings.get()));
- RetainPtr<CFArrayRef> httpsProxyArray = adoptCF(CFNetworkCopyProxiesForURL(httpsCFURL.get(), proxySettings.get()));
-
- CFIndex httpProxyCount = CFArrayGetCount(httpProxyArray.get());
- CFIndex httpsProxyCount = CFArrayGetCount(httpsProxyArray.get());
- if (httpProxyCount == 1 && CFEqual(CFDictionaryGetValue(static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(httpProxyArray.get(), 0)), kCFProxyTypeKey), kCFProxyTypeNone))
- httpProxyCount = 0;
- if (httpsProxyCount == 1 && CFEqual(CFDictionaryGetValue(static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(httpsProxyArray.get(), 0)), kCFProxyTypeKey), kCFProxyTypeNone))
- httpsProxyCount = 0;
-
- m_isUsingProxy = httpProxyCount || httpsProxyCount;
-}
-
-static void clientCallback(CFHostRef theHost, CFHostInfoType, const CFStreamError*, void*)
-{
- DNSResolveQueue::singleton().decrementRequestCount(); // It's ok to call singleton() from a secondary thread, the static variable has already been initialized by now.
- CFRelease(theHost);
-}
-
-void DNSResolveQueue::platformResolve(const String& hostname)
-{
- ASSERT(isMainThread());
-
- RetainPtr<CFHostRef> host = adoptCF(CFHostCreateWithName(0, hostname.createCFString().get()));
- if (!host) {
- decrementRequestCount();
- return;
- }
-
- CFHostClientContext context = { 0, 0, 0, 0, 0 };
- CFHostRef leakedHost = host.leakRef(); // The host will be released from clientCallback().
- Boolean result = CFHostSetClient(leakedHost, clientCallback, &context);
- ASSERT_UNUSED(result, result);
-#if !PLATFORM(WIN)
- CFHostScheduleWithRunLoop(leakedHost, CFRunLoopGetMain(), kCFRunLoopCommonModes);
-#else
- // On Windows, we run a separate thread with CFRunLoop, which is where clientCallback will be called.
- CFHostScheduleWithRunLoop(leakedHost, loaderRunLoop(), kCFRunLoopDefaultMode);
-#endif
- CFHostStartInfoResolution(leakedHost, kCFHostAddresses, 0);
-}
-
-void prefetchDNS(const String& hostname)
-{
- ASSERT(isMainThread());
- if (hostname.isEmpty())
- return;
- DNSResolveQueue::singleton().add(hostname);
-}
-
-}
Copied: trunk/Source/WebCore/platform/network/cf/DNSResolveQueueCFNet.cpp (from rev 229358, trunk/Source/WebCore/platform/network/cf/DNSCFNet.cpp) (0 => 229359)
--- trunk/Source/WebCore/platform/network/cf/DNSResolveQueueCFNet.cpp (rev 0)
+++ trunk/Source/WebCore/platform/network/cf/DNSResolveQueueCFNet.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2008 Collin Jackson <coll...@webkit.org>
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * 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 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
+ * 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 "DNSResolveQueueCFNet.h"
+
+#include "NotImplemented.h"
+#include "Timer.h"
+#include "URL.h"
+#include <wtf/HashSet.h>
+#include <wtf/MainThread.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/StdLibExtras.h>
+#include <wtf/text/StringHash.h>
+
+#if PLATFORM(WIN)
+#include "LoaderRunLoopCF.h"
+#endif
+
+#if PLATFORM(WIN) || PLATFORM(IOS)
+#include <CFNetwork/CFNetwork.h>
+#endif
+
+namespace WebCore {
+
+void DNSResolveQueueCFNet::updateIsUsingProxy()
+{
+ RetainPtr<CFDictionaryRef> proxySettings = adoptCF(CFNetworkCopySystemProxySettings());
+ if (!proxySettings) {
+ m_isUsingProxy = false;
+ return;
+ }
+
+ RetainPtr<CFURLRef> httpCFURL = URL(ParsedURLString, "http://example.com/").createCFURL();
+ RetainPtr<CFURLRef> httpsCFURL = URL(ParsedURLString, "https://example.com/").createCFURL();
+
+ RetainPtr<CFArrayRef> httpProxyArray = adoptCF(CFNetworkCopyProxiesForURL(httpCFURL.get(), proxySettings.get()));
+ RetainPtr<CFArrayRef> httpsProxyArray = adoptCF(CFNetworkCopyProxiesForURL(httpsCFURL.get(), proxySettings.get()));
+
+ CFIndex httpProxyCount = CFArrayGetCount(httpProxyArray.get());
+ CFIndex httpsProxyCount = CFArrayGetCount(httpsProxyArray.get());
+ if (httpProxyCount == 1 && CFEqual(CFDictionaryGetValue(static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(httpProxyArray.get(), 0)), kCFProxyTypeKey), kCFProxyTypeNone))
+ httpProxyCount = 0;
+ if (httpsProxyCount == 1 && CFEqual(CFDictionaryGetValue(static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(httpsProxyArray.get(), 0)), kCFProxyTypeKey), kCFProxyTypeNone))
+ httpsProxyCount = 0;
+
+ m_isUsingProxy = httpProxyCount || httpsProxyCount;
+}
+
+static void clientCallback(CFHostRef theHost, CFHostInfoType, const CFStreamError*, void*)
+{
+ DNSResolveQueue::singleton().decrementRequestCount(); // It's ok to call singleton() from a secondary thread, the static variable has already been initialized by now.
+ CFRelease(theHost);
+}
+
+void DNSResolveQueueCFNet::platformResolve(const String& hostname)
+{
+ ASSERT(isMainThread());
+
+ RetainPtr<CFHostRef> host = adoptCF(CFHostCreateWithName(0, hostname.createCFString().get()));
+ if (!host) {
+ decrementRequestCount();
+ return;
+ }
+
+ CFHostClientContext context = { 0, 0, 0, 0, 0 };
+ CFHostRef leakedHost = host.leakRef(); // The host will be released from clientCallback().
+ Boolean result = CFHostSetClient(leakedHost, clientCallback, &context);
+ ASSERT_UNUSED(result, result);
+#if !PLATFORM(WIN)
+ CFHostScheduleWithRunLoop(leakedHost, CFRunLoopGetMain(), kCFRunLoopCommonModes);
+#else
+ // On Windows, we run a separate thread with CFRunLoop, which is where clientCallback will be called.
+ CFHostScheduleWithRunLoop(leakedHost, loaderRunLoop(), kCFRunLoopDefaultMode);
+#endif
+ CFHostStartInfoResolution(leakedHost, kCFHostAddresses, 0);
+}
+
+void DNSResolveQueueCFNet::resolve(const String& /* hostname */, uint64_t /* identifier */, DNSCompletionHandler&& /* completionHandler */)
+{
+ notImplemented();
+}
+
+void DNSResolveQueueCFNet::stopResolve(uint64_t /* identifier */)
+{
+ notImplemented();
+}
+
+}
Copied: trunk/Source/WebCore/platform/network/cf/DNSResolveQueueCFNet.h (from rev 229358, trunk/Source/WebCore/platform/network/curl/DNSCurl.cpp) (0 => 229359)
--- trunk/Source/WebCore/platform/network/cf/DNSResolveQueueCFNet.h (rev 0)
+++ trunk/Source/WebCore/platform/network/cf/DNSResolveQueueCFNet.h 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * 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 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
+ * 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
+
+#include "DNSResolveQueue.h"
+
+namespace WebCore {
+
+class DNSResolveQueueCFNet final : public DNSResolveQueue {
+public:
+ DNSResolveQueueCFNet() = default;
+ void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) final;
+ void stopResolve(uint64_t identifier) final;
+
+private:
+ void updateIsUsingProxy() final;
+ void platformResolve(const String&) final;
+};
+
+using DNSResolveQueuePlatform = DNSResolveQueueCFNet;
+
+}
Deleted: trunk/Source/WebCore/platform/network/curl/DNSCurl.cpp (229358 => 229359)
--- trunk/Source/WebCore/platform/network/curl/DNSCurl.cpp 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/platform/network/curl/DNSCurl.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2008 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 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
- * 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 "DNS.h"
-#include "DNSResolveQueue.h"
-
-#if USE(CURL)
-
-#include "NotImplemented.h"
-
-namespace WebCore {
-
-void DNSResolveQueue::updateIsUsingProxy()
-{
- notImplemented();
-}
-
-void DNSResolveQueue::platformResolve(const String& /* hostname */)
-{
- notImplemented();
-}
-
-void prefetchDNS(const String& /* hostname */)
-{
- notImplemented();
-}
-
-}
-
-#endif
Copied: trunk/Source/WebCore/platform/network/curl/DNSResolveQueueCurl.cpp (from rev 229358, trunk/Source/WebCore/platform/network/curl/DNSCurl.cpp) (0 => 229359)
--- trunk/Source/WebCore/platform/network/curl/DNSResolveQueueCurl.cpp (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/DNSResolveQueueCurl.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2008 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 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
+ * 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 "DNSResolveQueueCurl.h"
+
+#if USE(CURL)
+
+#include "NotImplemented.h"
+
+namespace WebCore {
+
+void DNSResolveQueueCurl::updateIsUsingProxy()
+{
+ notImplemented();
+}
+
+void DNSResolveQueueCurl::platformResolve(const String& /* hostname */)
+{
+ notImplemented();
+}
+
+void DNSResolveQueueCurl::resolve(const String& /* hostname */, uint64_t /* identifier */, DNSCompletionHandler&& /* completionHandler */)
+{
+ notImplemented();
+}
+
+void DNSResolveQueueCurl::stopResolve(uint64_t /* identifier */)
+{
+ notImplemented();
+}
+
+}
+
+#endif
Copied: trunk/Source/WebCore/platform/network/curl/DNSResolveQueueCurl.h (from rev 229358, trunk/Source/WebCore/platform/network/curl/DNSCurl.cpp) (0 => 229359)
--- trunk/Source/WebCore/platform/network/curl/DNSResolveQueueCurl.h (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/DNSResolveQueueCurl.h 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * 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 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
+ * 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
+
+#include "DNSResolveQueue.h"
+
+namespace WebCore {
+
+class DNSResolveQueueCurl final : public DNSResolveQueue {
+public:
+ DNSResolveQueueCurl() = default;
+ void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) final;
+ void stopResolve(uint64_t identifier) final;
+
+private:
+ void updateIsUsingProxy() final;
+ void platformResolve(const String&) final;
+};
+
+using DNSResolveQueuePlatform = DNSResolveQueueCurl;
+
+}
Copied: trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.cpp (from rev 229358, trunk/Source/WebCore/platform/network/soup/DNSSoup.cpp) (0 => 229359)
--- trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.cpp (rev 0)
+++ trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2012 Igalia S.L.
+ *
+ * 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 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
+ * 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 "DNSResolveQueueSoup.h"
+
+#if USE(SOUP)
+
+#include "NetworkStorageSession.h"
+#include "SoupNetworkSession.h"
+#include <libsoup/soup.h>
+#include <wtf/CompletionHandler.h>
+#include <wtf/MainThread.h>
+#include <wtf/glib/GUniquePtr.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+// Initially true to ensure prefetch stays disabled until we have proxy settings.
+static bool isUsingHttpProxy = true;
+static bool isUsingHttpsProxy = true;
+
+static bool didResolveProxy(char** uris)
+{
+ // We have a list of possible proxies to use for the URI. If the first item in the list is
+ // direct:// (the usual case), then the user prefers not to use a proxy. This is similar to
+ // resolving hostnames: there could be many possibilities returned in order of preference, and
+ // if we're trying to connect we should attempt each one in order, but here we are not trying
+ // to connect, merely to decide whether a proxy "should" be used.
+ return uris && *uris && strcmp(*uris, "direct://");
+}
+
+static void didResolveProxy(GProxyResolver* resolver, GAsyncResult* result, bool* isUsingProxyType, bool* isUsingProxy)
+{
+ GUniqueOutPtr<GError> error;
+ GUniquePtr<char*> uris(g_proxy_resolver_lookup_finish(resolver, result, &error.outPtr()));
+ if (error) {
+ WTFLogAlways("Error determining system proxy settings: %s", error->message);
+ return;
+ }
+
+ *isUsingProxyType = didResolveProxy(uris.get());
+ *isUsingProxy = isUsingHttpProxy || isUsingHttpsProxy;
+}
+
+static void proxyResolvedForHttpUriCallback(GObject* source, GAsyncResult* result, void* userData)
+{
+ didResolveProxy(G_PROXY_RESOLVER(source), result, &isUsingHttpProxy, static_cast<bool*>(userData));
+}
+
+static void proxyResolvedForHttpsUriCallback(GObject* source, GAsyncResult* result, void* userData)
+{
+ didResolveProxy(G_PROXY_RESOLVER(source), result, &isUsingHttpsProxy, static_cast<bool*>(userData));
+}
+
+void DNSResolveQueueSoup::updateIsUsingProxy()
+{
+ GRefPtr<GProxyResolver> resolver;
+ g_object_get(NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession(), "proxy-resolver", &resolver.outPtr(), nullptr);
+ ASSERT(resolver);
+
+ g_proxy_resolver_lookup_async(resolver.get(), "http://example.com/", nullptr, proxyResolvedForHttpUriCallback, &m_isUsingProxy);
+ g_proxy_resolver_lookup_async(resolver.get(), "https://example.com/", nullptr, proxyResolvedForHttpsUriCallback, &m_isUsingProxy);
+}
+
+static void resolvedCallback(SoupAddress*, guint, void*)
+{
+ DNSResolveQueue::singleton().decrementRequestCount();
+}
+
+static void resolvedWithObserverCallback(SoupAddress* address, guint status, void* data)
+{
+ ASSERT(data);
+ auto* resolveQueue = static_cast<DNSResolveQueueSoup*>(data);
+
+ uint64_t identifier = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(address), "identifier"));
+
+ auto completionAndCancelHandlers = resolveQueue->takeCompletionAndCancelHandlers(identifier);
+
+ if (!completionAndCancelHandlers)
+ return;
+
+ auto completionHandler = WTFMove(completionAndCancelHandlers.get()->first);
+
+ if (status != SOUP_STATUS_OK) {
+ DNSError error = DNSError::Unknown;
+
+ switch (status) {
+ case SOUP_STATUS_CANT_RESOLVE:
+ error = DNSError::CannotResolve;
+ break;
+ case SOUP_STATUS_CANCELLED:
+ error = DNSError::Cancelled;
+ break;
+ case SOUP_STATUS_OK:
+ default:
+ ASSERT_NOT_REACHED();
+ };
+
+ completionHandler(makeUnexpected(error));
+ return;
+ }
+
+ if (!soup_address_is_resolved(address)) {
+ completionHandler(makeUnexpected(DNSError::Unknown));
+ return;
+ }
+
+ Vector<WebCore::IPAddress> addresses;
+ addresses.reserveInitialCapacity(1);
+ int len;
+ auto* ipAddress = reinterpret_cast<const struct sockaddr_in*>(soup_address_get_sockaddr(address, &len));
+ for (unsigned i = 0; i < sizeof(*ipAddress) / len; i++)
+ addresses.uncheckedAppend(WebCore::IPAddress(ipAddress[i]));
+
+ completionHandler(addresses);
+}
+
+std::unique_ptr<DNSResolveQueueSoup::CompletionAndCancelHandlers> DNSResolveQueueSoup::takeCompletionAndCancelHandlers(uint64_t identifier)
+{
+ ASSERT(isMainThread());
+
+ auto completionAndCancelHandlers = m_completionAndCancelHandlers.take(identifier);
+
+ if (!completionAndCancelHandlers)
+ return nullptr;
+
+ return WTFMove(completionAndCancelHandlers);
+}
+
+void DNSResolveQueueSoup::removeCancelAndCompletionHandler(uint64_t identifier)
+{
+ ASSERT(isMainThread());
+
+ m_completionAndCancelHandlers.remove(identifier);
+}
+
+void DNSResolveQueueSoup::platformResolve(const String& hostname)
+{
+ ASSERT(isMainThread());
+
+ soup_session_prefetch_dns(NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession(), hostname.utf8().data(), nullptr, resolvedCallback, nullptr);
+}
+
+void DNSResolveQueueSoup::resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&& completionHandler)
+{
+ ASSERT(isMainThread());
+
+ auto address = adoptGRef(soup_address_new(hostname.utf8().data(), 0));
+ auto cancellable = adoptGRef(g_cancellable_new());
+ soup_address_resolve_async(address.get(), soup_session_get_async_context(WebCore::NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession()), cancellable.get(), resolvedWithObserverCallback, this);
+
+ g_object_set_data(G_OBJECT(address.get()), "identifier", GUINT_TO_POINTER(identifier));
+
+ m_completionAndCancelHandlers.add(identifier, std::make_unique<DNSResolveQueueSoup::CompletionAndCancelHandlers>(WTFMove(completionHandler), WTFMove(cancellable)));
+}
+
+void DNSResolveQueueSoup::stopResolve(uint64_t identifier)
+{
+ ASSERT(isMainThread());
+
+ if (auto completionAndCancelHandler = m_completionAndCancelHandlers.take(identifier)) {
+ g_cancellable_cancel(completionAndCancelHandler.get()->second.get());
+ completionAndCancelHandler.get()->first(makeUnexpected(DNSError::Cancelled));
+ }
+}
+
+}
+
+#endif
Copied: trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.h (from rev 229358, trunk/Source/WebCore/platform/network/DNSResolveQueue.h) (0 => 229359)
--- trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.h (rev 0)
+++ trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.h 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * 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 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
+ * 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
+
+#include "DNSResolveQueue.h"
+
+#include <wtf/HashMap.h>
+#include <wtf/glib/GRefPtr.h>
+
+namespace WebCore {
+
+class DNSResolveQueueSoup final : public DNSResolveQueue {
+public:
+ using CompletionAndCancelHandlers = std::pair<WebCore::DNSCompletionHandler, GRefPtr<GCancellable>>;
+
+ DNSResolveQueueSoup() = default;
+ void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) final;
+ void stopResolve(uint64_t identifier) final;
+
+ std::unique_ptr<CompletionAndCancelHandlers> takeCompletionAndCancelHandlers(uint64_t identifier);
+ void removeCancelAndCompletionHandler(uint64_t identifier);
+
+private:
+ void updateIsUsingProxy() final;
+
+ HashMap<uint64_t, std::unique_ptr<CompletionAndCancelHandlers>> m_completionAndCancelHandlers;
+
+ void platformResolve(const String&) final;
+};
+
+using DNSResolveQueuePlatform = DNSResolveQueueSoup;
+
+}
Deleted: trunk/Source/WebCore/platform/network/soup/DNSSoup.cpp (229358 => 229359)
--- trunk/Source/WebCore/platform/network/soup/DNSSoup.cpp 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebCore/platform/network/soup/DNSSoup.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
- * Copyright (C) 2009, 2012 Igalia S.L.
- *
- * 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 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
- * 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 "DNS.h"
-#include "DNSResolveQueue.h"
-
-#if USE(SOUP)
-
-#include "NetworkStorageSession.h"
-#include "SoupNetworkSession.h"
-#include <libsoup/soup.h>
-#include <wtf/MainThread.h>
-#include <wtf/glib/GUniquePtr.h>
-#include <wtf/text/CString.h>
-
-namespace WebCore {
-
-// Initially true to ensure prefetch stays disabled until we have proxy settings.
-static bool isUsingHttpProxy = true;
-static bool isUsingHttpsProxy = true;
-
-static bool didResolveProxy(char** uris)
-{
- // We have a list of possible proxies to use for the URI. If the first item in the list is
- // direct:// (the usual case), then the user prefers not to use a proxy. This is similar to
- // resolving hostnames: there could be many possibilities returned in order of preference, and
- // if we're trying to connect we should attempt each one in order, but here we are not trying
- // to connect, merely to decide whether a proxy "should" be used.
- return uris && *uris && strcmp(*uris, "direct://");
-}
-
-static void didResolveProxy(GProxyResolver* resolver, GAsyncResult* result, bool* isUsingProxyType, bool* isUsingProxy)
-{
- GUniqueOutPtr<GError> error;
- GUniquePtr<char*> uris(g_proxy_resolver_lookup_finish(resolver, result, &error.outPtr()));
- if (error) {
- WTFLogAlways("Error determining system proxy settings: %s", error->message);
- return;
- }
-
- *isUsingProxyType = didResolveProxy(uris.get());
- *isUsingProxy = isUsingHttpProxy || isUsingHttpsProxy;
-}
-
-static void proxyResolvedForHttpUriCallback(GObject* source, GAsyncResult* result, void* userData)
-{
- didResolveProxy(G_PROXY_RESOLVER(source), result, &isUsingHttpProxy, static_cast<bool*>(userData));
-}
-
-static void proxyResolvedForHttpsUriCallback(GObject* source, GAsyncResult* result, void* userData)
-{
- didResolveProxy(G_PROXY_RESOLVER(source), result, &isUsingHttpsProxy, static_cast<bool*>(userData));
-}
-
-void DNSResolveQueue::updateIsUsingProxy()
-{
- GRefPtr<GProxyResolver> resolver;
- g_object_get(NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession(), "proxy-resolver", &resolver.outPtr(), nullptr);
- ASSERT(resolver);
-
- g_proxy_resolver_lookup_async(resolver.get(), "http://example.com/", nullptr, proxyResolvedForHttpUriCallback, &m_isUsingProxy);
- g_proxy_resolver_lookup_async(resolver.get(), "https://example.com/", nullptr, proxyResolvedForHttpsUriCallback, &m_isUsingProxy);
-}
-
-static void resolvedCallback(SoupAddress*, guint, void*)
-{
- DNSResolveQueue::singleton().decrementRequestCount();
-}
-
-void DNSResolveQueue::platformResolve(const String& hostname)
-{
- ASSERT(isMainThread());
-
- soup_session_prefetch_dns(NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession(), hostname.utf8().data(), nullptr, resolvedCallback, nullptr);
-}
-
-void prefetchDNS(const String& hostname)
-{
- ASSERT(isMainThread());
- if (hostname.isEmpty())
- return;
-
- DNSResolveQueue::singleton().add(hostname);
-}
-
-}
-
-#endif
Modified: trunk/Source/WebKit/ChangeLog (229358 => 229359)
--- trunk/Source/WebKit/ChangeLog 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebKit/ChangeLog 2018-03-07 15:21:24 UTC (rev 229359)
@@ -1,3 +1,35 @@
+2018-03-07 Alejandro G. Castro <a...@igalia.com>
+
+ Make NetworkRTCResolver port agnostic
+ https://bugs.webkit.org/show_bug.cgi?id=178855
+
+ Reviewed by Youenn Fablet.
+
+ 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.
+
2018-03-06 Brent Fulgham <bfulg...@apple.com>
NetworkDataTask should enable logging for automation clients
Modified: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp (229358 => 229359)
--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -40,6 +40,10 @@
#include <wtf/MainThread.h>
#include <wtf/text/WTFString.h>
+#if PLATFORM(COCOA)
+#include "NetworkRTCResolverCocoa.h"
+#endif
+
namespace WebKit {
static inline std::unique_ptr<rtc::Thread> createThread()
@@ -162,15 +166,22 @@
NetworkRTCSocket(decoder.destinationID(), *this).didReceiveMessage(connection, decoder);
}
+#if PLATFORM(COCOA)
+
void NetworkRTCProvider::createResolver(uint64_t identifier, const String& address)
{
- auto resolver = std::make_unique<NetworkRTCResolver>([this, identifier](NetworkRTCResolver::AddressesOrError&& result) mutable {
+ auto resolver = NetworkRTCResolver::create(identifier, [this, identifier](WebCore::DNSAddressesOrError&& result) mutable {
if (!result.has_value()) {
- if (result.error() != NetworkRTCResolver::Error::Cancelled)
+ if (result.error() != WebCore::DNSError::Cancelled)
m_connection->connection().send(Messages::WebRTCResolver::ResolvedAddressError(1), identifier);
return;
}
- m_connection->connection().send(Messages::WebRTCResolver::SetResolvedAddress(result.value()), identifier);
+
+ auto addresses = WTF::map(result.value(), [] (auto& address) {
+ return RTCNetwork::IPAddress { rtc::IPAddress { address.getSinAddr() } };
+ });
+
+ m_connection->connection().send(Messages::WebRTCResolver::SetResolvedAddress(addresses), identifier);
});
resolver->start(address);
m_resolvers.add(identifier, WTFMove(resolver));
@@ -182,6 +193,34 @@
resolver->stop();
}
+#else
+
+void NetworkRTCProvider::createResolver(uint64_t identifier, const String& address)
+{
+ auto completionHandler = [this, identifier](WebCore::DNSAddressesOrError&& result) mutable {
+ if (!result.has_value()) {
+ if (result.error() != WebCore::DNSError::Cancelled)
+ m_connection->connection().send(Messages::WebRTCResolver::ResolvedAddressError(1), identifier);
+ return;
+ }
+
+ auto addresses = WTF::map(result.value(), [] (auto& address) {
+ return RTCNetwork::IPAddress { rtc::IPAddress { address.getSinAddr() } };
+ });
+
+ m_connection->connection().send(Messages::WebRTCResolver::SetResolvedAddress(addresses), identifier);
+ };
+
+ WebCore::resolveDNS(address, identifier, WTFMove(completionHandler));
+}
+
+void NetworkRTCProvider::stopResolver(uint64_t identifier)
+{
+ WebCore::stopResolveDNS(identifier);
+}
+
+#endif
+
void NetworkRTCProvider::closeListeningSockets(Function<void()>&& completionHandler)
{
if (!m_isListeningSocketAuthorized) {
Modified: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.cpp (229358 => 229359)
--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.cpp 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -32,70 +32,36 @@
namespace WebKit {
-static void resolvedName(CFHostRef hostRef, CFHostInfoType typeInfo, const CFStreamError *error, void *info)
+// FIXME: Use the function after removing the NetworkRTCResolverCocoa.
+#if !PLATFORM(COCOA)
+std::unique_ptr<NetworkRTCResolver> NetworkRTCResolver::create(uint64_t identifier, WebCore::DNSCompletionHandler&& completionHandler)
{
- ASSERT_UNUSED(typeInfo, !typeInfo);
-
- if (error->domain) {
- // FIXME: Need to handle failure, but info is not provided in the callback.
- return;
- }
-
- ASSERT(info);
- auto* resolver = static_cast<NetworkRTCResolver*>(info);
-
- Boolean result;
- CFArrayRef resolvedAddresses = (CFArrayRef)CFHostGetAddressing(hostRef, &result);
- ASSERT_UNUSED(result, result);
-
- size_t count = CFArrayGetCount(resolvedAddresses);
- Vector<RTCNetwork::IPAddress> addresses;
- addresses.reserveInitialCapacity(count);
-
- for (size_t index = 0; index < count; ++index) {
- CFDataRef data = "" index);
- auto* address = reinterpret_cast<const struct sockaddr_in*>(CFDataGetBytePtr(data));
- addresses.uncheckedAppend(RTCNetwork::IPAddress(rtc::IPAddress(address->sin_addr)));
- }
- resolver->completed(addresses);
+ return std::unique_ptr<NetworkRTCResolver>(new NetworkRTCResolver(identifier, WTFMove(completionHandler)));
}
+#endif
-NetworkRTCResolver::NetworkRTCResolver(CompletionHandler&& completionHandler)
- : m_completionHandler(WTFMove(completionHandler))
+NetworkRTCResolver::NetworkRTCResolver(uint64_t identifier, WebCore::DNSCompletionHandler&& completionHandler)
+ : m_identifier(identifier)
+ , m_completionHandler(WTFMove(completionHandler))
{
}
NetworkRTCResolver::~NetworkRTCResolver()
{
- CFHostUnscheduleFromRunLoop(m_host.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
- CFHostSetClient(m_host.get(), nullptr, nullptr);
if (auto completionHandler = WTFMove(m_completionHandler))
- completionHandler(makeUnexpected(Error::Unknown));
+ completionHandler(makeUnexpected(WebCore::DNSError::Unknown));
}
void NetworkRTCResolver::start(const String& address)
{
- m_host = adoptCF(CFHostCreateWithName(kCFAllocatorDefault, address.createCFString().get()));
- CFHostClientContext context = { 0, this, nullptr, nullptr, nullptr };
- CFHostSetClient(m_host.get(), resolvedName, &context);
- CFHostScheduleWithRunLoop(m_host.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
- Boolean result = CFHostStartInfoResolution(m_host.get(), kCFHostAddresses, nullptr);
- ASSERT_UNUSED(result, result);
+ WebCore::resolveDNS(address, m_identifier, WTFMove(m_completionHandler));
}
void NetworkRTCResolver::stop()
{
- CFHostCancelInfoResolution(m_host.get(), CFHostInfoType::kCFHostAddresses);
- if (auto completionHandler = WTFMove(m_completionHandler))
- completionHandler(makeUnexpected(Error::Cancelled));
+ WebCore::stopResolveDNS(m_identifier);
}
-void NetworkRTCResolver::completed(const Vector<RTCNetwork::IPAddress>& addresses)
-{
- if (auto completionHandler = WTFMove(m_completionHandler))
- completionHandler({ addresses });
-}
-
} // namespace WebKit
#endif // USE(LIBWEBRTC)
Modified: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.h (229358 => 229359)
--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.h 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.h 2018-03-07 15:21:24 UTC (rev 229359)
@@ -28,7 +28,7 @@
#if USE(LIBWEBRTC)
#include "RTCNetwork.h"
-#include <CFNetwork/CFHost.h>
+#include <WebCore/DNS.h>
#include <wtf/CompletionHandler.h>
#include <wtf/text/WTFString.h>
@@ -36,22 +36,17 @@
class NetworkRTCResolver {
public:
- enum class Error { Unknown, Cancelled };
+ static std::unique_ptr<NetworkRTCResolver> create(uint64_t identifier, WebCore::DNSCompletionHandler&&);
- using AddressesOrError = Expected<std::reference_wrapper<const Vector<RTCNetwork::IPAddress>>, Error>;
- using CompletionHandler = WTF::CompletionHandler<void(AddressesOrError&&)>;
+ NetworkRTCResolver(uint64_t identifier, WebCore::DNSCompletionHandler&&);
+ virtual ~NetworkRTCResolver();
- explicit NetworkRTCResolver(CompletionHandler&&);
- ~NetworkRTCResolver();
+ virtual void start(const String& address);
+ virtual void stop();
- void start(const String& address);
- void stop();
-
- void completed(const Vector<RTCNetwork::IPAddress>&);
-
-private:
- CompletionHandler m_completionHandler;
- RetainPtr<CFHostRef> m_host;
+protected:
+ uint64_t m_identifier;
+ WebCore::DNSCompletionHandler m_completionHandler;
};
} // namespace WebKit
Copied: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolverCocoa.cpp (from rev 229358, trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.cpp) (0 => 229359)
--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolverCocoa.cpp (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolverCocoa.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2017 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 "NetworkRTCResolverCocoa.h"
+
+#if USE(LIBWEBRTC)
+
+#include <wtf/Expected.h>
+
+namespace WebKit {
+
+static void resolvedName(CFHostRef hostRef, CFHostInfoType typeInfo, const CFStreamError *error, void *info)
+{
+ ASSERT_UNUSED(typeInfo, !typeInfo);
+
+ ASSERT(info);
+ auto* resolver = static_cast<NetworkRTCResolverCocoa*>(info);
+
+ if (error->domain) {
+ // FIXME: Need to handle failure, but info is not provided in the callback.
+ resolver->completed(makeUnexpected(WebCore::DNSError::Unknown));
+ return;
+ }
+
+ Boolean result;
+ CFArrayRef resolvedAddresses = (CFArrayRef)CFHostGetAddressing(hostRef, &result);
+ ASSERT_UNUSED(result, result);
+
+ size_t count = CFArrayGetCount(resolvedAddresses);
+ Vector<WebCore::IPAddress> addresses;
+ addresses.reserveInitialCapacity(count);
+
+ for (size_t index = 0; index < count; ++index) {
+ CFDataRef data = "" index);
+ auto* address = reinterpret_cast<const struct sockaddr_in*>(CFDataGetBytePtr(data));
+ addresses.uncheckedAppend(WebCore::IPAddress(*address));
+ }
+ resolver->completed(WTFMove(addresses));
+}
+
+std::unique_ptr<NetworkRTCResolver> NetworkRTCResolver::create(uint64_t identifier, WebCore::DNSCompletionHandler&& completionHandler)
+{
+ return std::unique_ptr<NetworkRTCResolver>(new NetworkRTCResolverCocoa(identifier, WTFMove(completionHandler)));
+}
+
+NetworkRTCResolverCocoa::NetworkRTCResolverCocoa(uint64_t identifier, WebCore::DNSCompletionHandler&& completionHandler)
+ : NetworkRTCResolver(identifier, WTFMove(completionHandler))
+{
+}
+
+NetworkRTCResolverCocoa::~NetworkRTCResolverCocoa()
+{
+ CFHostUnscheduleFromRunLoop(m_host.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+ CFHostSetClient(m_host.get(), nullptr, nullptr);
+}
+
+void NetworkRTCResolverCocoa::start(const String& address)
+{
+ m_host = adoptCF(CFHostCreateWithName(kCFAllocatorDefault, address.createCFString().get()));
+ CFHostClientContext context = { 0, this, nullptr, nullptr, nullptr };
+ CFHostSetClient(m_host.get(), resolvedName, &context);
+ CFHostScheduleWithRunLoop(m_host.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+ Boolean result = CFHostStartInfoResolution(m_host.get(), kCFHostAddresses, nullptr);
+ ASSERT_UNUSED(result, result);
+}
+
+void NetworkRTCResolverCocoa::stop()
+{
+ CFHostCancelInfoResolution(m_host.get(), CFHostInfoType::kCFHostAddresses);
+ if (auto completionHandler = WTFMove(m_completionHandler))
+ completionHandler(makeUnexpected(WebCore::DNSError::Cancelled));
+}
+
+void NetworkRTCResolverCocoa::completed(WebCore::DNSAddressesOrError&& addressesOrError)
+{
+ if (auto completionHandler = WTFMove(m_completionHandler))
+ completionHandler(WTFMove(addressesOrError));
+}
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
Copied: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolverCocoa.h (from rev 229358, trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolver.h) (0 => 229359)
--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolverCocoa.h (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCResolverCocoa.h 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 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 "NetworkRTCResolver.h"
+
+#include <CFNetwork/CFHost.h>
+
+namespace WebKit {
+
+// FIXME: Remove this class when we complete the implementation of the DNSResolveQueueCFNet.
+class NetworkRTCResolverCocoa final : public NetworkRTCResolver {
+public:
+ explicit NetworkRTCResolverCocoa(uint64_t identifier, WebCore::DNSCompletionHandler&&);
+ ~NetworkRTCResolverCocoa() final;
+
+ void start(const String& address) final;
+ void stop() final;
+
+ void completed(WebCore::DNSAddressesOrError&&);
+
+private:
+ RetainPtr<CFHostRef> m_host;
+};
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (229358 => 229359)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2018-03-07 15:21:24 UTC (rev 229359)
@@ -915,6 +915,7 @@
410482CD1DDD324C00F006D0 /* RTCNetwork.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 410482CB1DDD2FB500F006D0 /* RTCNetwork.cpp */; };
410482CE1DDD324F00F006D0 /* RTCNetwork.h in Headers */ = {isa = PBXBuildFile; fileRef = 410482CC1DDD2FB500F006D0 /* RTCNetwork.h */; };
4112B5551FA0EA7A00E67875 /* NetworkRTCResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4112B5471F9FD3AB00E67875 /* NetworkRTCResolver.cpp */; };
+ 4112B5551FA0EA7A00E67986 /* NetworkRTCResolverCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4112B5471F9FD3AB00E67986 /* NetworkRTCResolverCocoa.cpp */; };
411B22641E371BA6004F7363 /* LibWebRTCNetwork.h in Headers */ = {isa = PBXBuildFile; fileRef = 411B22621E371244004F7363 /* LibWebRTCNetwork.h */; };
413075A91DE85F2C0039EC69 /* NetworkRTCSocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413075981DE84FB00039EC69 /* NetworkRTCSocket.cpp */; };
413075AA1DE85F300039EC69 /* NetworkRTCMonitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4130759A1DE84FB00039EC69 /* NetworkRTCMonitor.cpp */; };
@@ -3287,6 +3288,8 @@
410482CC1DDD2FB500F006D0 /* RTCNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCNetwork.h; sourceTree = "<group>"; };
4112B5471F9FD3AB00E67875 /* NetworkRTCResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkRTCResolver.cpp; path = NetworkProcess/webrtc/NetworkRTCResolver.cpp; sourceTree = "<group>"; };
4112B5481F9FD3AC00E67875 /* NetworkRTCResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkRTCResolver.h; path = NetworkProcess/webrtc/NetworkRTCResolver.h; sourceTree = "<group>"; };
+ 4112B5471F9FD3AB00E67986 /* NetworkRTCResolverCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkRTCResolverCocoa.cpp; path = NetworkProcess/webrtc/NetworkRTCResolverCocoa.cpp; sourceTree = "<group>"; };
+ 4112B5481F9FD3AC00E67986 /* NetworkRTCResolverCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkRTCResolverCocoa.h; path = NetworkProcess/webrtc/NetworkRTCResolverCocoa.h; sourceTree = "<group>"; };
411B22621E371244004F7363 /* LibWebRTCNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCNetwork.h; path = Network/webrtc/LibWebRTCNetwork.h; sourceTree = "<group>"; };
413075981DE84FB00039EC69 /* NetworkRTCSocket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkRTCSocket.cpp; path = NetworkProcess/webrtc/NetworkRTCSocket.cpp; sourceTree = "<group>"; };
413075991DE84FB00039EC69 /* NetworkRTCSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkRTCSocket.h; path = NetworkProcess/webrtc/NetworkRTCSocket.h; sourceTree = "<group>"; };
@@ -6236,6 +6239,8 @@
41DC45981E3D6ED600B11F51 /* NetworkRTCProvider.messages.in */,
4112B5471F9FD3AB00E67875 /* NetworkRTCResolver.cpp */,
4112B5481F9FD3AC00E67875 /* NetworkRTCResolver.h */,
+ 4112B5471F9FD3AB00E67986 /* NetworkRTCResolverCocoa.cpp */,
+ 4112B5481F9FD3AC00E67986 /* NetworkRTCResolverCocoa.h */,
413075981DE84FB00039EC69 /* NetworkRTCSocket.cpp */,
413075991DE84FB00039EC69 /* NetworkRTCSocket.h */,
4130759D1DE84FB00039EC69 /* NetworkRTCSocket.messages.in */,
@@ -10621,6 +10626,7 @@
41DC45971E3D6E2200B11F51 /* NetworkRTCProvider.cpp in Sources */,
51F060E11654318500F3282E /* NetworkRTCProviderMessageReceiver.cpp in Sources */,
4112B5551FA0EA7A00E67875 /* NetworkRTCResolver.cpp in Sources */,
+ 4112B5551FA0EA7A00E67986 /* NetworkRTCResolverCocoa.cpp in Sources */,
413075A91DE85F2C0039EC69 /* NetworkRTCSocket.cpp in Sources */,
51F060E11654318500F3281D /* NetworkRTCSocketMessageReceiver.cpp in Sources */,
BC8283AC16B4BF3F00A278FE /* NetworkServiceEntryPoint.mm in Sources */,
Modified: trunk/Tools/ChangeLog (229358 => 229359)
--- trunk/Tools/ChangeLog 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Tools/ChangeLog 2018-03-07 15:21:24 UTC (rev 229359)
@@ -1,3 +1,16 @@
+2018-03-07 Alejandro G. Castro <a...@igalia.com>
+
+ Make NetworkRTCResolver port agnostic
+ https://bugs.webkit.org/show_bug.cgi?id=178855
+
+ Reviewed by Youenn Fablet.
+
+ 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:
+
2018-03-06 Youenn Fablet <you...@apple.com>
didReceiveServerRedirectForProvisionalNavigation is not called in case of document redirection with service worker registration change
Modified: trunk/Tools/TestWebKitAPI/PlatformGTK.cmake (229358 => 229359)
--- trunk/Tools/TestWebKitAPI/PlatformGTK.cmake 2018-03-07 11:59:20 UTC (rev 229358)
+++ trunk/Tools/TestWebKitAPI/PlatformGTK.cmake 2018-03-07 15:21:24 UTC (rev 229359)
@@ -87,6 +87,7 @@
${TESTWEBKITAPI_DIR}/TestsController.cpp
${TESTWEBKITAPI_DIR}/Tests/WebCore/CSSParser.cpp
${TESTWEBKITAPI_DIR}/Tests/WebCore/ComplexTextController.cpp
+ ${TESTWEBKITAPI_DIR}/Tests/WebCore/DNS.cpp
${TESTWEBKITAPI_DIR}/Tests/WebCore/FileMonitor.cpp
${TESTWEBKITAPI_DIR}/Tests/WebCore/FileSystem.cpp
${TESTWEBKITAPI_DIR}/Tests/WebCore/GridPosition.cpp
Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/DNS.cpp (0 => 229359)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/DNS.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/DNS.cpp 2018-03-07 15:21:24 UTC (rev 229359)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2018 Igalia, S.L. 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 "Utilities.h"
+#include "WTFStringUtilities.h"
+
+#include <WebCore/DNS.h>
+#include <wtf/CompletionHandler.h>
+#include <wtf/Expected.h>
+#include <wtf/RunLoop.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+bool done = false;
+
+TEST(DNSTest, cancelResolveDNS)
+{
+ RunLoop::initializeMainRunLoop();
+
+ const String hostname = String("www.webkit.org");
+ uint64_t identifier = 1;
+
+ DNSCompletionHandler completionHandler = [](WebCore::DNSAddressesOrError&& result) mutable {
+ done = true;
+
+ ASSERT_FALSE(result.has_value());
+ ASSERT_TRUE(result.error() == WebCore::DNSError::Cancelled);
+
+ return;
+ };
+
+ done = false;
+ resolveDNS(hostname, identifier, WTFMove(completionHandler));
+ stopResolveDNS(identifier);
+ Util::run(&done);
+}
+
+TEST(DNSTest, cannotResolveDNS)
+{
+ RunLoop::initializeMainRunLoop();
+
+ const String hostname = String("notavaliddomain.notavaliddomain");
+ uint64_t identifier = 1;
+
+ DNSCompletionHandler completionHandler = [](WebCore::DNSAddressesOrError&& result) mutable {
+ done = true;
+
+ ASSERT_FALSE(result.has_value());
+ ASSERT_TRUE(result.error() == WebCore::DNSError::CannotResolve);
+
+ return;
+ };
+
+ done = false;
+ resolveDNS(hostname, identifier, WTFMove(completionHandler));
+ Util::run(&done);
+}
+
+TEST(DNSTest, resolveDNS)
+{
+ RunLoop::initializeMainRunLoop();
+
+ const String hostname = String("www.webkit.org");
+ uint64_t identifier = 1;
+
+ DNSCompletionHandler completionHandler = [](WebCore::DNSAddressesOrError&& result) mutable {
+ done = true;
+
+ ASSERT_TRUE(result.has_value());
+
+ return;
+ };
+
+ done = false;
+ resolveDNS(hostname, identifier, WTFMove(completionHandler));
+ Util::run(&done);
+}
+
+} // namespace TestWebKitAPI