Fix error messages so reported to listener.
Change the errors to report to listener rather than return them.
Also fixed set function to take a const parameter as it should.
Bug: 10458767
Change-Id: Iaba9bc7ca384961ea420b31b9e03d30d3093a3cd
diff --git a/src/proxy_resolver_v8.cc b/src/proxy_resolver_v8.cc
index ee0510b..cb08ebb 100644
--- a/src/proxy_resolver_v8.cc
+++ b/src/proxy_resolver_v8.cc
@@ -170,13 +170,8 @@
}
std::string UTF16ToASCII(const android::String16& str) {
- android::String8 rstr(str);
- return std::string(rstr.string());
-}
-
-android::String16 ASCIIToUTF16(const std::string str) {
- android::String8 str8(str.c_str());
- return android::String16(str8);
+ android::String8 rstr(str);
+ return std::string(rstr.string());
}
// Converts an ASCII std::string to a V8 string.
@@ -369,7 +364,8 @@
PurgeMemory();
}
- int ResolveProxy(const android::String16 url, const android::String16 host, android::String16* results) {
+ int ResolveProxy(const android::String16 url, const android::String16 host,
+ android::String16* results) {
v8::Locker locked;
v8::HandleScope scope;
@@ -377,7 +373,8 @@
v8::Local<v8::Value> function;
if (!GetFindProxyForURL(&function)) {
- *results = ASCIIToUTF16("FindProxyForURL() is undefined");
+ error_listener_->ErrorMessage(
+ android::String16("FindProxyForURL() is undefined"));
return ERR_PAC_SCRIPT_FAILED;
}
@@ -390,12 +387,14 @@
v8_context_->Global(), 2, argv);
if (try_catch.HasCaught()) {
- *results = V8StringToUTF16(try_catch.Message()->Get());
+ error_listener_->ErrorMessage(
+ V8StringToUTF16(try_catch.Message()->Get()));
return ERR_PAC_SCRIPT_FAILED;
}
if (!ret->IsString()) {
- *results = ASCIIToUTF16("FindProxyForURL() did not return a string.");
+ error_listener_->ErrorMessage(
+ android::String16("FindProxyForURL() did not return a string."));
return ERR_PAC_SCRIPT_FAILED;
}
@@ -406,7 +405,8 @@
// could extend the parsing to handle IDNA hostnames by
// converting them to ASCII punycode.
// crbug.com/47234
- *results = ASCIIToUTF16("FindProxyForURL() returned a non-ASCII string");
+ error_listener_->ErrorMessage(
+ android::String16("FindProxyForURL() returned a non-ASCII string"));
return ERR_PAC_SCRIPT_FAILED;
}
@@ -715,7 +715,7 @@
context_->PurgeMemory();
}
-int ProxyResolverV8::SetPacScript(android::String16& script_data) {
+int ProxyResolverV8::SetPacScript(const android::String16& script_data) {
if (context_ != NULL) {
delete context_;
context_ = NULL;
diff --git a/src/proxy_resolver_v8.h b/src/proxy_resolver_v8.h
index ea36f03..818cb58 100644
--- a/src/proxy_resolver_v8.h
+++ b/src/proxy_resolver_v8.h
@@ -59,7 +59,7 @@
virtual int GetProxyForURL(const android::String16 spec, const android::String16 host,
android::String16* results);
virtual void PurgeMemory();
- virtual int SetPacScript(android::String16& script_data);
+ virtual int SetPacScript(const android::String16& script_data);
private:
// Context holds the Javascript state for the most recently loaded PAC