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

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: Recurse instead of duplicate; clean-up. 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..313f4a4a0a5a749ee84b6a13eaa56d7471314736 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 FormatOriginForDisplay(const GURL& url,
+ const std::string& languages) {
+ if (!url.is_valid() || url.is_empty() || !url.IsStandard())
+ return net::FormatUrl(url, languages);
Ryan Sleevi 2015/06/01 21:18:46 In writing my comment about the function comment,
palmer 2015/06/01 23:30:34 Most pressing for me right now is fixing bugs in C
+
+ 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();
+ if (inner_origin.SchemeIsFile()) {
+ return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
+ FormatOriginForDisplay(*inner_url, languages) +
+ base::UTF8ToUTF16(url.path());
+ }
+ return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
+ FormatOriginForDisplay(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));
Ryan Sleevi 2015/06/01 21:18:46 EXTREME PEDANTRY REDUX: I suggested the "=" initi
palmer 2015/06/01 23:30:34 Done.
+ 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());
+
+ return result;
+}

Powered by Google App Engine
This is Rietveld 408576698