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

Unified Diff: components/url_formatter/elide_url.cc

Issue 2375803002: Use Unicode in Format{Origin,URL}forSecurityDisplay (Closed)
Patch Set: mention {LSI, PDI} as well Created 4 years, 2 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
« no previous file with comments | « components/url_formatter/elide_url.h ('k') | components/url_formatter/elide_url_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/url_formatter/elide_url.cc
diff --git a/components/url_formatter/elide_url.cc b/components/url_formatter/elide_url.cc
index a27506bfb1acc3c11b01ca6f594bba83b262ea03..e19da1f7339b33d5d0379a255405786c7788d7f2 100644
--- a/components/url_formatter/elide_url.cc
+++ b/components/url_formatter/elide_url.cc
@@ -6,6 +6,7 @@
#include <stddef.h>
+#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
@@ -127,6 +128,16 @@ bool ShouldShowScheme(base::StringPiece scheme,
return true;
}
+// TODO(jshin): Come up with a way to show Bidi URLs 'safely' (e.g. wrap up
+// the entire url with {LSI, PDI} and individual domain labels with {FSI, PDI}).
+// See http://crbug.com/650760 . For now, fall back to punycode if there's a
+// strong RTL character.
+base::string16 HostForDisplay(base::StringPiece host_in_puny) {
+ base::string16 host = url_formatter::IDNToUnicode(host_in_puny);
+ return base::i18n::StringContainsStrongRTLChars(host) ?
+ base::ASCIIToUTF16(host_in_puny) : host;
+}
+
} // namespace
namespace url_formatter {
@@ -363,7 +374,7 @@ base::string16 FormatUrlForSecurityDisplay(const GURL& url,
base::string16 result;
if (ShouldShowScheme(scheme, scheme_display))
result = base::UTF8ToUTF16(scheme) + scheme_separator;
- result += base::UTF8ToUTF16(host);
+ result += HostForDisplay(host);
const int port = origin.IntPort();
const int default_port = url::DefaultPortForScheme(
@@ -389,7 +400,7 @@ base::string16 FormatOriginForSecurityDisplay(
base::string16 result;
if (ShouldShowScheme(scheme, scheme_display))
result = base::UTF8ToUTF16(scheme) + scheme_separator;
- result += base::UTF8ToUTF16(host);
+ result += HostForDisplay(host);
int port = static_cast<int>(origin.port());
const int default_port = url::DefaultPortForScheme(
« no previous file with comments | « components/url_formatter/elide_url.h ('k') | components/url_formatter/elide_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698