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

Unified Diff: net/proxy/proxy_resolver_v8.cc

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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_script.h ('k') | net/quic/quic_stream_factory.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
diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc
index 963153d2576cbd9f1d14806d3bcdcb9c24ca53b0..57ee7147d02eb1c08c7051e86101334622cee341 100644
--- a/net/proxy/proxy_resolver_v8.cc
+++ b/net/proxy/proxy_resolver_v8.cc
@@ -334,6 +334,17 @@ bool IsInNetEx(const std::string& ip_address, const std::string& ip_prefix) {
return IPNumberMatchesPrefix(address, prefix, prefix_length_in_bits);
}
+// Consider only single component domains like 'foo' as plain host names.
+bool IsPlainHostName(const std::string& hostname_utf8) {
+ if (hostname_utf8.find('.') != std::string::npos)
+ return false;
+
+ // IPv6 addresses may not contain periods, however are not be considered a
+ // plain host name.
+ IPAddressNumber unused;
+ return !ParseIPLiteralToNumber(hostname_utf8, &unused);
+}
+
} // namespace
// ProxyResolverV8::Context ---------------------------------------------------
@@ -439,6 +450,11 @@ class ProxyResolverV8::Context {
global_template->Set(ASCIILiteralToV8String(isolate_, "dnsResolve"),
dns_resolve_template);
+ v8::Local<v8::FunctionTemplate> is_plain_host_name_template =
+ v8::FunctionTemplate::New(isolate_, &IsPlainHostNameCallback, v8_this);
+ global_template->Set(ASCIILiteralToV8String(isolate_, "isPlainHostName"),
+ is_plain_host_name_template);
+
// Microsoft's PAC extensions:
v8::Local<v8::FunctionTemplate> dns_resolve_ex_template =
@@ -698,6 +714,22 @@ class ProxyResolverV8::Context {
args.GetReturnValue().Set(IsInNetEx(ip_address, ip_prefix));
}
+ // V8 callback for when "isPlainHostName()" is invoked by the PAC script.
+ static void IsPlainHostNameCallback(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ // Need at least 1 string arguments.
+ if (args.Length() < 1 || args[0].IsEmpty() || !args[0]->IsString()) {
+ args.GetIsolate()->ThrowException(
+ v8::Exception::TypeError(ASCIIStringToV8String(
+ args.GetIsolate(), "Requires 1 string parameter")));
+ return;
+ }
+
+ std::string hostname_utf8 =
+ V8StringToUTF8(v8::Local<v8::String>::Cast(args[0]));
+ args.GetReturnValue().Set(IsPlainHostName(hostname_utf8));
+ }
+
mutable base::Lock lock_;
ProxyResolverV8* parent_;
v8::Isolate* isolate_;
« no previous file with comments | « net/proxy/proxy_resolver_script.h ('k') | net/quic/quic_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698