summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/http/http_network_transaction_unittest.cc2
-rw-r--r--net/proxy/init_proxy_resolver.cc4
-rw-r--r--net/proxy/init_proxy_resolver.h2
-rw-r--r--net/proxy/init_proxy_resolver_unittest.cc50
-rw-r--r--net/proxy/mock_proxy_resolver.h12
-rw-r--r--net/proxy/proxy_resolver.h13
-rw-r--r--net/proxy/proxy_resolver_mac.h2
-rw-r--r--net/proxy/proxy_resolver_perftest.cc3
-rw-r--r--net/proxy/proxy_resolver_v8.cc153
-rw-r--r--net/proxy/proxy_resolver_v8.h4
-rw-r--r--net/proxy/proxy_resolver_v8_unittest.cc4
-rw-r--r--net/proxy/proxy_resolver_winhttp.cc2
-rw-r--r--net/proxy/proxy_resolver_winhttp.h2
-rw-r--r--net/proxy/proxy_script_fetcher.cc58
-rw-r--r--net/proxy/proxy_script_fetcher.h15
-rw-r--r--net/proxy/proxy_script_fetcher_unittest.cc96
-rw-r--r--net/proxy/proxy_service.cc2
-rw-r--r--net/proxy/proxy_service_unittest.cc43
-rw-r--r--net/proxy/single_threaded_proxy_resolver.cc12
-rw-r--r--net/proxy/single_threaded_proxy_resolver.h2
-rw-r--r--net/proxy/single_threaded_proxy_resolver_unittest.cc19
-rw-r--r--net/proxy/sync_host_resolver_bridge_unittest.cc2
22 files changed, 304 insertions, 198 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 3716255..85753b2 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -5232,7 +5232,7 @@ class CapturingProxyResolver : public ProxyResolver {
private:
virtual int SetPacScript(const GURL& /*pac_url*/,
- const std::string& /*pac_bytes*/,
+ const string16& /*pac_script*/,
CompletionCallback* /*callback*/) {
return OK;
}
diff --git a/net/proxy/init_proxy_resolver.cc b/net/proxy/init_proxy_resolver.cc
index ea1e475..3817468 100644
--- a/net/proxy/init_proxy_resolver.cc
+++ b/net/proxy/init_proxy_resolver.cc
@@ -134,7 +134,7 @@ int InitProxyResolver::DoFetchPacScript() {
return ERR_UNEXPECTED;
}
- return proxy_script_fetcher_->Fetch(pac_url, &pac_bytes_, &io_callback_);
+ return proxy_script_fetcher_->Fetch(pac_url, &pac_script_, &io_callback_);
}
int InitProxyResolver::DoFetchPacScriptComplete(int result) {
@@ -161,7 +161,7 @@ int InitProxyResolver::DoSetPacScript() {
next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE;
return resolver_->expects_pac_bytes() ?
- resolver_->SetPacScriptByData(pac_bytes_, &io_callback_) :
+ resolver_->SetPacScriptByData(pac_script_, &io_callback_) :
resolver_->SetPacScriptByUrl(pac_url, &io_callback_);
}
diff --git a/net/proxy/init_proxy_resolver.h b/net/proxy/init_proxy_resolver.h
index e8d4ab2..ab1301a 100644
--- a/net/proxy/init_proxy_resolver.h
+++ b/net/proxy/init_proxy_resolver.h
@@ -97,7 +97,7 @@ class InitProxyResolver {
size_t current_pac_url_index_;
// Filled when the PAC script fetch completes.
- std::string pac_bytes_;
+ string16 pac_script_;
UrlList pac_urls_;
State next_state_;
diff --git a/net/proxy/init_proxy_resolver_unittest.cc b/net/proxy/init_proxy_resolver_unittest.cc
index 397db1ef..681e12d 100644
--- a/net/proxy/init_proxy_resolver_unittest.cc
+++ b/net/proxy/init_proxy_resolver_unittest.cc
@@ -4,6 +4,8 @@
#include <vector>
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "net/base/net_errors.h"
#include "net/base/net_log.h"
#include "net/base/net_log_unittest.h"
@@ -33,12 +35,12 @@ class Rules {
set_pac_error(set_pac_error) {
}
- std::string bytes() const {
+ string16 text() const {
if (set_pac_error == OK)
- return url.spec() + "!valid-script";
+ return UTF8ToUTF16(url.spec() + "!valid-script");
if (fetch_error == OK)
- return url.spec() + "!invalid-script";
- return std::string();
+ return UTF8ToUTF16(url.spec() + "!invalid-script");
+ return string16();
}
GURL url;
@@ -72,13 +74,13 @@ class Rules {
return rules_[0];
}
- const Rule& GetRuleByBytes(const std::string& bytes) const {
+ const Rule& GetRuleByText(const string16& text) const {
for (RuleList::const_iterator it = rules_.begin(); it != rules_.end();
++it) {
- if (it->bytes() == bytes)
+ if (it->text() == text)
return *it;
}
- LOG(FATAL) << "Rule not found for " << bytes;
+ LOG(FATAL) << "Rule not found for " << text;
return rules_[0];
}
@@ -93,13 +95,13 @@ class RuleBasedProxyScriptFetcher : public ProxyScriptFetcher {
// ProxyScriptFetcher implementation.
virtual int Fetch(const GURL& url,
- std::string* bytes,
+ string16* text,
CompletionCallback* callback) {
const Rules::Rule& rule = rules_->GetRuleByUrl(url);
int rv = rule.fetch_error;
EXPECT_NE(ERR_UNEXPECTED, rv);
if (rv == OK)
- *bytes = rule.bytes();
+ *text = rule.text();
return rv;
}
@@ -129,33 +131,33 @@ class RuleBasedProxyResolver : public ProxyResolver {
}
virtual int SetPacScript(const GURL& pac_url,
- const std::string& pac_bytes,
+ const string16& pac_script,
CompletionCallback* callback) {
const Rules::Rule& rule = expects_pac_bytes() ?
- rules_->GetRuleByBytes(pac_bytes) :
+ rules_->GetRuleByText(pac_script) :
rules_->GetRuleByUrl(pac_url);
int rv = rule.set_pac_error;
EXPECT_NE(ERR_UNEXPECTED, rv);
if (expects_pac_bytes())
- EXPECT_EQ(rule.bytes(), pac_bytes);
+ EXPECT_EQ(rule.text(), pac_script);
else
EXPECT_EQ(rule.url, pac_url);
if (rv == OK) {
- pac_bytes_ = pac_bytes;
+ pac_script_ = pac_script;
pac_url_ = pac_url;
}
return rv;
}
- const std::string& pac_bytes() const { return pac_bytes_; }
+ const string16& pac_script() const { return pac_script_; }
const GURL& pac_url() const { return pac_url_; }
private:
const Rules* rules_;
- std::string pac_bytes_;
+ string16 pac_script_;
GURL pac_url_;
};
@@ -174,7 +176,7 @@ TEST(InitProxyResolverTest, CustomPacSucceeds) {
CapturingNetLog log(CapturingNetLog::kUnbounded);
InitProxyResolver init(&resolver, &fetcher, &log);
EXPECT_EQ(OK, init.Init(config, &callback));
- EXPECT_EQ(rule.bytes(), resolver.pac_bytes());
+ EXPECT_EQ(rule.text(), resolver.pac_script());
// Check the NetLog was filled correctly.
EXPECT_EQ(6u, log.entries().size());
@@ -207,7 +209,7 @@ TEST(InitProxyResolverTest, CustomPacFails1) {
CapturingNetLog log(CapturingNetLog::kUnbounded);
InitProxyResolver init(&resolver, &fetcher, &log);
EXPECT_EQ(kFailedDownloading, init.Init(config, &callback));
- EXPECT_EQ("", resolver.pac_bytes());
+ EXPECT_EQ(string16(), resolver.pac_script());
// Check the NetLog was filled correctly.
EXPECT_EQ(4u, log.entries().size());
@@ -235,7 +237,7 @@ TEST(InitProxyResolverTest, CustomPacFails2) {
TestCompletionCallback callback;
InitProxyResolver init(&resolver, &fetcher, NULL);
EXPECT_EQ(kFailedParsing, init.Init(config, &callback));
- EXPECT_EQ("", resolver.pac_bytes());
+ EXPECT_EQ(string16(), resolver.pac_script());
}
// Fail downloading the custom PAC script, because the fetcher was NULL.
@@ -249,7 +251,7 @@ TEST(InitProxyResolverTest, HasNullProxyScriptFetcher) {
TestCompletionCallback callback;
InitProxyResolver init(&resolver, NULL, NULL);
EXPECT_EQ(ERR_UNEXPECTED, init.Init(config, &callback));
- EXPECT_EQ("", resolver.pac_bytes());
+ EXPECT_EQ(string16(), resolver.pac_script());
}
// Succeeds in choosing autodetect (wpad).
@@ -266,7 +268,7 @@ TEST(InitProxyResolverTest, AutodetectSuccess) {
TestCompletionCallback callback;
InitProxyResolver init(&resolver, &fetcher, NULL);
EXPECT_EQ(OK, init.Init(config, &callback));
- EXPECT_EQ(rule.bytes(), resolver.pac_bytes());
+ EXPECT_EQ(rule.text(), resolver.pac_script());
}
// Fails at WPAD (downloading), but succeeds in choosing the custom PAC.
@@ -285,7 +287,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess1) {
TestCompletionCallback callback;
InitProxyResolver init(&resolver, &fetcher, NULL);
EXPECT_EQ(OK, init.Init(config, &callback));
- EXPECT_EQ(rule.bytes(), resolver.pac_bytes());
+ EXPECT_EQ(rule.text(), resolver.pac_script());
}
// Fails at WPAD (parsing), but succeeds in choosing the custom PAC.
@@ -305,7 +307,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2) {
CapturingNetLog log(CapturingNetLog::kUnbounded);
InitProxyResolver init(&resolver, &fetcher, &log);
EXPECT_EQ(OK, init.Init(config, &callback));
- EXPECT_EQ(rule.bytes(), resolver.pac_bytes());
+ EXPECT_EQ(rule.text(), resolver.pac_script());
// Check the NetLog was filled correctly.
// (Note that the Fetch and Set states are repeated since both WPAD and custom
@@ -353,7 +355,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomFails1) {
TestCompletionCallback callback;
InitProxyResolver init(&resolver, &fetcher, NULL);
EXPECT_EQ(kFailedDownloading, init.Init(config, &callback));
- EXPECT_EQ("", resolver.pac_bytes());
+ EXPECT_EQ(string16(), resolver.pac_script());
}
// Fails at WPAD (downloading), and fails at custom PAC (parsing).
@@ -372,7 +374,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomFails2) {
TestCompletionCallback callback;
InitProxyResolver init(&resolver, &fetcher, NULL);
EXPECT_EQ(kFailedParsing, init.Init(config, &callback));
- EXPECT_EQ("", resolver.pac_bytes());
+ EXPECT_EQ(string16(), resolver.pac_script());
}
// Fails at WPAD (parsing), but succeeds in choosing the custom PAC.
diff --git a/net/proxy/mock_proxy_resolver.h b/net/proxy/mock_proxy_resolver.h
index 88d3246..5087d6c 100644
--- a/net/proxy/mock_proxy_resolver.h
+++ b/net/proxy/mock_proxy_resolver.h
@@ -61,17 +61,17 @@ class MockAsyncProxyResolverBase : public ProxyResolver {
public:
SetPacScriptRequest(MockAsyncProxyResolverBase* resolver,
const GURL& pac_url,
- const std::string& pac_bytes,
+ const string16& pac_script,
CompletionCallback* callback)
: resolver_(resolver),
pac_url_(pac_url),
- pac_bytes_(pac_bytes),
+ pac_script_(pac_script),
callback_(callback),
origin_loop_(MessageLoop::current()) {
}
const GURL& pac_url() const { return pac_url_; }
- const std::string& pac_bytes() const { return pac_bytes_; }
+ const string16& pac_script() const { return pac_script_; }
void CompleteNow(int rv) {
CompletionCallback* callback = callback_;
@@ -85,7 +85,7 @@ class MockAsyncProxyResolverBase : public ProxyResolver {
private:
MockAsyncProxyResolverBase* resolver_;
const GURL pac_url_;
- const std::string pac_bytes_;
+ const string16 pac_script_;
CompletionCallback* callback_;
MessageLoop* origin_loop_;
};
@@ -115,11 +115,11 @@ class MockAsyncProxyResolverBase : public ProxyResolver {
}
virtual int SetPacScript(const GURL& pac_url,
- const std::string& pac_bytes,
+ const string16& pac_script,
CompletionCallback* callback) {
DCHECK(!pending_set_pac_script_request_.get());
pending_set_pac_script_request_.reset(
- new SetPacScriptRequest(this, pac_url, pac_bytes, callback));
+ new SetPacScriptRequest(this, pac_url, pac_script, callback));
// Finished when user calls SetPacScriptRequest::CompleteNow().
return ERR_IO_PENDING;
}
diff --git a/net/proxy/proxy_resolver.h b/net/proxy/proxy_resolver.h
index 50f855a..b200206 100644
--- a/net/proxy/proxy_resolver.h
+++ b/net/proxy/proxy_resolver.h
@@ -5,9 +5,8 @@
#ifndef NET_PROXY_PROXY_RESOLVER_H_
#define NET_PROXY_PROXY_RESOLVER_H_
-#include <string>
-
#include "base/logging.h"
+#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "net/base/completion_callback.h"
@@ -55,14 +54,14 @@ class ProxyResolver {
// Sets the PAC script backend to use for this proxy resolver (by URL).
int SetPacScriptByUrl(const GURL& url, CompletionCallback* callback) {
DCHECK(!expects_pac_bytes());
- return SetPacScript(url, std::string(), callback);
+ return SetPacScript(url, string16(), callback);
}
// Sets the PAC script backend to use for this proxy resolver (by contents).
- int SetPacScriptByData(const std::string& bytes_utf8,
+ int SetPacScriptByData(const string16& script,
CompletionCallback* callback) {
DCHECK(expects_pac_bytes());
- return SetPacScript(GURL(), bytes_utf8, callback);
+ return SetPacScript(GURL(), script, callback);
}
// TODO(eroman): Make this =0.
@@ -77,12 +76,12 @@ class ProxyResolver {
private:
// Called to set the PAC script backend to use. If |pac_url| is invalid,
- // this is a request to use WPAD (auto detect). |bytes_utf8| may be empty if
+ // this is a request to use WPAD (auto detect). |pac_script| may be empty if
// the fetch failed, or if the fetch returned no content.
// Returns ERR_IO_PENDING in the case of asynchronous completion, and notifies
// the result through |callback|.
virtual int SetPacScript(const GURL& pac_url,
- const std::string& bytes_utf8,
+ const string16& pac_script,
CompletionCallback* callback) = 0;
const bool expects_pac_bytes_;
diff --git a/net/proxy/proxy_resolver_mac.h b/net/proxy/proxy_resolver_mac.h
index 43de83c..29fb96a 100644
--- a/net/proxy/proxy_resolver_mac.h
+++ b/net/proxy/proxy_resolver_mac.h
@@ -32,7 +32,7 @@ class ProxyResolverMac : public ProxyResolver {
private:
virtual int SetPacScript(const GURL& pac_url,
- const std::string& /*pac_bytes*/,
+ const string16& /*pac_script*/,
CompletionCallback* /*callback*/) {
pac_url_ = pac_url;
return OK;
diff --git a/net/proxy/proxy_resolver_perftest.cc b/net/proxy/proxy_resolver_perftest.cc
index c093506..6f7d340 100644
--- a/net/proxy/proxy_resolver_perftest.cc
+++ b/net/proxy/proxy_resolver_perftest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/perftimer.h"
+#include "base/string_util.h"
#include "net/base/mock_host_resolver.h"
#include "net/proxy/proxy_resolver_js_bindings.h"
#include "net/proxy/proxy_resolver_v8.h"
@@ -166,7 +167,7 @@ class PacPerfSuiteRunner {
ASSERT_TRUE(ok);
// Load the PAC script into the ProxyResolver.
- int rv = resolver_->SetPacScriptByData(file_contents, NULL);
+ int rv = resolver_->SetPacScriptByData(ASCIIToUTF16(file_contents), NULL);
EXPECT_EQ(net::OK, rv);
}
diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc
index 4b54cb7..504dc0c 100644
--- a/net/proxy/proxy_resolver_v8.cc
+++ b/net/proxy/proxy_resolver_v8.cc
@@ -4,6 +4,7 @@
#include "net/proxy/proxy_resolver_v8.h"
+#include "base/basictypes.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -72,6 +73,76 @@ const char kPacResourceName[] = "proxy-pac-script.js";
// Pseudo-name for the PAC utility script.
const char kPacUtilityResourceName[] = "proxy-pac-utility-script.js";
+// External string wrapper so V8 can access a string16.
+class V8ExternalString16 : public v8::String::ExternalStringResource {
+ public:
+ explicit V8ExternalString16(const string16& string) : string_(string) {}
+
+ virtual const uint16_t* data() const {
+ return reinterpret_cast<const uint16*>(string_.data());
+ }
+
+ virtual size_t length() const {
+ return string_.size();
+ }
+
+ private:
+ const string16 string_;
+ DISALLOW_COPY_AND_ASSIGN(V8ExternalString16);
+};
+
+// External string wrapper so V8 can access a string literal.
+class V8ExternalASCIILiteral : public v8::String::ExternalAsciiStringResource {
+ public:
+ // |ascii| must be a NULL-terminated C string, and must remain valid
+ // throughout this object's lifetime.
+ V8ExternalASCIILiteral(const char* ascii, size_t length)
+ : ascii_(ascii), length_(length) {
+ DCHECK(IsStringASCII(ascii));
+ }
+
+ virtual const char* data() const {
+ return ascii_;
+ }
+
+ virtual size_t length() const {
+ return length_;
+ }
+
+ private:
+ const char* ascii_;
+ size_t length_;
+ DISALLOW_COPY_AND_ASSIGN(V8ExternalASCIILiteral);
+};
+
+// External string wrapper so V8 can access a std::string.
+class V8ExternalASCIIString : public v8::String::ExternalAsciiStringResource {
+ public:
+ explicit V8ExternalASCIIString(const std::string& ascii)
+ : ascii_(ascii) {
+ DCHECK(IsStringASCII(ascii));
+ }
+
+ virtual const char* data() const {
+ return ascii_.data();
+ }
+
+ virtual size_t length() const {
+ return ascii_.size();
+ }
+
+ private:
+ const std::string ascii_;
+ DISALLOW_COPY_AND_ASSIGN(V8ExternalASCIIString);
+};
+
+// When creating a v8::String from a C++ string we have two choices: create
+// a copy, or create a wrapper that shares the same underlying storage.
+// For small strings it is better to just make a copy, whereas for large
+// strings there are savings by sharing the storage. This number identifies
+// the cutoff length for when to start wrapping rather than creating copies.
+const size_t kMaxStringBytesForCopy = 256;
+
// Converts a V8 String to a UTF16 string16.
string16 V8StringToUTF16(v8::Handle<v8::String> s) {
int len = s->Length();
@@ -82,9 +153,30 @@ string16 V8StringToUTF16(v8::Handle<v8::String> s) {
return result;
}
-// Converts a std::string (UTF8) to a V8 string.
-v8::Local<v8::String> UTF8StdStringToV8String(const std::string& s) {
- return v8::String::New(s.data(), s.size());
+// Converts an ASCII std::string to a V8 string.
+v8::Local<v8::String> ASCIIStringToV8String(const std::string& s) {
+ DCHECK(IsStringASCII(s));
+ if (s.size() <= kMaxStringBytesForCopy)
+ return v8::String::New(s.data(), s.size());
+ return v8::String::NewExternal(new V8ExternalASCIIString(s));
+}
+
+// Converts a UTF16 string16 to a V8 string.
+v8::Local<v8::String> UTF16StringToV8String(const string16& s) {
+ if (s.size() * 2 <= kMaxStringBytesForCopy) {
+ return v8::String::New(
+ reinterpret_cast<const uint16_t*>(s.data()), s.size());
+ }
+ return v8::String::NewExternal(new V8ExternalString16(s));
+}
+
+// Converts an ASCII string literal to a V8 string.
+v8::Local<v8::String> ASCIILiteralToV8String(const char* ascii) {
+ DCHECK(IsStringASCII(ascii));
+ size_t length = strlen(ascii);
+ if (length <= kMaxStringBytesForCopy)
+ return v8::String::New(ascii, length);
+ return v8::String::NewExternal(new V8ExternalASCIILiteral(ascii, length));
}
// Stringizes a V8 object by calling its toString() method. Returns true
@@ -169,8 +261,8 @@ class ProxyResolverV8::Context {
}
v8::Handle<v8::Value> argv[] = {
- UTF8StdStringToV8String(query_url.spec()),
- UTF8StdStringToV8String(query_url.host()),
+ ASCIIStringToV8String(query_url.spec()),
+ ASCIIStringToV8String(query_url.host()),
};
v8::TryCatch try_catch;
@@ -206,7 +298,7 @@ class ProxyResolverV8::Context {
return OK;
}
- int InitV8(const std::string& pac_data_utf8) {
+ int InitV8(const string16& pac_script) {
v8::Locker locked;
v8::HandleScope scope;
@@ -216,28 +308,28 @@ class ProxyResolverV8::Context {
// Attach the javascript bindings.
v8::Local<v8::FunctionTemplate> alert_template =
v8::FunctionTemplate::New(&AlertCallback, v8_this_);
- global_template->Set(v8::String::New("alert"), alert_template);
+ global_template->Set(ASCIILiteralToV8String("alert"), alert_template);
v8::Local<v8::FunctionTemplate> my_ip_address_template =
v8::FunctionTemplate::New(&MyIpAddressCallback, v8_this_);
- global_template->Set(v8::String::New("myIpAddress"),
+ global_template->Set(ASCIILiteralToV8String("myIpAddress"),
my_ip_address_template);
v8::Local<v8::FunctionTemplate> dns_resolve_template =
v8::FunctionTemplate::New(&DnsResolveCallback, v8_this_);
- global_template->Set(v8::String::New("dnsResolve"),
+ global_template->Set(ASCIILiteralToV8String("dnsResolve"),
dns_resolve_template);
// Microsoft's PAC extensions (incomplete):
v8::Local<v8::FunctionTemplate> dns_resolve_ex_template =
v8::FunctionTemplate::New(&DnsResolveExCallback, v8_this_);
- global_template->Set(v8::String::New("dnsResolveEx"),
+ global_template->Set(ASCIILiteralToV8String("dnsResolveEx"),
dns_resolve_ex_template);
v8::Local<v8::FunctionTemplate> my_ip_address_ex_template =
v8::FunctionTemplate::New(&MyIpAddressExCallback, v8_this_);
- global_template->Set(v8::String::New("myIpAddressEx"),
+ global_template->Set(ASCIILiteralToV8String("myIpAddressEx"),
my_ip_address_ex_template);
v8_context_ = v8::Context::New(NULL, global_template);
@@ -247,16 +339,18 @@ class ProxyResolverV8::Context {
// Add the PAC utility functions to the environment.
// (This script should never fail, as it is a string literal!)
// Note that the two string literals are concatenated.
- int rv = RunScript(PROXY_RESOLVER_SCRIPT
- PROXY_RESOLVER_SCRIPT_EX,
- kPacUtilityResourceName);
+ int rv = RunScript(
+ ASCIILiteralToV8String(
+ PROXY_RESOLVER_SCRIPT
+ PROXY_RESOLVER_SCRIPT_EX),
+ kPacUtilityResourceName);
if (rv != OK) {
NOTREACHED();
return rv;
}
// Add the user's PAC code to the environment.
- rv = RunScript(pac_data_utf8, kPacResourceName);
+ rv = RunScript(UTF16StringToV8String(pac_script), kPacResourceName);
if (rv != OK)
return rv;
@@ -285,7 +379,8 @@ class ProxyResolverV8::Context {
private:
bool GetFindProxyForURL(v8::Local<v8::Value>* function) {
- *function = v8_context_->Global()->Get(v8::String::New("FindProxyForURL"));
+ *function = v8_context_->Global()->Get(
+ ASCIILiteralToV8String("FindProxyForURL"));
return (*function)->IsFunction();
}
@@ -301,15 +396,15 @@ class ProxyResolverV8::Context {
js_bindings_->OnError(line_number, error_message);
}
- // Compiles and runs |script_utf8| in the current V8 context.
+ // Compiles and runs |script| in the current V8 context.
// Returns OK on success, otherwise an error code.
- int RunScript(const std::string& script_utf8, const char* script_name) {
+ int RunScript(v8::Handle<v8::String> script, const char* script_name) {
v8::TryCatch try_catch;
// Compile the script.
- v8::Local<v8::String> text = UTF8StdStringToV8String(script_utf8);
- v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New(script_name));
- v8::Local<v8::Script> code = v8::Script::Compile(text, &origin);
+ v8::ScriptOrigin origin =
+ v8::ScriptOrigin(ASCIILiteralToV8String(script_name));
+ v8::Local<v8::Script> code = v8::Script::Compile(script, &origin);
// Execute.
if (!code.IsEmpty())
@@ -370,8 +465,8 @@ class ProxyResolverV8::Context {
}
if (!success)
- result = "127.0.0.1";
- return UTF8StdStringToV8String(result);
+ return ASCIILiteralToV8String("127.0.0.1");
+ return ASCIIStringToV8String(result);
}
// V8 callback for when "myIpAddressEx()" is invoked by the PAC script.
@@ -403,7 +498,7 @@ class ProxyResolverV8::Context {
if (!success)
ip_address_list = std::string();
- return UTF8StdStringToV8String(ip_address_list);
+ return ASCIIStringToV8String(ip_address_list);
}
// V8 callback for when "dnsResolve()" is invoked by the PAC script.
@@ -435,7 +530,7 @@ class ProxyResolverV8::Context {
NULL);
}
- return success ? UTF8StdStringToV8String(ip_address) : v8::Null();
+ return success ? ASCIIStringToV8String(ip_address) : v8::Null();
}
// V8 callback for when "dnsResolveEx()" is invoked by the PAC script.
@@ -471,7 +566,7 @@ class ProxyResolverV8::Context {
if (!success)
ip_address_list = std::string();
- return UTF8StdStringToV8String(ip_address_list);
+ return ASCIIStringToV8String(ip_address_list);
}
static void LogEventToCurrentRequest(Context* context,
@@ -540,15 +635,15 @@ void ProxyResolverV8::PurgeMemory() {
}
int ProxyResolverV8::SetPacScript(const GURL& /*url*/,
- const std::string& bytes_utf8,
+ const string16& pac_script,
CompletionCallback* /*callback*/) {
context_.reset();
- if (bytes_utf8.empty())
+ if (pac_script.empty())
return ERR_PAC_SCRIPT_FAILED;
// Try parsing the PAC script.
scoped_ptr<Context> context(new Context(js_bindings_.get()));
- int rv = context->InitV8(bytes_utf8);
+ int rv = context->InitV8(pac_script);
if (rv == OK)
context_.reset(context.release());
return rv;
diff --git a/net/proxy/proxy_resolver_v8.h b/net/proxy/proxy_resolver_v8.h
index 4424a30..bc4d731 100644
--- a/net/proxy/proxy_resolver_v8.h
+++ b/net/proxy/proxy_resolver_v8.h
@@ -5,8 +5,6 @@
#ifndef NET_PROXY_PROXY_RESOLVER_V8_H_
#define NET_PROXY_PROXY_RESOLVER_V8_H_
-#include <string>
-
#include "base/scoped_ptr.h"
#include "net/proxy/proxy_resolver.h"
@@ -63,7 +61,7 @@ class ProxyResolverV8 : public ProxyResolver {
// ProxyResolver implementation:
virtual int SetPacScript(const GURL& /*pac_url*/,
- const std::string& bytes_utf8,
+ const string16& pac_script,
CompletionCallback* /*callback*/);
scoped_ptr<Context> context_;
diff --git a/net/proxy/proxy_resolver_v8_unittest.cc b/net/proxy/proxy_resolver_v8_unittest.cc
index 9f9f50d..2e09e4a 100644
--- a/net/proxy/proxy_resolver_v8_unittest.cc
+++ b/net/proxy/proxy_resolver_v8_unittest.cc
@@ -109,7 +109,7 @@ class ProxyResolverV8WithMockBindings : public ProxyResolverV8 {
}
// Load the PAC script into the ProxyResolver.
- return SetPacScriptByData(file_contents, NULL);
+ return SetPacScriptByData(UTF8ToUTF16(file_contents), NULL);
}
};
@@ -366,7 +366,7 @@ TEST(ProxyResolverV8Test, NoSetPacScript) {
EXPECT_EQ(OK, result);
// Clear it, by initializing with an empty string.
- resolver.SetPacScriptByData(std::string(), NULL);
+ resolver.SetPacScriptByData(string16(), NULL);
// Resolve should fail again now.
result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL,
diff --git a/net/proxy/proxy_resolver_winhttp.cc b/net/proxy/proxy_resolver_winhttp.cc
index e1faf95..9715f02 100644
--- a/net/proxy/proxy_resolver_winhttp.cc
+++ b/net/proxy/proxy_resolver_winhttp.cc
@@ -141,7 +141,7 @@ void ProxyResolverWinHttp::CancelRequest(RequestHandle request) {
}
int ProxyResolverWinHttp::SetPacScript(const GURL& pac_url,
- const std::string& /*pac_bytes*/,
+ const string16& /*pac_script*/,
CompletionCallback* /*callback*/) {
pac_url_ = pac_url.is_valid() ? pac_url : GURL("http://wpad/wpad.dat");
return OK;
diff --git a/net/proxy/proxy_resolver_winhttp.h b/net/proxy/proxy_resolver_winhttp.h
index 6062fbe..4eba3f4 100644
--- a/net/proxy/proxy_resolver_winhttp.h
+++ b/net/proxy/proxy_resolver_winhttp.h
@@ -32,7 +32,7 @@ class ProxyResolverWinHttp : public ProxyResolver {
private:
// ProxyResolver implementation:
virtual int SetPacScript(const GURL& pac_url,
- const std::string& /*pac_bytes*/,
+ const string16& /*pac_script*/,
CompletionCallback* /*callback*/);
bool OpenWinHttpSession();
void CloseWinHttpSession();
diff --git a/net/proxy/proxy_script_fetcher.cc b/net/proxy/proxy_script_fetcher.cc
index 7dc800e..719c380 100644
--- a/net/proxy/proxy_script_fetcher.cc
+++ b/net/proxy/proxy_script_fetcher.cc
@@ -1,6 +1,6 @@
-// Copyright (c) 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.
+// Copyright (c) 2010 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_script_fetcher.h"
@@ -45,9 +45,12 @@ bool IsPacMimeType(const std::string& mime_type) {
return false;
}
-// Convert |bytes| (which is encoded by |charset|) in place to UTF8.
+// Converts |bytes| (which is encoded by |charset|) to UTF16, saving the resul
+// to |*utf16|.
// If |charset| is empty, then we don't know what it was and guess.
-void ConvertResponseToUTF8(const std::string& charset, std::string* bytes) {
+void ConvertResponseToUTF16(const std::string& charset,
+ const std::string& bytes,
+ string16* utf16) {
const char* codepage;
if (charset.empty()) {
@@ -61,12 +64,9 @@ void ConvertResponseToUTF8(const std::string& charset, std::string* bytes) {
// We will be generous in the conversion -- if any characters lie
// outside of |charset| (i.e. invalid), then substitute them with
// U+FFFD rather than failing.
- std::wstring tmp_wide;
- base::CodepageToWide(*bytes, codepage,
- base::OnStringConversionError::SUBSTITUTE,
- &tmp_wide);
- // TODO(eroman): would be nice to have a CodepageToUTF8() function.
- *bytes = WideToUTF8(tmp_wide);
+ base::CodepageToUTF16(bytes, codepage,
+ base::OnStringConversionError::SUBSTITUTE,
+ utf16);
}
} // namespace
@@ -83,7 +83,7 @@ class ProxyScriptFetcherImpl : public ProxyScriptFetcher,
// ProxyScriptFetcher methods:
- virtual int Fetch(const GURL& url, std::string* bytes,
+ virtual int Fetch(const GURL& url, string16* text,
CompletionCallback* callback);
virtual void Cancel();
virtual URLRequestContext* GetRequestContext();
@@ -103,7 +103,7 @@ class ProxyScriptFetcherImpl : public ProxyScriptFetcher,
void ReadBody(URLRequest* request);
// Called once the request has completed to notify the caller of
- // |response_code_| and |response_bytes_|.
+ // |response_code_| and |response_text_|.
void FetchCompleted();
// Clear out the state for the current request.
@@ -140,9 +140,12 @@ class ProxyScriptFetcherImpl : public ProxyScriptFetcher,
// Holds the error condition that was hit on the current request, or OK.
int result_code_;
- // Holds the bytes read so far. Will not exceed |max_response_bytes|. This
- // buffer is owned by the owner of |callback|.
- std::string* result_bytes_;
+ // Holds the bytes read so far. Will not exceed |max_response_bytes|.
+ std::string bytes_read_so_far_;
+
+ // This buffer is owned by the owner of |callback|, and will be filled with
+ // UTF16 response on completion.
+ string16* result_text_;
};
ProxyScriptFetcherImpl::ProxyScriptFetcherImpl(
@@ -155,7 +158,7 @@ ProxyScriptFetcherImpl::ProxyScriptFetcherImpl(
cur_request_id_(0),
callback_(NULL),
result_code_(OK),
- result_bytes_(NULL) {
+ result_text_(NULL) {
DCHECK(url_request_context);
}
@@ -165,13 +168,13 @@ ProxyScriptFetcherImpl::~ProxyScriptFetcherImpl() {
}
int ProxyScriptFetcherImpl::Fetch(const GURL& url,
- std::string* bytes,
+ string16* text,
CompletionCallback* callback) {
// It is invalid to call Fetch() while a request is already in progress.
DCHECK(!cur_request_.get());
DCHECK(callback);
- DCHECK(bytes);
+ DCHECK(text);
cur_request_.reset(new URLRequest(url, this));
cur_request_->set_context(url_request_context_);
@@ -186,8 +189,9 @@ int ProxyScriptFetcherImpl::Fetch(const GURL& url,
// Save the caller's info for notification on completion.
callback_ = callback;
- result_bytes_ = bytes;
- result_bytes_->clear();
+ result_text_ = text;
+
+ bytes_read_so_far_.clear();
// Post a task to timeout this request if it takes too long.
cur_request_id_ = ++next_id_;
@@ -269,13 +273,13 @@ void ProxyScriptFetcherImpl::OnReadCompleted(URLRequest* request,
DCHECK(request == cur_request_.get());
if (num_bytes > 0) {
// Enforce maximum size bound.
- if (num_bytes + result_bytes_->size() >
+ if (num_bytes + bytes_read_so_far_.size() >
static_cast<size_t>(max_response_bytes)) {
result_code_ = ERR_FILE_TOO_BIG;
request->Cancel();
return;
}
- result_bytes_->append(buf_->data(), num_bytes);
+ bytes_read_so_far_.append(buf_->data(), num_bytes);
ReadBody(request);
} else { // Error while reading, or EOF
OnResponseCompleted(request);
@@ -305,13 +309,13 @@ void ProxyScriptFetcherImpl::ReadBody(URLRequest* request) {
void ProxyScriptFetcherImpl::FetchCompleted() {
if (result_code_ == OK) {
- // The caller expects the response to be encoded as UTF8.
+ // The caller expects the response to be encoded as UTF16.
std::string charset;
cur_request_->GetCharset(&charset);
- ConvertResponseToUTF8(charset, result_bytes_);
+ ConvertResponseToUTF16(charset, bytes_read_so_far_, result_text_);
} else {
// On error, the caller expects empty string for bytes.
- result_bytes_->clear();
+ result_text_->clear();
}
int result_code = result_code_;
@@ -327,7 +331,7 @@ void ProxyScriptFetcherImpl::ResetCurRequestState() {
cur_request_id_ = 0;
callback_ = NULL;
result_code_ = OK;
- result_bytes_ = NULL;
+ result_text_ = NULL;
}
void ProxyScriptFetcherImpl::OnTimeout(int id) {
diff --git a/net/proxy/proxy_script_fetcher.h b/net/proxy/proxy_script_fetcher.h
index 09ac84e..8899cbb 100644
--- a/net/proxy/proxy_script_fetcher.h
+++ b/net/proxy/proxy_script_fetcher.h
@@ -1,6 +1,6 @@
-// Copyright (c) 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.
+// Copyright (c) 2010 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.
// ProxyScriptFetcher is an async interface for fetching a proxy auto config
// script. It is specific to fetching a PAC script; enforces timeout, max-size,
@@ -9,8 +9,7 @@
#ifndef NET_PROXY_PROXY_SCRIPT_FETCHER_H_
#define NET_PROXY_PROXY_SCRIPT_FETCHER_H_
-#include <string>
-
+#include "base/string16.h"
#include "net/base/completion_callback.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
@@ -25,8 +24,8 @@ 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, and a
- // string of the response bytes (as UTF8). On failure, the result bytes is
+ // On success |callback| is executed 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:
//
@@ -39,7 +38,7 @@ class ProxyScriptFetcher {
// deleting |this|), then no callback is invoked.
//
// Only one fetch is allowed to be outstanding at a time.
- virtual int Fetch(const GURL& url, std::string* utf8_bytes,
+ virtual int Fetch(const GURL& url, string16* utf16_text,
CompletionCallback* callback) = 0;
// Aborts the in-progress fetch (if any).
diff --git a/net/proxy/proxy_script_fetcher_unittest.cc b/net/proxy/proxy_script_fetcher_unittest.cc
index c3925e3..c843739 100644
--- a/net/proxy/proxy_script_fetcher_unittest.cc
+++ b/net/proxy/proxy_script_fetcher_unittest.cc
@@ -24,7 +24,7 @@ const wchar_t kDocRoot[] = L"net/data/proxy_script_fetcher_unittest";
struct FetchResult {
int code;
- std::string bytes;
+ string16 text;
};
// A non-mock URL request which can access http:// and file:// urls.
@@ -70,22 +70,22 @@ TEST_F(ProxyScriptFetcherTest, FileUrl) {
ProxyScriptFetcher::Create(context));
{ // Fetch a non-existent file.
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
int result = pac_fetcher->Fetch(GetTestFileUrl("does-not-exist"),
- &bytes, &callback);
+ &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult());
- EXPECT_TRUE(bytes.empty());
+ EXPECT_TRUE(text.empty());
}
{ // Fetch a file that exists.
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
int result = pac_fetcher->Fetch(GetTestFileUrl("pac.txt"),
- &bytes, &callback);
+ &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("-pac.txt-\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text);
}
}
@@ -101,30 +101,30 @@ TEST_F(ProxyScriptFetcherTest, HttpMimeType) {
{ // Fetch a PAC with mime type "text/plain"
GURL url = server->TestServerPage("files/pac.txt");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("-pac.txt-\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text);
}
{ // Fetch a PAC with mime type "text/html"
GURL url = server->TestServerPage("files/pac.html");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("-pac.html-\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("-pac.html-\n"), text);
}
{ // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig"
GURL url = server->TestServerPage("files/pac.nsproxy");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("-pac.nsproxy-\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
}
}
@@ -138,21 +138,21 @@ TEST_F(ProxyScriptFetcherTest, HttpStatusCode) {
{ // Fetch a PAC which gives a 500 -- FAIL
GURL url = server->TestServerPage("files/500.pac");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult());
- EXPECT_TRUE(bytes.empty());
+ EXPECT_TRUE(text.empty());
}
{ // Fetch a PAC which gives a 404 -- FAIL
GURL url = server->TestServerPage("files/404.pac");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult());
- EXPECT_TRUE(bytes.empty());
+ EXPECT_TRUE(text.empty());
}
}
@@ -167,12 +167,12 @@ TEST_F(ProxyScriptFetcherTest, ContentDisposition) {
// Fetch PAC scripts via HTTP with a Content-Disposition header -- should
// have no effect.
GURL url = server->TestServerPage("files/downloadable.pac");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("-downloadable.pac-\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text);
}
TEST_F(ProxyScriptFetcherTest, NoCache) {
@@ -186,12 +186,12 @@ TEST_F(ProxyScriptFetcherTest, NoCache) {
// Fetch a PAC script whose HTTP headers make it cacheable for 1 hour.
GURL url = server->TestServerPage("files/cacheable_1hr.pac");
{
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("-cacheable_1hr.pac-\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text);
}
// Now kill the HTTP server.
@@ -202,9 +202,9 @@ TEST_F(ProxyScriptFetcherTest, NoCache) {
// running anymore. (If it were instead being loaded from cache, we would
// get a success.
{
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
}
@@ -231,12 +231,12 @@ TEST_F(ProxyScriptFetcherTest, TooLarge) {
// after 50 bytes have been read, and fail with a too large error.
for (size_t i = 0; i < arraysize(urls); ++i) {
const GURL& url = urls[i];
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(ERR_FILE_TOO_BIG, callback.WaitForResult());
- EXPECT_TRUE(bytes.empty());
+ EXPECT_TRUE(text.empty());
}
// Restore the original size bound.
@@ -244,12 +244,12 @@ TEST_F(ProxyScriptFetcherTest, TooLarge) {
{ // Make sure we can still fetch regular URLs.
GURL url = server->TestServerPage("files/pac.nsproxy");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("-pac.nsproxy-\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
}
}
@@ -268,12 +268,12 @@ TEST_F(ProxyScriptFetcherTest, Hang) {
// Try fetching a URL which takes 1.2 seconds. We should abort the request
// after 500 ms, and fail with a timeout error.
{ GURL url = server->TestServerPage("slow/proxy.pac?1.2");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult());
- EXPECT_TRUE(bytes.empty());
+ EXPECT_TRUE(text.empty());
}
// Restore the original timeout period.
@@ -281,12 +281,12 @@ TEST_F(ProxyScriptFetcherTest, Hang) {
{ // Make sure we can still fetch regular URLs.
GURL url = server->TestServerPage("files/pac.nsproxy");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("-pac.nsproxy-\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
}
}
@@ -304,24 +304,24 @@ TEST_F(ProxyScriptFetcherTest, Encodings) {
// Test a response that is gzip-encoded -- should get inflated.
{
GURL url = server->TestServerPage("files/gzipped_pac");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("This data was gzipped.\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text);
}
// Test a response that was served as UTF-16 (BE). It should
// be converted to UTF8.
{
GURL url = server->TestServerPage("files/utf16be_pac");
- std::string bytes;
+ string16 text;
TestCompletionCallback callback;
- int result = pac_fetcher->Fetch(url, &bytes, &callback);
+ int result = pac_fetcher->Fetch(url, &text, &callback);
EXPECT_EQ(ERR_IO_PENDING, result);
EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_EQ("This was encoded as UTF-16BE.\n", bytes);
+ EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text);
}
}
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index cb7da0c..26cb1b6 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -69,7 +69,7 @@ class ProxyResolverNull : public ProxyResolver {
private:
virtual int SetPacScript(const GURL& /*pac_url*/,
- const std::string& /*pac_bytes*/,
+ const string16& /*pac_script*/,
CompletionCallback* /*callback*/) {
return ERR_NOT_IMPLEMENTED;
}
diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
index 3cf80cd..adad32fb 100644
--- a/net/proxy/proxy_service_unittest.cc
+++ b/net/proxy/proxy_service_unittest.cc
@@ -48,25 +48,25 @@ class MockProxyConfigService: public ProxyConfigService {
class MockProxyScriptFetcher : public ProxyScriptFetcher {
public:
MockProxyScriptFetcher()
- : pending_request_callback_(NULL), pending_request_bytes_(NULL) {
+ : pending_request_callback_(NULL), pending_request_text_(NULL) {
}
// ProxyScriptFetcher implementation.
virtual int Fetch(const GURL& url,
- std::string* bytes,
+ string16* text,
CompletionCallback* callback) {
DCHECK(!has_pending_request());
// Save the caller's information, and have them wait.
pending_request_url_ = url;
pending_request_callback_ = callback;
- pending_request_bytes_ = bytes;
+ pending_request_text_ = text;
return ERR_IO_PENDING;
}
- void NotifyFetchCompletion(int result, const std::string& bytes) {
+ void NotifyFetchCompletion(int result, const std::string& ascii_text) {
DCHECK(has_pending_request());
- *pending_request_bytes_ = bytes;
+ *pending_request_text_ = ASCIIToUTF16(ascii_text);
CompletionCallback* callback = pending_request_callback_;
pending_request_callback_ = NULL;
callback->Run(result);
@@ -85,7 +85,7 @@ class MockProxyScriptFetcher : public ProxyScriptFetcher {
private:
GURL pending_request_url_;
CompletionCallback* pending_request_callback_;
- std::string* pending_request_bytes_;
+ string16* pending_request_text_;
};
TEST(ProxyServiceTest, Direct) {
@@ -957,7 +957,8 @@ TEST(ProxyServiceTest, InitialPACScriptDownload) {
// Now that the PAC script is downloaded, it will have been sent to the proxy
// resolver.
- EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("pac-v1"),
+ resolver->pending_set_pac_script_request()->pac_script());
resolver->pending_set_pac_script_request()->CompleteNow(OK);
ASSERT_EQ(3u, resolver->pending_requests().size());
@@ -1037,7 +1038,8 @@ TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) {
// Now that the PAC script is downloaded, it will have been sent to the proxy
// resolver.
- EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("pac-v1"),
+ resolver->pending_set_pac_script_request()->pac_script());
resolver->pending_set_pac_script_request()->CompleteNow(OK);
ASSERT_EQ(2u, resolver->pending_requests().size());
@@ -1099,7 +1101,8 @@ TEST(ProxyServiceTest, CancelWhilePACFetching) {
// Now that the PAC script is downloaded, it will have been sent to the
// proxy resolver.
- EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("pac-v1"),
+ resolver->pending_set_pac_script_request()->pac_script());
resolver->pending_set_pac_script_request()->CompleteNow(OK);
ASSERT_EQ(1u, resolver->pending_requests().size());
@@ -1176,8 +1179,8 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) {
EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
fetcher->NotifyFetchCompletion(OK, "custom-pac-script");
- EXPECT_EQ("custom-pac-script",
- resolver->pending_set_pac_script_request()->pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("custom-pac-script"),
+ resolver->pending_set_pac_script_request()->pac_script());
resolver->pending_set_pac_script_request()->CompleteNow(OK);
// Now finally, the pending requests should have been sent to the resolver
@@ -1242,8 +1245,8 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) {
fetcher->NotifyFetchCompletion(OK, "invalid-script-contents");
// Simulate a parse error.
- EXPECT_EQ("invalid-script-contents",
- resolver->pending_set_pac_script_request()->pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("invalid-script-contents"),
+ resolver->pending_set_pac_script_request()->pac_script());
resolver->pending_set_pac_script_request()->CompleteNow(
ERR_PAC_SCRIPT_FAILED);
@@ -1252,8 +1255,8 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) {
EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
fetcher->NotifyFetchCompletion(OK, "custom-pac-script");
- EXPECT_EQ("custom-pac-script",
- resolver->pending_set_pac_script_request()->pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("custom-pac-script"),
+ resolver->pending_set_pac_script_request()->pac_script());
resolver->pending_set_pac_script_request()->CompleteNow(OK);
// Now finally, the pending requests should have been sent to the resolver
@@ -1368,8 +1371,8 @@ TEST(ProxyServiceTest, BypassDoesntApplyToPac) {
EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url());
fetcher->NotifyFetchCompletion(OK, "auto-detect");
- EXPECT_EQ("auto-detect",
- resolver->pending_set_pac_script_request()->pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("auto-detect"),
+ resolver->pending_set_pac_script_request()->pac_script());
resolver->pending_set_pac_script_request()->CompleteNow(OK);
ASSERT_EQ(1u, resolver->pending_requests().size());
@@ -1631,7 +1634,8 @@ TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) {
// Now that the PAC script is downloaded, the request will have been sent to
// the proxy resolver.
- EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("pac-v1"),
+ resolver->pending_set_pac_script_request()->pac_script());
resolver->pending_set_pac_script_request()->CompleteNow(OK);
ASSERT_EQ(1u, resolver->pending_requests().size());
@@ -1672,7 +1676,8 @@ TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) {
// Now that the PAC script is downloaded, the second request will have been
// sent to the proxy resolver.
- EXPECT_EQ("pac-v2", resolver->pending_set_pac_script_request()->pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("pac-v2"),
+ resolver->pending_set_pac_script_request()->pac_script());
resolver->pending_set_pac_script_request()->CompleteNow(OK);
ASSERT_EQ(1u, resolver->pending_requests().size());
diff --git a/net/proxy/single_threaded_proxy_resolver.cc b/net/proxy/single_threaded_proxy_resolver.cc
index 1903820..2fdc3ac 100644
--- a/net/proxy/single_threaded_proxy_resolver.cc
+++ b/net/proxy/single_threaded_proxy_resolver.cc
@@ -35,11 +35,11 @@ class SingleThreadedProxyResolver::SetPacScriptTask
public:
SetPacScriptTask(SingleThreadedProxyResolver* coordinator,
const GURL& pac_url,
- const std::string& pac_bytes,
+ const string16& pac_script,
CompletionCallback* callback)
: coordinator_(coordinator),
callback_(callback),
- pac_bytes_(pac_bytes),
+ pac_script_(pac_script),
pac_url_(pac_url),
origin_loop_(MessageLoop::current()) {
DCHECK(callback);
@@ -71,7 +71,7 @@ class SingleThreadedProxyResolver::SetPacScriptTask
// Runs on the worker thread.
void DoRequest(ProxyResolver* resolver) {
int rv = resolver->expects_pac_bytes() ?
- resolver->SetPacScriptByData(pac_bytes_, NULL) :
+ resolver->SetPacScriptByData(pac_script_, NULL) :
resolver->SetPacScriptByUrl(pac_url_, NULL);
DCHECK_NE(rv, ERR_IO_PENDING);
@@ -92,7 +92,7 @@ class SingleThreadedProxyResolver::SetPacScriptTask
// Must only be used on the "origin" thread.
SingleThreadedProxyResolver* coordinator_;
CompletionCallback* callback_;
- std::string pac_bytes_;
+ string16 pac_script_;
GURL pac_url_;
// Usable from within DoQuery on the worker thread.
@@ -300,13 +300,13 @@ void SingleThreadedProxyResolver::PurgeMemory() {
int SingleThreadedProxyResolver::SetPacScript(
const GURL& pac_url,
- const std::string& pac_bytes,
+ const string16& pac_script,
CompletionCallback* callback) {
EnsureThreadStarted();
DCHECK(!outstanding_set_pac_script_task_);
SetPacScriptTask* task = new SetPacScriptTask(
- this, pac_url, pac_bytes, callback);
+ this, pac_url, pac_script, callback);
outstanding_set_pac_script_task_ = task;
task->Start();
return ERR_IO_PENDING;
diff --git a/net/proxy/single_threaded_proxy_resolver.h b/net/proxy/single_threaded_proxy_resolver.h
index 2da6085..1c9582c 100644
--- a/net/proxy/single_threaded_proxy_resolver.h
+++ b/net/proxy/single_threaded_proxy_resolver.h
@@ -58,7 +58,7 @@ class SingleThreadedProxyResolver : public ProxyResolver {
// ProxyResolver implementation:
virtual int SetPacScript(const GURL& pac_url,
- const std::string& pac_bytes,
+ const string16& pac_script,
CompletionCallback* callback);
// Starts the worker thread if it isn't already running.
diff --git a/net/proxy/single_threaded_proxy_resolver_unittest.cc b/net/proxy/single_threaded_proxy_resolver_unittest.cc
index 753fcdd..a84253c 100644
--- a/net/proxy/single_threaded_proxy_resolver_unittest.cc
+++ b/net/proxy/single_threaded_proxy_resolver_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/string_util.h"
#include "base/waitable_event.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_log.h"
@@ -55,10 +56,10 @@ class MockProxyResolver : public ProxyResolver {
}
virtual int SetPacScript(const GURL& pac_url,
- const std::string& bytes,
+ const string16& text,
CompletionCallback* callback) {
CheckIsOnWorkerThread();
- last_pac_bytes_ = bytes;
+ last_pac_script_ = text;
return OK;
}
@@ -69,7 +70,7 @@ class MockProxyResolver : public ProxyResolver {
int purge_count() const { return purge_count_; }
- const std::string& last_pac_bytes() const { return last_pac_bytes_; }
+ const string16& last_pac_script() const { return last_pac_script_; }
void SetResolveLatency(int latency_ms) {
resolve_latency_ms_ = latency_ms;
@@ -87,7 +88,7 @@ class MockProxyResolver : public ProxyResolver {
MessageLoop* wrong_loop_;
int request_count_;
int purge_count_;
- std::string last_pac_bytes_;
+ string16 last_pac_script_;
int resolve_latency_ms_;
};
@@ -151,10 +152,11 @@ TEST(SingleThreadedProxyResolverTest, Basic) {
// Call SetPacScriptByData() -- verify that it reaches the synchronous
// resolver.
TestCompletionCallback set_script_callback;
- rv = resolver.SetPacScriptByData("pac script bytes", &set_script_callback);
+ rv = resolver.SetPacScriptByData(ASCIIToUTF16("pac script bytes"),
+ &set_script_callback);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, set_script_callback.WaitForResult());
- EXPECT_EQ("pac script bytes", mock->last_pac_bytes());
+ EXPECT_EQ(ASCIIToUTF16("pac script bytes"), mock->last_pac_script());
// Start request 0.
TestCompletionCallback callback0;
@@ -216,7 +218,7 @@ TEST(SingleThreadedProxyResolverTest, Basic) {
// we queue up a dummy request after the PurgeMemory() call and wait until it
// finishes to ensure PurgeMemory() has had a chance to run.
TestCompletionCallback dummy_callback;
- rv = resolver.SetPacScriptByData("dummy", &dummy_callback);
+ rv = resolver.SetPacScriptByData(ASCIIToUTF16("dummy"), &dummy_callback);
EXPECT_EQ(OK, dummy_callback.WaitForResult());
EXPECT_EQ(1, mock->purge_count());
}
@@ -437,7 +439,8 @@ TEST(SingleThreadedProxyResolverTest, CancelSetPacScript) {
mock->WaitUntilBlocked();
TestCompletionCallback set_pac_script_callback;
- rv = resolver.SetPacScriptByData("data", &set_pac_script_callback);
+ rv = resolver.SetPacScriptByData(ASCIIToUTF16("data"),
+ &set_pac_script_callback);
EXPECT_EQ(ERR_IO_PENDING, rv);
// Cancel the SetPacScriptByData request (it can't have finished yet,
diff --git a/net/proxy/sync_host_resolver_bridge_unittest.cc b/net/proxy/sync_host_resolver_bridge_unittest.cc
index 42dbacc..62c662a 100644
--- a/net/proxy/sync_host_resolver_bridge_unittest.cc
+++ b/net/proxy/sync_host_resolver_bridge_unittest.cc
@@ -103,7 +103,7 @@ class SyncProxyResolver : public ProxyResolver {
private:
virtual int SetPacScript(const GURL& pac_url,
- const std::string& bytes_utf8,
+ const string16& pac_script,
CompletionCallback* callback) {
NOTREACHED();
return OK;