commit db6fd99f46e02501c0bda6f3b67fac4226f1bd93
parent aceee0f33fe0b9ffc62850e42d9241e346c8afa0
Author: mark <mkennedy@mozilla.com>
Date: Fri, 3 Oct 2025 15:58:01 +0000
Bug 1969949 - Convert 'Open previous windows' control to config-based setting r=hjones
Differential Revision: https://phabricator.services.mozilla.com/D260310
Diffstat:
4 files changed, 148 insertions(+), 59 deletions(-)
diff --git a/browser/components/preferences/main.inc.xhtml b/browser/components/preferences/main.inc.xhtml
@@ -27,8 +27,7 @@
<label><html:h2 data-l10n-id="startup-header"/></label>
<vbox id="startupPageBox">
- <checkbox id="browserRestoreSession"
- data-l10n-id="startup-restore-windows-and-tabs"/>
+ <html:setting-group groupid="startup"/>
#ifdef XP_WIN
<hbox id="windowsLaunchOnLoginBox" align="center" hidden="true">
<checkbox id="windowsLaunchOnLogin"
diff --git a/browser/components/preferences/main.js b/browser/components/preferences/main.js
@@ -214,6 +214,56 @@ if (AppConstants.MOZ_UPDATER) {
}
Preferences.addSetting({
+ id: "privateBrowsingAutoStart",
+ pref: "browser.privatebrowsing.autostart",
+});
+
+Preferences.addSetting({
+ /**
+ * The "Open previous windows and tabs" option on about:preferences page.
+ */
+ id: "browserRestoreSession",
+ pref: "browser.startup.page",
+ deps: ["privateBrowsingAutoStart"],
+ get:
+ /**
+ * Returns the value of the "Open previous windows and tabs" option based
+ * on the value of the browser.privatebrowsing.autostart pref.
+ *
+ * @param {number | undefined} value
+ * @returns {boolean}
+ */
+ value => {
+ const pbAutoStartPref = Preferences.get(
+ "browser.privatebrowsing.autostart"
+ );
+ let newValue = pbAutoStartPref.value
+ ? false
+ : value === gMainPane.STARTUP_PREF_RESTORE_SESSION;
+
+ return newValue;
+ },
+ set: checked => {
+ const startupPref = Preferences.get("browser.startup.page");
+ let newValue;
+
+ if (checked) {
+ // We need to restore the blank homepage setting in our other pref
+ if (startupPref.value === gMainPane.STARTUP_PREF_BLANK) {
+ HomePage.safeSet("about:blank");
+ }
+ newValue = gMainPane.STARTUP_PREF_RESTORE_SESSION;
+ } else {
+ newValue = gMainPane.STARTUP_PREF_HOMEPAGE;
+ }
+ return newValue;
+ },
+ disabled: deps => {
+ return deps.privateBrowsingAutoStart.value;
+ },
+});
+
+Preferences.addSetting({
id: "useAutoScroll",
pref: "general.autoScroll",
});
@@ -718,6 +768,14 @@ let SETTINGS_CONFIG = {
},
],
},
+ startup: {
+ items: [
+ {
+ id: "browserRestoreSession",
+ l10nId: "startup-restore-windows-and-tabs",
+ },
+ ],
+ },
zoom: {
// This section is marked as in progress for testing purposes
inProgress: true,
@@ -1222,6 +1280,7 @@ var gMainPane = {
initSettingGroup("browsing");
initSettingGroup("zoom");
initSettingGroup("performance");
+ initSettingGroup("startup");
if (AppConstants.platform == "win") {
// Functionality for "Show tabs in taskbar" on Windows 7 and up.
@@ -1304,11 +1363,6 @@ var gMainPane = {
}
// Startup pref
- setEventListener(
- "browserRestoreSession",
- "command",
- gMainPane.onBrowserRestoreSessionChange
- );
if (AppConstants.platform == "win") {
setEventListener(
"windowsLaunchOnLogin",
@@ -1327,21 +1381,6 @@ var gMainPane = {
});
}
}
- gMainPane.updateBrowserStartupUI =
- gMainPane.updateBrowserStartupUI.bind(gMainPane);
- Preferences.get("browser.privatebrowsing.autostart").on(
- "change",
- gMainPane.updateBrowserStartupUI
- );
- Preferences.get("browser.startup.page").on(
- "change",
- gMainPane.updateBrowserStartupUI
- );
- Preferences.get("browser.startup.homepage").on(
- "change",
- gMainPane.updateBrowserStartupUI
- );
- gMainPane.updateBrowserStartupUI();
if (AppConstants.HAVE_SHELL_SERVICE) {
setEventListener(
@@ -1832,26 +1871,6 @@ var gMainPane = {
},
/**
- * Hide/show the "Show my windows and tabs from last time" option based
- * on the value of the browser.privatebrowsing.autostart pref.
- */
- updateBrowserStartupUI() {
- const pbAutoStartPref = Preferences.get(
- "browser.privatebrowsing.autostart"
- );
- const startupPref = Preferences.get("browser.startup.page");
-
- let newValue;
- let checkbox = document.getElementById("browserRestoreSession");
- checkbox.disabled = pbAutoStartPref.value || startupPref.locked;
- newValue = pbAutoStartPref.value
- ? false
- : startupPref.value === this.STARTUP_PREF_RESTORE_SESSION;
- if (checkbox.checked !== newValue) {
- checkbox.checked = newValue;
- }
- },
- /**
* Fetch the existing default zoom value, initialise and unhide
* the preferences menu. This method also establishes a listener
* to ensure handleDefaultZoomChange is called on future menu
@@ -2537,23 +2556,6 @@ var gMainPane = {
cps2.setGlobal(win.FullZoom.name, newZoom, nonPrivateLoadContext);
},
- onBrowserRestoreSessionChange(event) {
- const value = event.target.checked;
- const startupPref = Preferences.get("browser.startup.page");
- let newValue;
-
- if (value) {
- // We need to restore the blank homepage setting in our other pref
- if (startupPref.value === this.STARTUP_PREF_BLANK) {
- HomePage.safeSet("about:blank");
- }
- newValue = this.STARTUP_PREF_RESTORE_SESSION;
- } else {
- newValue = this.STARTUP_PREF_HOMEPAGE;
- }
- startupPref.value = newValue;
- },
-
async onWindowsLaunchOnLoginChange(event) {
if (AppConstants.platform !== "win") {
return;
diff --git a/browser/components/preferences/tests/browser.toml b/browser/components/preferences/tests/browser.toml
@@ -284,6 +284,8 @@ skip-if = ["tsan"] # Bug 1678829
["browser_spotlight.js"]
+["browser_startup_browser_restore_session.js"]
+
["browser_statePartitioning_PBM_strings.js"]
["browser_statePartitioning_strings.js"]
diff --git a/browser/components/preferences/tests/browser_startup_browser_restore_session.js b/browser/components/preferences/tests/browser_startup_browser_restore_session.js
@@ -0,0 +1,86 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests for "Open previous windows
+ * and tabs" checkbox on about:preferences.
+ */
+
+registerCleanupFunction(() => {
+ gBrowser.removeCurrentTab();
+});
+
+add_setup(async function () {
+ await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
+});
+
+add_task(async function test_startup_browser_restore() {
+ const PREF = "browser.privatebrowsing.autostart";
+ const FALSE_INITIAL_VALUE = false;
+
+ /**
+ * Assume pref is set to false initially.
+ */
+ Services.prefs.setBoolPref(PREF, FALSE_INITIAL_VALUE);
+
+ const { document } = gBrowser.contentWindow;
+ let browserRestoreSession = document.getElementById("browserRestoreSession");
+ const { parentElement: control } = browserRestoreSession;
+ const checkbox = control.querySelector("moz-checkbox");
+
+ is(
+ browserRestoreSession.localName,
+ "moz-checkbox",
+ "Checkbox is a moz-checkbox."
+ );
+
+ ok(!control.hidden, "Control element is visible by default");
+
+ ok(!checkbox.disabled, "Checkbox is NOT disabled by default");
+
+ ok(!checkbox.checked, "Checkbox is NOT checked by default");
+
+ is(
+ content.document.l10n.getAttributes(browserRestoreSession).id,
+ "startup-restore-windows-and-tabs",
+ `Checkbox has the correct data-l10n-id attribute`
+ );
+
+ Services.prefs.setBoolPref(PREF, true);
+ await control.updateComplete;
+
+ ok(checkbox.disabled, "Checkbox is disabled after pref is set to true");
+
+ /**
+ * Re-enable control.
+ */
+ Services.prefs.setBoolPref(PREF, FALSE_INITIAL_VALUE);
+ await control.updateComplete;
+
+ Services.prefs.setIntPref("browser.startup.page", 0);
+
+ ok(
+ !checkbox.checked,
+ "Checkbox is NOT checked after browser.startup.page is set to 0 = STARTUP_PREF_BLANK"
+ );
+
+ Services.prefs.setIntPref("browser.startup.page", 1);
+ await control.updateComplete;
+
+ ok(
+ !checkbox.checked,
+ "Checkbox is still NOT checked after changing browser.startup.page to 1 = STARTUP_PREF_HOMEPAGE"
+ );
+
+ Services.prefs.setIntPref("browser.startup.page", 3);
+ await control.updateComplete;
+
+ ok(
+ checkbox.checked,
+ "Checkbox is checked after changing browser.startup.page to 3 = STARTUP_PREF_RESTORE_SESSION"
+ );
+
+ Services.prefs.clearUserPref(PREF);
+});