From 51fff29dc2dae1a8be5ea107d2b13205510c4e46 Mon Sep 17 00:00:00 2001 From: "ericroman@google.com" Date: Fri, 19 Dec 2008 22:17:53 +0000 Subject: Split ProxyResolver into two interfaces: A. interface for retrieving the system proxy settings (ProxyConfigService) B. interface for resolving the proxy (ProxyResolver)The motivation behind this change is: 1. Simplify sharing the WinHTTP code that fetches IE settings, with the V8 proxy resolver (avoids having platform-specific code in ProxyResolverV8). 2. Restrict objects to one thread. (ProxyService calls the config getter on IO thread, and the proxy resolving on the PAC thread).(ProxyResolver is now only 1 method, but this will grow shortly). Review URL: http://codereview.chromium.org/15070 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7323 0039d316-1c4b-4281-b951-d872f2087c98 --- net/proxy/proxy_config_service_win.cc | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 net/proxy/proxy_config_service_win.cc (limited to 'net/proxy/proxy_config_service_win.cc') diff --git a/net/proxy/proxy_config_service_win.cc b/net/proxy/proxy_config_service_win.cc new file mode 100644 index 0000000..f356ac9 --- /dev/null +++ b/net/proxy/proxy_config_service_win.cc @@ -0,0 +1,58 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/proxy/proxy_config_service_win.h" + +#include +#include + +#include "base/string_tokenizer.h" +#include "net/base/net_errors.h" + +#pragma comment(lib, "winhttp.lib") + +namespace net { + +static void FreeConfig(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* config) { + if (config->lpszAutoConfigUrl) + GlobalFree(config->lpszAutoConfigUrl); + if (config->lpszProxy) + GlobalFree(config->lpszProxy); + if (config->lpszProxyBypass) + GlobalFree(config->lpszProxyBypass); +} + +int ProxyConfigServiceWin::GetProxyConfig(ProxyConfig* config) { + WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config = {0}; + if (!WinHttpGetIEProxyConfigForCurrentUser(&ie_config)) { + LOG(ERROR) << "WinHttpGetIEProxyConfigForCurrentUser failed: " << + GetLastError(); + return ERR_FAILED; // TODO(darin): Bug 1189288: translate error code. + } + + if (ie_config.fAutoDetect) + config->auto_detect = true; + if (ie_config.lpszProxy) + config->proxy_server = WideToASCII(ie_config.lpszProxy); + if (ie_config.lpszProxyBypass) { + std::string proxy_bypass = WideToASCII(ie_config.lpszProxyBypass); + + StringTokenizer proxy_server_bypass_list(proxy_bypass, "; \t\n\r"); + while (proxy_server_bypass_list.GetNext()) { + std::string bypass_url_domain = proxy_server_bypass_list.token(); + if (bypass_url_domain == "") + config->proxy_bypass_local_names = true; + else + config->proxy_bypass.push_back(bypass_url_domain); + } + } + if (ie_config.lpszAutoConfigUrl) + config->pac_url = GURL(ie_config.lpszAutoConfigUrl); + + FreeConfig(&ie_config); + return OK; +} + +} // namespace net + -- cgit v1.1