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

Unified Diff: net/proxy/proxy_resolver_js_bindings.cc

Issue 333006: Add three of the six extensions to PAC that Internet Explorer supports. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address more of wtc's comments Created 11 years, 2 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
Index: net/proxy/proxy_resolver_js_bindings.cc
===================================================================
--- net/proxy/proxy_resolver_js_bindings.cc (revision 29974)
+++ net/proxy/proxy_resolver_js_bindings.cc (working copy)
@@ -2,6 +2,14 @@
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+#include <ws2tcpip.h>
+#else
+#include <netdb.h>
+#endif
+
#include "net/proxy/proxy_resolver_js_bindings.h"
#include "base/compiler_specific.h"
@@ -97,18 +105,20 @@
}
// Handler for "myIpAddress()". Returns empty string on failure.
+ // TODO(eroman): Perhaps enumerate the interfaces directly, using
+ // getifaddrs().
virtual std::string MyIpAddress() {
// DnsResolve("") returns "", so no need to check for failure.
return DnsResolve(GetHostName());
}
+ // Handler for "myIpAddressEx()". Returns empty string on failure.
+ virtual std::string MyIpAddressEx() {
+ return DnsResolveEx(GetHostName());
+ }
+
// Handler for "dnsResolve(host)". Returns empty string on failure.
virtual std::string DnsResolve(const std::string& host) {
- // TODO(eroman): Should this return our IP address, or fail, or
- // simply be unspecified (works differently on windows and mac os x).
- if (host.empty())
- return std::string();
-
// Do a sync resolve of the hostname.
// Disable IPv6 results. We do this because Internet Explorer does it --
wtc 2009/10/24 04:40:59 I studied the original specification of the PAC sc
// consequently a lot of existing PAC scripts assume they will only get
@@ -130,6 +140,31 @@
return net::NetAddressToString(address_list.head());
}
+ // Handler for "dnsResolveEx(host)". Returns empty string on failure.
+ virtual std::string DnsResolveEx(const std::string& host) {
+ // Do a sync resolve of the hostname.
+ net::AddressList address_list;
+ int result = host_resolver_->Resolve(host,
+ ADDRESS_FAMILY_UNSPECIFIED,
+ &address_list);
+
+ if (result != OK)
+ return std::string(); // Failed.
+
+ // Stringify all of the addresses in the address list, separated
+ // by semicolons.
+ std::string address_list_str;
+ const struct addrinfo* current_address = address_list.head();
+ while (current_address) {
+ if (!address_list_str.empty())
+ address_list_str += ";";
+ address_list_str += net::NetAddressToString(current_address);
+ current_address = current_address->ai_next;
+ }
+
+ return address_list_str;
+ }
+
// Handler for when an error is encountered. |line_number| may be -1.
virtual void OnError(int line_number, const std::string& message) {
if (line_number == -1)

Powered by Google App Engine
This is Rietveld 408576698