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

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 testing strategy, respond to comments. 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
« no previous file with comments | « chrome/browser/ui/elide_url.h ('k') | chrome/browser/ui/elide_url_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..afa6d7a880abc4916742a14268cf672da2e5d4f9 100644
--- a/chrome/browser/ui/elide_url.cc
+++ b/chrome/browser/ui/elide_url.cc
@@ -13,6 +13,7 @@
#include "ui/gfx/text_elider.h"
#include "ui/gfx/text_utils.h"
#include "url/gurl.h"
+#include "url/url_constants.h"
using base::UTF8ToUTF16;
using gfx::ElideText;
@@ -301,3 +302,45 @@ base::string16 ElideHost(const GURL& url,
url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD);
return elided_subdomain + url_domain;
}
+
+base::string16 FormatUrlForSecurityDisplay(const GURL& url,
+ const std::string& languages) {
+ if (!url.is_valid() || url.is_empty() || !url.IsStandard())
+ return net::FormatUrl(url, languages);
+
+ const base::string16 colon(base::ASCIIToUTF16(":"));
+ const base::string16 scheme_separator(
+ base::ASCIIToUTF16(url::kStandardSchemeSeparator));
+
+ if (url.SchemeIsFile()) {
+ return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator +
+ base::UTF8ToUTF16(url.path());
+ }
+
+ if (url.SchemeIsFileSystem()) {
+ const GURL* inner_url = url.inner_url();
+ if (inner_url->SchemeIsFile()) {
+ return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
+ FormatUrlForSecurityDisplay(*inner_url, languages) +
+ base::UTF8ToUTF16(url.path());
+ }
+ return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
+ FormatUrlForSecurityDisplay(*inner_url, languages);
+ }
+
+ const GURL origin = url.GetOrigin();
+ const std::string& scheme = origin.scheme();
+ const std::string& host = origin.host();
+
+ base::string16 result = base::UTF8ToUTF16(scheme);
+ result += scheme_separator;
+ result += base::UTF8ToUTF16(host);
+
+ const int port = origin.IntPort();
+ const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(),
+ origin.scheme().length());
+ if (port != url::PORT_UNSPECIFIED && port != default_port)
+ result += colon + base::UTF8ToUTF16(origin.port());
+
+ return result;
+}
« no previous file with comments | « chrome/browser/ui/elide_url.h ('k') | chrome/browser/ui/elide_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698