| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/proxy/proxy_resolver_mac.h" | 5 #include "net/proxy/proxy_resolver_mac.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 ProxyResolverMac::~ProxyResolverMac() {} | 71 ProxyResolverMac::~ProxyResolverMac() {} |
| 72 | 72 |
| 73 // Gets the proxy information for a query URL from a PAC. Implementation | 73 // Gets the proxy information for a query URL from a PAC. Implementation |
| 74 // inspired by http://developer.apple.com/samplecode/CFProxySupportTool/ | 74 // inspired by http://developer.apple.com/samplecode/CFProxySupportTool/ |
| 75 int ProxyResolverMac::GetProxyForURL(const GURL& query_url, | 75 int ProxyResolverMac::GetProxyForURL(const GURL& query_url, |
| 76 ProxyInfo* results, | 76 ProxyInfo* results, |
| 77 const CompletionCallback& /*callback*/, | 77 const CompletionCallback& /*callback*/, |
| 78 RequestHandle* /*request*/, | 78 RequestHandle* /*request*/, |
| 79 const BoundNetLog& net_log) { | 79 const BoundNetLog& net_log) { |
| 80 base::mac::ScopedCFTypeRef<CFStringRef> query_ref( | 80 base::ScopedCFTypeRef<CFStringRef> query_ref( |
| 81 base::SysUTF8ToCFStringRef(query_url.spec())); | 81 base::SysUTF8ToCFStringRef(query_url.spec())); |
| 82 base::mac::ScopedCFTypeRef<CFURLRef> query_url_ref( | 82 base::ScopedCFTypeRef<CFURLRef> query_url_ref( |
| 83 CFURLCreateWithString(kCFAllocatorDefault, | 83 CFURLCreateWithString(kCFAllocatorDefault, query_ref.get(), NULL)); |
| 84 query_ref.get(), | |
| 85 NULL)); | |
| 86 if (!query_url_ref.get()) | 84 if (!query_url_ref.get()) |
| 87 return ERR_FAILED; | 85 return ERR_FAILED; |
| 88 base::mac::ScopedCFTypeRef<CFStringRef> pac_ref( | 86 base::ScopedCFTypeRef<CFStringRef> pac_ref(base::SysUTF8ToCFStringRef( |
| 89 base::SysUTF8ToCFStringRef( | 87 script_data_->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT |
| 90 script_data_->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT ? | 88 ? std::string() |
| 91 std::string() : script_data_->url().spec())); | 89 : script_data_->url().spec())); |
| 92 base::mac::ScopedCFTypeRef<CFURLRef> pac_url_ref( | 90 base::ScopedCFTypeRef<CFURLRef> pac_url_ref( |
| 93 CFURLCreateWithString(kCFAllocatorDefault, | 91 CFURLCreateWithString(kCFAllocatorDefault, pac_ref.get(), NULL)); |
| 94 pac_ref.get(), | |
| 95 NULL)); | |
| 96 if (!pac_url_ref.get()) | 92 if (!pac_url_ref.get()) |
| 97 return ERR_FAILED; | 93 return ERR_FAILED; |
| 98 | 94 |
| 99 // Work around <rdar://problem/5530166>. This dummy call to | 95 // Work around <rdar://problem/5530166>. This dummy call to |
| 100 // CFNetworkCopyProxiesForURL initializes some state within CFNetwork that is | 96 // CFNetworkCopyProxiesForURL initializes some state within CFNetwork that is |
| 101 // required by CFNetworkExecuteProxyAutoConfigurationURL. | 97 // required by CFNetworkExecuteProxyAutoConfigurationURL. |
| 102 | 98 |
| 103 CFArrayRef dummy_result = CFNetworkCopyProxiesForURL(query_url_ref.get(), | 99 CFArrayRef dummy_result = CFNetworkCopyProxiesForURL(query_url_ref.get(), |
| 104 NULL); | 100 NULL); |
| 105 if (dummy_result) | 101 if (dummy_result) |
| 106 CFRelease(dummy_result); | 102 CFRelease(dummy_result); |
| 107 | 103 |
| 108 // We cheat here. We need to act as if we were synchronous, so we pump the | 104 // We cheat here. We need to act as if we were synchronous, so we pump the |
| 109 // runloop ourselves. Our caller moved us to a new thread anyway, so this is | 105 // runloop ourselves. Our caller moved us to a new thread anyway, so this is |
| 110 // OK to do. (BTW, CFNetworkExecuteProxyAutoConfigurationURL returns a | 106 // OK to do. (BTW, CFNetworkExecuteProxyAutoConfigurationURL returns a |
| 111 // runloop source we need to release despite its name.) | 107 // runloop source we need to release despite its name.) |
| 112 | 108 |
| 113 CFTypeRef result = NULL; | 109 CFTypeRef result = NULL; |
| 114 CFStreamClientContext context = { 0, &result, NULL, NULL, NULL }; | 110 CFStreamClientContext context = { 0, &result, NULL, NULL, NULL }; |
| 115 base::mac::ScopedCFTypeRef<CFRunLoopSourceRef> runloop_source( | 111 base::ScopedCFTypeRef<CFRunLoopSourceRef> runloop_source( |
| 116 CFNetworkExecuteProxyAutoConfigurationURL(pac_url_ref.get(), | 112 CFNetworkExecuteProxyAutoConfigurationURL( |
| 117 query_url_ref.get(), | 113 pac_url_ref.get(), query_url_ref.get(), ResultCallback, &context)); |
| 118 ResultCallback, | |
| 119 &context)); | |
| 120 if (!runloop_source) | 114 if (!runloop_source) |
| 121 return ERR_FAILED; | 115 return ERR_FAILED; |
| 122 | 116 |
| 123 const CFStringRef private_runloop_mode = | 117 const CFStringRef private_runloop_mode = |
| 124 CFSTR("org.chromium.ProxyResolverMac"); | 118 CFSTR("org.chromium.ProxyResolverMac"); |
| 125 | 119 |
| 126 CFRunLoopAddSource(CFRunLoopGetCurrent(), runloop_source.get(), | 120 CFRunLoopAddSource(CFRunLoopGetCurrent(), runloop_source.get(), |
| 127 private_runloop_mode); | 121 private_runloop_mode); |
| 128 CFRunLoopRunInMode(private_runloop_mode, DBL_MAX, false); | 122 CFRunLoopRunInMode(private_runloop_mode, DBL_MAX, false); |
| 129 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runloop_source.get(), | 123 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runloop_source.get(), |
| 130 private_runloop_mode); | 124 private_runloop_mode); |
| 131 DCHECK(result != NULL); | 125 DCHECK(result != NULL); |
| 132 | 126 |
| 133 if (CFGetTypeID(result) == CFErrorGetTypeID()) { | 127 if (CFGetTypeID(result) == CFErrorGetTypeID()) { |
| 134 // TODO(avi): do something better than this | 128 // TODO(avi): do something better than this |
| 135 CFRelease(result); | 129 CFRelease(result); |
| 136 return ERR_FAILED; | 130 return ERR_FAILED; |
| 137 } | 131 } |
| 138 base::mac::ScopedCFTypeRef<CFArrayRef> proxy_array_ref( | 132 base::ScopedCFTypeRef<CFArrayRef> proxy_array_ref( |
| 139 base::mac::CFCastStrict<CFArrayRef>(result)); | 133 base::mac::CFCastStrict<CFArrayRef>(result)); |
| 140 DCHECK(proxy_array_ref != NULL); | 134 DCHECK(proxy_array_ref != NULL); |
| 141 | 135 |
| 142 // This string will be an ordered list of <proxy-uri> entries, separated by | 136 // This string will be an ordered list of <proxy-uri> entries, separated by |
| 143 // semi-colons. It is the format that ProxyInfo::UseNamedProxy() expects. | 137 // semi-colons. It is the format that ProxyInfo::UseNamedProxy() expects. |
| 144 // proxy-uri = [<proxy-scheme>"://"]<proxy-host>":"<proxy-port> | 138 // proxy-uri = [<proxy-scheme>"://"]<proxy-host>":"<proxy-port> |
| 145 // (This also includes entries for direct connection, as "direct://"). | 139 // (This also includes entries for direct connection, as "direct://"). |
| 146 std::string proxy_uri_list; | 140 std::string proxy_uri_list; |
| 147 | 141 |
| 148 CFIndex proxy_array_count = CFArrayGetCount(proxy_array_ref.get()); | 142 CFIndex proxy_array_count = CFArrayGetCount(proxy_array_ref.get()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 195 } |
| 202 | 196 |
| 203 int ProxyResolverMac::SetPacScript( | 197 int ProxyResolverMac::SetPacScript( |
| 204 const scoped_refptr<ProxyResolverScriptData>& script_data, | 198 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 205 const CompletionCallback& /*callback*/) { | 199 const CompletionCallback& /*callback*/) { |
| 206 script_data_ = script_data; | 200 script_data_ = script_data; |
| 207 return OK; | 201 return OK; |
| 208 } | 202 } |
| 209 | 203 |
| 210 } // namespace net | 204 } // namespace net |
| OLD | NEW |