Bug 788275 - Tab preview should respect the private browsing mode when attempting to load a favicon; r=jdm,jimm
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 17 Sep 2012 14:47:49 -0400
changeset 108144 7c3acad5cf39d78d6ef42ba7d72f0e827e9bd46c
parent 108143 4cda2cc454660949ec6faf5911c04f3dd09d71d9
child 108145 474968430d66897d0172d705c3d3b5cfe4c3df25
push id23539
push userryanvm@gmail.com
push dateWed, 26 Sep 2012 22:55:55 +0000
treeherderautoland@ec079fd92224 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm, jimm
bugs788275
milestone18.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 788275 - Tab preview should respect the private browsing mode when attempting to load a favicon; r=jdm,jimm
browser/modules/WindowsPreviewPerTab.jsm
--- a/browser/modules/WindowsPreviewPerTab.jsm
+++ b/browser/modules/WindowsPreviewPerTab.jsm
@@ -67,18 +67,24 @@ XPCOMUtils.defineLazyServiceGetter(this,
 XPCOMUtils.defineLazyServiceGetter(this, "imgTools",
                                    "@mozilla.org/image/tools;1",
                                    "imgITools");
 XPCOMUtils.defineLazyServiceGetter(this, "faviconSvc",
                                    "@mozilla.org/browser/favicon-service;1",
                                    "nsIFaviconService");
 
 // nsIURI -> imgIContainer
-function _imageFromURI(uri, callback) {
+function _imageFromURI(uri, privateMode, callback) {
   let channel = ioSvc.newChannelFromURI(uri);
+  try {
+    channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
+    channel.setPrivate(privateMode);
+  } catch (e) {
+    // Ignore channels which do not support nsIPrivateBrowsingChannel
+  }
   NetUtil.asyncFetch(channel, function(inputStream, resultCode) {
     if (!Components.isSuccessCode(resultCode))
       return;
     try {
       let out_img = { value: null };
       imgTools.decodeImageData(inputStream, channel.contentType, out_img);
       callback(out_img.value);
     } catch (e) {
@@ -87,21 +93,21 @@ function _imageFromURI(uri, callback) {
       let defaultURI = faviconSvc.defaultFavicon;
       if (!defaultURI.equals(uri))
         _imageFromURI(defaultURI, callback);
     }
   });
 }
 
 // string? -> imgIContainer
-function getFaviconAsImage(iconurl, callback) {
+function getFaviconAsImage(iconurl, privateMode, callback) {
   if (iconurl)
-    _imageFromURI(NetUtil.newURI(iconurl), callback);
+    _imageFromURI(NetUtil.newURI(iconurl), privateMode, callback);
   else
-    _imageFromURI(faviconSvc.defaultFavicon, callback);
+    _imageFromURI(faviconSvc.defaultFavicon, privateMode, callback);
 }
 
 // Snaps the given rectangle to be pixel-aligned at the given scale
 function snapRectAtScale(r, scale) {
   let x = Math.floor(r.x * scale);
   let y = Math.floor(r.y * scale);
   let width = Math.ceil((r.x + r.width) * scale) - x;
   let height = Math.ceil((r.y + r.height) * scale) - y;
@@ -431,17 +437,17 @@ TabWindow.prototype = {
     let docShell = this.win
                   .QueryInterface(Ci.nsIInterfaceRequestor)
                   .getInterface(Ci.nsIWebNavigation)
                   .QueryInterface(Ci.nsIDocShell);
     let preview = AeroPeek.taskbar.createTaskbarTabPreview(docShell, controller);
     preview.visible = AeroPeek.enabled;
     preview.active = this.tabbrowser.selectedTab == tab;
     // Grab the default favicon
-    getFaviconAsImage(null, function (img) {
+    getFaviconAsImage(null, this.win.gPrivateBrowsingUI.privateWindow, function (img) {
       // It is possible that we've already gotten the real favicon, so make sure
       // we have not set one before setting this default one.
       if (!preview.icon)
         preview.icon = img;
     });
 
     // It's OK to add the preview now while the favicon still loads.
     this.previews.splice(tab._tPos, 0, preview);
@@ -530,17 +536,17 @@ TabWindow.prototype = {
         this.enabled = true;
         break;
     }
   },
 
   //// Browser progress listener
   onLinkIconAvailable: function (aBrowser, aIconURL) {
     let self = this;
-    getFaviconAsImage(aIconURL, function (img) {
+    getFaviconAsImage(aIconURL, this.win.gPrivateBrowsingUI.privateWindow, function (img) {
       let index = self.tabbrowser.browsers.indexOf(aBrowser);
       // Only add it if we've found the index.  The tab could have closed!
       if (index != -1)
         self.previews[index].icon = img;
     });
   }
 }