Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Unified Diff: net/proxy/proxy_resolver_v8.cc

Issue 160510: Better match IE's proxy settings.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix merge conflict Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/proxy/proxy_resolver_v8.h ('k') | net/proxy/proxy_resolver_v8_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_resolver_v8.cc
===================================================================
--- net/proxy/proxy_resolver_v8.cc (revision 22399)
+++ net/proxy/proxy_resolver_v8.cc (working copy)
@@ -53,10 +53,9 @@
class ProxyResolverV8::Context {
public:
- Context(ProxyResolverJSBindings* js_bindings, const std::string& pac_data)
+ explicit Context(ProxyResolverJSBindings* js_bindings)
: js_bindings_(js_bindings) {
DCHECK(js_bindings != NULL);
- InitV8(pac_data);
}
~Context() {
@@ -72,9 +71,8 @@
v8::Context::Scope function_scope(v8_context_);
- v8::Local<v8::Value> function =
- v8_context_->Global()->Get(v8::String::New("FindProxyForURL"));
- if (!function->IsFunction()) {
+ v8::Local<v8::Value> function;
+ if (!GetFindProxyForURL(&function)) {
js_bindings_->OnError(-1, "FindProxyForURL() is undefined.");
return ERR_PAC_SCRIPT_FAILED;
}
@@ -105,8 +103,7 @@
return OK;
}
- private:
- void InitV8(const std::string& pac_data) {
+ int InitV8(const std::string& pac_data) {
v8::Locker locked;
v8::HandleScope scope;
@@ -145,10 +142,26 @@
if (!code.IsEmpty())
code->Run();
- if (try_catch.HasCaught())
+ if (try_catch.HasCaught()) {
HandleError(try_catch.Message());
+ return ERR_PAC_SCRIPT_FAILED;
+ }
+
+ // At a minimum, the FindProxyForURL() function must be defined for this
+ // to be a legitimiate PAC script.
+ v8::Local<v8::Value> function;
+ if (!GetFindProxyForURL(&function))
+ return ERR_PAC_SCRIPT_FAILED;
+
+ return OK;
}
+ private:
+ bool GetFindProxyForURL(v8::Local<v8::Value>* function) {
+ *function = v8_context_->Global()->Get(v8::String::New("FindProxyForURL"));
+ return (*function)->IsFunction();
+ }
+
// Handle an exception thrown by V8.
void HandleError(v8::Handle<v8::Message> message) {
if (message.IsEmpty())
@@ -233,8 +246,7 @@
CompletionCallback* /*callback*/,
RequestHandle* /*request*/) {
// If the V8 instance has not been initialized (either because
- // SetPacScriptByData() wasn't called yet, or because it was called with
- // empty string).
+ // SetPacScript() wasn't called yet, or because it failed.
if (!context_.get())
return ERR_FAILED;
@@ -247,10 +259,19 @@
NOTREACHED();
}
-void ProxyResolverV8::SetPacScriptByDataInternal(const std::string& data) {
+int ProxyResolverV8::SetPacScript(const GURL& /*url*/,
+ const std::string& bytes,
+ CompletionCallback* /*callback*/) {
context_.reset();
- if (!data.empty())
- context_.reset(new Context(js_bindings_.get(), data));
+ if (bytes.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);
+ if (rv == OK)
+ context_.reset(context.release());
+ return rv;
}
} // namespace net
« no previous file with comments | « net/proxy/proxy_resolver_v8.h ('k') | net/proxy/proxy_resolver_v8_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698