Skip to content

Commit

Permalink
Workaround to remove private tabs after File - Exit
Browse files Browse the repository at this point in the history
(for #36)
  • Loading branch information
Infocatcher committed Apr 16, 2013
1 parent 42115bf commit f78d3b4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function shutdown(params, reason) {

var windowsObserver = {
initialized: false,
_hasQuitObserver: false,
init: function(reason) {
if(this.initialized)
return;
Expand All @@ -51,6 +52,10 @@ var windowsObserver = {
this.destroyWindow(window, reason);
}, this);
Services.ww.unregisterNotification(this);
if(this._hasQuitObserver) {
this._hasQuitObserver = false;
Services.obs.removeObserver(this, "quit-application-requested");
}

this.unloadStyles();
this.restoreAppButtonWidth();
Expand All @@ -72,6 +77,8 @@ var windowsObserver = {
}
else if(topic == "domwindowclosed")
this.destroyWindow(subject, WINDOW_CLOSED);
else if(topic == "quit-application-requested")
this.closeAllPrivateTabs();
},

handleEvent: function(e) {
Expand Down Expand Up @@ -126,6 +133,13 @@ var windowsObserver = {
this.ensureTitleModifier(document);
this.patchBrowsers(gBrowser, true);
window.setTimeout(function() {
// Trick to remove private tabs on browser exit: we should call
// addObserver() after resource:///modules/sessionstore/SessionStore.jsm
// to be notified before SessionStore will save windows data
if(!this._hasQuitObserver) {
this._hasQuitObserver = true;
Services.obs.addObserver(this, "quit-application-requested", false);
}
// We don't need patched functions right after window "load", so it's better to
// apply patches after any other extensions
this.patchTabBrowserDND(window, gBrowser, true);
Expand Down Expand Up @@ -499,6 +513,15 @@ var windowsObserver = {
else
this.forgetClosedTab(window);
},
closeAllPrivateTabs: function() {
if(prefs.get("savePrivateTabsInSessions"))
return;
_log("closeAllPrivateTabs()");
this.windows.forEach(function(window) {
if(!this.isPrivateWindow(window))
this.closePrivateTabs(window);
}, this);
},
closePrivateTabs: function(window) {
var gBrowser = window.gBrowser;
var tabs = gBrowser.tabs;
Expand Down

0 comments on commit f78d3b4

Please sign in to comment.