DNSResolveQueueCFNet.cpp [plain text]
#include "config.h"
#include "DNSResolveQueueCFNet.h"
#include "NotImplemented.h"
#include "Timer.h"
#include <wtf/HashSet.h>
#include <wtf/MainThread.h>
#include <wtf/RetainPtr.h>
#include <wtf/StdLibExtras.h>
#include <wtf/URL.h>
#include <wtf/text/StringHash.h>
#if PLATFORM(WIN)
#include "LoaderRunLoopCF.h"
#endif
#if PLATFORM(WIN) || PLATFORM(IOS_FAMILY)
#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({ }, "http://example.com/").createCFURL();
RetainPtr<CFURLRef> httpsCFURL = URL({ }, "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(); 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(); Boolean result = CFHostSetClient(leakedHost, clientCallback, &context);
ASSERT_UNUSED(result, result);
#if !PLATFORM(WIN)
CFHostScheduleWithRunLoop(leakedHost, CFRunLoopGetMain(), kCFRunLoopCommonModes);
#else
CFHostScheduleWithRunLoop(leakedHost, loaderRunLoop(), kCFRunLoopDefaultMode);
#endif
CFHostStartInfoResolution(leakedHost, kCFHostAddresses, 0);
}
void DNSResolveQueueCFNet::resolve(const String& , uint64_t , DNSCompletionHandler&& )
{
notImplemented();
}
void DNSResolveQueueCFNet::stopResolve(uint64_t )
{
notImplemented();
}
}