Skip to content

Commit

Permalink
Bug 1732366 - When closing last tab while having private window, remo…
Browse files Browse the repository at this point in the history
…ve the tab from the tabs list . r=Gijs

With session restore and close window on last tab close both enabled, if the last tab is closed while having another private window, move it from the winData.tabs list to the winData._closedTabs list.

Differential Revision: https://phabricator.services.mozilla.com/D126590
  • Loading branch information
AntoninLoubiere committed Nov 1, 2021
1 parent 9b7ffaf commit d3cdb6e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
22 changes: 16 additions & 6 deletions browser/components/sessionstore/SessionStore.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ var SessionStore = {
},

maybeDontSaveTabs(aWindow) {
if (this.willAutoRestore) {
aWindow._dontSaveTabs = true;
}
SessionStoreInternal.maybeDontSaveTabs(aWindow);
},

undoCloseWindow: function ss_undoCloseWindow(aIndex) {
Expand Down Expand Up @@ -1853,9 +1851,7 @@ var SessionStoreInternal = {
// with tabs we deem not worth saving then we might end up with a
// random closed or even a pop-up window re-opened. To prevent that
// we explicitly allow saving an "empty" window state.
let isLastWindow =
Object.keys(this._windows).length == 1 &&
!this._closedWindows.some(win => win._shouldRestore || false);
let isLastWindow = this.isLastRestorableWindow();

// clear this window from the list, since it has definitely been closed.
delete this._windows[aWindow.__SSi];
Expand Down Expand Up @@ -3250,6 +3246,20 @@ var SessionStoreInternal = {
return Cu.cloneInto(this._closedWindows, {});
},

maybeDontSaveTabs(aWindow) {
if (this.willAutoRestore && this.isLastRestorableWindow()) {
aWindow._dontSaveTabs = true;
}
},

isLastRestorableWindow() {
return (
Object.values(this._windows).filter(winData => !winData.isPrivate)
.length == 1 &&
!this._closedWindows.some(win => win._shouldRestore || false)
);
},

undoCloseWindow: function ssi_undoCloseWindow(aIndex) {
if (!(aIndex in this._closedWindows)) {
throw Components.Exception(
Expand Down
1 change: 1 addition & 0 deletions browser/components/sessionstore/test/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ skip-if = (verify && debug && (os == 'mac' || os == 'win'))
[browser_819510_perwindowpb.js]
skip-if = true # Bug 1284312, Bug 1341980, bug 1381451
[browser_not_collect_when_idle.js]
[browser_close_last_nonprivate_tab.js]

# Disabled for frequent intermittent failures
[browser_464620_a.js]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
* With session restore enabled and quit on last tab close enabled
* When closing the last tab while having another private window,
* it shouldn't be restored at the next startup of Firefox.
* See bug 1732366 for more information.
*/
add_task(async function test_bug_1730021() {
await SpecialPowers.pushPrefEnv({
set: [["browser.sessionstore.resume_session_once", true]],
});
ok(SessionStore.willAutoRestore, "the session will be restored if we quit");

SessionStore.maybeDontSaveTabs(window);
ok(window._dontSaveTabs, "the tabs should be closed at quit");
delete window._dontSaveTabs;
ok(!window._dontSaveTabs, "the flag should be reset");

let newWin = await BrowserTestUtils.openNewBrowserWindow({ private: true });

SessionStore.maybeDontSaveTabs(window);
ok(
window._dontSaveTabs,
"the tabs should be closed at quit even if a private window is open"
);
delete window._dontSaveTabs;
ok(!window._dontSaveTabs, "the flag should be reset");

await BrowserTestUtils.closeWindow(newWin);
});
8 changes: 8 additions & 0 deletions toolkit/components/printing/content/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,14 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
this._pagesSet.clear();
return;
}

if (rangeParts[0] == "odd") {
for (let i = 1; i <= numPages; i += 2) {
this._pagesSet.add(i);
}
return;
}

let startRange = parseInt(rangeParts[0], 10);
let endRange = parseInt(
rangeParts.length == 2 ? rangeParts[1] : rangeParts[0],
Expand Down
5 changes: 2 additions & 3 deletions toolkit/content/globalOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ function closeWindow(aClose, aPromptFunction, aSource) {
return false;
}

// If the user explicitly closes the last tabs in the window and it's the last window
// close remaining tabs. Bug 490136
if (aClose && windowCount == 1) {
// If the user explicitly closes the last tabs in the window close remaining tabs. Bug 490136
if (aClose) {
window.SessionStore?.maybeDontSaveTabs(window);
}
} else if (
Expand Down

0 comments on commit d3cdb6e

Please sign in to comment.