Chromium Code Reviews| 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 "chrome/browser/ui/elide_url.h" | 5 #include "chrome/browser/ui/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 "net/base/escape.h" | 10 #include "net/base/escape.h" |
| 11 #include "net/base/net_util.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 | 17 |
| 17 using base::UTF8ToUTF16; | 18 using base::UTF8ToUTF16; |
| 18 using gfx::ElideText; | 19 using gfx::ElideText; |
| 19 using gfx::GetStringWidthF; | 20 using gfx::GetStringWidthF; |
| 20 using gfx::kEllipsisUTF16; | 21 using gfx::kEllipsisUTF16; |
| 21 using gfx::kForwardSlash; | 22 using gfx::kForwardSlash; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const base::char16 kDot = '.'; | 26 const base::char16 kDot = '.'; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 | 295 |
| 295 const float pixel_width_url_domain = GetStringWidthF(url_domain, font_list); | 296 const float pixel_width_url_domain = GetStringWidthF(url_domain, font_list); |
| 296 float subdomain_width = available_pixel_width - pixel_width_url_domain; | 297 float subdomain_width = available_pixel_width - pixel_width_url_domain; |
| 297 if (subdomain_width <= 0) | 298 if (subdomain_width <= 0) |
| 298 return base::string16(kEllipsisUTF16) + kDot + url_domain; | 299 return base::string16(kEllipsisUTF16) + kDot + url_domain; |
| 299 | 300 |
| 300 const base::string16 elided_subdomain = ElideText( | 301 const base::string16 elided_subdomain = ElideText( |
| 301 url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); | 302 url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); |
| 302 return elided_subdomain + url_domain; | 303 return elided_subdomain + url_domain; |
| 303 } | 304 } |
| 305 | |
| 306 base::string16 FormatUrlForSecurityDisplay(const GURL& url, | |
| 307 const std::string& languages) { | |
| 308 if (!url.is_valid() || url.is_empty() || !url.IsStandard()) | |
| 309 return net::FormatUrl(url, languages); | |
| 310 | |
| 311 const base::string16 colon(base::ASCIIToUTF16(":")); | |
| 312 const base::string16 scheme_separator( | |
| 313 (base::ASCIIToUTF16(url::kStandardSchemeSeparator))); | |
|
msw
2015/06/02 23:45:16
nit: drop extra parens around base::ASCII...
palmer
2015/06/03 01:01:46
Done.
| |
| 314 | |
| 315 if (url.SchemeIsFile()) { | |
| 316 return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator + | |
| 317 base::UTF8ToUTF16(url.path()); | |
| 318 } | |
| 319 | |
| 320 if (url.SchemeIsFileSystem()) { | |
| 321 const GURL* inner_url = url.inner_url(); | |
| 322 const GURL& inner_origin = inner_url->GetOrigin(); | |
| 323 if (inner_origin.SchemeIsFile()) { | |
| 324 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon + | |
| 325 FormatUrlForSecurityDisplay(*inner_url, languages) + | |
| 326 base::UTF8ToUTF16(url.path()); | |
| 327 } | |
| 328 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon + | |
| 329 FormatUrlForSecurityDisplay(inner_origin, languages); | |
| 330 } | |
| 331 | |
| 332 const GURL origin = url.GetOrigin(); | |
| 333 const std::string& scheme = origin.scheme(); | |
| 334 const std::string& host = origin.host(); | |
| 335 | |
| 336 base::string16 result = base::UTF8ToUTF16(scheme); | |
| 337 result += scheme_separator; | |
| 338 result += base::UTF8ToUTF16(host); | |
| 339 | |
| 340 const int port = origin.IntPort(); | |
| 341 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(), | |
| 342 origin.scheme().length()); | |
| 343 if (port != url::PORT_UNSPECIFIED && port != default_port) | |
| 344 result += base::ASCIIToUTF16(":") + base::UTF8ToUTF16(origin.port()); | |
| 345 | |
| 346 return result; | |
| 347 } | |
| OLD | NEW |