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

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: Update some test expectations, and fix nits. 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..b11f2b6f65dac09bfbb5a8c2a7fbd3d103de7cae 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,46 @@ 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();
+ const GURL& inner_origin = inner_url->GetOrigin();
Ryan Sleevi 2015/06/03 19:09:04 nit: Strictly speaking, it'd probably be better/sa
palmer 2015/06/03 21:24:38 Done.
+ if (inner_origin.SchemeIsFile()) {
+ return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
+ FormatUrlForSecurityDisplay(*inner_url, languages) +
+ base::UTF8ToUTF16(url.path());
+ }
+ return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
+ FormatUrlForSecurityDisplay(inner_origin, 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 += base::ASCIIToUTF16(":") + base::UTF8ToUTF16(origin.port());
felt 2015/06/03 01:31:58 should this use the |colon| var?
palmer 2015/06/03 21:24:38 Done.
+
+ return result;
+}

Powered by Google App Engine
This is Rietveld 408576698