Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: components/url_formatter/elide_url.cc

Issue 1861213002: Convert host names in ACE to Unicode in ElideHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ace => puny; comment added Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/url_formatter/elide_url_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/url_formatter/elide_url.h" 5 #include "components/url_formatter/elide_url.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 return base::string16(); 72 return base::string16();
73 } 73 }
74 74
75 // Splits the hostname in the |url| into sub-strings for the full hostname, 75 // Splits the hostname in the |url| into sub-strings for the full hostname,
76 // the domain (TLD+1), and the subdomain (everything leading the domain). 76 // the domain (TLD+1), and the subdomain (everything leading the domain).
77 void SplitHost(const GURL& url, 77 void SplitHost(const GURL& url,
78 base::string16* url_host, 78 base::string16* url_host,
79 base::string16* url_domain, 79 base::string16* url_domain,
80 base::string16* url_subdomain) { 80 base::string16* url_subdomain) {
81 // Get Host. 81 // GURL stores IDN hostnames in punycode. Convert back to Unicode for
82 *url_host = base::UTF8ToUTF16(url.host()); 82 // display to the user. (IDNToUnicode() will only perform this conversion
83 // if it's safe to display this host/domain in Unicode.)
84 *url_host = url_formatter::IDNToUnicode(url.host());
83 85
84 // Get domain and registry information from the URL. 86 // Get domain and registry information from the URL.
85 *url_domain = 87 std::string domain_puny =
86 base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry( 88 net::registry_controlled_domains::GetDomainAndRegistry(
87 url, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)); 89 url, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
88 if (url_domain->empty()) 90 *url_domain = domain_puny.empty() ?
89 *url_domain = *url_host; 91 *url_host : url_formatter::IDNToUnicode(domain_puny);
90 92
91 // Add port if required. 93 // Add port if required.
92 if (!url.port().empty()) { 94 if (!url.port().empty()) {
93 *url_host += base::UTF8ToUTF16(":" + url.port()); 95 *url_host += base::UTF8ToUTF16(":" + url.port());
94 *url_domain += base::UTF8ToUTF16(":" + url.port()); 96 *url_domain += base::UTF8ToUTF16(":" + url.port());
95 } 97 }
96 98
97 // Get sub domain. 99 // Get sub domain.
98 const size_t domain_start_index = url_host->find(*url_domain); 100 const size_t domain_start_index = url_host->find(*url_domain);
99 base::string16 kWwwPrefix = base::UTF8ToUTF16("www."); 101 base::string16 kWwwPrefix = base::UTF8ToUTF16("www.");
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 358
357 base::string16 FormatUrlForSecurityDisplay(const GURL& url) { 359 base::string16 FormatUrlForSecurityDisplay(const GURL& url) {
358 return FormatUrlForSecurityDisplayInternal(url, false); 360 return FormatUrlForSecurityDisplayInternal(url, false);
359 } 361 }
360 362
361 base::string16 FormatUrlForSecurityDisplayOmitScheme(const GURL& url) { 363 base::string16 FormatUrlForSecurityDisplayOmitScheme(const GURL& url) {
362 return FormatUrlForSecurityDisplayInternal(url, true); 364 return FormatUrlForSecurityDisplayInternal(url, true);
363 } 365 }
364 366
365 } // namespace url_formatter 367 } // namespace url_formatter
OLDNEW
« no previous file with comments | « no previous file | components/url_formatter/elide_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698