MozillaZine

how to use mozIAsyncFavicons interface?

Talk about add-ons and extension development.
lastdream2013
 
Posts: 4
Joined: May 5th, 2013, 10:38 pm

Post Posted May 6th, 2013, 1:30 am

I use this API to export fake internal faviconURI to icon base64 code:
Code: Select all
  getFaviconBase64 : function(uri) {
      var faviconURI = NetUtil.newURI(uri);
      if ( PlacesUtils.favicons.getFaviconDataAsDataURL )
         return  PlacesUtils.favicons.getFaviconDataAsDataURL(faviconURI);
      else if ( PlacesUtils.favicons.getFaviconData ) {
         var aMimeType = {};
         var aData = PlacesUtils.favicons.getFaviconData(faviconURI, aMimeType, {});
         return 'data:' + aMimeType.value + ';base64,' + btoa(String.fromCharCode.apply(null, aData));
      }
     else {
                /* how to do under firefox 23a1? */
      return;
       }
   },


for example:
ICON_FAKE_URI: "http://www.mozilla.org/2005/made-up-favicon/3-1366822463005"
getFaviconBase64 can export ICON_FAKE_URI to icon_base64_data:
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACAElEQVQ4jaXQP2gaARzF8V9JoYMdjFcogdKCq5NQG4UDIYJOdjluENQSSkSOQpa0W0ICCUeGdD3xUJBcPBN6YP0zZAsJbcE2t8g1Qj3CgSDJUAiF4nHV10UyKQHz3d9neETjPB7Ps5WVlZwsy72jo6N/29vb3ziOe09ELrqrYDD4ulwu/766usJoNMJoNIJt2zg9PYUkST9dLtfTqeP5+fnniqL86fV6t+PhcAjHcWBZFvb397G5ufl5KpDJZD4Wi0VUq1Xc3NzcIo7j4Pj4GLlcDqIoDhcWFl5MBNbW1r4mk0mIooiTkxMMBgPYtg1d17G7u4v19XWk02nE4/HENOA8lUpBlmVUKhXouo5ut4tarYaDgwOUSiUIggCe599OBLLZrJxIJKBpGs7OzmCaJvr9PjqdDlqtFur1OnZ2dhAKhSITAb/fH15dXYUkSTAMA5Zl4fr6GpeXlzAMA4qioFAo9Ijo0dQjBUGQtra20Gw2cXFxAdM00W630Wg0oKoqNjY2ylPH4x7wPP9OluW+qqo4PDyEpmnI5/O/YrHYh729vb+RSOQTET25C3ro8/leLS0t8V6v9yURzRERMQyTXl5edsLh8DkRMXchE2MY5g3HcQ7LsvdC0tFo1FlcXPxBRJ6ZEZZlnUAg8J2I3DMhbrc77fP5vhDR45mAcXNERP8Bl14gWgfFzO0AAAAASUVORK5CYII="

viewtopic.php?f=19&t=2649539
The following APIs will be removed: (replaced by mozIAsyncFavicons)
nsIFaviconService::getFaviconData
nsIFaviconService::getFaviconDataAsDataURL
As this two APIS don't works under lastest firefox23a1, I searched "mozIAsyncFavicons" and can't found only API or interface works. Could someone tell me how to do under firefox 23a1?

Infocatcher

User avatar
 
Posts: 255
Joined: July 1st, 2007, 3:45 am

Post Posted May 6th, 2013, 2:00 am

https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/mozIAsyncFavicons
=> http://mxr.mozilla.org/mozilla-central/source/toolkit/components/places/mozIAsyncFavicons.idl#162

Code: Select all
//var faviconService = Components.classes["@mozilla.org/browser/favicon-service;1"]
//   .getService(Components.interfaces.mozIAsyncFavicons);
var faviconService = PlacesUtils.favicons;
faviconService.getFaviconDataForPage(
   Services.io.newURI("https://developer.mozilla.org/en-US/", null, null),
   {
      onComplete: function(aURI, aDataLen, aData, aMimeType) {
         alert('data:' + aMimeType + ';base64,' + btoa(String.fromCharCode.apply(null, aData)));
      }
   }
);
This game has no name. It will never be the same. ©

lastdream2013
 
Posts: 4
Joined: May 5th, 2013, 10:38 pm

Post Posted May 6th, 2013, 8:22 am

thanks a lot.
I tried your method, it works on an internet url well but still can't export internal fake favicon url like this:"moz-anno:favicon:http://www.mozilla.org/2005/made-up-favicon/3-1366822463005" ,

lithopsian
 
Posts: 3664
Joined: September 15th, 2010, 9:03 am

Post Posted May 6th, 2013, 2:30 pm

Can't find it documented anywhere, but this is how you call getFaviconDataForPage() now:
https://bugzilla.mozilla.org/show_bug.cgi?id=737133#c14

lastdream2013
 
Posts: 4
Joined: May 5th, 2013, 10:38 pm

Post Posted May 7th, 2013, 12:23 am

