public
Description: The solution for tabitus of the browser
Homepage: http://overstimulate.com/projects/taboo
Clone URL: git://github.com/anotherjesse/taboo.git
Search Repo:
Use nsIFaviconService for favicon saving
yosh (author)
Sat Jul 12 17:03:47 -0700 2008
commit  906d87ac386298ef8603f870007aa85b7090e1cf
tree    953415fcdb4d682cd4dcf0f2d641ffc1f1984e43
parent  8f3ac1948b4a3d6e37cc27d87f2dbe1c3335c10f
...
642
643
644
645
646
647
648
649
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650
651
652
...
1001
1002
1003
1004
1005
 
 
1006
1007
1008
...
642
643
644
 
 
 
 
 
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
...
1031
1032
1033
 
 
1034
1035
1036
1037
1038
0
@@ -642,11 +642,41 @@ TabooService.prototype = {
0
     if (faviconURL) {
0
       var ios = Cc['@mozilla.org/network/io-service;1']
0
         .getService(Ci.nsIIOService);
0
- var chan = ios.newChannel(faviconURL, null, null);
0
- var listener = new tabooFavIconLoadListener(url, faviconURL, chan,
0
- this._storage);
0
- chan.notificationCallbacks = listener;
0
- chan.asyncOpen(listener, null);
0
+ var faviconURI = ios.newURI(faviconURL, null, null);
0
+
0
+ if (Ci.nsIFaviconService) {
0
+ var faviconSvc = Cc['@mozilla.org/browser/favicon-service;1']
0
+ .getService(Ci.nsIFaviconService);
0
+
0
+ var dataURL = null;
0
+
0
+ try {
0
+ if (faviconSvc.getFaviconDataAsDataURL) {
0
+ dataURL = faviconSvc.getFaviconDataAsDataURL(faviconURI);
0
+ } else {
0
+ var mimeType = {};
0
+ var bytes = faviconSvc.getFaviconData(faviconURI, mimeType, {});
0
+ if (bytes) {
0
+ dataURL = 'data:';
0
+ dataURL += mimeType.value;
0
+ dataURL += ';base64,';
0
+ dataURL += btoa(String.fromCharCode.apply(null, bytes));
0
+ }
0
+ }
0
+ } catch (ex) {
0
+ // do nothing, use default value
0
+ }
0
+
0
+ if (dataURL) {
0
+ this._storage.saveFavicon(url, dataURL);
0
+ }
0
+ } else {
0
+ var chan = ios.newChannelFromURI(faviconURI);
0
+ var listener = new tabooFavIconLoadListener(url, faviconURL, chan,
0
+ this._storage);
0
+ chan.notificationCallbacks = listener;
0
+ chan.asyncOpen(listener, null);
0
+ }
0
     }
0
 
0
     for (var i = 0; i < this._observers.length; i++) {
0
@@ -1001,8 +1031,8 @@ TabooService.prototype = {
0
 }
0
 
0
 
0
-/* This is swiped from bookmarks.js in Firefox. In Firefox 3, this *should*
0
- * be easier, and not require cut'n'pasting
0
+/* This is swiped from bookmarks.js in Firefox. It's only used when we're
0
+ * on Gecko 1.8.x, since Gecko 1.9 has nsIFaviconService.
0
  */
0
 function tabooFavIconLoadListener(url, faviconurl, channel, storage) {
0
   this.mURL = url;

Comments

    No one has commented yet.