Bug 657961 - Use async API to get favicons for site permissions page. r=sdwilsh
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 24 May 2011 10:34:30 -0400
changeset 70134 a0dc4a9ff450ac0ccc4c336402d58b28f3caa416
parent 70133 4b1200504a4c9096b679c966be70904977a4dc37
child 70135 063f67e146ece440016fedabd447df4b6c1425fc
push id20198
push userdgottwald@mozilla.com
push dateWed, 25 May 2011 06:51:36 +0000
treeherdermozilla-central@059d3632e2c4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh
bugs657961
milestone7.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 657961 - Use async API to get favicons for site permissions page. r=sdwilsh
browser/components/preferences/aboutPermissions.js
browser/themes/gnomestripe/browser/preferences/aboutPermissions.css
browser/themes/pinstripe/browser/preferences/aboutPermissions.css
browser/themes/winstripe/browser/preferences/aboutPermissions.css
--- a/browser/components/preferences/aboutPermissions.js
+++ b/browser/components/preferences/aboutPermissions.js
@@ -76,39 +76,39 @@ let TEST_EXACT_PERM_TYPES = ["geo"];
  * Site object represents a single site, uniquely identified by a host.
  */
 function Site(host) {
   this.host = host;
   this.listitem = null;
 
   this.httpURI = NetUtil.newURI("http://" + this.host);
   this.httpsURI = NetUtil.newURI("https://" + this.host);
-
-  this._favicon = "";
 }
 
 Site.prototype = {
   /**
-   * Gets the favicon to use for the site. This will return the default favicon
-   * if there is no favicon stored for the site.
+   * Gets the favicon to use for the site. The callback only gets called if
+   * a favicon is found for either the http URI or the https URI.
    *
-   * @return A favicon image URL.
+   * @param aCallback
+   *        A callback function that takes a favicon image URL as a parameter.
    */
-  get favicon() {
-    if (!this._favicon) {
-      // TODO: Bug 657961: Make this async when bug 655270 is fixed.
+  getFavicon: function Site_getFavicon(aCallback) {
+    function faviconDataCallback(aURI, aDataLen, aData, aMimeType) {
       try {
-        // First try to see if a favicon is stored for the http URI.
-        this._favicon = gFaviconService.getFaviconForPage(this.httpURI).spec;
+        aCallback(aURI.spec);
       } catch (e) {
-        // getFaviconImageForPage returns the default favicon if no stored favicon is found.
-        this._favicon = gFaviconService.getFaviconImageForPage(this.httpsURI).spec;
+        Cu.reportError("AboutPermissions: " + e);
       }
     }
-    return this._favicon;
+
+    // Try to find favicion for both URIs. Callback will only be called if a
+    // favicon URI is found, so this means we'll always prefer the https favicon.
+    gFaviconService.getFaviconURLForPage(this.httpURI, faviconDataCallback);
+    gFaviconService.getFaviconURLForPage(this.httpsURI, faviconDataCallback);
   },
 
   /**
    * Gets the number of history visits for the site.
    *
    * @param aCallback
    *        A function that takes the visit count (a number) as a parameter.
    */
@@ -537,17 +537,20 @@ let AboutPermissions = {
    *
    * @param aSite
    *        A Site object.
    */
   addToSitesList: function(aSite) {
     let item = document.createElement("richlistitem");
     item.setAttribute("class", "site");
     item.setAttribute("value", aSite.host);
-    item.setAttribute("favicon", aSite.favicon);
+
+    aSite.getFavicon(function(aURL) {
+      item.setAttribute("favicon", aURL);
+    });
     aSite.listitem = item;
 
     this.sitesList.appendChild(item);    
   },
 
   /**
    * Hides sites in richlistbox based on search text in sites-filter textbox.
    */
--- a/browser/themes/gnomestripe/browser/preferences/aboutPermissions.css
+++ b/browser/themes/gnomestripe/browser/preferences/aboutPermissions.css
@@ -27,16 +27,21 @@
   padding: 4px;
   border-bottom: 1px solid ThreeDLightShadow;
 }
 
 .site-favicon {
   height: 16px;
   width: 16px;
   -moz-margin-end: 4px;
+  list-style-image: url("chrome://mozapps/skin/places/defaultFavicon.png");
+}
+
+#all-sites-item > .site-container > .site-favicon {
+  list-style-image: none;
 }
 
 .site-domain {
   max-width: 200px; /* crop set in XBL will ellipsize the domain if it's too long */
 }
 
 /* permissions box */
 
--- a/browser/themes/pinstripe/browser/preferences/aboutPermissions.css
+++ b/browser/themes/pinstripe/browser/preferences/aboutPermissions.css
@@ -29,16 +29,21 @@
   padding: 4px;
   border-bottom: 1px solid ThreeDLightShadow;
 }
 
 .site-favicon {
   height: 16px;
   width: 16px;
   -moz-margin-end: 4px;
+  list-style-image: url("chrome://mozapps/skin/places/defaultFavicon.png");
+}
+
+#all-sites-item > .site-container > .site-favicon {
+  list-style-image: none;
 }
 
 .site-domain {
   max-width: 200px; /* crop set in XBL will ellipsize the domain if it's too long */
 }
 
 /* permissions box */
 
--- a/browser/themes/winstripe/browser/preferences/aboutPermissions.css
+++ b/browser/themes/winstripe/browser/preferences/aboutPermissions.css
@@ -32,16 +32,21 @@
   padding: 4px;
   border-bottom: 1px solid ThreeDLightShadow;
 }
 
 .site-favicon {
   height: 16px;
   width: 16px;
   -moz-margin-end: 4px;
+  list-style-image: url("chrome://mozapps/skin/places/defaultFavicon.png");
+}
+
+#all-sites-item > .site-container > .site-favicon {
+  list-style-image: none;
 }
 
 .site-domain {
   max-width: 200px; /* crop set in XBL will ellipsize the domain if it's too long */
 }
 
 /* permissions box */