Chromium Code Reviews| Index: components/secure_display/elide_url.cc |
| diff --git a/chrome/browser/ui/elide_url.cc b/components/secure_display/elide_url.cc |
| similarity index 89% |
| rename from chrome/browser/ui/elide_url.cc |
| rename to components/secure_display/elide_url.cc |
| index afa6d7a880abc4916742a14268cf672da2e5d4f9..8b6838e9eafc5f4801a0c4ce19059c09c3ad971f 100644 |
| --- a/chrome/browser/ui/elide_url.cc |
| +++ b/components/secure_display/elide_url.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/ui/elide_url.h" |
| +#include "components/secure_display/elide_url.h" |
| #include "base/logging.h" |
| #include "base/strings/string_split.h" |
| @@ -23,6 +23,7 @@ using gfx::kForwardSlash; |
| namespace { |
| +#if !defined(OS_ANDROID) |
| const base::char16 kDot = '.'; |
| // Build a path from the first |num_components| elements in |path_elements|. |
| @@ -61,8 +62,8 @@ base::string16 ElideComponentizedPath( |
| CHECK(url_path_number_of_elements); |
| for (size_t i = url_path_number_of_elements - 1; i > 0; --i) { |
| - base::string16 elided_path = BuildPathFromComponents(url_path_prefix, |
| - url_path_elements, url_filename, i); |
| + base::string16 elided_path = BuildPathFromComponents( |
| + url_path_prefix, url_path_elements, url_filename, i); |
| if (available_pixel_width >= GetStringWidthF(elided_path, font_list)) |
| return ElideText(elided_path + url_query, font_list, |
| available_pixel_width, gfx::ELIDE_TAIL); |
| @@ -81,8 +82,8 @@ void SplitHost(const GURL& url, |
| *url_host = UTF8ToUTF16(url.host()); |
| // Get domain and registry information from the URL. |
| - *url_domain = UTF8ToUTF16( |
| - net::registry_controlled_domains::GetDomainAndRegistry( |
| + *url_domain = |
| + UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry( |
| url, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)); |
| if (url_domain->empty()) |
| *url_domain = *url_host; |
| @@ -99,13 +100,18 @@ void SplitHost(const GURL& url, |
| if (domain_start_index != base::string16::npos) |
| *url_subdomain = url_host->substr(0, domain_start_index); |
| if ((*url_subdomain == kWwwPrefix || url_subdomain->empty() || |
| - url.SchemeIsFile())) { |
| + url.SchemeIsFile())) { |
| url_subdomain->clear(); |
| } |
| } |
| +#endif |
|
noyau (Ping after 24h)
2015/07/22 09:44:00
nit
#endif // !defined(OS_ANDROID)
Miguel Garcia
2015/07/22 12:33:06
Done.
|
| } // namespace |
| +namespace secure_display { |
| + |
| +#if !defined(OS_ANDROID) |
| + |
| // TODO(pkasting): http://crbug.com/77883 This whole function gets |
| // kerning/ligatures/etc. issues potentially wrong by assuming that the width of |
| // a rendered string is always the sum of the widths of its substrings. Also I |
| @@ -171,10 +177,9 @@ base::string16 ElideUrl(const GURL& url, |
| // Second Pass - remove scheme - the rest fits. |
| const float pixel_width_url_host = GetStringWidthF(url_host, font_list); |
| - const float pixel_width_url_path = GetStringWidthF(url_path_query_etc, |
| - font_list); |
| - if (available_pixel_width >= |
| - pixel_width_url_host + pixel_width_url_path) |
| + const float pixel_width_url_path = |
| + GetStringWidthF(url_path_query_etc, font_list); |
| + if (available_pixel_width >= pixel_width_url_host + pixel_width_url_path) |
| return url_host + url_path_query_etc; |
| // Third Pass: Subdomain, domain and entire path fits. |
| @@ -182,14 +187,13 @@ base::string16 ElideUrl(const GURL& url, |
| const float pixel_width_url_subdomain = |
| GetStringWidthF(url_subdomain, font_list); |
| if (available_pixel_width >= |
| - pixel_width_url_subdomain + pixel_width_url_domain + |
| - pixel_width_url_path) |
| + pixel_width_url_subdomain + pixel_width_url_domain + pixel_width_url_path) |
| return url_subdomain + url_domain + url_path_query_etc; |
| // Query element. |
| base::string16 url_query; |
| - const float kPixelWidthDotsTrailer = GetStringWidthF( |
| - base::string16(kEllipsisUTF16), font_list); |
| + const float kPixelWidthDotsTrailer = |
| + GetStringWidthF(base::string16(kEllipsisUTF16), font_list); |
| if (parsed.query.is_nonempty()) { |
| url_query = UTF8ToUTF16("?") + url_string.substr(parsed.query.begin); |
| if (available_pixel_width >= |
| @@ -212,8 +216,8 @@ base::string16 ElideUrl(const GURL& url, |
| if (url_filename.empty() && (url_path_number_of_elements > 1)) { |
| // Path ends with a '/'. |
| --url_path_number_of_elements; |
| - url_filename = url_path_elements[url_path_number_of_elements - 1] + |
| - kForwardSlash; |
| + url_filename = |
| + url_path_elements[url_path_number_of_elements - 1] + kForwardSlash; |
| } |
| const size_t kMaxNumberOfUrlPathElementsAllowed = 1024; |
| @@ -232,10 +236,9 @@ base::string16 ElideUrl(const GURL& url, |
| GetStringWidthF(kEllipsisAndSlash, font_list); |
| // Check with both subdomain and domain. |
| - base::string16 elided_path = |
| - ElideComponentizedPath(url_subdomain + url_domain, url_path_elements, |
| - url_filename, url_query, font_list, |
| - available_pixel_width); |
| + base::string16 elided_path = ElideComponentizedPath( |
| + url_subdomain + url_domain, url_path_elements, url_filename, url_query, |
| + font_list, available_pixel_width); |
| if (!elided_path.empty()) |
| return elided_path; |
| @@ -261,15 +264,15 @@ base::string16 ElideUrl(const GURL& url, |
| // Return elided domain/.../filename anyway. |
| base::string16 final_elided_url_string(url_elided_domain); |
| - const float url_elided_domain_width = GetStringWidthF(url_elided_domain, |
| - font_list); |
| + const float url_elided_domain_width = |
| + GetStringWidthF(url_elided_domain, font_list); |
| // A hack to prevent trailing ".../...". |
| if ((available_pixel_width - url_elided_domain_width) > |
| pixel_width_ellipsis_slash + kPixelWidthDotsTrailer + |
| - GetStringWidthF(base::ASCIIToUTF16("UV"), font_list)) { |
| - final_elided_url_string += BuildPathFromComponents(base::string16(), |
| - url_path_elements, url_filename, 1); |
| + GetStringWidthF(base::ASCIIToUTF16("UV"), font_list)) { |
| + final_elided_url_string += BuildPathFromComponents( |
| + base::string16(), url_path_elements, url_filename, 1); |
| } else { |
| final_elided_url_string += url_path; |
| } |
| @@ -298,11 +301,13 @@ base::string16 ElideHost(const GURL& url, |
| if (subdomain_width <= 0) |
| return base::string16(kEllipsisUTF16) + kDot + url_domain; |
| - const base::string16 elided_subdomain = ElideText( |
| - url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); |
| + const base::string16 elided_subdomain = |
| + ElideText(url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); |
| return elided_subdomain + url_domain; |
| } |
| +#endif |
| + |
| base::string16 FormatUrlForSecurityDisplay(const GURL& url, |
| const std::string& languages) { |
| if (!url.is_valid() || url.is_empty() || !url.IsStandard()) |
| @@ -344,3 +349,4 @@ base::string16 FormatUrlForSecurityDisplay(const GURL& url, |
| return result; |
| } |
| +} // namespace |