Bug 677596 - Don't store thumbnails in private browsing mode; r=dietrich
authorTim Taubert <tim.taubert@gmx.de>
Thu, 01 Sep 2011 15:17:42 +0200
changeset 76391 b7a7127396f63ac9400ae382efe87314db64339c
parent 76390 b5bb731a58a9a823f6a0f458343c5f454a0afbae
child 76392 cefb66e240599967110214d47daa812b6f514efa
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersdietrich
bugs677596
milestone9.0a1
Bug 677596 - Don't store thumbnails in private browsing mode; r=dietrich
browser/base/content/tabview/storagePolicy.js
browser/base/content/test/tabview/browser_tabview_storage_policy.js
--- a/browser/base/content/tabview/storagePolicy.js
+++ b/browser/base/content/tabview/storagePolicy.js
@@ -185,16 +185,21 @@ let StoragePolicy = {
     if (index > -1)
       this._deniedBrowsers.splice(index, 1);
   },
 
   // ----------
   // Function: canStoreThumbnailForTab
   // Returns whether we're allowed to store the thumbnail of the given tab.
   canStoreThumbnailForTab: function StoragePolicy_canStoreThumbnailForTab(tab) {
+    // deny saving thumbnails in private browsing mode
+    if (gPrivateBrowsing.privateBrowsingEnabled &&
+        UI._privateBrowsing.transitionMode != "enter")
+      return false;
+
     return (this._deniedBrowsers.indexOf(tab.linkedBrowser) == -1);
   },
 
   // ----------
   // Function: observe
   // Observe pref changes.
   observe: function StoragePolicy_observe(subject, topic, data) {
     this._enablePersistentHttpsCaching =
--- a/browser/base/content/test/tabview/browser_tabview_storage_policy.js
+++ b/browser/base/content/test/tabview/browser_tabview_storage_policy.js
@@ -1,13 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const PREF_DISK_CACHE_SSL = "browser.cache.disk_cache_ssl";
 
+let pb = Cc["@mozilla.org/privatebrowsing;1"].
+         getService(Ci.nsIPrivateBrowsingService);
+
 let contentWindow;
 let newTab;
 
 function test() {
   waitForExplicitFinish();
 
   newTab = gBrowser.addTab();
 
@@ -15,16 +18,17 @@ function test() {
 
   registerCleanupFunction(function () {
     HttpRequestObserver.unregister();
     if (gBrowser.tabs[1])
       gBrowser.removeTab(gBrowser.tabs[1]);
     hideTabView();
 
     Services.prefs.clearUserPref(PREF_DISK_CACHE_SSL);
+    pb.privateBrowsingEnabled = false;
   });
 
   showTabView(function() {
     contentWindow = TabView.getContentWindow();
     test1();
   });
 }
 
@@ -105,27 +109,40 @@ function test5() {
 
   whenStorageDenied(newTab, function () {
     let tabItem = newTab._tabViewTabItem;
 
     ok(!contentWindow.StoragePolicy.canStoreThumbnailForTab(newTab),
        "Should not save the thumbnail for tab");
 
     whenDeniedToSaveImageData(tabItem, function () {
-      hideTabView(function () {
-        gBrowser.removeTab(gBrowser.tabs[1]);
-        finish();
-      });
+      gBrowser.removeTab(newTab);
+      test6();
     });
+
     tabItem.saveThumbnail({synchronously: true});
   });
 
   newTab.linkedBrowser.loadURI("https://example.com/");
 }
 
+// ensure that no thumbnails are saved while in private browsing mode
+function test6() {
+  HttpRequestObserver.cacheControlValue = "public";
+
+  togglePrivateBrowsing(function () {
+    let tab = gBrowser.tabs[0];
+
+    ok(!contentWindow.StoragePolicy.canStoreThumbnailForTab(tab),
+       "Should not save the thumbnail for tab");
+
+    togglePrivateBrowsing(finish);
+  });
+}
+
 let HttpRequestObserver = {
   cacheControlValue: null,
 
   observe: function(subject, topic, data) {
     if (topic == "http-on-examine-response" && this.cacheControlValue) {
       let httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
       httpChannel.setResponseHeader("Cache-Control", this.cacheControlValue, false);
     }