diff --git a/mobile/android/base/BrowserToolbar.java b/mobile/android/base/BrowserToolbar.java index 1f55a128c8e9..4560577b5963 100644 --- a/mobile/android/base/BrowserToolbar.java +++ b/mobile/android/base/BrowserToolbar.java @@ -20,6 +20,7 @@ import org.mozilla.gecko.util.HardwareUtils; import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.UiAsyncTask; import org.mozilla.gecko.util.GeckoEventListener; +import org.mozilla.gecko.util.StringUtils; import org.json.JSONObject; @@ -1092,8 +1093,7 @@ public class BrowserToolbar extends GeckoRelativeLayout return; } - url = StringUtils.stripScheme(url); - CharSequence title = StringUtils.stripCommonSubdomains(url); + CharSequence title = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url)); String baseDomain = tab.getBaseDomain(); if (!TextUtils.isEmpty(baseDomain)) { diff --git a/mobile/android/base/home/HomeListView.java b/mobile/android/base/home/HomeListView.java index 68bd74350453..03a09006da8f 100644 --- a/mobile/android/base/home/HomeListView.java +++ b/mobile/android/base/home/HomeListView.java @@ -10,6 +10,7 @@ import org.mozilla.gecko.db.BrowserContract.Bookmarks; import org.mozilla.gecko.db.BrowserContract.Combined; import org.mozilla.gecko.db.BrowserContract.URLColumns; import org.mozilla.gecko.home.HomePager.OnUrlOpenListener; +import org.mozilla.gecko.util.StringUtils; import android.content.Context; import android.content.res.TypedArray; @@ -126,9 +127,6 @@ public class HomeListView extends ListView */ public static class HomeContextMenuInfo extends AdapterContextMenuInfo { - // URL to Title replacement regex. - private static final String REGEX_URL_TO_TITLE = "^([a-z]+://)?(www\\.)?"; - public int bookmarkId; public int historyId; public String url; @@ -200,7 +198,8 @@ public class HomeListView extends ListView } public String getDisplayTitle() { - return TextUtils.isEmpty(title) ? url.replaceAll(REGEX_URL_TO_TITLE, "") : title; + return TextUtils.isEmpty(title) ? + StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url, StringUtils.UrlFlags.STRIP_HTTPS)) : title; } } } diff --git a/mobile/android/base/home/TopBookmarksView.java b/mobile/android/base/home/TopBookmarksView.java index 9a25ccb563cc..18debb1dc670 100644 --- a/mobile/android/base/home/TopBookmarksView.java +++ b/mobile/android/base/home/TopBookmarksView.java @@ -10,6 +10,7 @@ import org.mozilla.gecko.ThumbnailHelper; import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper; import org.mozilla.gecko.db.BrowserDB.URLColumns; import org.mozilla.gecko.home.HomePager.OnUrlOpenListener; +import org.mozilla.gecko.util.StringUtils; import android.content.Context; import android.content.res.TypedArray; @@ -217,9 +218,6 @@ public class TopBookmarksView extends GridView { */ public static class TopBookmarksContextMenuInfo extends AdapterContextMenuInfo { - // URL to Title replacement regex. - private static final String REGEX_URL_TO_TITLE = "^([a-z]+://)?(www\\.)?"; - public String url; public String title; public boolean isPinned; @@ -237,7 +235,8 @@ public class TopBookmarksView extends GridView { } public String getDisplayTitle() { - return TextUtils.isEmpty(title) ? url.replaceAll(REGEX_URL_TO_TITLE, "") : title; + return TextUtils.isEmpty(title) ? + StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url, StringUtils.UrlFlags.STRIP_HTTPS)) : title; } } } diff --git a/mobile/android/base/util/StringUtils.java b/mobile/android/base/util/StringUtils.java index 129d32c4d6c0..99eaf217e152 100644 --- a/mobile/android/base/util/StringUtils.java +++ b/mobile/android/base/util/StringUtils.java @@ -47,7 +47,16 @@ public class StringUtils { return wasSearchQuery; } + public static class UrlFlags { + public static final int NONE = 0; + public static final int STRIP_HTTPS = 1; + } + public static String stripScheme(String url) { + return stripScheme(url, UrlFlags.NONE); + } + + public static String stripScheme(String url, int flags) { if (url == null) { return url; } @@ -57,6 +66,8 @@ public class StringUtils { if (url.startsWith("http://")) { start = 7; + } else if (url.startsWith("https://") && flags == UrlFlags.STRIP_HTTPS) { + start = 8; } if (url.endsWith("/")) {