summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-30 05:00:05 +0000
committerpauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-30 05:00:05 +0000
commitb3ae2db17876dcab65a6e23218dcc745a3f267bf (patch)
tree125a7806f24829ca121ca38589df0e0a0488f031
parente087b77fbfc5f501df0eb0da4b16b4a788a45dc4 (diff)
downloadchromium_src-b3ae2db17876dcab65a6e23218dcc745a3f267bf.zip
chromium_src-b3ae2db17876dcab65a6e23218dcc745a3f267bf.tar.gz
chromium_src-b3ae2db17876dcab65a6e23218dcc745a3f267bf.tar.bz2
Allow specifying proxy scripts using file:, data:, and ftp: URLs. This addresses a regression from r198915.
BUG=243974 Review URL: https://chromiumcodereview.appspot.com/15665006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203074 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/io_thread.cc24
-rw-r--r--chrome/browser/io_thread.h5
-rw-r--r--chrome/browser/net/proxy_browsertest.cc128
-rw-r--r--chrome/test/data/bad_server.pac1
4 files changed, 158 insertions, 0 deletions
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index bf9ba65..5ab3961 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -40,6 +40,7 @@
#include "chrome/browser/policy/policy_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/host_mapping_rules.h"
#include "net/base/net_util.h"
@@ -50,6 +51,7 @@
#include "net/dns/host_cache.h"
#include "net/dns/host_resolver.h"
#include "net/dns/mapped_host_resolver.h"
+#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_auth_filter.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_network_layer.h"
@@ -61,7 +63,11 @@
#include "net/spdy/spdy_session.h"
#include "net/ssl/default_server_bound_cert_store.h"
#include "net/ssl/server_bound_cert_service.h"
+#include "net/url_request/data_protocol_handler.h"
+#include "net/url_request/file_protocol_handler.h"
+#include "net/url_request/ftp_protocol_handler.h"
#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_throttler_manager.h"
#include "net/websockets/websocket_job.h"
@@ -188,6 +194,8 @@ ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
context->set_http_transaction_factory(
globals->proxy_script_fetcher_http_transaction_factory.get());
+ context->set_job_factory(
+ globals->proxy_script_fetcher_url_request_job_factory.get());
context->set_cookie_store(globals->system_cookie_store.get());
context->set_server_bound_cert_service(
globals->system_server_bound_cert_service.get());
@@ -547,6 +555,22 @@ void IOThread::Init() {
new net::HttpNetworkSession(session_params));
globals_->proxy_script_fetcher_http_transaction_factory.reset(
new net::HttpNetworkLayer(network_session));
+ scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
+ new net::URLRequestJobFactoryImpl());
+ job_factory->SetProtocolHandler(chrome::kDataScheme,
+ new net::DataProtocolHandler());
+ job_factory->SetProtocolHandler(chrome::kFileScheme,
+ new net::FileProtocolHandler());
+#if !defined(DISABLE_FTP_SUPPORT)
+ globals_->proxy_script_fetcher_ftp_transaction_factory.reset(
+ new net::FtpNetworkLayer(globals_->host_resolver.get()));
+ job_factory->SetProtocolHandler(
+ chrome::kFtpScheme,
+ new net::FtpProtocolHandler(
+ globals_->proxy_script_fetcher_ftp_transaction_factory.get()));
+#endif
+ globals_->proxy_script_fetcher_url_request_job_factory =
+ job_factory.PassAs<net::URLRequestJobFactory>();
globals_->throttler_manager.reset(new net::URLRequestThrottlerManager());
globals_->throttler_manager->set_net_log(net_log_);
diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h
index a8573c4..0c4b4d9 100644
--- a/chrome/browser/io_thread.h
+++ b/chrome/browser/io_thread.h
@@ -57,6 +57,7 @@ class SSLConfigService;
class TransportSecurityState;
class URLRequestContext;
class URLRequestContextGetter;
+class URLRequestJobFactory;
class URLRequestThrottlerManager;
class URLSecurityManager;
} // namespace net
@@ -122,6 +123,10 @@ class IOThread : public content::BrowserThreadDelegate {
scoped_ptr<net::ProxyService> proxy_script_fetcher_proxy_service;
scoped_ptr<net::HttpTransactionFactory>
proxy_script_fetcher_http_transaction_factory;
+ scoped_ptr<net::FtpTransactionFactory>
+ proxy_script_fetcher_ftp_transaction_factory;
+ scoped_ptr<net::URLRequestJobFactory>
+ proxy_script_fetcher_url_request_job_factory;
scoped_ptr<net::URLRequestThrottlerManager> throttler_manager;
scoped_ptr<net::URLSecurityManager> url_security_manager;
// TODO(willchan): Remove proxy script fetcher context since it's not
diff --git a/chrome/browser/net/proxy_browsertest.cc b/chrome/browser/net/proxy_browsertest.cc
index 16bd7c5..75e157b 100644
--- a/chrome/browser/net/proxy_browsertest.cc
+++ b/chrome/browser/net/proxy_browsertest.cc
@@ -26,6 +26,25 @@
namespace {
+// PAC script that sends all requests to an invalid proxy server.
+const base::FilePath::CharType kPACScript[] = FILE_PATH_LITERAL(
+ "bad_server.pac");
+
+// Verify kPACScript is installed as the PAC script.
+void VerifyProxyScript(Browser* browser) {
+ ui_test_utils::NavigateToURL(browser, GURL("http://google.com"));
+
+ // Verify we get the ERR_PROXY_CONNECTION_FAILED screen.
+ bool result = false;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ browser->tab_strip_model()->GetActiveWebContents(),
+ "var textContent = document.body.textContent;"
+ "var hasError = textContent.indexOf('ERR_PROXY_CONNECTION_FAILED') >= 0;"
+ "domAutomationController.send(hasError);",
+ &result));
+ EXPECT_TRUE(result);
+}
+
// This class observes chrome::NOTIFICATION_AUTH_NEEDED and supplies
// the credential which is required by the test proxy server.
// "foo:bar" is the required username and password for our test proxy server.
@@ -123,4 +142,113 @@ IN_PROC_BROWSER_TEST_F(ProxyBrowserTest, MAYBE_BasicAuthWSConnect) {
EXPECT_TRUE(observer.auth_handled());
}
+// Fetch PAC script via an http:// URL.
+class HttpProxyScriptBrowserTest : public InProcessBrowserTest {
+ public:
+ HttpProxyScriptBrowserTest()
+ : http_server_(net::SpawnedTestServer::TYPE_HTTP,
+ net::SpawnedTestServer::kLocalhost,
+ base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) {
+ }
+ virtual ~HttpProxyScriptBrowserTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ ASSERT_TRUE(http_server_.Start());
+ InProcessBrowserTest::SetUp();
+ }
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ base::FilePath pac_script_path(FILE_PATH_LITERAL("files"));
+ command_line->AppendSwitchASCII(switches::kProxyPacUrl, http_server_.GetURL(
+ pac_script_path.Append(kPACScript).MaybeAsASCII()).spec());
+ }
+
+ private:
+ net::SpawnedTestServer http_server_;
+
+ DISALLOW_COPY_AND_ASSIGN(HttpProxyScriptBrowserTest);
+};
+
+IN_PROC_BROWSER_TEST_F(HttpProxyScriptBrowserTest, Verify) {
+ VerifyProxyScript(browser());
+}
+
+// Fetch PAC script via a file:// URL.
+class FileProxyScriptBrowserTest : public InProcessBrowserTest {
+ public:
+ FileProxyScriptBrowserTest() {}
+ virtual ~FileProxyScriptBrowserTest() {}
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ command_line->AppendSwitchASCII(switches::kProxyPacUrl,
+ ui_test_utils::GetTestUrl(
+ base::FilePath(base::FilePath::kCurrentDirectory),
+ base::FilePath(kPACScript)).spec());
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FileProxyScriptBrowserTest);
+};
+
+IN_PROC_BROWSER_TEST_F(FileProxyScriptBrowserTest, Verify) {
+ VerifyProxyScript(browser());
+}
+
+// Fetch PAC script via an ftp:// URL.
+class FtpProxyScriptBrowserTest : public InProcessBrowserTest {
+ public:
+ FtpProxyScriptBrowserTest()
+ : ftp_server_(net::SpawnedTestServer::TYPE_FTP,
+ net::SpawnedTestServer::kLocalhost,
+ base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) {
+ }
+ virtual ~FtpProxyScriptBrowserTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ ASSERT_TRUE(ftp_server_.Start());
+ InProcessBrowserTest::SetUp();
+ }
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ base::FilePath pac_script_path(kPACScript);
+ command_line->AppendSwitchASCII(
+ switches::kProxyPacUrl,
+ ftp_server_.GetURL(pac_script_path.MaybeAsASCII()).spec());
+ }
+
+ private:
+ net::SpawnedTestServer ftp_server_;
+
+ DISALLOW_COPY_AND_ASSIGN(FtpProxyScriptBrowserTest);
+};
+
+IN_PROC_BROWSER_TEST_F(FtpProxyScriptBrowserTest, Verify) {
+ VerifyProxyScript(browser());
+}
+
+// Fetch PAC script via a data: URL.
+class DataProxyScriptBrowserTest : public InProcessBrowserTest {
+ public:
+ DataProxyScriptBrowserTest() {}
+ virtual ~DataProxyScriptBrowserTest() {}
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ std::string contents;
+ // Read in kPACScript contents.
+ ASSERT_TRUE(file_util::ReadFileToString(ui_test_utils::GetTestFilePath(
+ base::FilePath(base::FilePath::kCurrentDirectory),
+ base::FilePath(kPACScript)),
+ &contents));
+ command_line->AppendSwitchASCII(switches::kProxyPacUrl,
+ std::string("data:,") + contents);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DataProxyScriptBrowserTest);
+};
+
+IN_PROC_BROWSER_TEST_F(DataProxyScriptBrowserTest, Verify) {
+ VerifyProxyScript(browser());
+}
+
} // namespace
diff --git a/chrome/test/data/bad_server.pac b/chrome/test/data/bad_server.pac
new file mode 100644
index 0000000..8fa998d
--- /dev/null
+++ b/chrome/test/data/bad_server.pac
@@ -0,0 +1 @@
+function FindProxyForURL(url, host){ return "PROXY 0.0.0.0:8000;"; }