Bug 728142 - Replace old synchronous favicons calls in tabview. r=ttaubert
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Thu, 12 Apr 2012 12:27:27 +0200
changeset 91530 308e3b7254b397b8837131ac5c6782f85d7a6636
parent 91529 1a445c628b535e303f5b61d52af78bf9deed30b4
child 91531 27616988a4a1489faac211601cd6494b699b0a1b
push id22455
push usermak77@bonardo.net
push dateFri, 13 Apr 2012 10:41:14 +0000
treeherdermozilla-central@9c81a70ddb1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert
bugs728142
milestone14.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 728142 - Replace old synchronous favicons calls in tabview. r=ttaubert
browser/components/tabview/test/browser_tabview_bug600645.js
browser/components/tabview/ui.js
--- a/browser/components/tabview/test/browser_tabview_bug600645.js
+++ b/browser/components/tabview/test/browser_tabview_bug600645.js
@@ -1,11 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+/**
+ * This file tests that, when there is an app tab that references an invalid
+ * favicon, the default favicon appears the group app tab tray, instead of an
+ * empty image that would not be visible.
+ */
+
 const fi = Cc["@mozilla.org/browser/favicon-service;1"].
            getService(Ci.nsIFaviconService);
 
 let newTab;
 
 function test() {
   waitForExplicitFinish();
 
@@ -35,28 +41,30 @@ function onTabPinned() {
   let errorHandler = function(event) {
     newTab.removeEventListener("error", errorHandler, false);
 
     // since the browser code and test code are invoked when an error event is 
     // fired, a delay is used here to avoid the test code run before the browser 
     // code.
     executeSoon(function() {
       let iconSrc = $icon.attr("src");
-      let hasData = true;
-      try {
-        fi.getFaviconDataAsDataURL(iconSrc);
-      } catch(e) {
-        hasData = false;
-      }
-      ok(!hasData, "The icon src doesn't return any data");
+
       // with moz-anno:favicon automatically redirects to the default favIcon 
       // if the given url is invalid
       ok(/^moz-anno:favicon:/.test(iconSrc),
          "The icon url starts with moz-anno:favicon so the default fav icon would be displayed");
 
+      // At this point, as an additional integrity check we could also verify
+      // that the iconSrc URI does not have any associated favicon data.  This
+      // kind of check, however, is not easily supported by the asynchronous
+      // favicon API.  Fortunately, the fact that we received the error event
+      // already indicates that the original favicon was not available.
+      // Morevover, since we are using a "moz-anno:favicon:" URI, we know that
+      // we'll not display an empty icon, but the default favicon.
+
       // clean up
       gBrowser.removeTab(newTab);
       let endGame = function() {
         window.removeEventListener("tabviewhidden", endGame, false);
 
         ok(!TabView.isVisible(), "Tab View is hidden");
         finish();
       }
--- a/browser/components/tabview/ui.js
+++ b/browser/components/tabview/ui.js
@@ -1690,36 +1690,44 @@ let UI = {
         Services.prefs.getBoolPref(this.PREF_CHROME_FAVICONS);
 
     return (this._prefFavicons && ("schemeIs" in uri) &&
             (uri.schemeIs("http") || uri.schemeIs("https")));
   },
 
   // ----------
   // Function: getFavIconUrlForTab
-  // Gets fav icon url for the given xul:tab.
+  // Gets the "favicon link URI" for the given xul:tab, or null if unavailable.
   getFavIconUrlForTab: function UI_getFavIconUrlForTab(tab, callback) {
     this._isImageDocument(tab, function(isImageDoc) {
       if (isImageDoc) {
         callback(tab.pinned ? tab.image : null);
       } else {
         let tabImage = tab.image;
         if (tabImage) {
           // if starts with http/https, fetch icon from favicon service via the moz-anno protocal
           if (/^https?:/.test(tabImage))
             tabImage = gFavIconService.getFaviconLinkForIcon(gWindow.makeURI(tab.image)).spec;
 
           callback(tabImage);
         } else {
-          // determine to load the default/cached icon or not and also ensure we don't show the default icon
-          // for about:-style error pages
-          let url = null;
-          if (this._shouldLoadFavIcon(tab))
-            url = gFavIconService.getFaviconImageForPage(tab.linkedBrowser.currentURI).spec;
-          callback(url);
+          // ensure we don't show the default icon for about:-style error pages
+          if (!this._shouldLoadFavIcon(tab)) {
+            callback(null);
+          } else {
+            // determine to load the default/cached icon or not
+            gFavIconService.getFaviconURLForPage(tab.linkedBrowser.currentURI,
+              function (uri) {
+                if (!uri) {
+                  callback(gFavIconService.defaultFavicon.spec);
+                } else {
+                  callback(gFavIconService.getFaviconLinkForIcon(uri).spec);
+                }
+              });
+          }
         }
       }
     }.bind(this));
   },
 
   // ----------
   // Function: notifySessionRestoreEnabled
   // Notify the user that session restore has been automatically enabled