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

Unified Diff: components/url_formatter/elide_url.cc

Issue 1959933002: Add FormatOriginForSecurityDisplay which takes a const url::Origin& origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added FormatUrlForSecurityDisplay which takes a const url::Origin Created 4 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: components/url_formatter/elide_url.cc
diff --git a/components/url_formatter/elide_url.cc b/components/url_formatter/elide_url.cc
index ad058c2262eca8db465959dfa9c851cb145a15b3..b2488fc88acee21f15562dd17277ec1fd19ec8a6 100644
--- a/components/url_formatter/elide_url.cc
+++ b/components/url_formatter/elide_url.cc
@@ -7,6 +7,7 @@
#include <stddef.h>
#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
@@ -14,6 +15,7 @@
#include "net/base/escape.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/gurl.h"
+#include "url/origin.h"
#include "url/url_constants.h"
#if !defined(OS_ANDROID)
@@ -125,6 +127,24 @@ bool ShouldShowScheme(const GURL& url,
return true;
}
+bool ShouldShowScheme(const url::Origin& origin,
palmer 2016/05/09 19:40:48 Rather than (essentially) duplicate this code, how
juncai 2016/05/10 02:16:57 Done.
+ const url_formatter::SchemeDisplay scheme_display) {
+ const std::string& scheme = origin.scheme();
+
+ switch (scheme_display) {
+ case url_formatter::SchemeDisplay::SHOW:
+ return true;
+
+ case url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS:
+ return scheme != url::kHttpsScheme && scheme != url::kHttpScheme;
+
+ case url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC:
+ return scheme != url::kHttpsScheme && scheme != url::kWssScheme;
+ }
+
+ return true;
+}
+
} // namespace
namespace url_formatter {
@@ -372,4 +392,27 @@ base::string16 FormatUrlForSecurityDisplay(const GURL& url,
return result;
}
+base::string16 FormatUrlForSecurityDisplay(const url::Origin& origin,
+ const SchemeDisplay scheme_display) {
+ const base::string16 colon(base::ASCIIToUTF16(":"));
+ const base::string16 scheme_separator(
+ base::ASCIIToUTF16(url::kStandardSchemeSeparator));
+
+ const std::string& scheme = origin.scheme();
+ const std::string& host = origin.host();
+
+ base::string16 result;
+ if (ShouldShowScheme(origin, scheme_display))
+ result = base::UTF8ToUTF16(scheme) + scheme_separator;
+ result += base::UTF8ToUTF16(host);
+
+ uint16_t port = origin.port();
+ const int default_port = url::DefaultPortForScheme(
+ scheme.c_str(), static_cast<int>(scheme.length()));
+ if (port != default_port)
+ result += colon + base::UintToString16(origin.port());
+
+ return result;
+}
+
} // namespace url_formatter
« components/url_formatter/elide_url.h ('K') | « components/url_formatter/elide_url.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698