Bug 1524857 - Part 2: Use display URI's base domain for domain highlighting. r=snorp a=lizzard
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 07 Feb 2019 19:21:45 +0000
changeset 512993 8b10cbe1b8877f492a4d54bb7c6f5fe03b4016b2
parent 512992 7c5414a3d4b04aa772211fb9aca5b2f7f038992d
child 512994 a5b7aa318e6101a6ebe071bbf374c36f5e9d9b90
push id10672
push usernbeleuzu@mozilla.com
push dateMon, 11 Feb 2019 16:55:03 +0000
treeherdermozilla-beta@95b884dcbd6f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, lizzard
bugs1524857, 1479311
milestone66.0
Bug 1524857 - Part 2: Use display URI's base domain for domain highlighting. r=snorp a=lizzard That way, domain highlighting (and therefore the URL justification code that right-justifies the TLD within the URL bar) can run even on error pages. This also means that the workaround from bug 1479311 for blocking javascript: URIs from being highlighted in ToolbarDisplayLayout is no longer required - the base domain for domain highlighting is now being generated from the same URI that actually ends up being displayed in the URL bar, and as such the existing checks in browser.js for only generating a base domain for HTTP(S)/ FTP-URIs, but not any other schemes, finally work the way they are intended. Differential Revision: https://phabricator.services.mozilla.com/D18587
mobile/android/base/java/org/mozilla/gecko/Tab.java
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
--- a/mobile/android/base/java/org/mozilla/gecko/Tab.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tab.java
@@ -44,16 +44,17 @@ public class Tab {
     private static final String LOGTAG = "GeckoTab";
 
     private static Pattern sColorPattern;
     private final int mId;
     private final BrowserDB mDB;
     private long mLastUsed;
     private String mUrl;
     private String mBaseDomain;
+    private String mHighlightDomain;
     private String mUserRequested; // The original url requested. May be typed by the user or sent by an extneral app for example.
     private String mTitle;
     private Bitmap mFavicon;
     private String mFaviconUrl;
     private String mApplicationId; // Intended to be null after explicit user action.
 
     private IconRequestBuilder mIconRequestBuilder;
     private Future<IconResponse> mRunningIconRequest;
@@ -129,16 +130,17 @@ public class Tab {
     }
 
     public Tab(Context context, int id, String url, boolean external, int parentId, String title) {
         mAppContext = context.getApplicationContext();
         mDB = BrowserDB.from(context);
         mId = id;
         mUrl = url;
         mBaseDomain = "";
+        mHighlightDomain = "";
         mUserRequested = "";
         mExternal = external;
         mParentId = parentId;
         mTitle = title == null ? "" : title;
         mSiteIdentity = new SiteIdentity();
         mContentType = "";
         mState = shouldShowProgress(url) ? STATE_LOADING : STATE_SUCCESS;
         mLoadProgress = LOAD_PROGRESS_INIT;
@@ -202,23 +204,30 @@ public class Tab {
         if (mTitle != null && mTitle.length() > 0) {
             return mTitle;
         }
 
         return mUrl;
     }
 
     /**
-     * Returns the base domain of the loaded uri. Note that if the page is
-     * a Reader mode uri, the base domain returned is that of the original uri.
+     * Returns the base domain based on the node principal of the loaded document. Note that if the
+     * page is a Reader mode URI, the base domain returned is that of the original URI.
      */
     public String getBaseDomain() {
         return mBaseDomain;
     }
 
+    /**
+     * Return the base domain based on the display URI used in the URL bar.
+     */
+    public String getHighlightDomain() {
+        return mHighlightDomain;
+    }
+
     public Bitmap getFavicon() {
         return mFavicon;
     }
 
     protected String getApplicationId() {
         return mApplicationId;
     }
 
@@ -651,16 +660,17 @@ public class Tab {
             // Notify listeners so that buttons like back or forward will update themselves
             Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, oldUrl);
             return;
         }
 
         setContentType(message.getString("contentType"));
         updateUserRequested(message.getString("userRequested"));
         mBaseDomain = message.getString("baseDomain", "");
+        mHighlightDomain = message.getString("highlightDomain", "");
 
         setHasFeeds(false);
         setManifestUrl(null);
         setHasOpenSearch(false);
         mSiteIdentity.reset();
         setSiteLogins(null);
         setHasTouchListeners(false);
         setErrorType(ErrorType.NONE);
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -301,17 +301,17 @@ public class ToolbarDisplayLayout extend
                     : mBlockedColorSpan;
             builder.setSpan(fgColorSpan, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
 
             setTitle(builder);
             setContentDescription(null);
             return;
         }
 
-        final String baseDomain = tab.getBaseDomain();
+        final String baseDomain = tab.getHighlightDomain();
 
         String strippedURL = stripAboutReaderURL(url);
 
         if (mPrefs.shouldTrimUrls()) {
             strippedURL = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(strippedURL));
         }
 
         // The URL bar does not support RTL currently (See bug 928688 and meta bug 702845).
@@ -330,17 +330,17 @@ public class ToolbarDisplayLayout extend
 
     private void updateAndColorTitleFromFullURL(String url, String baseDomain, boolean isPrivate) {
         if (TextUtils.isEmpty(baseDomain)) {
             setTitle(url);
             return;
         }
 
         int index = url.indexOf(baseDomain);
-        if (index == -1 || url.startsWith("javascript:")) {
+        if (index == -1) {
             setTitle(url);
             return;
         }
 
         final SpannableStringBuilder builder = new SpannableStringBuilder(url);
 
         builder.setSpan(isPrivate ? mPrivateUrlColorSpan : mUrlColorSpan, 0, url.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
         builder.setSpan(isPrivate ? mPrivateDomainColorSpan : mDomainColorSpan,