Bug 1732366 - When closing last tab while having private window, remove 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
This commit is contained in:
Antonin LOUBIERE 2021-11-01 17:09:28 +00:00
Родитель c4cd6ed3ef
Коммит 03900c9f8a
5 изменённых файлов: 61 добавлений и 9 удалений

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

@ -339,9 +339,7 @@ var SessionStore = {
},
maybeDontSaveTabs(aWindow) {
if (this.willAutoRestore) {
aWindow._dontSaveTabs = true;
}
SessionStoreInternal.maybeDontSaveTabs(aWindow);
},
undoCloseWindow: function ss_undoCloseWindow(aIndex) {
@ -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];
@ -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(

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

@ -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]

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

@ -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);
});

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

@ -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],

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

@ -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 (