| Index: components/url_formatter/url_formatter.cc
|
| diff --git a/components/url_formatter/url_formatter.cc b/components/url_formatter/url_formatter.cc
|
| index 298b1c18ff42bfae9102433a16200dd4a65d642b..ee32aaa893ccdb49db2de16fc3cb7ca81f6b1392 100644
|
| --- a/components/url_formatter/url_formatter.cc
|
| +++ b/components/url_formatter/url_formatter.cc
|
| @@ -17,6 +17,7 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/threading/thread_local_storage.h"
|
| #include "components/url_formatter/idn_spoof_checker.h"
|
| +#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
|
| #include "third_party/icu/source/common/unicode/uidna.h"
|
| #include "third_party/icu/source/common/unicode/utypes.h"
|
| #include "url/gurl.h"
|
| @@ -578,9 +579,29 @@ base::string16 StripWWW(const base::string16& text) {
|
| ? text.substr(www.length()) : text;
|
| }
|
|
|
| -base::string16 StripWWWFromHost(const GURL& url) {
|
| +std::string StripSubdomains(const GURL& url, StripSubdomainTypes subdomains) {
|
| DCHECK(url.is_valid());
|
| - return StripWWW(base::ASCIIToUTF16(url.host_piece()));
|
| +
|
| + base::StringPiece host_piece = url.host_piece();
|
| + std::string domain_and_registry =
|
| + net::registry_controlled_domains::GetDomainAndRegistry(
|
| + host_piece,
|
| + net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
|
| +
|
| + if (host_piece == domain_and_registry)
|
| + return host_piece.as_string();
|
| +
|
| + std::string subdomain_piece =
|
| + host_piece.substr(0, host_piece.length() - domain_and_registry.length())
|
| + .as_string();
|
| +
|
| + if (subdomains & kStripWWW)
|
| + base::ReplaceSubstringsAfterOffset(&subdomain_piece, 0, "www.", "");
|
| +
|
| + if (subdomains & kStripM)
|
| + base::ReplaceSubstringsAfterOffset(&subdomain_piece, 0, "m.", "");
|
| +
|
| + return subdomain_piece + domain_and_registry;
|
| }
|
|
|
| } // namespace url_formatter
|
|
|