Skip to content

Commit

Permalink
Remove private tabs on "SSWindowClosing" event
Browse files Browse the repository at this point in the history
+ workaround for SeaMonkey
(for #36)
  • Loading branch information
Infocatcher committed Apr 17, 2013
1 parent c2c5099 commit c8fffed
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ var windowsObserver = {
handleEvent: function(e) {
switch(e.type) {
case "load": this.loadHandler(e); break;
case "close":
case "beforeunload": this.beforeunloadHandler(e); break;
case "TabOpen": this.tabOpenHandler(e); break;
case "SSTabRestoring": this.tabRestoringHandler(e); break;
case "TabSelect": this.tabSelectHandler(e); break;
Expand All @@ -98,24 +96,36 @@ var windowsObserver = {
case "keypress": this.keypressHandler(e); break;
case "PrivateTab:PrivateChanged": this.privateChangedHandler(e); break;
case "SSWindowStateBusy": this.setWindowBusy(e, true); break;
case "SSWindowStateReady": this.setWindowBusy(e, false);
case "SSWindowStateReady": this.setWindowBusy(e, false); break;
case "close":
case "beforeunload":
case "SSWindowClosing": this.windowClosingHandler(e);
}
},
loadHandler: function(e) {
var window = e.originalTarget.defaultView;
window.removeEventListener("load", this, false);
this.initWindow(window, WINDOW_LOADED);
},
beforeunloadHandler: function(e) {
windowClosingHandler: function(e) {
var window = e.currentTarget;
_log("beforeunloadHandler() [" + e.type + "]");
_log("windowClosingHandler() [" + e.type + "]");
if(
!this.isPrivateWindow(window)
&& !prefs.get("savePrivateTabsInSessions")
) {
_log(e.type + " => closePrivateTabs()");
this.closePrivateTabs(window);
}
this.destroyWindowClosingHandler(window);
},
destroyWindowClosingHandler: function(window) {
window.removeEventListener("TabClose", this, false);
window.removeEventListener("SSWindowClosing", this, true);
if(this.isSeaMonkey) {
window.removeEventListener("close", this, false);
window.removeEventListener("beforeunload", this, false);
}
},

initWindow: function(window, reason) {
Expand Down Expand Up @@ -167,8 +177,11 @@ var windowsObserver = {
window.addEventListener("PrivateTab:PrivateChanged", this, false);
window.addEventListener("SSWindowStateBusy", this, true);
window.addEventListener("SSWindowStateReady", this, true);
window.addEventListener("close", this, false);
window.addEventListener("beforeunload", this, false);
window.addEventListener("SSWindowClosing", this, true);
if(this.isSeaMonkey) { // SeaMonkey doesn't dispatch "SSWindowClosing" event :(
window.addEventListener("close", this, false);
window.addEventListener("beforeunload", this, false);
}
if(this.hotkeys)
window.addEventListener(this.keyEvent, this, true);
window.setTimeout(function() {
Expand Down Expand Up @@ -211,16 +224,19 @@ var windowsObserver = {
window.removeEventListener("TabOpen", this, false);
window.removeEventListener("SSTabRestoring", this, false);
window.removeEventListener("TabSelect", this, false);
window.removeEventListener("TabClose", this, false);
window.removeEventListener("dragstart", this, true);
window.removeEventListener("dragend", this, true);
window.removeEventListener("drop", this, true);
window.removeEventListener(this.keyEvent, this, true);
window.removeEventListener("PrivateTab:PrivateChanged", this, false);
window.removeEventListener("SSWindowStateBusy", this, true);
window.removeEventListener("SSWindowStateReady", this, true);
window.removeEventListener("close", this, false);
window.removeEventListener("beforeunload", this, false);
if(reason != WINDOW_CLOSED) {
// See resource:///modules/sessionstore/SessionStore.jsm
// "domwindowclosed" => onClose() => "SSWindowClosing"
// This may happens after our "domwindowclosed" notification!
this.destroyWindowClosingHandler(window);
}
this.destroyControls(window, force);
},
get isSeaMonkey() {
Expand Down Expand Up @@ -499,10 +515,9 @@ var windowsObserver = {
+ "\nTry don't save it in undo close history"
);
var window = tab.ownerDocument.defaultView;
this.forgetClosedTab(window);
if(this.isSeaMonkey)
window.setTimeout(this.forgetClosedTab.bind(this, window), 0);
else
this.forgetClosedTab(window);
window.setTimeout(this.forgetClosedTab.bind(this, window, true), 0);
},
closePrivateTabs: function(window) {
var gBrowser = window.gBrowser;
Expand All @@ -515,7 +530,7 @@ var windowsObserver = {
}
}
},
forgetClosedTab: function(window) {
forgetClosedTab: function(window, _secondTry) {
var closedTabs = JSON.parse(this.ss.getClosedTabData(window));
for(var i = 0, l = closedTabs.length; i < l; ++i) {
var closedTab = closedTabs[i];
Expand All @@ -526,7 +541,7 @@ var windowsObserver = {
&& this.privateAttr in state.attributes
) {
this.ss.forgetClosedTab(window, i);
_log("Forget about closed tab #" + i);
_log("Forget about closed tab #" + i + (_secondTry ? " (workaround for SeaMonkey)" : ""));
return;
}
}
Expand Down

0 comments on commit c8fffed

Please sign in to comment.