| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/network/NetworkUtils.h" | 5 #include "platform/network/NetworkUtils.h" |
| 6 | 6 |
| 7 #include "net/base/ip_address.h" | 7 #include "net/base/ip_address.h" |
| 8 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 8 #include "net/base/url_util.h" | 9 #include "net/base/url_util.h" |
| 9 #include "wtf/text/StringUTF8Adaptor.h" | 10 #include "wtf/text/StringUTF8Adaptor.h" |
| 10 #include "wtf/text/WTFString.h" | 11 #include "wtf/text/WTFString.h" |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 | 14 |
| 14 namespace NetworkUtils { | 15 namespace NetworkUtils { |
| 15 | 16 |
| 16 bool isReservedIPAddress(const String& host) | 17 bool isReservedIPAddress(const String& host) |
| 17 { | 18 { |
| 18 net::IPAddress address; | 19 net::IPAddress address; |
| 19 StringUTF8Adaptor utf8(host); | 20 StringUTF8Adaptor utf8(host); |
| 20 if (!net::ParseURLHostnameToAddress(utf8.asStringPiece(), &address)) | 21 if (!net::ParseURLHostnameToAddress(utf8.asStringPiece(), &address)) |
| 21 return false; | 22 return false; |
| 22 return address.IsReserved(); | 23 return address.IsReserved(); |
| 23 } | 24 } |
| 24 | 25 |
| 25 bool isLocalHostname(const String& host, bool* isLocal6) | 26 bool isLocalHostname(const String& host, bool* isLocal6) |
| 26 { | 27 { |
| 27 StringUTF8Adaptor utf8(host); | 28 StringUTF8Adaptor utf8(host); |
| 28 return net::IsLocalHostname(utf8.asStringPiece(), isLocal6); | 29 return net::IsLocalHostname(utf8.asStringPiece(), isLocal6); |
| 29 } | 30 } |
| 30 | 31 |
| 32 String getDomainAndRegistry(const String& host, bool includePrivateRegistries) |
| 33 { |
| 34 StringUTF8Adaptor hostUtf8(host); |
| 35 net::registry_controlled_domains::PrivateRegistryFilter registryFilter = inc
ludePrivateRegistries ? net::registry_controlled_domains::INCLUDE_PRIVATE_REGIST
RIES : net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; |
| 36 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
hostUtf8.asStringPiece(), registryFilter); |
| 37 return String(domain.data(), domain.length()); |
| 38 } |
| 39 |
| 31 } // NetworkUtils | 40 } // NetworkUtils |
| 32 | 41 |
| 33 } // namespace blink | 42 } // namespace blink |
| OLD | NEW |