Bug 1362774 - Reduce flickering of the tab title when opening tabs and loading pages. r?florian draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Thu, 17 Aug 2017 01:44:20 -0700
changeset 648142 4d10716dc6b01314b5bcad5c6f5a027de9fbf96b
parent 647200 4e93516e92e58d166ad37b8544c3230024afb587
child 726720 cb3959c49e2bd05506b8cfddc75a547a6dfeeb05
push id74639
push userbmo:gandalf@aviary.pl
push dateThu, 17 Aug 2017 09:00:48 +0000
reviewersflorian
bugs1362774
milestone57.0a1
Bug 1362774 - Reduce flickering of the tab title when opening tabs and loading pages. r?florian MozReview-Commit-ID: 70Xwj38HJqd
browser/base/content/tabbrowser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -825,17 +825,20 @@
                   let findBar = this.mTabBrowser.getFindBar(this.mTab);
 
                   // Close the Find toolbar if we're in old-style TAF mode
                   if (findBar.findMode != findBar.FIND_NORMAL) {
                     findBar.close();
                   }
                 }
 
-                this.mTabBrowser.setTabTitle(this.mTab);
+                let uri = this.mTab.linkedBrowser.currentURI.spec;
+                if (!isBlankPageURL(uri) && !uri.startsWith('about:')) {
+                  this.mTabBrowser.setTabTitle(this.mTab);
+                }
 
                 // Don't clear the favicon if this tab is in the pending
                 // state, as SessionStore will have set the icon for us even
                 // though we're pointed at an about:blank. Also don't clear it
                 // if onLocationChange was triggered by a pushState or a
                 // replaceState (bug 550565) or a hash change (bug 408415).
                 if (!this.mTab.hasAttribute("pending") &&
                     aWebProgress.isLoadingDocument &&
@@ -1460,23 +1463,16 @@
           }
           this._tabAttrModified(tab, ["sharing"]);
 
           if (aBrowser == this.mCurrentBrowser)
             gIdentityHandler.updateSharingIndicator();
         ]]></body>
       </method>
 
-
-      <!-- TODO: remove after 57, once we know add-ons can no longer use it. -->
-      <method name="setTabTitleLoading">
-        <parameter name="aTab"/>
-        <body/>
-      </method>
-
       <method name="setInitialTabTitle">
         <parameter name="aTab"/>
         <parameter name="aTitle"/>
         <parameter name="aOptions"/>
         <body><![CDATA[
           if (aTitle) {
             if (!aTab.getAttribute("label")) {
               aTab._labelIsInitialTitle = true;
@@ -1499,47 +1495,43 @@
             if (aTab._labelIsInitialTitle) {
               if (!title) {
                 return false;
               }
               delete aTab._labelIsInitialTitle;
             }
 
             let isContentTitle = false;
-            if (title) {
-              isContentTitle = true;
-            } else if (aTab.hasAttribute("customizemode")) {
+            let uri = aTab.linkedBrowser.currentURI.spec;
+            if (aTab.hasAttribute("customizemode")) {
               let brandBundle = document.getElementById("bundle_brand");
               let brandShortName = brandBundle.getString("brandShortName");
               title = gNavigatorBundle.getFormattedString("customizeMode.tabTitle",
                                                           [ brandShortName ]);
+            } else if (isBlankPageURL(uri)) {
+              title = this.mStringBundle.getString("tabs.emptyTabTitle");
+            } else if (title) {
               isContentTitle = true;
             } else {
-              if (browser.currentURI.displaySpec) {
-                try {
-                  title = this.mURIFixup.createExposableURI(browser.currentURI).displaySpec;
-                } catch (ex) {
-                  title = browser.currentURI.displaySpec;
-                }
+              let readableUri;
+              try {
+                readableUri = this.mURIFixup.createExposableURI(uri).displaySpec;
+              } catch (ex) {
+                readableUri = uri;
               }
-
-              if (title && !isBlankPageURL(title)) {
-                // At this point, we now have a URI.
-                // Let's try to unescape it using a character set
-                // in case the URI is not ASCII.
-                try {
-                  var characterSet = browser.characterSet;
-                  const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
-                                                 .getService(Components.interfaces.nsITextToSubURI);
-                  title = textToSubURI.unEscapeNonAsciiURI(characterSet, title);
-                } catch (ex) { /* Do nothing. */ }
-              } else {
-                // Still no title? Fall back to our untitled string.
-                title = this.mStringBundle.getString("tabs.emptyTabTitle");
-              }
+              // At this point, we now have a URI.
+              // Let's try to unescape it using a character set
+              // in case the URI is not ASCII.
+              try {
+                var characterSet = browser.characterSet;
+                const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
+                                               .getService(Components.interfaces.nsITextToSubURI);
+                readableUri = textToSubURI.unEscapeNonAsciiURI(characterSet, readableUri);
+              } catch (ex) { /* Do nothing. */ }
+              title = radableUri;
             }
 
             return this._setTabLabel(aTab, title, { isContentTitle });
           ]]>
         </body>
       </method>
 
       <method name="_setTabLabel">
@@ -2458,19 +2450,16 @@
               aURI = "about:blank";
             }
 
             var uriIsAboutBlank = aURI == "about:blank";
 
             if (!aNoInitialLabel) {
               if (isBlankPageURL(aURI)) {
                 t.setAttribute("label", this.mStringBundle.getString("tabs.emptyTabTitle"));
-              } else {
-                // Set URL as label so that the tab isn't empty initially.
-                this.setInitialTabTitle(t, aURI, { beforeTabOpen: true });
               }
             }
 
             if (aIsPrerendered) {
               t.setAttribute("hidden", "true");
             }
 
             // Related tab inherits current tab's user context unless a different
@@ -5934,17 +5923,16 @@
       <constructor>
         <![CDATA[
           this.mTabClipWidth = Services.prefs.getIntPref("browser.tabs.tabClipWidth");
 
           let { restoreTabsButton } = this;
           restoreTabsButton.setAttribute("label", this.tabbrowser.mStringBundle.getString("tabs.restoreLastTabs"));
 
           var tab = this.firstChild;
-          tab.label = this.tabbrowser.mStringBundle.getString("tabs.emptyTabTitle");
           tab.setAttribute("onerror", "this.removeAttribute('image');");
 
           window.addEventListener("resize", this);
           window.addEventListener("load", this);
 
           Services.prefs.addObserver("privacy.userContext", this);
           this.observe(null, "nsPref:changed", "privacy.userContext.enabled");