Bug 1524857 - Part 2: Use display URI's base domain for domain highlighting. r=snorp
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 07 Feb 2019 19:21:45 +0000
changeset 457659 f110ae482730f491e621bae28ee5bb145d127670
parent 457658 d32c9ce0d3661194e8f6d850e52e6b794f24b05e
child 457660 22322a39835a1c9dd514ddcfa46452a8f285117a
push id35516
push userrmaries@mozilla.com
push dateFri, 08 Feb 2019 04:23:26 +0000
treeherdermozilla-central@d599d1a73a3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1524857, 1479311
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1524857 - Part 2: Use display URI's base domain for domain highlighting. r=snorp 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,