Chromium Code Reviews| 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..752fd1efb876e2dfa48b903d8a065db7e34e80a1 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,30 @@ base::string16 StripWWW(const base::string16& text) { |
| ? text.substr(www.length()) : text; |
| } |
| -base::string16 StripWWWFromHost(const GURL& url) { |
| +base::StringPiece 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 etld_plus_one = |
|
Peter Kasting
2017/06/17 02:46:55
Nit: Prefer to use the same terminology as the RCD
tommycli
2017/06/19 23:03:07
Done.
|
| + net::registry_controlled_domains::GetDomainAndRegistry( |
| + host_piece, |
| + net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| + |
| + if (host_piece == etld_plus_one) |
| + return host_piece; |
| + |
| + if ((subdomains & kStripWWW) != 0 && |
| + base::StartsWith(host_piece, "www.", base::CompareCase::SENSITIVE)) { |
| + return host_piece.substr(4); |
|
Peter Kasting
2017/06/17 02:46:55
This early-returns if the host is www.m.foo.com, w
tommycli
2017/06/19 23:03:08
Done.
|
| + } |
| + |
| + if ((subdomains & kStripM) != 0 && |
| + base::StartsWith(host_piece, "m.", base::CompareCase::SENSITIVE)) { |
|
Peter Kasting
2017/06/17 02:46:55
This fails to fix up the most common mobile host I
tommycli
2017/06/19 23:03:07
Done.
|
| + return host_piece.substr(2); |
| + } |
| + |
| + return host_piece; |
| } |
| } // namespace url_formatter |