Chromium Code Reviews| 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 |
| 13 namespace { | |
| 14 | |
| 15 net::registry_controlled_domains::PrivateRegistryFilter getNetPrivateRegistryFil ter(blink::NetworkUtils::PrivateRegistryFilter filter) | |
| 16 { | |
| 17 switch (filter) { | |
| 18 case blink::NetworkUtils::IncludePrivateRegistries: | |
| 19 return net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES; | |
| 20 case blink::NetworkUtils::ExcludePrivateRegistries: | |
| 21 return net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; | |
| 22 } | |
| 23 // There are only two NetworkUtils::PrivateRegistryFilter enum entries, so | |
| 24 // we should never reach this point. However, we must have a default return | |
| 25 // value to avoid a compiler error. | |
| 26 NOTREACHED(); | |
| 27 return net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES; | |
| 28 } | |
|
kinuko
2016/08/04 18:08:04
nit: Probably we can just have static_assert's (l
| |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 12 namespace blink { | 32 namespace blink { |
| 13 | 33 |
| 14 namespace NetworkUtils { | 34 namespace NetworkUtils { |
| 15 | 35 |
| 16 bool isReservedIPAddress(const String& host) | 36 bool isReservedIPAddress(const String& host) |
| 17 { | 37 { |
| 18 net::IPAddress address; | 38 net::IPAddress address; |
| 19 StringUTF8Adaptor utf8(host); | 39 StringUTF8Adaptor utf8(host); |
| 20 if (!net::ParseURLHostnameToAddress(utf8.asStringPiece(), &address)) | 40 if (!net::ParseURLHostnameToAddress(utf8.asStringPiece(), &address)) |
| 21 return false; | 41 return false; |
| 22 return address.IsReserved(); | 42 return address.IsReserved(); |
| 23 } | 43 } |
| 24 | 44 |
| 25 bool isLocalHostname(const String& host, bool* isLocal6) | 45 bool isLocalHostname(const String& host, bool* isLocal6) |
| 26 { | 46 { |
| 27 StringUTF8Adaptor utf8(host); | 47 StringUTF8Adaptor utf8(host); |
| 28 return net::IsLocalHostname(utf8.asStringPiece(), isLocal6); | 48 return net::IsLocalHostname(utf8.asStringPiece(), isLocal6); |
| 29 } | 49 } |
| 30 | 50 |
| 51 String getDomainAndRegistry(const String& host, PrivateRegistryFilter filter) | |
| 52 { | |
| 53 StringUTF8Adaptor hostUtf8(host); | |
| 54 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( hostUtf8.asStringPiece(), getNetPrivateRegistryFilter(filter)); | |
| 55 return String(domain.data(), domain.length()); | |
| 56 } | |
| 57 | |
| 31 } // NetworkUtils | 58 } // NetworkUtils |
| 32 | 59 |
| 33 } // namespace blink | 60 } // namespace blink |
| OLD | NEW |