tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 5b8fe027b47780542708a8b89a9c0f795235b04d
parent db6fd99f46e02501c0bda6f3b67fac4226f1bd93
Author: mark <mkennedy@mozilla.com>
Date:   Fri,  3 Oct 2025 15:58:01 +0000

Bug 1969949 - Convert Open upon startup (windows-only) controls to config-based setting r=tgiles,mstriemer

Differential Revision: https://phabricator.services.mozilla.com/D261476

Diffstat:
Mbrowser/components/preferences/main.inc.xhtml | 20--------------------
Mbrowser/components/preferences/main.js | 238+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Mbrowser/components/preferences/tests/browser_windows_launch_on_login.js | 12+++++++++++-
Mbrowser/locales/en-US/browser/preferences/preferences.ftl | 3++-
Apython/l10n/fluent_migrations/bug_1969949_convert_startup_windows_launch_on_login_disabled_moz-message-bar_conversion.py | 29+++++++++++++++++++++++++++++
5 files changed, 202 insertions(+), 100 deletions(-)

diff --git a/browser/components/preferences/main.inc.xhtml b/browser/components/preferences/main.inc.xhtml @@ -28,26 +28,6 @@ <vbox id="startupPageBox"> <html:setting-group groupid="startup"/> -#ifdef XP_WIN - <hbox id="windowsLaunchOnLoginBox" align="center" hidden="true"> - <checkbox id="windowsLaunchOnLogin" - data-l10n-id="windows-launch-on-login"/> - </hbox> - <hbox id="windowsLaunchOnLoginDisabledBox" align="center" class="indent" hidden="true"> - <hbox class="info-icon-container"> - <html:img class="info-icon"/> - </hbox> - <html:div data-l10n-id="windows-launch-on-login-disabled"> - <html:a id="windowsAutostartLink" class="text-link" data-l10n-name="startup-link" href="ms-settings:startupapps" target="_self" /> - </html:div> - </hbox> - <hbox id="windowsLaunchOnLoginDisabledProfileBox" align="center" class="indent" hidden="true"> - <hbox class="info-icon-container"> - <html:img class="info-icon"/> - </hbox> - <html:div data-l10n-id="windows-launch-on-login-profile-disabled"/> - </hbox> -#endif </vbox> #ifdef HAVE_SHELL_SERVICE diff --git a/browser/components/preferences/main.js b/browser/components/preferences/main.js @@ -54,6 +54,7 @@ const APP_ICON_ATTR_NAME = "appHandlerIcon"; Preferences.addAll([ // Startup { id: "browser.startup.page", type: "int" }, + { id: "browser.startup.windowsLaunchOnLogin.enabled", type: "bool" }, { id: "browser.privatebrowsing.autostart", type: "bool" }, // Downloads @@ -219,6 +220,139 @@ Preferences.addSetting({ }); Preferences.addSetting({ + id: "launchOnLoginApproved", + _getLaunchOnLoginApprovedCachedValue: true, + get() { + return this._getLaunchOnLoginApprovedCachedValue; + }, + // Check for a launch on login registry key + // This accounts for if a user manually changes it in the registry + // Disabling in Task Manager works outside of just deleting the registry key + // in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run + // but it is not possible to change it back to enabled as the disabled value is just a random + // hexadecimal number + async setup() { + if (AppConstants.platform !== "win") { + /** + * WindowsLaunchOnLogin isnt available if not on windows + * but this setup function still fires, so must prevent + * WindowsLaunchOnLogin.getLaunchOnLoginApproved + * below from executing unnecessarily. + */ + return; + } + this._getLaunchOnLoginApprovedCachedValue = + await WindowsLaunchOnLogin.getLaunchOnLoginApproved(); + }, +}); + +Preferences.addSetting({ + id: "windowsLaunchOnLoginEnabled", + pref: "browser.startup.windowsLaunchOnLogin.enabled", +}); + +Preferences.addSetting({ + id: "windowsLaunchOnLogin", + deps: ["launchOnLoginApproved", "windowsLaunchOnLoginEnabled"], + _getLaunchOnLoginEnabledValue: false, + get startWithLastProfile() { + return Cc["@mozilla.org/toolkit/profile-service;1"].getService( + Ci.nsIToolkitProfileService + ).startWithLastProfile; + }, + get() { + return this._getLaunchOnLoginEnabledValue; + }, + async setup(emitChange) { + if (AppConstants.platform !== "win") { + /** + * WindowsLaunchOnLogin isnt available if not on windows + * but this setup function still fires, so must prevent + * WindowsLaunchOnLogin.getLaunchOnLoginEnabled + * below from executing unnecessarily. + */ + return; + } + + let getLaunchOnLoginEnabledValue; + if (!this.startWithLastProfile) { + getLaunchOnLoginEnabledValue = false; + } else { + getLaunchOnLoginEnabledValue = + await WindowsLaunchOnLogin.getLaunchOnLoginEnabled(); + } + if (getLaunchOnLoginEnabledValue !== this._getLaunchOnLoginEnabledValue) { + this._getLaunchOnLoginEnabledValue = getLaunchOnLoginEnabledValue; + emitChange(); + } + }, + visible: ({ windowsLaunchOnLoginEnabled }) => { + let isVisible = + AppConstants.platform === "win" && windowsLaunchOnLoginEnabled.value; + if (isVisible) { + NimbusFeatures.windowsLaunchOnLogin.recordExposureEvent({ + once: true, + }); + } + return isVisible; + }, + disabled({ launchOnLoginApproved }) { + return !this.startWithLastProfile || !launchOnLoginApproved.value; + }, + onUserChange(checked) { + if (checked) { + // windowsLaunchOnLogin has been checked: create registry key or shortcut + // The shortcut is created with the same AUMID as Firefox itself. However, + // this is not set during browser tests and the fallback of checking the + // registry fails. As such we pass an arbitrary AUMID for the purpose + // of testing. + WindowsLaunchOnLogin.createLaunchOnLogin(); + Services.prefs.setBoolPref( + "browser.startup.windowsLaunchOnLogin.disableLaunchOnLoginPrompt", + true + ); + } else { + // windowsLaunchOnLogin has been unchecked: delete registry key and shortcut + WindowsLaunchOnLogin.removeLaunchOnLogin(); + } + }, +}); + +Preferences.addSetting({ + id: "windowsLaunchOnLoginDisabledProfileBox", + deps: ["windowsLaunchOnLoginEnabled"], + visible: ({ windowsLaunchOnLoginEnabled }) => { + if (AppConstants.platform !== "win") { + return false; + } + let startWithLastProfile = Cc[ + "@mozilla.org/toolkit/profile-service;1" + ].getService(Ci.nsIToolkitProfileService).startWithLastProfile; + + return !startWithLastProfile && windowsLaunchOnLoginEnabled.value; + }, +}); + +Preferences.addSetting({ + id: "windowsLaunchOnLoginDisabledBox", + deps: ["launchOnLoginApproved", "windowsLaunchOnLoginEnabled"], + visible: ({ launchOnLoginApproved, windowsLaunchOnLoginEnabled }) => { + if (AppConstants.platform !== "win") { + return false; + } + let startWithLastProfile = Cc[ + "@mozilla.org/toolkit/profile-service;1" + ].getService(Ci.nsIToolkitProfileService).startWithLastProfile; + + return ( + startWithLastProfile && + !launchOnLoginApproved.value && + windowsLaunchOnLoginEnabled.value + ); + }, +}); + +Preferences.addSetting({ /** * The "Open previous windows and tabs" option on about:preferences page. */ @@ -774,6 +908,32 @@ let SETTINGS_CONFIG = { id: "browserRestoreSession", l10nId: "startup-restore-windows-and-tabs", }, + { + id: "windowsLaunchOnLogin", + l10nId: "windows-launch-on-login", + }, + { + id: "windowsLaunchOnLoginDisabledBox", + control: "moz-box-item", + l10nId: "windows-launch-on-login-disabled", + options: [ + { + control: "a", + controlAttrs: { + "data-l10n-name": "startup-link", + href: "ms-settings:startupapps", + _target: "self", + }, + }, + ], + }, + { + id: "windowsLaunchOnLoginDisabledProfileBox", + control: "moz-message-bar", + controlAttrs: { + l10nId: "startup-windows-launch-on-login-profile-disabled", + }, + }, ], }, zoom: { @@ -1362,26 +1522,6 @@ var gMainPane = { }); } - // Startup pref - if (AppConstants.platform == "win") { - setEventListener( - "windowsLaunchOnLogin", - "command", - gMainPane.onWindowsLaunchOnLoginChange - ); - if ( - Services.prefs.getBoolPref( - "browser.startup.windowsLaunchOnLogin.enabled", - false - ) - ) { - document.getElementById("windowsLaunchOnLoginBox").hidden = false; - NimbusFeatures.windowsLaunchOnLogin.recordExposureEvent({ - once: true, - }); - } - } - if (AppConstants.HAVE_SHELL_SERVICE) { setEventListener( "setDefaultButton", @@ -1595,43 +1735,6 @@ var gMainPane = { } if (AppConstants.platform == "win") { - // Check for a launch on login registry key - // This accounts for if a user manually changes it in the registry - // Disabling in Task Manager works outside of just deleting the registry key - // in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run - // but it is not possible to change it back to enabled as the disabled value is just a random - // hexadecimal number - let launchOnLoginCheckbox = document.getElementById( - "windowsLaunchOnLogin" - ); - - let startWithLastProfile = Cc[ - "@mozilla.org/toolkit/profile-service;1" - ].getService(Ci.nsIToolkitProfileService).startWithLastProfile; - - // Grey out the launch on login checkbox if startWithLastProfile is false - document.getElementById( - "windowsLaunchOnLoginDisabledProfileBox" - ).hidden = startWithLastProfile; - launchOnLoginCheckbox.disabled = !startWithLastProfile; - - if (!startWithLastProfile) { - launchOnLoginCheckbox.checked = false; - } else { - WindowsLaunchOnLogin.getLaunchOnLoginEnabled().then(enabled => { - launchOnLoginCheckbox.checked = enabled; - }); - - WindowsLaunchOnLogin.getLaunchOnLoginApproved().then( - approvedByWindows => { - launchOnLoginCheckbox.disabled = !approvedByWindows; - document.getElementById( - "windowsLaunchOnLoginDisabledBox" - ).hidden = approvedByWindows; - } - ); - } - // On Windows, the Application Update setting is an installation- // specific preference, not a profile-specific one. Show a warning to // inform users of this. @@ -2556,27 +2659,6 @@ var gMainPane = { cps2.setGlobal(win.FullZoom.name, newZoom, nonPrivateLoadContext); }, - async onWindowsLaunchOnLoginChange(event) { - if (AppConstants.platform !== "win") { - return; - } - if (event.target.checked) { - // windowsLaunchOnLogin has been checked: create registry key or shortcut - // The shortcut is created with the same AUMID as Firefox itself. However, - // this is not set during browser tests and the fallback of checking the - // registry fails. As such we pass an arbitrary AUMID for the purpose - // of testing. - await WindowsLaunchOnLogin.createLaunchOnLogin(); - Services.prefs.setBoolPref( - "browser.startup.windowsLaunchOnLogin.disableLaunchOnLoginPrompt", - true - ); - } else { - // windowsLaunchOnLogin has been unchecked: delete registry key and shortcut - await WindowsLaunchOnLogin.removeLaunchOnLogin(); - } - }, - // TABS /* diff --git a/browser/components/preferences/tests/browser_windows_launch_on_login.js b/browser/components/preferences/tests/browser_windows_launch_on_login.js @@ -52,8 +52,18 @@ add_task(async function test_check_uncheck_checkbox() { let doc = gBrowser.contentDocument; let launchOnLoginCheckbox = doc.getElementById("windowsLaunchOnLogin"); + let launchOnLoginControl = launchOnLoginCheckbox.parentElement; + + ok(!launchOnLoginControl.hidden, "Autostart control is visible"); + + ok( + !launchOnLoginCheckbox.checked, + "Autostart checkbox NOT checked by default" + ); + launchOnLoginCheckbox.click(); - ok(launchOnLoginCheckbox.checked, "Autostart checkbox checked"); + + ok(launchOnLoginCheckbox.checked, "Autostart checkbox checked after click"); ok( wrk.hasValue(WindowsLaunchOnLogin.getLaunchOnLoginRegistryName()), diff --git a/browser/locales/en-US/browser/preferences/preferences.ftl b/browser/locales/en-US/browser/preferences/preferences.ftl @@ -152,12 +152,13 @@ set-as-my-default-browser = startup-restore-windows-and-tabs = .label = Open previous windows and tabs .accesskey = s +startup-windows-launch-on-login-profile-disabled = + .message = Enable this preference by checking “{ profile-manager-use-selected.label }” in the “Choose User Profile” window. windows-launch-on-login = .label = Open { -brand-short-name } automatically when your computer starts up .accesskey = O windows-launch-on-login-disabled = This preference has been disabled in Windows. To change, visit <a data-l10n-name="startup-link">Startup Apps</a> in System settings. -windows-launch-on-login-profile-disabled = Enable this preference by checking “{ profile-manager-use-selected.label }” in the “Choose User Profile” window. disable-extension = .label = Disable Extension diff --git a/python/l10n/fluent_migrations/bug_1969949_convert_startup_windows_launch_on_login_disabled_moz-message-bar_conversion.py b/python/l10n/fluent_migrations/bug_1969949_convert_startup_windows_launch_on_login_disabled_moz-message-bar_conversion.py @@ -0,0 +1,29 @@ +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +import re +import fluent.syntax.ast as FTL +from fluent.migrate import COPY_PATTERN +from fluent.migrate.transforms import TransformPattern + + +def migrate(ctx): + """Bug 1969949 - Convert startup windows launch on login disabled moz-message-bar conversion, part {index}.""" + path = "browser/browser/preferences/preferences.ftl" + ctx.add_transforms( + path, + path, + [ + FTL.Message( + id=FTL.Identifier("startup-windows-launch-on-login-profile-disabled"), + attributes=[ + FTL.Attribute( + id=FTL.Identifier("message"), + value=COPY_PATTERN( + path, "windows-launch-on-login-profile-disabled" + ), + ), + ], + ), + ], + )