Bug 1401955 - Prevent favicon flickering on about:home and about:newtab. r=florian draft
authorJohann Hofmann <jhofmann@mozilla.com>
Sat, 18 Nov 2017 15:19:46 +0100
changeset 700157 1c887d035d031b5f2367d4599d18d4066282bbd5
parent 699096 a3f183201f7f183c263d554bfb15fbf0b0ed2ea4
child 740791 b069332bc5afa869dd709a0b777a1a19ec8291c3
push id89746
push userbmo:jhofmann@mozilla.com
push dateSat, 18 Nov 2017 15:07:41 +0000
reviewersflorian
bugs1401955
milestone59.0a1
Bug 1401955 - Prevent favicon flickering on about:home and about:newtab. r=florian This sets the hardcoded favicon paths before painting the tab or window to ensure they're painted right away. MozReview-Commit-ID: 5V3gQP7XkNP
browser/base/content/browser.js
browser/base/content/tabbrowser.xml
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1347,16 +1347,24 @@ var gBrowserInit = {
         gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, tabToOpen);
       } catch (e) {
         Cu.reportError(e);
       }
     }
 
     this._setInitialFocus();
 
+    // Hack to ensure that the about:home favicon is loaded
+    // instantaneously, to avoid flickering and improve perceived performance.
+    this._uriToLoadPromise.then(uriToLoad => {
+      if (uriToLoad == "about:home") {
+        gBrowser.setIcon(gBrowser.selectedTab, "chrome://branding/content/icon32.png");
+      }
+    });
+
     // Wait until chrome is painted before executing code not critical to making the window visible
     this._boundDelayedStartup = this._delayedStartup.bind(this);
     window.addEventListener("MozAfterPaint", this._boundDelayedStartup);
 
     this._loadHandled = true;
   },
 
   _cancelDelayedStartup() {
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -832,17 +832,18 @@
                     let inLoadURI = this.mBrowser.inLoadURI;
                     if (this.mTab.selected && gURLBar && !inLoadURI) {
                       URLBarSetURI();
                     }
                   } else if (isSuccessful) {
                     this.mBrowser.urlbarChangeTracker.finishedLoad();
                   }
 
-                  if (!this.mBrowser.mIconURL) {
+                  // Ignore initial about:blank to prevent flickering.
+                  if (!this.mBrowser.mIconURL && !ignoreBlank) {
                     this.mTabBrowser.useDefaultIcon(this.mTab);
                   }
                 }
 
                 // For keyword URIs clear the user typed value since they will be changed into real URIs
                 if (location.scheme == "keyword")
                   this.mBrowser.userTypedValue = null;
 
@@ -2842,16 +2843,22 @@
                 this._tabFilters.delete(t);
                 this._tabListeners.delete(t);
                 let notificationbox = this.getNotificationBox(t.linkedBrowser);
                 notificationbox.remove();
               }
               throw e;
             }
 
+            // Hack to ensure that the about:newtab favicon is loaded
+            // instantaneously, to avoid flickering and improve perceived performance.
+            if (aURI == BROWSER_NEW_TAB_URL) {
+              this.setIcon(t, "chrome://branding/content/icon32.png");
+            }
+
             // Dispatch a new tab notification.  We do this once we're
             // entirely done, so that things are in a consistent state
             // even if the event listener opens or closes tabs.
             var detail = aEventDetail || {};
             var evt = new CustomEvent("TabOpen", { bubbles: true, detail });
             t.dispatchEvent(evt);
 
             if (!usingPreloadedContent && aOriginPrincipal && aURI) {