diff options
author | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-16 11:44:28 +0000 |
---|---|---|
committer | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-16 11:44:28 +0000 |
commit | d9d71e087d93e99c4bfb8be52314cc046513ad37 (patch) | |
tree | 28d5c4af1f96b6b1217858ae487eb2a9b12a4739 /net | |
parent | ad4d97af6f6f8a9f7e0af7dda6448437db744848 (diff) | |
download | chromium_src-d9d71e087d93e99c4bfb8be52314cc046513ad37.zip chromium_src-d9d71e087d93e99c4bfb8be52314cc046513ad37.tar.gz chromium_src-d9d71e087d93e99c4bfb8be52314cc046513ad37.tar.bz2 |
Implementation of custom PAC scripts in Proxy Settings API.
BUG=50725
TEST=
Review URL: http://codereview.chromium.org/6504004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75102 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/proxy/proxy_script_fetcher.h | 7 | ||||
-rw-r--r-- | net/proxy/proxy_script_fetcher_impl.cc | 13 | ||||
-rw-r--r-- | net/proxy/proxy_script_fetcher_impl_unittest.cc | 38 |
3 files changed, 56 insertions, 2 deletions
diff --git a/net/proxy/proxy_script_fetcher.h b/net/proxy/proxy_script_fetcher.h index 9829316..c8cda24 100644 --- a/net/proxy/proxy_script_fetcher.h +++ b/net/proxy/proxy_script_fetcher.h @@ -27,8 +27,11 @@ class ProxyScriptFetcher { virtual ~ProxyScriptFetcher() {} // Downloads the given PAC URL, and invokes |callback| on completion. - // On success |callback| is executed with a result code of OK, |*utf16_text| - // is filled with the response. On failure, the result text is + // Returns OK on success, otherwise the error code. If the return code is + // ERR_IO_PENDING, then the request completes asynchronously, and |callback| + // will be invoked later with the final error code. + // After synchronous or asynchronous completion with a result code of OK, + // |*utf16_text| is filled with the response. On failure, the result text is // an empty string, and the result code is a network error. Some special // network errors that may occur are: // diff --git a/net/proxy/proxy_script_fetcher_impl.cc b/net/proxy/proxy_script_fetcher_impl.cc index bc245a2..e840189 100644 --- a/net/proxy/proxy_script_fetcher_impl.cc +++ b/net/proxy/proxy_script_fetcher_impl.cc @@ -9,6 +9,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/string_util.h" +#include "net/base/data_url.h" #include "net/base/io_buffer.h" #include "net/base/load_flags.h" #include "net/base/net_errors.h" @@ -123,6 +124,18 @@ int ProxyScriptFetcherImpl::Fetch(const GURL& url, DCHECK(callback); DCHECK(text); + // Handle base-64 encoded data-urls that contain custom PAC scripts. + if (url.SchemeIs("data")) { + std::string mime_type; + std::string charset; + std::string data; + if (!DataURL::Parse(url, &mime_type, &charset, &data)) + return ERR_FAILED; + + ConvertResponseToUTF16(charset, data, text); + return OK; + } + cur_request_.reset(new URLRequest(url, this)); cur_request_->set_context(url_request_context_); cur_request_->set_method("GET"); diff --git a/net/proxy/proxy_script_fetcher_impl_unittest.cc b/net/proxy/proxy_script_fetcher_impl_unittest.cc index ce92986..3dc4494 100644 --- a/net/proxy/proxy_script_fetcher_impl_unittest.cc +++ b/net/proxy/proxy_script_fetcher_impl_unittest.cc @@ -340,4 +340,42 @@ TEST_F(ProxyScriptFetcherImplTest, Encodings) { } } +TEST_F(ProxyScriptFetcherImplTest, DataURLs) { + scoped_refptr<URLRequestContext> context(new RequestContext); + ProxyScriptFetcherImpl pac_fetcher(context); + + const char kEncodedUrl[] = + "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R" + "m9yVVJMKHVybCwgaG9zdCkgewogIGlmIChob3N0ID09ICdmb29iYXIuY29tJykKICAgIHJl" + "dHVybiAnUFJPWFkgYmxhY2tob2xlOjgwJzsKICByZXR1cm4gJ0RJUkVDVCc7Cn0="; + const char kPacScript[] = + "function FindProxyForURL(url, host) {\n" + " if (host == 'foobar.com')\n" + " return 'PROXY blackhole:80';\n" + " return 'DIRECT';\n" + "}"; + + // Test fetching a "data:"-url containing a base64 encoded PAC script. + { + GURL url(kEncodedUrl); + string16 text; + TestCompletionCallback callback; + int result = pac_fetcher.Fetch(url, &text, &callback); + EXPECT_EQ(OK, result); + EXPECT_EQ(ASCIIToUTF16(kPacScript), text); + } + + const char kEncodedUrlBroken[] = + "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R"; + + // Test a broken "data:"-url containing a base64 encoded PAC script. + { + GURL url(kEncodedUrlBroken); + string16 text; + TestCompletionCallback callback; + int result = pac_fetcher.Fetch(url, &text, &callback); + EXPECT_EQ(ERR_FAILED, result); + } +} + } // namespace net |