lithopsian wrote:Can't find it documented anywhere, but this is how you call getFaviconDataForPage() now:
https://bugzilla.mozilla.org/show_bug.cgi?id=737133#c14


I tried but getFaviconDataForPage() don't works at internal fake faviconURI at all,callback result aDataLen is 0, "moz-anno:favicon:http://www.mozilla.org/2005/made-up-favicon/3-1366822463005"
this internal fake faviconURI is created by firefox and stored in places.sqlite for some special bookmark items,

Infocatcher

User avatar
 
Posts: 255
Joined: July 1st, 2007, 3:45 am

Post Posted May 7th, 2013, 4:17 am

Strange. Looks like bug.
Anyway you can try to use something like following:
https://addons.mozilla.org/files/browse/204430/file/components/CustomButtonsService.js#L210

Code: Select all
function ImageConverter (imageURL)
{
   this. imageURL = imageURL;
   this. channel = Services.io.newChannel(imageURL, null, null);
   this. channel. notificationCallbacks = this;
   this. channel. asyncOpen (this, null);
}
ImageConverter. prototype =
   {
      topic: "",
      id: "",
      imageURL: "",
      countRead: null,
      channel: null,
      bytes: [],
      stream: null,
      data: "",

      // nsISupports
      QueryInterface: function (iid)
      {
         if (!iid. equals (Components. interfaces. nsISupports) &&
            !iid. equals (Components. interfaces. nsIInterfaceRequestor) &&
            !iid. equals (Components. interfaces. nsIRequestObserver) &&
            !iid. equals (Components. interfaces. nsIStreamListener) &&
            !iid. equals (Components. interfaces. nsIProgressEventSink))
         {
            throw Components. results. NS_ERROR_NO_INTERFACE;
         }
         return this;
      },

      // nsIInterfaceRequestor
      getInterface: function (iid)
      {
         return this. QueryInterface (iid);
      },

      // nsIRequestObserver
      onStartRequest: function (aRequest, aContext)
      {
         this. stream = Components. classes ["@mozilla.org/binaryinputstream;1"]. createInstance (Components. interfaces. nsIBinaryInputStream);
      },

      onStopRequest: function (aRequest, aContext, aStatusCode)
      {
         alert('data:' + this.channel.contentType + ';base64,' + btoa(String.fromCharCode.apply(null, this.bytes)));
      },

      // nsIStreamListener
      onDataAvailable: function (aRequest, aContext, aInputStream, aOffset, aCount)
      {
         this. stream. setInputStream (aInputStream);
         var chunk = this. stream. readByteArray (aCount);
         this. bytes = this. bytes. concat (chunk);
      },

      // nsIProgressEventSink
      onProgress: function (aRequest, aContext, progress, progressMax) {},
      onStatus: function (aRequest, aContext, status, statusArg) {}
   };

new ImageConverter("moz-anno:favicon:http://www.mozilla.org/2005/made-up-favicon/3-1366822463005");


And seems like some code can be removed:
Code: Select all
function ImageConverter (imageURL)
{
   this. imageURL = imageURL;
   this. channel = Services.io.newChannel(imageURL, null, null);
   this. channel. asyncOpen (this, null);
}
ImageConverter. prototype =
   {
      imageURL: "",
      channel: null,
      bytes: [],
      stream: null,

      // nsISupports
      QueryInterface: function (iid)
      {
         if (!iid. equals (Components. interfaces. nsISupports) &&
            !iid. equals (Components. interfaces. nsIRequestObserver) &&
            !iid. equals (Components. interfaces. nsIStreamListener))
         {
            throw Components. results. NS_ERROR_NO_INTERFACE;
         }
         return this;
      },

      // nsIRequestObserver
      onStartRequest: function (aRequest, aContext)
      {
         this. stream = Components. classes ["@mozilla.org/binaryinputstream;1"]. createInstance (Components. interfaces. nsIBinaryInputStream);
      },

      onStopRequest: function (aRequest, aContext, aStatusCode)
      {
         alert('data:' + this.channel.contentType + ';base64,' + btoa(String.fromCharCode.apply(null, this.bytes)));
      },

      // nsIStreamListener
      onDataAvailable: function (aRequest, aContext, aInputStream, aOffset, aCount)
      {
         this. stream. setInputStream (aInputStream);
         var chunk = this. stream. readByteArray (aCount);
         this. bytes = this. bytes. concat (chunk);
      }
   };

new ImageConverter("moz-anno:favicon:http://www.mozilla.org/2005/made-up-favicon/3-1366822463005");
This game has no name. It will never be the same. ©

lastdream2013
 
Posts: 4
Joined: May 5th, 2013, 10:38 pm

Post Posted May 8th, 2013, 9:07 am

Infocatcher wrote:Strange. Looks like bug.
Anyway you can try to use something like following:
https://addons.mozilla.org/files/browse/204430/file/components/CustomButtonsService.js#L210


Good, this method works. thanks for your help.

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 2 guests