| Index: net/proxy/proxy_resolver_v8.cc
|
| diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc
|
| index 80ae06b7e55540b16ad7e8b0204012ef22610e7f..a0c9717baca4cbe6aa69752ab1161d0b6296f809 100644
|
| --- a/net/proxy/proxy_resolver_v8.cc
|
| +++ b/net/proxy/proxy_resolver_v8.cc
|
| @@ -21,7 +21,7 @@
|
| #include "gin/array_buffer.h"
|
| #include "gin/public/isolate_holder.h"
|
| #include "gin/v8_initializer.h"
|
| -#include "net/base/ip_address_number.h"
|
| +#include "net/base/ip_address.h"
|
| #include "net/base/net_errors.h"
|
| #include "net/proxy/proxy_info.h"
|
| #include "net/proxy/proxy_resolver_script.h"
|
| @@ -244,26 +244,29 @@ bool GetHostnameArgument(const v8::FunctionCallbackInfo<v8::Value>& args,
|
| return success;
|
| }
|
|
|
| -// Wrapper for passing around IP address strings and IPAddressNumber objects.
|
| -struct IPAddress {
|
| - IPAddress(const std::string& ip_string, const IPAddressNumber& ip_number)
|
| - : string_value(ip_string),
|
| - ip_address_number(ip_number) {
|
| - }
|
| +// Wrapper around an IP address that stores the original string as well as a
|
| +// corresponding parsed IPAddress.
|
| +
|
| +// This struct is used as a helper for sorting IP address strings - the IP
|
| +// literal is parsed just once and used as the sorting key, while also
|
| +// preserving the original IP literal string.
|
| +struct IPAddressSortingEntry {
|
| + IPAddressSortingEntry(const std::string& ip_string,
|
| + const IPAddress& ip_address)
|
| + : string_value(ip_string), ip_address(ip_address) {}
|
|
|
| // Used for sorting IP addresses in ascending order in SortIpAddressList().
|
| - // IP6 addresses are placed ahead of IPv4 addresses.
|
| - bool operator<(const IPAddress& rhs) const {
|
| - const IPAddressNumber& ip1 = this->ip_address_number;
|
| - const IPAddressNumber& ip2 = rhs.ip_address_number;
|
| + // IPv6 addresses are placed ahead of IPv4 addresses.
|
| + bool operator<(const IPAddressSortingEntry& rhs) const {
|
| + const IPAddress& ip1 = this->ip_address;
|
| + const IPAddress& ip2 = rhs.ip_address;
|
| if (ip1.size() != ip2.size())
|
| return ip1.size() > ip2.size(); // IPv6 before IPv4.
|
| - DCHECK(ip1.size() == ip2.size());
|
| - return memcmp(&ip1[0], &ip2[0], ip1.size()) < 0; // Ascending order.
|
| + return ip1 < ip2; // Ascending order.
|
| }
|
|
|
| std::string string_value;
|
| - IPAddressNumber ip_address_number;
|
| + IPAddress ip_address;
|
| };
|
|
|
| // Handler for "sortIpAddressList(IpAddressList)". |ip_address_list| is a
|
| @@ -284,13 +287,13 @@ bool SortIpAddressList(const std::string& ip_address_list,
|
| return false;
|
|
|
| // Split-up IP addresses and store them in a vector.
|
| - std::vector<IPAddress> ip_vector;
|
| - IPAddressNumber ip_num;
|
| + std::vector<IPAddressSortingEntry> ip_vector;
|
| + IPAddress ip_address;
|
| base::StringTokenizer str_tok(cleaned_ip_address_list, ";");
|
| while (str_tok.GetNext()) {
|
| - if (!ParseIPLiteralToNumber(str_tok.token(), &ip_num))
|
| + if (!ip_address.AssignFromIPLiteral(str_tok.token()))
|
| return false;
|
| - ip_vector.push_back(IPAddress(str_tok.token(), ip_num));
|
| + ip_vector.push_back(IPAddressSortingEntry(str_tok.token(), ip_address));
|
| }
|
|
|
| if (ip_vector.empty()) // Can happen if we have something like
|
| @@ -320,11 +323,11 @@ bool SortIpAddressList(const std::string& ip_address_list,
|
| // format, or if an address and prefix of different types are used (e.g. IPv6
|
| // address and IPv4 prefix).
|
| bool IsInNetEx(const std::string& ip_address, const std::string& ip_prefix) {
|
| - IPAddressNumber address;
|
| - if (!ParseIPLiteralToNumber(ip_address, &address))
|
| + IPAddress address;
|
| + if (!address.AssignFromIPLiteral(ip_address))
|
| return false;
|
|
|
| - IPAddressNumber prefix;
|
| + IPAddress prefix;
|
| size_t prefix_length_in_bits;
|
| if (!ParseCIDRBlock(ip_prefix, &prefix, &prefix_length_in_bits))
|
| return false;
|
| @@ -333,10 +336,10 @@ bool IsInNetEx(const std::string& ip_address, const std::string& ip_prefix) {
|
| if (address.size() != prefix.size())
|
| return false;
|
|
|
| - DCHECK((address.size() == 4 && prefix.size() == 4) ||
|
| - (address.size() == 16 && prefix.size() == 16));
|
| + DCHECK((address.IsIPv4() && prefix.IsIPv4()) ||
|
| + (address.IsIPv6() && prefix.IsIPv6()));
|
|
|
| - return IPNumberMatchesPrefix(address, prefix, prefix_length_in_bits);
|
| + return IPAddressMatchesPrefix(address, prefix, prefix_length_in_bits);
|
| }
|
|
|
| // Consider only single component domains like 'foo' as plain host names.
|
| @@ -346,8 +349,8 @@ bool IsPlainHostName(const std::string& hostname_utf8) {
|
|
|
| // IPv6 literals might not contain any periods, however are not considered
|
| // plain host names.
|
| - IPAddressNumber unused;
|
| - return !ParseIPLiteralToNumber(hostname_utf8, &unused);
|
| + IPAddress unused;
|
| + return !unused.AssignFromIPLiteral(hostname_utf8);
|
| }
|
|
|
| // All instances of ProxyResolverV8 share the same v8::Isolate. This isolate is
|
|
|