Bug 479461 - Private browsing, close window, can't restore session; r=gavin a1.9.1=blocking-firefox3.1+
authorMike Connor <mconnor@mozilla.com>
Fri, 27 Feb 2009 23:55:04 +0330
changeset 23594 53bc33d54b142b08ceb8fc97895703096942e97e
parent 23593 52f1c949d697c4739142d694de9fee42f7f0632a
child 23595 fc5fe8d3d743320f598287cd2b8a223ea9bc16bb
push id813
push userehsan.akhgari@gmail.com
push dateSat, 28 Feb 2009 05:18:35 +0000
reviewersgavin
bugs479461
milestone1.9.1b3pre
Bug 479461 - Private browsing, close window, can't restore session; r=gavin a1.9.1=blocking-firefox3.1+
browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
--- a/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
+++ b/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
@@ -166,21 +166,27 @@ PrivateBrowsingService.prototype = {
           }]
         };
         // load dummy session to get a distinct separation between private and
         // non-private sessions
         ss.setBrowserState(JSON.stringify(transitionState));
 
         let browser = Cc["@mozilla.org/appshell/window-mediator;1"].
                       getService(Ci.nsIWindowMediator).
-                      getMostRecentWindow("navigator:browser").gBrowser;
-        // this ensures a clean slate from which to transition into or out of
-        // private browsing
-        browser.addTab();
-        browser.removeTab(browser.tabContainer.firstChild);
+                      getMostRecentWindow("navigator:browser");
+
+        // if all browser windows are closed (i.e. on Mac) we won't have a window here
+        // this is only needed on Mac, but it's just good hygiene
+        if (browser) {
+          // this ensures a clean slate from which to transition into or out of
+          // private browsing
+          browser = browser.gBrowser;
+          browser.addTab();
+          browser.removeTab(browser.tabContainer.firstChild);
+        }
       }
     }
     else
       this._saveSession = false;
   },
 
   _onAfterPrivateBrowsingModeChange: function PBS__onAfterPrivateBrowsingModeChange() {
     // nothing to do here if we're auto-starting or the current session is being