Chromium Code Reviews| Index: third_party/WebKit/Source/platform/network/NetworkUtils.cpp |
| diff --git a/third_party/WebKit/Source/platform/network/NetworkUtils.cpp b/third_party/WebKit/Source/platform/network/NetworkUtils.cpp |
| index 57c0b4c7ea7822c0070c6c3fa10307bfee963020..49d0ba039d992cfd9446cee8ba172ddfc96ba164 100644 |
| --- a/third_party/WebKit/Source/platform/network/NetworkUtils.cpp |
| +++ b/third_party/WebKit/Source/platform/network/NetworkUtils.cpp |
| @@ -5,10 +5,30 @@ |
| #include "platform/network/NetworkUtils.h" |
| #include "net/base/ip_address.h" |
| +#include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| #include "net/base/url_util.h" |
| #include "wtf/text/StringUTF8Adaptor.h" |
| #include "wtf/text/WTFString.h" |
| +namespace { |
| + |
| +net::registry_controlled_domains::PrivateRegistryFilter getNetPrivateRegistryFilter(blink::NetworkUtils::PrivateRegistryFilter filter) |
| +{ |
| + switch (filter) { |
| + case blink::NetworkUtils::IncludePrivateRegistries: |
| + return net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES; |
| + case blink::NetworkUtils::ExcludePrivateRegistries: |
| + return net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; |
| + } |
| + // There are only two NetworkUtils::PrivateRegistryFilter enum entries, so |
| + // we should never reach this point. However, we must have a default return |
| + // value to avoid a compiler error. |
| + NOTREACHED(); |
| + return net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES; |
| +} |
|
kinuko
2016/08/04 18:08:04
nit: Probably we can just have static_assert's (l
|
| + |
| +} // namespace |
| + |
| namespace blink { |
| namespace NetworkUtils { |
| @@ -28,6 +48,13 @@ bool isLocalHostname(const String& host, bool* isLocal6) |
| return net::IsLocalHostname(utf8.asStringPiece(), isLocal6); |
| } |
| +String getDomainAndRegistry(const String& host, PrivateRegistryFilter filter) |
| +{ |
| + StringUTF8Adaptor hostUtf8(host); |
| + std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(hostUtf8.asStringPiece(), getNetPrivateRegistryFilter(filter)); |
| + return String(domain.data(), domain.length()); |
| +} |
| + |
| } // NetworkUtils |
| } // namespace blink |