2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "ProxyServer.h"
30 #include <wtf/RetainPtr.h>
33 #include <CFNetwork/CFNetwork.h>
38 #ifndef BUILDING_ON_LEOPARD
39 static void addProxyServersForURL(Vector<ProxyServer>& proxyServers, const KURL& url)
41 RetainPtr<CFDictionaryRef> proxySettings(AdoptCF, CFNetworkCopySystemProxySettings());
45 RetainPtr<CFURLRef> cfURL(AdoptCF, url.createCFURL());
46 RetainPtr<CFArrayRef> proxiesForURL(AdoptCF, CFNetworkCopyProxiesForURL(cfURL.get(), proxySettings.get()));
50 CFIndex numProxies = CFArrayGetCount(proxiesForURL.get());
51 for (CFIndex i = 0; i < numProxies; ++i) {
52 CFDictionaryRef proxyDictionary = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(proxiesForURL.get(), i));
54 ProxyServer::Type type = ProxyServer::Direct;
55 CFStringRef typeString = static_cast<CFStringRef>(CFDictionaryGetValue(proxyDictionary, kCFProxyTypeKey));
56 if (CFEqual(typeString, kCFProxyTypeAutoConfigurationURL)) {
57 // FIXME: Handle PAC URLs.
61 if (CFEqual(typeString, kCFProxyTypeNone)) {
62 proxyServers.append(ProxyServer(ProxyServer::Direct, String(), -1));
66 if (CFEqual(typeString, kCFProxyTypeHTTP))
67 type = ProxyServer::HTTP;
68 else if (CFEqual(typeString, kCFProxyTypeHTTPS))
69 type = ProxyServer::HTTPS;
70 else if (CFEqual(typeString, kCFProxyTypeSOCKS))
71 type = ProxyServer::SOCKS;
73 // We don't know how to handle this type.
77 CFStringRef host = static_cast<CFStringRef>(CFDictionaryGetValue(proxyDictionary, kCFProxyHostNameKey));
78 CFNumberRef port = static_cast<CFNumberRef>(CFDictionaryGetValue(proxyDictionary, kCFProxyPortNumberKey));
80 CFNumberGetValue(port, kCFNumberSInt32Type, &portValue);
82 proxyServers.append(ProxyServer(type, host, portValue));
86 Vector<ProxyServer> proxyServersForURL(const KURL& url, const NetworkingContext*)
88 Vector<ProxyServer> proxyServers;
90 addProxyServersForURL(proxyServers, url);
95 Vector<ProxyServer> proxyServersForURL(const KURL&, const NetworkingContext*)
98 return Vector<ProxyServer>();
102 } // namespace WebCore