bug 480854 - Start/Stop of Private Browsing mode from window-less state always opens 2 windows, r=gavin

This commit is contained in:
Mike Connor 2009-03-03 10:14:32 -08:00
Родитель 8a5ac77ac0
Коммит e0e71a5e57
1 изменённых файлов: 28 добавлений и 21 удалений

Просмотреть файл

@ -154,31 +154,32 @@ PrivateBrowsingService.prototype = {
this._savedBrowserState = ss.getBrowserState();
}
if (!this._quitting && this._saveSession) {
// dummy session used to transition from/to pb mode, see bug 476463
let transitionState = {
"windows": [{
"tabs": [{
"entries": [{
"url": "about:blank"
}]
}],
"_closedTabs": []
}]
};
// load dummy session to get a distinct separation between private and
// non-private sessions
ss.setBrowserState(JSON.stringify(transitionState));
let browserWindow = this._getBrowserWindow();
let browser = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator).
getMostRecentWindow("navigator:browser");
// if there are open browser windows, load a dummy session to get a distinct
// separation between private and non-private sessions
if (browserWindow) {
// dummy session used to transition from/to pb mode, see bug 476463
let transitionState = {
"windows": [{
"tabs": [{
"entries": [{
"url": "about:blank"
}]
}],
"_closedTabs": []
}]
};
ss.setBrowserState(JSON.stringify(transitionState));
// just in case the only remaining window after setBrowserState is different.
// it probably shouldn't be with the current sessionstore impl, but we shouldn't
// rely on behaviour the API doesn't guarantee
let browser = this._getBrowserWindow().gBrowser;
// 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);
}
@ -235,6 +236,12 @@ PrivateBrowsingService.prototype = {
return !cancelLeave.data;
},
_getBrowserWindow: function PBS__getBrowserWindow() {
return Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator).
getMostRecentWindow("navigator:browser");
},
// nsIObserver
observe: function PBS_observe(aSubject, aTopic, aData) {