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" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 | 294 |
295 const float pixel_width_url_domain = GetStringWidthF(url_domain, font_list); | 295 const float pixel_width_url_domain = GetStringWidthF(url_domain, font_list); |
296 float subdomain_width = available_pixel_width - pixel_width_url_domain; | 296 float subdomain_width = available_pixel_width - pixel_width_url_domain; |
297 if (subdomain_width <= 0) | 297 if (subdomain_width <= 0) |
298 return base::string16(kEllipsisUTF16) + kDot + url_domain; | 298 return base::string16(kEllipsisUTF16) + kDot + url_domain; |
299 | 299 |
300 const base::string16 elided_subdomain = ElideText( | 300 const base::string16 elided_subdomain = ElideText( |
301 url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); | 301 url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); |
302 return elided_subdomain + url_domain; | 302 return elided_subdomain + url_domain; |
303 } | 303 } |
304 | |
305 base::string16 FormatOriginForDisplay(const GURL& url, | |
306 const std::string& languages, | |
307 bool omit_scheme) { | |
308 if (!url.IsStandard() || url.is_empty() || !url.is_valid()) | |
309 return net::FormatUrl(url, languages); | |
310 | |
311 if (url.SchemeIsFile()) { | |
312 return (omit_scheme ? base::string16() : base::ASCIIToUTF16("file://")) + | |
msw
2015/05/29 00:18:51
If we aren't omitting the scheme from a file URL,
palmer
2015/05/29 17:52:12
Because it might have non-origin material such as
| |
313 base::UTF8ToUTF16(url.path()); | |
314 } | |
315 | |
316 if (url.SchemeIsFileSystem()) { | |
317 const GURL* inner_url = url.inner_url(); | |
318 const GURL& inner_origin = inner_url->GetOrigin(); | |
319 if (inner_origin.SchemeIsFile()) { | |
320 return base::ASCIIToUTF16("filesystem:") + | |
321 (omit_scheme ? base::string16() : base::ASCIIToUTF16("file://")) + | |
322 base::UTF8ToUTF16(inner_url->path()) + | |
323 base::UTF8ToUTF16(url.path()); | |
324 } else { | |
msw
2015/05/29 00:18:51
nit: no else after return.
palmer
2015/05/29 17:52:12
Done.
| |
325 return base::ASCIIToUTF16("filesystem:") + | |
326 FormatOriginForDisplay(inner_origin, languages, omit_scheme); | |
327 } | |
328 } | |
329 | |
330 const GURL origin = url.GetOrigin(); | |
331 const std::string& scheme = origin.scheme(); | |
332 const std::string& host = origin.host(); | |
333 if (scheme.empty() || host.empty()) | |
334 return net::FormatUrl(url, languages); | |
335 | |
336 base::string16 result; | |
337 if (!omit_scheme) | |
338 result = base::UTF8ToUTF16(scheme) + base::ASCIIToUTF16("://"); | |
339 | |
340 result += base::UTF8ToUTF16(host); | |
341 | |
342 const int port = origin.IntPort(); | |
343 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(), | |
344 origin.scheme().length()); | |
345 if (origin.port().length() > 0 && port != 0 && port != default_port) | |
346 result += base::ASCIIToUTF16(":") + base::UTF8ToUTF16(origin.port()); | |
347 | |
348 return result; | |
349 } | |
OLD | NEW |