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()) | |
Ryan Sleevi
2015/05/29 18:28:31
BUG: You want to reverse the order of these checks
palmer
2015/05/29 20:40:10
Done.
| |
309 return net::FormatUrl(url, languages); | |
310 | |
311 if (url.SchemeIsFile()) { | |
312 return (omit_scheme ? base::string16() : base::ASCIIToUTF16("file://")) + | |
313 base::UTF8ToUTF16(url.path()); | |
Ryan Sleevi
2015/05/29 18:28:31
So this is a little weird for a few reasons
As cr
palmer
2015/05/29 20:40:10
Although we humans know that (imagine Windows shar
brettw
2015/05/29 20:43:08
If true, this seems like a big bug.
| |
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()) + | |
Ryan Sleevi
2015/05/29 18:28:31
Does it make sense to recurse in to this function
palmer
2015/05/29 20:40:10
I don't think so; not sure. inner_url behaves extr
| |
323 base::UTF8ToUTF16(url.path()); | |
324 } | |
325 return base::ASCIIToUTF16("filesystem:") + | |
Ryan Sleevi
2015/05/29 18:28:31
I'd recommend you replace all of these constants w
palmer
2015/05/29 20:40:10
Done.
| |
326 FormatOriginForDisplay(inner_origin, languages, omit_scheme); | |
327 } | |
328 | |
329 const GURL origin = url.GetOrigin(); | |
330 const std::string& scheme = origin.scheme(); | |
331 const std::string& host = origin.host(); | |
332 if (scheme.empty() || host.empty()) | |
Ryan Sleevi
2015/05/29 18:28:31
Perhaps you could expand a comment about why this
palmer
2015/05/29 20:40:10
I was trying to be maximally defensive, but it tur
| |
333 return net::FormatUrl(url, languages); | |
334 | |
335 base::string16 result; | |
336 if (!omit_scheme) | |
337 result = base::UTF8ToUTF16(scheme) + base::ASCIIToUTF16("://"); | |
Ryan Sleevi
2015/05/29 18:28:31
This is kStandardSchemeSeparator, fwiw
palmer
2015/05/29 20:40:10
Done.
| |
338 | |
339 result += base::UTF8ToUTF16(host); | |
340 | |
341 const int port = origin.IntPort(); | |
342 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(), | |
343 origin.scheme().length()); | |
344 if (origin.port().length() > 0 && port != 0 && port != default_port) | |
Ryan Sleevi
2015/05/29 18:28:31
This != 0 check seems odd. If the port isn't speci
palmer
2015/05/29 20:40:10
Just trying to be maximally defensive, again.
Whe
Ryan Sleevi
2015/05/29 21:13:50
Yeah, I think :0 is correct, because that's actual
| |
345 result += base::ASCIIToUTF16(":") + base::UTF8ToUTF16(origin.port()); | |
346 | |
347 return result; | |
348 } | |
OLD | NEW |