Internal change PiperOrigin-RevId: 158864096 Change-Id: I6da047fc01ca7eaa37b5bb7882214dacc1e82c2e
diff --git a/src/base/optional.h b/src/base/optional.h index cf65ad7..485baf7 100644 --- a/src/base/optional.h +++ b/src/base/optional.h
@@ -10,6 +10,7 @@ #include "base/logging.h" #include "base/template_util.h" +namespace url { namespace base { // Specification: @@ -32,7 +33,7 @@ namespace internal { -template <typename T, bool = base::is_trivially_destructible<T>::value> +template <typename T, bool = std::is_trivially_destructible<T>::value> struct OptionalStorage { // Initializing |empty_| here instead of using default member initializing // to avoid errors in g++ 4.8. @@ -491,13 +492,14 @@ } } // namespace base +} // namespace url namespace std { template <class T> -struct hash<base::Optional<T>> { - size_t operator()(const base::Optional<T>& opt) const { - return opt == base::nullopt ? 0 : std::hash<T>()(*opt); +struct hash<url::base::Optional<T>> { + size_t operator()(const url::base::Optional<T>& opt) const { + return opt == url::base::nullopt ? 0 : std::hash<T>()(*opt); } };
diff --git a/src/base/strings/utf_string_conversions.cc b/src/base/strings/utf_string_conversions.cc index ffbfa53..d8a85ad 100644 --- a/src/base/strings/utf_string_conversions.cc +++ b/src/base/strings/utf_string_conversions.cc
@@ -44,6 +44,32 @@ } // namespace +// UTF-16 <-> Wide ------------------------------------------------------------- + +#if defined(WCHAR_T_IS_UTF16) + +string16 WideToUTF16(const std::wstring& wide) { + return wide; +} + +#elif defined(WCHAR_T_IS_UTF32) + +bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output) { + output->clear(); + // Assume that normally we won't have any non-BMP characters so the counts + // will be the same. + output->reserve(src_len); + return ConvertUnicode(src, src_len, output); +} + +string16 WideToUTF16(const std::wstring& wide) { + string16 ret; + WideToUTF16(wide.data(), wide.length(), &ret); + return ret; +} + +#endif // defined(WCHAR_T_IS_UTF32) + // UTF16 <-> UTF8 -------------------------------------------------------------- #if defined(WCHAR_T_IS_UTF32)
diff --git a/src/base/strings/utf_string_conversions.h b/src/base/strings/utf_string_conversions.h index d6876b3..7458519 100644 --- a/src/base/strings/utf_string_conversions.h +++ b/src/base/strings/utf_string_conversions.h
@@ -17,6 +17,7 @@ namespace url { namespace base { +BASE_EXPORT string16 WideToUTF16(const std::wstring& wide); BASE_EXPORT string16 UTF8ToUTF16(StringPiece utf8); BASE_EXPORT std::string UTF16ToUTF8(StringPiece16 utf16);
diff --git a/src/net/base/lookup_string_in_fixed_set.cc b/src/net/base/lookup_string_in_fixed_set.cc index 5c145f8..cdd1787 100644 --- a/src/net/base/lookup_string_in_fixed_set.cc +++ b/src/net/base/lookup_string_in_fixed_set.cc
@@ -6,6 +6,7 @@ #include "base/logging.h" +namespace url { namespace net { namespace { @@ -196,3 +197,4 @@ } } // namespace net +} // namespace url
diff --git a/src/net/base/lookup_string_in_fixed_set.h b/src/net/base/lookup_string_in_fixed_set.h index 3da3856..cedf8d7 100644 --- a/src/net/base/lookup_string_in_fixed_set.h +++ b/src/net/base/lookup_string_in_fixed_set.h
@@ -7,8 +7,9 @@ #include <stddef.h> -#include "net/base/net_export.h" +#define NET_EXPORT +namespace url { namespace net { enum { @@ -143,5 +144,6 @@ }; } // namespace net +} // namespace url #endif // NET_BASE_LOOKUP_STRING_IN_FIXED_SET_H_
diff --git a/src/net/base/lookup_string_in_fixed_set_unittest.cc b/src/net/base/lookup_string_in_fixed_set_unittest.cc index 612f640..3827d18 100644 --- a/src/net/base/lookup_string_in_fixed_set_unittest.cc +++ b/src/net/base/lookup_string_in_fixed_set_unittest.cc
@@ -12,30 +12,25 @@ #include <utility> #include <vector> -#include "base/base_paths.h" -#include "base/files/file_path.h" -#include "base/files/file_util.h" -#include "base/path_service.h" -#include "base/strings/string_util.h" -#include "base/strings/stringprintf.h" -#include "testing/gtest/include/gtest/gtest.h" +#include "testing/base/public/gunit.h" +namespace url { namespace net { namespace { namespace test1 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest1-inc.cc" +#include "effective_tld_names_unittest1.inc" } namespace test3 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest3-inc.cc" +#include "effective_tld_names_unittest3.inc" } namespace test4 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest4-inc.cc" +#include "effective_tld_names_unittest4.inc" } namespace test5 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest5-inc.cc" +#include "effective_tld_names_unittest5.inc" } namespace test6 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest6-inc.cc" +#include "effective_tld_names_unittest6.inc" } struct Expectation { @@ -74,7 +69,9 @@ int result = lookup.GetResultForCurrentSequence(); if (result != kDafsaNotFound) { std::string line(sequence->begin(), sequence->end()); - line += base::StringPrintf(", %d", result); + char buf[2 + sizeof(result) * 4 + 1]; + snprintf(buf, sizeof(buf), ", %d", result); + line += buf; language->emplace_back(std::move(line)); } // Try appending each char value. @@ -249,3 +246,4 @@ } // namespace } // namespace net +} // namespace url
diff --git a/src/net/base/registry_controlled_domains/registry_controlled_domain.cc b/src/net/base/registry_controlled_domains/registry_controlled_domain.cc index 3777582..3a2af19 100644 --- a/src/net/base/registry_controlled_domains/registry_controlled_domain.cc +++ b/src/net/base/registry_controlled_domains/registry_controlled_domain.cc
@@ -49,18 +49,18 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "net/base/lookup_string_in_fixed_set.h" -#include "net/base/net_module.h" #include "net/base/url_util.h" #include "url/gurl.h" #include "url/origin.h" #include "url/third_party/mozilla/url_parse.h" #include "url/url_util.h" +namespace url { namespace net { namespace registry_controlled_domains { namespace { -#include "net/base/registry_controlled_domains/effective_tld_names-inc.cc" +#include "effective_tld_names.inc" // See make_dafsa.py for documentation of the generated dafsa byte array. @@ -131,7 +131,7 @@ // "!foo"). This would only be valid if we had a corresponding // wildcard rule, which would have to be "*". But we explicitly // disallow that case, so this kind of rule is invalid. - NOTREACHED() << "Invalid exception rule"; + DCHECK(false) << "Invalid exception rule"; // NOTREACHED(); return 0; } return host.length() - next_dot - 1; @@ -172,7 +172,8 @@ // subcomponent length. DCHECK(host.length() >= 2); if (registry_length > (host.length() - 2)) { - NOTREACHED() << + // NOTREACHED() + DCHECK(false) << "Host does not have at least one subcomponent before registry!"; return base::StringPiece(); } @@ -305,7 +306,7 @@ } } - NOTREACHED(); + DCHECK(false); // NOTREACHED(); return canonical_rcd_len; } @@ -402,7 +403,7 @@ GetRegistryLengthImpl(canon_host, unknown_filter, private_filter); break; default: - NOTREACHED(); + DCHECK(false); // NOTREACHED(); return false; } return (rcd_length != 0) && (rcd_length != std::string::npos); @@ -448,3 +449,4 @@ } // namespace registry_controlled_domains } // namespace net +} // namespace url
diff --git a/src/net/base/registry_controlled_domains/registry_controlled_domain.h b/src/net/base/registry_controlled_domains/registry_controlled_domain.h index 9f3101a..76da91e 100644 --- a/src/net/base/registry_controlled_domains/registry_controlled_domain.h +++ b/src/net/base/registry_controlled_domains/registry_controlled_domain.h
@@ -117,16 +117,16 @@ #include <string> -#include "base/optional.h" -#include "base/strings/string_piece.h" -#include "net/base/net_export.h" +#include "third_party/googleurl/src/base/optional.h" +#include "third_party/googleurl/src/base/strings/string_piece.h" +#define NET_EXPORT +#define NET_EXPORT_PRIVATE class GURL; namespace url { -class Origin; -}; +class Origin; struct DomainRule; namespace net { @@ -299,5 +299,6 @@ } // namespace registry_controlled_domains } // namespace net +} // namespace url #endif // NET_BASE_REGISTRY_CONTROLLED_DOMAINS_REGISTRY_CONTROLLED_DOMAIN_H_
diff --git a/src/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc b/src/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc index fd19789..e690fb5 100644 --- a/src/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc +++ b/src/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc
@@ -4,34 +4,34 @@ #include "base/strings/utf_string_conversions.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" -#include "testing/gtest/include/gtest/gtest.h" +#include "testing/base/public/gunit.h" #include "url/gurl.h" #include "url/origin.h" -#include "url/url_features.h" namespace { namespace test1 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest1-inc.cc" +#include "effective_tld_names_unittest1.inc" } namespace test2 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest2-inc.cc" +#include "effective_tld_names_unittest2.inc" } namespace test3 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest3-inc.cc" +#include "effective_tld_names_unittest3.inc" } namespace test4 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest4-inc.cc" +#include "effective_tld_names_unittest4.inc" } namespace test5 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest5-inc.cc" +#include "effective_tld_names_unittest5.inc" } namespace test6 { -#include "net/base/registry_controlled_domains/effective_tld_names_unittest6-inc.cc" +#include "effective_tld_names_unittest6.inc" } } // namespace +namespace url { namespace net { namespace registry_controlled_domains { @@ -67,7 +67,9 @@ } // Only called when using ICU (avoids unused static function error). -#if !BUILDFLAG(USE_PLATFORM_ICU_ALTERNATIVES) +// if !BUILDFLAG(USE_PLATFORM_ICU_ALTERNATIVES) +// google3 has ICU. +#if 1 size_t PermissiveGetHostRegistryLength(base::StringPiece16 host) { return PermissiveGetHostRegistryLength(host, EXCLUDE_UNKNOWN_REGISTRIES, EXCLUDE_PRIVATE_REGISTRIES); @@ -596,7 +598,9 @@ EXPECT_EQ(4U, PermissiveGetHostRegistryLength("Www.Googl%45%2e%4Ap")); // IDN cases (not supported when not linking ICU). -#if !BUILDFLAG(USE_PLATFORM_ICU_ALTERNATIVES) +// if !BUILDFLAG(USE_PLATFORM_ICU_ALTERNATIVES) +// google3 has ICU. +#if 1 EXPECT_EQ(10U, PermissiveGetHostRegistryLength("foo.xn--fiqs8s")); EXPECT_EQ(11U, PermissiveGetHostRegistryLength("foo.xn--fiqs8s.")); EXPECT_EQ(18U, PermissiveGetHostRegistryLength("foo.%E4%B8%AD%E5%9B%BD")); @@ -607,7 +611,7 @@ PermissiveGetHostRegistryLength("foo.\xE4\xB8\xAD\xE5\x9B\xBD.")); // UTF-16 IDN. EXPECT_EQ(2U, PermissiveGetHostRegistryLength( - base::WideToUTF16(L"foo.\x4e2d\x56fd"))); + base::WideToUTF16(L"foo.\x4e2d\x56fd"))); // Fullwidth dot (u+FF0E) that will get canonicalized to a dot. EXPECT_EQ(2U, PermissiveGetHostRegistryLength("Www.Google\xEF\xBC\x8Ejp")); @@ -620,9 +624,10 @@ "Www.Google%EF%BC%8E%EF%BC%AA%EF%BD%90%EF%BC%8E")); // UTF-16 (ending in a dot). EXPECT_EQ(3U, PermissiveGetHostRegistryLength( - base::WideToUTF16(L"Www.Google\xFF0E\xFF2A\xFF50\xFF0E"))); + base::WideToUTF16(L"Www.Google\xFF0E\xFF2A\xFF50\xFF0E"))); #endif } } // namespace registry_controlled_domains } // namespace net +} // namespace url
diff --git a/src/net/base/url_util.cc b/src/net/base/url_util.cc index 062481f..b47074d 100644 --- a/src/net/base/url_util.cc +++ b/src/net/base/url_util.cc
@@ -12,249 +12,12 @@ #include <ws2tcpip.h> #endif -#include "base/logging.h" -#include "base/strings/string_util.h" -#include "base/strings/stringprintf.h" -#include "net/base/escape.h" -#include "net/base/ip_address.h" -#include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "url/gurl.h" #include "url/url_canon.h" -#include "url/url_canon_ip.h" +namespace url { namespace net { -namespace { - -bool IsHostCharAlphanumeric(char c) { - // We can just check lowercase because uppercase characters have already been - // normalized. - return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')); -} - -bool IsNormalizedLocalhostTLD(const std::string& host) { - return base::EndsWith(host, ".localhost", base::CompareCase::SENSITIVE); -} - -} // namespace - -GURL AppendQueryParameter(const GURL& url, - const std::string& name, - const std::string& value) { - std::string query(url.query()); - - if (!query.empty()) - query += "&"; - - query += (EscapeQueryParamValue(name, true) + "=" + - EscapeQueryParamValue(value, true)); - GURL::Replacements replacements; - replacements.SetQueryStr(query); - return url.ReplaceComponents(replacements); -} - -GURL AppendOrReplaceQueryParameter(const GURL& url, - const std::string& name, - const std::string& value) { - bool replaced = false; - std::string param_name = EscapeQueryParamValue(name, true); - std::string param_value = EscapeQueryParamValue(value, true); - - const std::string input = url.query(); - url::Component cursor(0, input.size()); - std::string output; - url::Component key_range, value_range; - while (url::ExtractQueryKeyValue(input.data(), &cursor, &key_range, - &value_range)) { - const base::StringPiece key( - input.data() + key_range.begin, key_range.len); - std::string key_value_pair; - // Check |replaced| as only the first pair should be replaced. - if (!replaced && key == param_name) { - replaced = true; - key_value_pair = (param_name + "=" + param_value); - } else { - key_value_pair.assign(input, key_range.begin, - value_range.end() - key_range.begin); - } - if (!output.empty()) - output += "&"; - - output += key_value_pair; - } - if (!replaced) { - if (!output.empty()) - output += "&"; - - output += (param_name + "=" + param_value); - } - GURL::Replacements replacements; - replacements.SetQueryStr(output); - return url.ReplaceComponents(replacements); -} - -QueryIterator::QueryIterator(const GURL& url) - : url_(url), - at_end_(!url.is_valid()) { - if (!at_end_) { - query_ = url.parsed_for_possibly_invalid_spec().query; - Advance(); - } -} - -QueryIterator::~QueryIterator() { -} - -std::string QueryIterator::GetKey() const { - DCHECK(!at_end_); - if (key_.is_nonempty()) - return url_.spec().substr(key_.begin, key_.len); - return std::string(); -} - -std::string QueryIterator::GetValue() const { - DCHECK(!at_end_); - if (value_.is_nonempty()) - return url_.spec().substr(value_.begin, value_.len); - return std::string(); -} - -const std::string& QueryIterator::GetUnescapedValue() { - DCHECK(!at_end_); - if (value_.is_nonempty() && unescaped_value_.empty()) { - unescaped_value_ = UnescapeURLComponent( - GetValue(), UnescapeRule::SPACES | UnescapeRule::PATH_SEPARATORS | - UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | - UnescapeRule::REPLACE_PLUS_WITH_SPACE); - } - return unescaped_value_; -} - -bool QueryIterator::IsAtEnd() const { - return at_end_; -} - -void QueryIterator::Advance() { - DCHECK (!at_end_); - key_.reset(); - value_.reset(); - unescaped_value_.clear(); - at_end_ = - !url::ExtractQueryKeyValue(url_.spec().c_str(), &query_, &key_, &value_); -} - -bool GetValueForKeyInQuery(const GURL& url, - const std::string& search_key, - std::string* out_value) { - for (QueryIterator it(url); !it.IsAtEnd(); it.Advance()) { - if (it.GetKey() == search_key) { - *out_value = it.GetUnescapedValue(); - return true; - } - } - return false; -} - -bool ParseHostAndPort(std::string::const_iterator host_and_port_begin, - std::string::const_iterator host_and_port_end, - std::string* host, - int* port) { - if (host_and_port_begin >= host_and_port_end) - return false; - - // When using url, we use char*. - const char* auth_begin = &(*host_and_port_begin); - int auth_len = host_and_port_end - host_and_port_begin; - - url::Component auth_component(0, auth_len); - url::Component username_component; - url::Component password_component; - url::Component hostname_component; - url::Component port_component; - - url::ParseAuthority(auth_begin, auth_component, &username_component, - &password_component, &hostname_component, &port_component); - - // There shouldn't be a username/password. - if (username_component.is_valid() || password_component.is_valid()) - return false; - - if (!hostname_component.is_nonempty()) - return false; // Failed parsing. - - int parsed_port_number = -1; - if (port_component.is_nonempty()) { - parsed_port_number = url::ParsePort(auth_begin, port_component); - - // If parsing failed, port_number will be either PORT_INVALID or - // PORT_UNSPECIFIED, both of which are negative. - if (parsed_port_number < 0) - return false; // Failed parsing the port number. - } - - if (port_component.len == 0) - return false; // Reject inputs like "foo:" - - unsigned char tmp_ipv6_addr[16]; - - // If the hostname starts with a bracket, it is either an IPv6 literal or - // invalid. If it is an IPv6 literal then strip the brackets. - if (hostname_component.len > 0 && - auth_begin[hostname_component.begin] == '[') { - if (auth_begin[hostname_component.end() - 1] == ']' && - url::IPv6AddressToNumber( - auth_begin, hostname_component, tmp_ipv6_addr)) { - // Strip the brackets. - hostname_component.begin++; - hostname_component.len -= 2; - } else { - return false; - } - } - - // Pass results back to caller. - host->assign(auth_begin + hostname_component.begin, hostname_component.len); - *port = parsed_port_number; - - return true; // Success. -} - -bool ParseHostAndPort(const std::string& host_and_port, - std::string* host, - int* port) { - return ParseHostAndPort( - host_and_port.begin(), host_and_port.end(), host, port); -} - - -std::string GetHostAndPort(const GURL& url) { - // For IPv6 literals, GURL::host() already includes the brackets so it is - // safe to just append a colon. - return base::StringPrintf("%s:%d", url.host().c_str(), - url.EffectiveIntPort()); -} - -std::string GetHostAndOptionalPort(const GURL& url) { - // For IPv6 literals, GURL::host() already includes the brackets - // so it is safe to just append a colon. - if (url.has_port()) - return base::StringPrintf("%s:%s", url.host().c_str(), url.port().c_str()); - return url.host(); -} - -std::string TrimEndingDot(base::StringPiece host) { - base::StringPiece host_trimmed = host; - size_t len = host_trimmed.length(); - if (len > 1 && host_trimmed[len - 1] == '.') { - host_trimmed.remove_suffix(1); - } - return host_trimmed.as_string(); -} - -std::string GetHostOrSpecFromURL(const GURL& url) { - return url.has_host() ? TrimEndingDot(url.host_piece()) : url.spec(); -} - std::string CanonicalizeHost(base::StringPiece host, url::CanonHostInfo* host_info) { // Try to canonicalize the host. @@ -277,166 +40,5 @@ return canon_host; } -bool IsCanonicalizedHostCompliant(const std::string& host) { - if (host.empty()) - return false; - - bool in_component = false; - bool most_recent_component_started_alphanumeric = false; - - for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) { - const char c = *i; - if (!in_component) { - most_recent_component_started_alphanumeric = IsHostCharAlphanumeric(c); - if (!most_recent_component_started_alphanumeric && (c != '-') && - (c != '_')) { - return false; - } - in_component = true; - } else if (c == '.') { - in_component = false; - } else if (!IsHostCharAlphanumeric(c) && (c != '-') && (c != '_')) { - return false; - } - } - - return most_recent_component_started_alphanumeric; -} - -bool IsHostnameNonUnique(const std::string& hostname) { - // CanonicalizeHost requires surrounding brackets to parse an IPv6 address. - const std::string host_or_ip = hostname.find(':') != std::string::npos ? - "[" + hostname + "]" : hostname; - url::CanonHostInfo host_info; - std::string canonical_name = CanonicalizeHost(host_or_ip, &host_info); - - // If canonicalization fails, then the input is truly malformed. However, - // to avoid mis-reporting bad inputs as "non-unique", treat them as unique. - if (canonical_name.empty()) - return false; - - // If |hostname| is an IP address, check to see if it's in an IANA-reserved - // range. - if (host_info.IsIPAddress()) { - IPAddress host_addr; - if (!host_addr.AssignFromIPLiteral(hostname.substr( - host_info.out_host.begin, host_info.out_host.len))) { - return false; - } - switch (host_info.family) { - case url::CanonHostInfo::IPV4: - case url::CanonHostInfo::IPV6: - return host_addr.IsReserved(); - case url::CanonHostInfo::NEUTRAL: - case url::CanonHostInfo::BROKEN: - return false; - } - } - - // Check for a registry controlled portion of |hostname|, ignoring private - // registries, as they already chain to ICANN-administered registries, - // and explicitly ignoring unknown registries. - // - // Note: This means that as new gTLDs are introduced on the Internet, they - // will be treated as non-unique until the registry controlled domain list - // is updated. However, because gTLDs are expected to provide significant - // advance notice to deprecate older versions of this code, this an - // acceptable tradeoff. - return !registry_controlled_domains::HostHasRegistryControlledDomain( - canonical_name, registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, - registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); -} - -bool IsLocalhost(base::StringPiece host) { - if (IsLocalHostname(host, nullptr)) - return true; - - IPAddress ip_address; - if (ip_address.AssignFromIPLiteral(host)) { - size_t size = ip_address.size(); - switch (size) { - case IPAddress::kIPv4AddressSize: { - const uint8_t prefix[] = {127}; - return IPAddressStartsWith(ip_address, prefix); - } - - case IPAddress::kIPv6AddressSize: - return ip_address == IPAddress::IPv6Localhost(); - - default: - NOTREACHED(); - } - } - - return false; -} - -GURL SimplifyUrlForRequest(const GURL& url) { - DCHECK(url.is_valid()); - // Fast path to avoid re-canonicalization via ReplaceComponents. - if (!url.has_username() && !url.has_password() && !url.has_ref()) - return url; - GURL::Replacements replacements; - replacements.ClearUsername(); - replacements.ClearPassword(); - replacements.ClearRef(); - return url.ReplaceComponents(replacements); -} - -void GetIdentityFromURL(const GURL& url, - base::string16* username, - base::string16* password) { - UnescapeRule::Type flags = - UnescapeRule::SPACES | UnescapeRule::PATH_SEPARATORS | - UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS; - *username = UnescapeAndDecodeUTF8URLComponent(url.username(), flags); - *password = UnescapeAndDecodeUTF8URLComponent(url.password(), flags); -} - -bool HasGoogleHost(const GURL& url) { - static const char* kGoogleHostSuffixes[] = { - ".google.com", - ".youtube.com", - ".gmail.com", - ".doubleclick.net", - ".gstatic.com", - ".googlevideo.com", - ".googleusercontent.com", - ".googlesyndication.com", - ".google-analytics.com", - ".googleadservices.com", - ".googleapis.com", - ".ytimg.com", - }; - base::StringPiece host = url.host_piece(); - for (const char* suffix : kGoogleHostSuffixes) { - // Here it's possible to get away with faster case-sensitive comparisons - // because the list above is all lowercase, and a GURL's host name will - // always be canonicalized to lowercase as well. - if (base::EndsWith(host, suffix, base::CompareCase::SENSITIVE)) - return true; - } - return false; -} - -bool IsLocalHostname(base::StringPiece host, bool* is_local6) { - std::string normalized_host = base::ToLowerASCII(host); - // Remove any trailing '.'. - if (!normalized_host.empty() && *normalized_host.rbegin() == '.') - normalized_host.resize(normalized_host.size() - 1); - - if (normalized_host == "localhost6" || - normalized_host == "localhost6.localdomain6") { - if (is_local6) - *is_local6 = true; - return true; - } - - if (is_local6) - *is_local6 = false; - return normalized_host == "localhost" || - normalized_host == "localhost.localdomain" || - IsNormalizedLocalhostTLD(normalized_host); -} - } // namespace net +} // namespace url
diff --git a/src/net/base/url_util.h b/src/net/base/url_util.h index 75f7b62..6810b89 100644 --- a/src/net/base/url_util.h +++ b/src/net/base/url_util.h
@@ -12,166 +12,23 @@ #include <string> -#include "base/macros.h" -#include "base/strings/string16.h" #include "base/strings/string_piece.h" -#include "net/base/net_export.h" -#include "url/third_party/mozilla/url_parse.h" +#define NET_EXPORT class GURL; namespace url { + struct CanonHostInfo; -} namespace net { -// Returns a new GURL by appending the given query parameter name and the -// value. Unsafe characters in the name and the value are escaped like -// %XX%XX. The original query component is preserved if it's present. -// -// Examples: -// -// AppendQueryParameter(GURL("http://example.com"), "name", "value").spec() -// => "http://example.com?name=value" -// AppendQueryParameter(GURL("http://example.com?x=y"), "name", "value").spec() -// => "http://example.com?x=y&name=value" -NET_EXPORT GURL AppendQueryParameter(const GURL& url, - const std::string& name, - const std::string& value); - -// Returns a new GURL by appending or replacing the given query parameter name -// and the value. If |name| appears more than once, only the first name-value -// pair is replaced. Unsafe characters in the name and the value are escaped -// like %XX%XX. The original query component is preserved if it's present. -// -// Examples: -// -// AppendOrReplaceQueryParameter( -// GURL("http://example.com"), "name", "new").spec() -// => "http://example.com?name=value" -// AppendOrReplaceQueryParameter( -// GURL("http://example.com?x=y&name=old"), "name", "new").spec() -// => "http://example.com?x=y&name=new" -NET_EXPORT GURL AppendOrReplaceQueryParameter(const GURL& url, - const std::string& name, - const std::string& value); - -// Iterates over the key-value pairs in the query portion of |url|. -class NET_EXPORT QueryIterator { - public: - explicit QueryIterator(const GURL& url); - ~QueryIterator(); - - std::string GetKey() const; - std::string GetValue() const; - const std::string& GetUnescapedValue(); - - bool IsAtEnd() const; - void Advance(); - - private: - const GURL& url_; - url::Component query_; - bool at_end_; - url::Component key_; - url::Component value_; - std::string unescaped_value_; - - DISALLOW_COPY_AND_ASSIGN(QueryIterator); -}; - -// Looks for |search_key| in the query portion of |url|. Returns true if the -// key is found and sets |out_value| to the unescaped value for the key. -// Returns false if the key is not found. -NET_EXPORT bool GetValueForKeyInQuery(const GURL& url, - const std::string& search_key, - std::string* out_value); - -// Splits an input of the form <host>[":"<port>] into its consitituent parts. -// Saves the result into |*host| and |*port|. If the input did not have -// the optional port, sets |*port| to -1. -// Returns true if the parsing was successful, false otherwise. -// The returned host is NOT canonicalized, and may be invalid. -// -// IPv6 literals must be specified in a bracketed form, for instance: -// [::1]:90 and [::1] -// -// The resultant |*host| in both cases will be "::1" (not bracketed). -NET_EXPORT bool ParseHostAndPort( - std::string::const_iterator host_and_port_begin, - std::string::const_iterator host_and_port_end, - std::string* host, - int* port); -NET_EXPORT bool ParseHostAndPort(const std::string& host_and_port, - std::string* host, - int* port); - -// Returns a host:port string for the given URL. -NET_EXPORT std::string GetHostAndPort(const GURL& url); - -// Returns a host[:port] string for the given URL, where the port is omitted -// if it is the default for the URL's scheme. -NET_EXPORT std::string GetHostAndOptionalPort(const GURL& url); - -// Returns the hostname by trimming the ending dot, if one exists. -NET_EXPORT std::string TrimEndingDot(base::StringPiece host); - -// Returns either the host from |url|, or, if the host is empty, the full spec. -NET_EXPORT std::string GetHostOrSpecFromURL(const GURL& url); - // Canonicalizes |host| and returns it. Also fills |host_info| with // IP address information. |host_info| must not be NULL. NET_EXPORT std::string CanonicalizeHost(base::StringPiece host, url::CanonHostInfo* host_info); -// Returns true if |host| is not an IP address and is compliant with a set of -// rules based on RFC 1738 and tweaked to be compatible with the real world. -// The rules are: -// * One or more components separated by '.' -// * Each component contains only alphanumeric characters and '-' or '_' -// * The last component begins with an alphanumeric character -// * Optional trailing dot after last component (means "treat as FQDN") -// -// NOTE: You should only pass in hosts that have been returned from -// CanonicalizeHost(), or you may not get accurate results. -NET_EXPORT bool IsCanonicalizedHostCompliant(const std::string& host); - -// Returns true if |hostname| contains a non-registerable or non-assignable -// domain name (eg: a gTLD that has not been assigned by IANA) or an IP address -// that falls in an IANA-reserved range. -NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); - -// Returns true if |host| is one of the local hostnames -// (e.g. "localhost") or IP addresses (IPv4 127.0.0.0/8 or IPv6 ::1). -// -// Note that this function does not check for IP addresses other than -// the above, although other IP addresses may point to the local -// machine. -NET_EXPORT bool IsLocalhost(base::StringPiece host); - -// Strip the portions of |url| that aren't core to the network request. -// - user name / password -// - reference section -NET_EXPORT GURL SimplifyUrlForRequest(const GURL& url); - -// Extracts the unescaped username/password from |url|, saving the results -// into |*username| and |*password|. -NET_EXPORT_PRIVATE void GetIdentityFromURL(const GURL& url, - base::string16* username, - base::string16* password); - -// Returns true if the url's host is a Google server. This should only be used -// for histograms and shouldn't be used to affect behavior. -NET_EXPORT_PRIVATE bool HasGoogleHost(const GURL& url); - -// This function tests |host| to see if it is of any local hostname form. -// |host| is normalized before being tested and if |is_local6| is not NULL then -// it it will be set to true if the localhost name implies an IPv6 interface ( -// for instance localhost6.localdomain6). -NET_EXPORT_PRIVATE bool IsLocalHostname(base::StringPiece host, - bool* is_local6); - } // namespace net +} // namespace url #endif // NET_BASE_URL_UTIL_H_
diff --git a/src/net/tools/dafsa/make_dafsa_unittest.py b/src/net/tools/dafsa/make_dafsa_unittest.py index 65a8244..95c8454 100755 --- a/src/net/tools/dafsa/make_dafsa_unittest.py +++ b/src/net/tools/dafsa/make_dafsa_unittest.py
@@ -6,7 +6,7 @@ import sys import unittest -import make_dafsa +from google3.third_party.googleurl.src.net.tools.dafsa import make_dafsa class ParseGperfTest(unittest.TestCase):