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..1162747c92eb15707c1542e4ee4463837080d251 100644 |
--- a/chrome/browser/ui/elide_url.cc |
+++ b/chrome/browser/ui/elide_url.cc |
@@ -301,3 +301,49 @@ 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()) |
+ return net::FormatUrl(url, languages); |
+ |
+ if (url.SchemeIsFile()) { |
+ 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
|
+ base::UTF8ToUTF16(url.path()); |
+ } |
+ |
+ 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()) + |
+ base::UTF8ToUTF16(url.path()); |
+ } else { |
msw
2015/05/29 00:18:51
nit: no else after return.
palmer
2015/05/29 17:52:12
Done.
|
+ return base::ASCIIToUTF16("filesystem:") + |
+ 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()) |
+ return net::FormatUrl(url, languages); |
+ |
+ base::string16 result; |
+ if (!omit_scheme) |
+ result = base::UTF8ToUTF16(scheme) + base::ASCIIToUTF16("://"); |
+ |
+ 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) |
+ result += base::ASCIIToUTF16(":") + base::UTF8ToUTF16(origin.port()); |
+ |
+ return result; |
+} |