Bug 1391421 - Translates URL from ASCII Compatible Encoding (ACE) to Unicode. r?sebastian,nechen draft
authorJing-wei Wu <topwu.tw@gmail.com>
Wed, 13 Sep 2017 15:26:06 +0800
changeset 663629 1b735c50a25cb21d1f519eefe5b0e6e235ad67df
parent 663628 3886b07d543f4a5c94e0f67a969ad6decff22f57
child 731248 f415468f0055d91fb1e1344dd62273fc640da224
push id79486
push userbmo:topwu.tw@gmail.com
push dateWed, 13 Sep 2017 07:27:12 +0000
reviewerssebastian, nechen
bugs1391421
milestone57.0a1
Bug 1391421 - Translates URL from ASCII Compatible Encoding (ACE) to Unicode. r?sebastian,nechen MozReview-Commit-ID: 66G2rXdFAKV
mobile/android/app/src/photon/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditLayout.java
--- a/mobile/android/app/src/photon/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/app/src/photon/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -1,15 +1,16 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.toolbar;
 
+import java.net.IDN;
 import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.List;
 
 import android.support.v4.content.ContextCompat;
 import org.mozilla.gecko.AboutPages;
 import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.R;
@@ -277,28 +278,35 @@ public class ToolbarDisplayLayout extend
 
         if (flags.contains(UpdateFlags.PRIVATE_MODE)) {
             mTitle.setPrivateMode(tab.isPrivate());
             mTitleBackground.setPrivateMode(tab.isPrivate());
         }
     }
 
     void setTitle(CharSequence title) {
-        mTitle.setText(title);
+        final String unicodeTitle;
+        if (title != null) {
+            // Translates text from ASCII Compatible Encoding (ACE) to Unicode
+            unicodeTitle = IDN.toUnicode(title.toString());
+        } else {
+            unicodeTitle = null;
+        }
+        mTitle.setText(unicodeTitle);
 
         if (TextUtils.isEmpty(title)) {
             //  Reset TextDirection to Locale in order to reveal text hint in correct direction
             ViewUtil.setTextDirection(mTitle, TEXT_DIRECTION_LOCALE);
         } else {
             //  Otherwise, fall back to default first strong strategy
             ViewUtil.setTextDirection(mTitle, TEXT_DIRECTION_FIRST_STRONG);
         }
 
         if (mTitleChangeListener != null) {
-            mTitleChangeListener.onTitleChange(title);
+            mTitleChangeListener.onTitleChange(unicodeTitle);
         }
     }
 
     private void updateTitle(@NonNull Tab tab) {
         // Keep the title unchanged if there's no selected tab,
         // or if the tab is entering reader mode.
         if (tab.isEnteringReaderMode()) {
             return;
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditLayout.java
@@ -34,16 +34,17 @@ import org.mozilla.gecko.widget.themed.T
 import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
 
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
 
+import java.net.IDN;
 import java.util.List;
 
 /**
 * {@code ToolbarEditLayout} is the UI for when the toolbar is in
 * edit state. It controls a text entry ({@code ToolbarEditText})
 * and its matching 'go' button which changes depending on the
 * current type of text in the entry.
 */
@@ -255,17 +256,24 @@ public class ToolbarEditLayout extends T
         mEditText.setText(suggestion);
         mEditText.setSelection(mEditText.getText().length());
         mEditText.requestFocus();
 
         showSoftInput();
     }
 
     void setText(String text) {
-        mEditText.setText(text);
+        final String unicodeText;
+        if (text != null) {
+            // Translates text from ASCII Compatible Encoding (ACE) to Unicode
+            unicodeText = IDN.toUnicode(text);
+        } else {
+            unicodeText = null;
+        }
+        mEditText.setText(unicodeText);
     }
 
     String getText() {
         return mEditText.getText().toString();
     }
 
     protected void saveTabEditingState(final TabEditingState editingState) {
         editingState.lastEditingText = mEditText.getNonAutocompleteText();