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..eb1e9ed5ce6b0ca606b6214eefcea2428d923cea 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) |
| @@ -108,18 +110,17 @@ void SplitHost(const GURL& url, |
| } |
| #endif // !defined(OS_ANDROID) |
| -bool ShouldShowScheme(const GURL& url, |
| +bool ShouldShowScheme(const std::string& scheme, |
| const url_formatter::SchemeDisplay scheme_display) { |
| switch (scheme_display) { |
| case url_formatter::SchemeDisplay::SHOW: |
| return true; |
| case url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS: |
| - return !url.SchemeIs(url::kHttpsScheme) && |
| - !url.SchemeIs(url::kHttpScheme); |
| + return scheme != url::kHttpsScheme && scheme != url::kHttpScheme; |
| case url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC: |
| - return !url.SchemeIsCryptographic(); |
| + return scheme != url::kHttpsScheme && scheme != url::kWssScheme; |
| } |
| return true; |
| @@ -359,7 +360,7 @@ base::string16 FormatUrlForSecurityDisplay(const GURL& url, |
| const std::string& host = origin.host(); |
| base::string16 result; |
| - if (ShouldShowScheme(url, scheme_display)) |
| + if (ShouldShowScheme(scheme, scheme_display)) |
| result = base::UTF8ToUTF16(scheme) + scheme_separator; |
| result += base::UTF8ToUTF16(host); |
| @@ -372,4 +373,30 @@ base::string16 FormatUrlForSecurityDisplay(const GURL& url, |
| return result; |
| } |
| +base::string16 FormatOriginForSecurityDisplay( |
| + const url::Origin& origin, |
| + const SchemeDisplay scheme_display) { |
| + const std::string& scheme = origin.scheme(); |
|
brettw
2016/05/12 16:47:24
Same, StringPiece, scheme_piece(), and host_piece(
juncai
2016/05/12 17:29:06
url::Origin doesn't have scheme_piece(), and host_
brettw
2016/05/12 23:22:22
Oh I see, these are const refs. This part is fine
|
| + const std::string& host = origin.host(); |
| + if (scheme.empty() && host.empty()) |
| + return base::string16(); |
| + |
| + const base::string16 colon(base::ASCIIToUTF16(":")); |
| + const base::string16 scheme_separator( |
| + base::ASCIIToUTF16(url::kStandardSchemeSeparator)); |
| + |
| + base::string16 result; |
| + if (ShouldShowScheme(scheme, scheme_display)) |
| + result = base::UTF8ToUTF16(scheme) + scheme_separator; |
| + result += base::UTF8ToUTF16(host); |
| + |
| + int port = static_cast<int>(origin.port()); |
| + const int default_port = url::DefaultPortForScheme( |
| + scheme.c_str(), static_cast<int>(scheme.length())); |
| + if (port != 0 && port != default_port) |
| + result += colon + base::UintToString16(origin.port()); |
| + |
| + return result; |
| +} |
| + |
| } // namespace url_formatter |