Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1204)

Unified Diff: chrome/browser/ui/elide_url.cc

Issue 1147363005: Create FormatUrlForSecurityDisplay helper function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change both call sites in content_setting_bubble_model, and supply the preferred languages! Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+}

Powered by Google App Engine
This is Rietveld 408576698