Allow specifying proxy scripts using file:, data:, and ftp: URLs. This...

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
parent e087b77f
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "chrome/browser/policy/policy_service.h" #include "chrome/browser/policy/policy_service.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "net/base/host_mapping_rules.h" #include "net/base/host_mapping_rules.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
...@@ -50,6 +51,7 @@ ...@@ -50,6 +51,7 @@
#include "net/dns/host_cache.h" #include "net/dns/host_cache.h"
#include "net/dns/host_resolver.h" #include "net/dns/host_resolver.h"
#include "net/dns/mapped_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_filter.h"
#include "net/http/http_auth_handler_factory.h" #include "net/http/http_auth_handler_factory.h"
#include "net/http/http_network_layer.h" #include "net/http/http_network_layer.h"
...@@ -61,7 +63,11 @@ ...@@ -61,7 +63,11 @@
#include "net/spdy/spdy_session.h" #include "net/spdy/spdy_session.h"
#include "net/ssl/default_server_bound_cert_store.h" #include "net/ssl/default_server_bound_cert_store.h"
#include "net/ssl/server_bound_cert_service.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_fetcher.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_throttler_manager.h" #include "net/url_request/url_request_throttler_manager.h"
#include "net/websockets/websocket_job.h" #include "net/websockets/websocket_job.h"
...@@ -188,6 +194,8 @@ ConstructProxyScriptFetcherContext(IOThread::Globals* globals, ...@@ -188,6 +194,8 @@ ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
context->set_http_transaction_factory( context->set_http_transaction_factory(
globals->proxy_script_fetcher_http_transaction_factory.get()); 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_cookie_store(globals->system_cookie_store.get());
context->set_server_bound_cert_service( context->set_server_bound_cert_service(
globals->system_server_bound_cert_service.get()); globals->system_server_bound_cert_service.get());
...@@ -547,6 +555,22 @@ void IOThread::Init() { ...@@ -547,6 +555,22 @@ void IOThread::Init() {
new net::HttpNetworkSession(session_params)); new net::HttpNetworkSession(session_params));
globals_->proxy_script_fetcher_http_transaction_factory.reset( globals_->proxy_script_fetcher_http_transaction_factory.reset(
new net::HttpNetworkLayer(network_session)); 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.reset(new net::URLRequestThrottlerManager());
globals_->throttler_manager->set_net_log(net_log_); globals_->throttler_manager->set_net_log(net_log_);
......
...@@ -57,6 +57,7 @@ class SSLConfigService; ...@@ -57,6 +57,7 @@ class SSLConfigService;
class TransportSecurityState; class TransportSecurityState;
class URLRequestContext; class URLRequestContext;
class URLRequestContextGetter; class URLRequestContextGetter;
class URLRequestJobFactory;
class URLRequestThrottlerManager; class URLRequestThrottlerManager;
class URLSecurityManager; class URLSecurityManager;
} // namespace net } // namespace net
...@@ -122,6 +123,10 @@ class IOThread : public content::BrowserThreadDelegate { ...@@ -122,6 +123,10 @@ class IOThread : public content::BrowserThreadDelegate {
scoped_ptr<net::ProxyService> proxy_script_fetcher_proxy_service; scoped_ptr<net::ProxyService> proxy_script_fetcher_proxy_service;
scoped_ptr<net::HttpTransactionFactory> scoped_ptr<net::HttpTransactionFactory>
proxy_script_fetcher_http_transaction_factory; 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::URLRequestThrottlerManager> throttler_manager;
scoped_ptr<net::URLSecurityManager> url_security_manager; scoped_ptr<net::URLSecurityManager> url_security_manager;
// TODO(willchan): Remove proxy script fetcher context since it's not // TODO(willchan): Remove proxy script fetcher context since it's not
......
...@@ -26,6 +26,25 @@ ...@@ -26,6 +26,25 @@
namespace { 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 // This class observes chrome::NOTIFICATION_AUTH_NEEDED and supplies
// the credential which is required by the test proxy server. // the credential which is required by the test proxy server.
// "foo:bar" is the required username and password for our 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) { ...@@ -123,4 +142,113 @@ IN_PROC_BROWSER_TEST_F(ProxyBrowserTest, MAYBE_BasicAuthWSConnect) {
EXPECT_TRUE(observer.auth_handled()); 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 } // namespace
function FindProxyForURL(url, host){ return "PROXY 0.0.0.0:8000;"; }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment