Bug 1422903 - Prevent about:privatebrowsing favicon from flickering. r=florian draft
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 13 Dec 2017 05:55:10 -0600
changeset 714053 12a6ed0973013ed68e783ca3d39a9492c5185411
parent 713998 5b1fdaa14d35ddf1a638c9422786ede707cacf1f
child 744503 3eccaf5ccf1acf4e0fb08a542784aed655c9665c
push id93829
push userbmo:jhofmann@mozilla.com
push dateThu, 21 Dec 2017 16:54:34 +0000
reviewersflorian
bugs1422903
milestone59.0a1
Bug 1422903 - Prevent about:privatebrowsing favicon from flickering. r=florian We apply a custom workaround to show about:home and about:newtab favicons as early as possible for perceived performance, but didn't previously consider the about:privatebrowsing page (which can act as both about:home and about:newtab). MozReview-Commit-ID: gPiV08h0j0
browser/base/content/browser.js
browser/base/content/tabbrowser.xml
browser/components/privatebrowsing/content/aboutPrivateBrowsing.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1341,16 +1341,18 @@ var gBrowserInit = {
 
     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");
+      } else if (uriToLoad == "about:privatebrowsing") {
+        gBrowser.setIcon(gBrowser.selectedTab, "chrome://browser/skin/privatebrowsing/favicon.svg");
       }
     });
 
     // 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;
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -796,17 +796,26 @@
                       URLBarSetURI();
                     }
                   } else if (isSuccessful) {
                     this.mBrowser.urlbarChangeTracker.finishedLoad();
                   }
 
                   // Ignore initial about:blank to prevent flickering.
                   if (!this.mBrowser.mIconURL && !ignoreBlank) {
-                    this.mTabBrowser.useDefaultIcon(this.mTab);
+                    // Don't switch to the default icon on about:home or about:newtab,
+                    // since these pages get their favicon set in browser code to
+                    // improve perceived performance.
+                    let isNewTab = originalLocation &&
+                      (originalLocation.spec == "about:newtab" ||
+                       originalLocation.spec == "about:privatebrowsing" ||
+                       originalLocation.spec == "about:home");
+                    if (!isNewTab) {
+                      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;
 
                 if (this.mTab.selected)
@@ -2808,18 +2817,20 @@
                 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) {
+            if (aURI == "about:newtab") {
               this.setIcon(t, "chrome://branding/content/icon32.png");
+            } else if (aURI == "about:privatebrowsing") {
+              this.setIcon(t, "chrome://browser/skin/privatebrowsing/favicon.svg");
             }
 
             // 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);
--- a/browser/components/privatebrowsing/content/aboutPrivateBrowsing.js
+++ b/browser/components/privatebrowsing/content/aboutPrivateBrowsing.js
@@ -4,17 +4,16 @@
 
 var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const FAVICON_QUESTION = "chrome://global/skin/icons/question-32.png";
-const FAVICON_PRIVACY = "chrome://browser/skin/privatebrowsing/favicon.svg";
 
 var stringBundle = Services.strings.createBundle(
                     "chrome://browser/locale/aboutPrivateBrowsing.properties");
 
 var prefBranch = Services.prefs.getBranch("privacy.trackingprotection.");
 var prefObserver = {
  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                         Ci.nsISupportsWeakReference]),
@@ -33,20 +32,16 @@ var prefObserver = {
    title.classList.toggle("hide", trackingEnabled);
    titleTracking.classList.toggle("hide", !trackingEnabled);
    tpSubHeader.classList.toggle("tp-off", !trackingEnabled);
  }
 };
 prefBranch.addObserver("pbmode.enabled", prefObserver, true);
 prefBranch.addObserver("enabled", prefObserver, true);
 
-function setFavIcon(url) {
- document.getElementById("favicon").setAttribute("href", url);
-}
-
 document.addEventListener("DOMContentLoaded", function() {
  if (!PrivateBrowsingUtils.isContentWindowPrivate(window)) {
    document.documentElement.classList.remove("private");
    document.documentElement.classList.add("normal");
    document.title = stringBundle.GetStringFromName("title.normal");
    document.getElementById("favicon")
            .setAttribute("href", FAVICON_QUESTION);
    document.getElementById("startPrivateBrowsing")
@@ -55,18 +50,16 @@ document.addEventListener("DOMContentLoa
  }
 
  let tpToggle = document.getElementById("tpToggle");
  document.getElementById("tpButton").addEventListener("click", () => {
    tpToggle.click();
  });
 
  document.title = stringBundle.GetStringFromName("title.head");
- document.getElementById("favicon")
-         .setAttribute("href", FAVICON_PRIVACY);
  tpToggle.addEventListener("change", toggleTrackingProtection);
  document.getElementById("startTour")
          .addEventListener("click", dontShowIntroPanelAgain);
 
  document.getElementById("startTour").setAttribute("href",
    Services.urlFormatter.formatURLPref("privacy.trackingprotection.introURL"));
  document.getElementById("learnMore").setAttribute("href",
    Services.urlFormatter.formatURLPref("app.support.baseURL") + "private-browsing");