summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net
diff options
context:
space:
mode:
authorrobertshield@google.com <robertshield@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-12 15:07:50 +0000
committerrobertshield@google.com <robertshield@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-12 15:07:50 +0000
commitab501a6a67596eb43d233f91f7500779dcbe8740 (patch)
tree90bfc9f94bf80c4ed7081d8d54454f02075c3c26 /chrome/browser/net
parent481fe3bfb2359849d1d3fc9d0ceba4161fbb5a3e (diff)
downloadchromium_src-ab501a6a67596eb43d233f91f7500779dcbe8740.zip
chromium_src-ab501a6a67596eb43d233f91f7500779dcbe8740.tar.gz
chromium_src-ab501a6a67596eb43d233f91f7500779dcbe8740.tar.bz2
Making command-line specified proxy settings more flexible - allowing for setting of auto-detect, pac url, per-schema proxy settings, proxy bypass urls.
BUG=http://crbug.com/266 Review URL: http://codereview.chromium.org/115029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc64
-rw-r--r--chrome/browser/net/chrome_url_request_context.h8
-rw-r--r--chrome/browser/net/chrome_url_request_context_unittest.cc181
3 files changed, 242 insertions, 11 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index b15db26..85a33c9 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -23,26 +23,68 @@
#include "net/proxy/proxy_service.h"
#include "webkit/glue/webkit_glue.h"
-// Sets up proxy info if overrides were specified on the command line.
-// Otherwise returns NULL (meaning we should use the system defaults).
-// The caller is responsible for deleting returned pointer.
-static net::ProxyInfo* CreateProxyInfo(const CommandLine& command_line) {
- net::ProxyInfo* proxy_info = NULL;
+net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) {
+ // Scan for all "enable" type proxy switches.
+ static const wchar_t* proxy_switches[] = {
+ switches::kProxyServer,
+ switches::kProxyServerPacUrl,
+ switches::kProxyServerAutoDetect,
+ switches::kProxyServerBypassUrls
+ };
+
+ bool found_enable_proxy_switch = false;
+ for (size_t i = 0; i < arraysize(proxy_switches); i++) {
+ if (command_line.HasSwitch(proxy_switches[i])) {
+ found_enable_proxy_switch = true;
+ break;
+ }
+ }
+
+ if (!found_enable_proxy_switch &&
+ !command_line.HasSwitch(switches::kNoProxyServer)) {
+ return NULL;
+ }
+
+ net::ProxyConfig* proxy_config = new net::ProxyConfig();
+ if (command_line.HasSwitch(switches::kNoProxyServer)) {
+ // Ignore (and warn about) all the other proxy config switches we get if
+ // the no-proxy-server command line argument is present.
+ if (found_enable_proxy_switch) {
+ LOG(WARNING) << "Additional command line proxy switches found when --"
+ << switches::kNoProxyServer << " was specified.";
+ }
+ return proxy_config;
+ }
if (command_line.HasSwitch(switches::kProxyServer)) {
- proxy_info = new net::ProxyInfo();
const std::wstring& proxy_server =
command_line.GetSwitchValue(switches::kProxyServer);
- proxy_info->UseNamedProxy(WideToASCII(proxy_server));
+ proxy_config->proxy_rules.ParseFromString(WideToASCII(proxy_server));
+ }
+
+ if (command_line.HasSwitch(switches::kProxyServerPacUrl)) {
+ proxy_config->pac_url =
+ GURL(WideToASCII(command_line.GetSwitchValue(
+ switches::kProxyServerPacUrl)));
+ }
+
+ if (command_line.HasSwitch(switches::kProxyServerAutoDetect)) {
+ proxy_config->auto_detect = true;
+ }
+
+ if (command_line.HasSwitch(switches::kProxyServerBypassUrls)) {
+ proxy_config->ParseNoProxyList(
+ WideToASCII(command_line.GetSwitchValue(
+ switches::kProxyServerBypassUrls)));
}
- return proxy_info;
+ return proxy_config;
}
// Create a proxy service according to the options on command line.
static net::ProxyService* CreateProxyService(URLRequestContext* context,
const CommandLine& command_line) {
- scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo(command_line));
+ scoped_ptr<net::ProxyConfig> proxy_config(CreateProxyConfig(command_line));
bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver);
if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) {
@@ -53,8 +95,8 @@ static net::ProxyService* CreateProxyService(URLRequestContext* context,
}
return use_v8 ?
- net::ProxyService::CreateUsingV8Resolver(proxy_info.get(), context) :
- net::ProxyService::Create(proxy_info.get());
+ net::ProxyService::CreateUsingV8Resolver(proxy_config.get(), context) :
+ net::ProxyService::Create(proxy_config.get());
}
// static
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h
index 34b3d97..6f392a7 100644
--- a/chrome/browser/net/chrome_url_request_context.h
+++ b/chrome/browser/net/chrome_url_request_context.h
@@ -9,6 +9,10 @@
#include "net/url_request/url_request_context.h"
class Profile;
+class CommandLine;
+namespace net {
+class ProxyConfig;
+}
// A URLRequestContext subclass used by the browser. This can be used to store
// extra information about requests, beyond what is supported by the base
@@ -96,3 +100,7 @@ class ChromeURLRequestContext : public URLRequestContext,
bool is_media_;
bool is_off_the_record_;
};
+
+// Creates a proxy configuration using the overrides specified on the command
+// line. Returns NULL if the system defaults should be used instead.
+net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line);
diff --git a/chrome/browser/net/chrome_url_request_context_unittest.cc b/chrome/browser/net/chrome_url_request_context_unittest.cc
new file mode 100644
index 0000000..e74e7a8
--- /dev/null
+++ b/chrome/browser/net/chrome_url_request_context_unittest.cc
@@ -0,0 +1,181 @@
+// Copyright (c) 2006-2009 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 "base/command_line.h"
+#include "chrome/browser/net/chrome_url_request_context.h"
+#include "chrome/common/chrome_switches.h"
+#include "net/proxy/proxy_config.h"
+#include "net/proxy/proxy_config_service_common_unittest.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+// Builds an identifier for each test in an array.
+#define TEST_DESC(desc) StringPrintf("at line %d <%s>", __LINE__, desc)
+
+TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
+ // Build the input command lines here.
+ CommandLine empty(L"foo.exe");
+ CommandLine no_proxy(L"foo.exe");
+ no_proxy.AppendSwitch(switches::kNoProxyServer);
+ CommandLine no_proxy_extra_params(L"foo.exe");
+ no_proxy_extra_params.AppendSwitch(switches::kNoProxyServer);
+ no_proxy_extra_params.AppendSwitchWithValue(switches::kProxyServer,
+ L"http://proxy:8888");
+ CommandLine single_proxy(L"foo.exe");
+ single_proxy.AppendSwitchWithValue(switches::kProxyServer,
+ L"http://proxy:8888");
+ CommandLine per_scheme_proxy(L"foo.exe");
+ per_scheme_proxy.AppendSwitchWithValue(switches::kProxyServer,
+ L"http=httpproxy:8888;ftp=ftpproxy:8889");
+ CommandLine per_scheme_proxy_bypass(L"foo.exe");
+ per_scheme_proxy_bypass.AppendSwitchWithValue(switches::kProxyServer,
+ L"http=httpproxy:8888;ftp=ftpproxy:8889");
+ per_scheme_proxy_bypass.AppendSwitchWithValue(
+ switches::kProxyServerBypassUrls,
+ L".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8");
+ CommandLine with_pac_url(L"foo.exe");
+ with_pac_url.AppendSwitchWithValue(switches::kProxyServerPacUrl,
+ L"http://wpad/wpad.dat");
+ with_pac_url.AppendSwitchWithValue(
+ switches::kProxyServerBypassUrls,
+ L".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8");
+ CommandLine with_auto_detect(L"foo.exe");
+ with_auto_detect.AppendSwitch(switches::kProxyServerAutoDetect);
+
+ // Inspired from proxy_config_service_win_unittest.cc.
+ const struct {
+ // Short description to identify the test
+ std::string description;
+
+ // The command line to build a ProxyConfig from.
+ const CommandLine& command_line;
+
+ // Expected outputs (fields of the ProxyConfig).
+ bool is_null;
+ bool auto_detect;
+ GURL pac_url;
+ net::ProxyConfig::ProxyRules proxy_rules;
+ const char* proxy_bypass_list; // newline separated
+ bool bypass_local_names;
+ } tests[] = {
+ {
+ TEST_DESC("Empty command line"),
+ // Input
+ empty,
+ // Expected result
+ true, // is_null
+ false, // auto_detect
+ GURL(), // pac_url
+ net::ProxyConfig::ProxyRules(), // proxy_rules
+ "", // proxy_bypass_list
+ false // bypass_local_names
+ },
+ {
+ TEST_DESC("No proxy"),
+ // Input
+ no_proxy,
+ // Expected result
+ false, // is_null
+ false, // auto_detect
+ GURL(), // pac_url
+ net::ProxyConfig::ProxyRules(), // proxy_rules
+ "", // proxy_bypass_list
+ false // bypass_local_names
+ },
+ {
+ TEST_DESC("No proxy with extra parameters."),
+ // Input
+ no_proxy_extra_params,
+ // Expected result
+ false, // is_null
+ false, // auto_detect
+ GURL(), // pac_url
+ net::ProxyConfig::ProxyRules(), // proxy_rules
+ "", // proxy_bypass_list
+ false // bypass_local_names
+ },
+ {
+ TEST_DESC("Single proxy."),
+ // Input
+ single_proxy,
+ // Expected result
+ false, // is_null
+ false, // auto_detect
+ GURL(), // pac_url
+ net::MakeSingleProxyRules("http://proxy:8888"), // proxy_rules
+ "", // proxy_bypass_list
+ false // bypass_local_names
+ },
+ {
+ TEST_DESC("Per scheme proxy."),
+ // Input
+ per_scheme_proxy,
+ // Expected result
+ false, // is_null
+ false, // auto_detect
+ GURL(), // pac_url
+ net::MakeProxyPerSchemeRules("httpproxy:8888",
+ "",
+ "ftpproxy:8889"), // proxy_rules
+ "", // proxy_bypass_list
+ false // bypass_local_names
+ },
+ {
+ TEST_DESC("Per scheme proxy with bypass URLs."),
+ // Input
+ per_scheme_proxy_bypass,
+ // Expected result
+ false, // is_null
+ false, // auto_detect
+ GURL(), // pac_url
+ net::MakeProxyPerSchemeRules("httpproxy:8888",
+ "",
+ "ftpproxy:8889"), // proxy_rules
+ "*.google.com\n*foo.com:99\n1.2.3.4:22\n127.0.0.1/8\n",
+ false // bypass_local_names
+ },
+ {
+ TEST_DESC("Pac URL with proxy bypass URLs"),
+ // Input
+ with_pac_url,
+ // Expected result
+ false, // is_null
+ false, // auto_detect
+ GURL("http://wpad/wpad.dat"), // pac_url
+ net::ProxyConfig::ProxyRules(), // proxy_rules
+ "*.google.com\n*foo.com:99\n1.2.3.4:22\n127.0.0.1/8\n",
+ false // bypass_local_names
+ },
+ {
+ TEST_DESC("Autodetect"),
+ // Input
+ with_auto_detect,
+ // Expected result
+ false, // is_null
+ true, // auto_detect
+ GURL(), // pac_url
+ net::ProxyConfig::ProxyRules(), // proxy_rules
+ "", // proxy_bypass_list
+ false // bypass_local_names
+ }
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
+ SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str()));
+ scoped_ptr<net::ProxyConfig> config(CreateProxyConfig(
+ CommandLine(tests[i].command_line)));
+
+ if (tests[i].is_null) {
+ EXPECT_TRUE(config == NULL);
+ } else {
+ EXPECT_TRUE(config != NULL);
+ EXPECT_EQ(tests[i].auto_detect, config->auto_detect);
+ EXPECT_EQ(tests[i].pac_url, config->pac_url);
+ EXPECT_EQ(tests[i].proxy_bypass_list,
+ net::FlattenProxyBypass(config->proxy_bypass));
+ EXPECT_EQ(tests[i].bypass_local_names, config->proxy_bypass_local_names);
+ EXPECT_EQ(tests[i].proxy_rules, config->proxy_rules);
+ }
+ }
+}