OLD | NEW |
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/secure_display/elide_url.h" | 5 #include "components/url_formatter/elide_url.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/url_formatter/url_formatter.h" |
10 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
11 #include "net/base/net_util.h" | |
12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
13 #include "ui/gfx/text_elider.h" | 13 #include "ui/gfx/text_elider.h" |
14 #include "ui/gfx/text_utils.h" | 14 #include "ui/gfx/text_utils.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 #include "url/url_constants.h" | 16 #include "url/url_constants.h" |
17 | 17 |
18 using base::UTF8ToUTF16; | 18 using base::UTF8ToUTF16; |
19 using gfx::ElideText; | 19 using gfx::ElideText; |
20 using gfx::GetStringWidthF; | 20 using gfx::GetStringWidthF; |
21 using gfx::kEllipsisUTF16; | 21 using gfx::kEllipsisUTF16; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 *url_subdomain = url_host->substr(0, domain_start_index); | 101 *url_subdomain = url_host->substr(0, domain_start_index); |
102 if ((*url_subdomain == kWwwPrefix || url_subdomain->empty() || | 102 if ((*url_subdomain == kWwwPrefix || url_subdomain->empty() || |
103 url.SchemeIsFile())) { | 103 url.SchemeIsFile())) { |
104 url_subdomain->clear(); | 104 url_subdomain->clear(); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 #endif // !defined(OS_ANDROID) | 108 #endif // !defined(OS_ANDROID) |
109 } // namespace | 109 } // namespace |
110 | 110 |
111 namespace secure_display { | 111 namespace url_formatter { |
112 | 112 |
113 #if !defined(OS_ANDROID) | 113 #if !defined(OS_ANDROID) |
114 | 114 |
115 // TODO(pkasting): http://crbug.com/77883 This whole function gets | 115 // TODO(pkasting): http://crbug.com/77883 This whole function gets |
116 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of | 116 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of |
117 // a rendered string is always the sum of the widths of its substrings. Also I | 117 // a rendered string is always the sum of the widths of its substrings. Also I |
118 // suspect it could be made simpler. | 118 // suspect it could be made simpler. |
119 base::string16 ElideUrl(const GURL& url, | 119 base::string16 ElideUrl(const GURL& url, |
120 const gfx::FontList& font_list, | 120 const gfx::FontList& font_list, |
121 float available_pixel_width, | 121 float available_pixel_width, |
122 const std::string& languages) { | 122 const std::string& languages) { |
123 // Get a formatted string and corresponding parsing of the url. | 123 // Get a formatted string and corresponding parsing of the url. |
124 url::Parsed parsed; | 124 url::Parsed parsed; |
125 const base::string16 url_string = | 125 const base::string16 url_string = url_formatter::FormatUrl( |
126 net::FormatUrl(url, languages, net::kFormatUrlOmitAll, | 126 url, languages, url_formatter::kFormatUrlOmitAll, |
127 net::UnescapeRule::SPACES, &parsed, NULL, NULL); | 127 net::UnescapeRule::SPACES, &parsed, nullptr, nullptr); |
128 if (available_pixel_width <= 0) | 128 if (available_pixel_width <= 0) |
129 return url_string; | 129 return url_string; |
130 | 130 |
131 // If non-standard, return plain eliding. | 131 // If non-standard, return plain eliding. |
132 if (!url.IsStandard()) | 132 if (!url.IsStandard()) |
133 return ElideText(url_string, font_list, available_pixel_width, | 133 return ElideText(url_string, font_list, available_pixel_width, |
134 gfx::ELIDE_TAIL); | 134 gfx::ELIDE_TAIL); |
135 | 135 |
136 // Now start eliding url_string to fit within available pixel width. | 136 // Now start eliding url_string to fit within available pixel width. |
137 // Fist pass - check to see whether entire url_string fits. | 137 // Fist pass - check to see whether entire url_string fits. |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 const base::string16 elided_subdomain = | 305 const base::string16 elided_subdomain = |
306 ElideText(url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); | 306 ElideText(url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); |
307 return elided_subdomain + url_domain; | 307 return elided_subdomain + url_domain; |
308 } | 308 } |
309 | 309 |
310 #endif // !defined(OS_ANDROID) | 310 #endif // !defined(OS_ANDROID) |
311 | 311 |
312 base::string16 FormatUrlForSecurityDisplay(const GURL& url, | 312 base::string16 FormatUrlForSecurityDisplay(const GURL& url, |
313 const std::string& languages) { | 313 const std::string& languages) { |
314 if (!url.is_valid() || url.is_empty() || !url.IsStandard()) | 314 if (!url.is_valid() || url.is_empty() || !url.IsStandard()) |
315 return net::FormatUrl(url, languages); | 315 return url_formatter::FormatUrl(url, languages); |
316 | 316 |
317 const base::string16 colon(base::ASCIIToUTF16(":")); | 317 const base::string16 colon(base::ASCIIToUTF16(":")); |
318 const base::string16 scheme_separator( | 318 const base::string16 scheme_separator( |
319 base::ASCIIToUTF16(url::kStandardSchemeSeparator)); | 319 base::ASCIIToUTF16(url::kStandardSchemeSeparator)); |
320 | 320 |
321 if (url.SchemeIsFile()) { | 321 if (url.SchemeIsFile()) { |
322 return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator + | 322 return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator + |
323 base::UTF8ToUTF16(url.path()); | 323 base::UTF8ToUTF16(url.path()); |
324 } | 324 } |
325 | 325 |
(...skipping 17 matching lines...) Expand all Loading... |
343 result += base::UTF8ToUTF16(host); | 343 result += base::UTF8ToUTF16(host); |
344 | 344 |
345 const int port = origin.IntPort(); | 345 const int port = origin.IntPort(); |
346 const int default_port = url::DefaultPortForScheme( | 346 const int default_port = url::DefaultPortForScheme( |
347 scheme.c_str(), static_cast<int>(scheme.length())); | 347 scheme.c_str(), static_cast<int>(scheme.length())); |
348 if (port != url::PORT_UNSPECIFIED && port != default_port) | 348 if (port != url::PORT_UNSPECIFIED && port != default_port) |
349 result += colon + base::UTF8ToUTF16(origin.port()); | 349 result += colon + base::UTF8ToUTF16(origin.port()); |
350 | 350 |
351 return result; | 351 return result; |
352 } | 352 } |
353 } // namespace secure_display | 353 } // namespace url_formatter |
OLD | NEW |