Commit e1fa8fc5 authored by tommycli's avatar tommycli Committed by Commit bot

Android URL formatting: Disable RTL URLs for Android 4.2 and below.

Android 4.2 and below has a problematic RTL implementation. Force
formatted URLs to display in LTR.

BUG=709417

Review-Url: https://codereview.chromium.org/2839843002
Cr-Commit-Position: refs/heads/master@{#467740}
parent 8fdab620
...@@ -12,6 +12,7 @@ import android.graphics.Canvas; ...@@ -12,6 +12,7 @@ import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.StrictMode; import android.os.StrictMode;
import android.os.SystemClock; import android.os.SystemClock;
import android.text.Editable; import android.text.Editable;
...@@ -67,6 +68,9 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -67,6 +68,9 @@ public class UrlBar extends VerticallyFixedEditText {
private static final int MAX_DISPLAYABLE_LENGTH = 4000; private static final int MAX_DISPLAYABLE_LENGTH = 4000;
private static final int MAX_DISPLAYABLE_LENGTH_LOW_END = 1000; private static final int MAX_DISPLAYABLE_LENGTH_LOW_END = 1000;
// Unicode "Left-To-Right Mark" (LRM) character.
private static final char LRM = '\u200E';
/** The contents of the URL that precede the path/query after being formatted. */ /** The contents of the URL that precede the path/query after being formatted. */
private String mFormattedUrlLocation; private String mFormattedUrlLocation;
...@@ -789,6 +793,13 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -789,6 +793,13 @@ public class UrlBar extends VerticallyFixedEditText {
*/ */
public boolean setUrl(String url, String formattedUrl) { public boolean setUrl(String url, String formattedUrl) {
if (!TextUtils.isEmpty(formattedUrl)) { if (!TextUtils.isEmpty(formattedUrl)) {
// Because Android versions 4.2 and before lack proper RTL support,
// force the formatted URL to render as LTR using an LRM character.
// See: https://www.ietf.org/rfc/rfc3987.txt and crbug.com/709417
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
formattedUrl = LRM + formattedUrl;
}
try { try {
URL javaUrl = new URL(url); URL javaUrl = new URL(url);
mFormattedUrlLocation = mFormattedUrlLocation =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment