Chromium Code Reviews| 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 |