Index: chrome/browser/ui/elide_url.cc |
diff --git a/chrome/browser/ui/elide_url.cc b/chrome/browser/ui/elide_url.cc |
index 88b393c4165555de6cbc73e7e4021ae319e65916..9254aaf447a0db73cc97bc129676cd38d913ff9b 100644 |
--- a/chrome/browser/ui/elide_url.cc |
+++ b/chrome/browser/ui/elide_url.cc |
@@ -301,3 +301,48 @@ base::string16 ElideHost(const GURL& url, |
url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); |
return elided_subdomain + url_domain; |
} |
+ |
+base::string16 FormatOriginForDisplay(const GURL& url, |
+ const std::string& languages, |
+ bool omit_scheme) { |
+ 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.
|
+ return net::FormatUrl(url, languages); |
+ |
+ if (url.SchemeIsFile()) { |
+ return (omit_scheme ? base::string16() : base::ASCIIToUTF16("file://")) + |
+ 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.
|
+ } |
+ |
+ if (url.SchemeIsFileSystem()) { |
+ const GURL* inner_url = url.inner_url(); |
+ const GURL& inner_origin = inner_url->GetOrigin(); |
+ if (inner_origin.SchemeIsFile()) { |
+ return base::ASCIIToUTF16("filesystem:") + |
+ (omit_scheme ? base::string16() : base::ASCIIToUTF16("file://")) + |
+ 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
|
+ base::UTF8ToUTF16(url.path()); |
+ } |
+ 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.
|
+ FormatOriginForDisplay(inner_origin, languages, omit_scheme); |
+ } |
+ |
+ const GURL origin = url.GetOrigin(); |
+ const std::string& scheme = origin.scheme(); |
+ const std::string& host = origin.host(); |
+ 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
|
+ return net::FormatUrl(url, languages); |
+ |
+ base::string16 result; |
+ if (!omit_scheme) |
+ 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.
|
+ |
+ result += base::UTF8ToUTF16(host); |
+ |
+ const int port = origin.IntPort(); |
+ const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(), |
+ origin.scheme().length()); |
+ 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
|
+ result += base::ASCIIToUTF16(":") + base::UTF8ToUTF16(origin.port()); |
+ |
+ return result; |
+} |