commit 94d0c59e525f9a4531119b4e07088e655a70bb5c
parent d16c4b830ffdff9714602263653a60b27c58919d
Author: Jared Hirsch <ohai@6a68.net>
Date: Thu, 27 Nov 2025 08:34:03 +0000
Bug 1998209 - Prevent copied profile from managing original profile shortcut r=profiles-reviewers,niklas
Differential Revision: https://phabricator.services.mozilla.com/D273511
Diffstat:
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/browser/components/profiles/SelectableProfile.sys.mjs b/browser/components/profiles/SelectableProfile.sys.mjs
@@ -479,6 +479,18 @@ export class SelectableProfile {
// We set the pref here so the copied profile will inherit this pref and
// the copied profile will not show the backup welcome messaging.
Services.prefs.setBoolPref("browser.profiles.profile-copied", true);
+
+ // If the user has created a desktop shortcut, clear the shortcut name pref
+ // to prevent the copied profile trying to manage the original profile's
+ // shortcut.
+ let shortcutFileName = Services.prefs.getCharPref(
+ "browser.profiles.shortcutFileName",
+ ""
+ );
+ if (shortcutFileName !== "") {
+ Services.prefs.clearUserPref("browser.profiles.shortcutFileName");
+ }
+
const backupServiceInstance = new BackupService();
let encState = await backupServiceInstance.loadEncryptionState(this.path);
@@ -500,6 +512,15 @@ export class SelectableProfile {
// Clear the pref now that the copied profile has inherited it.
Services.prefs.clearUserPref("browser.profiles.profile-copied");
+ // Restore the desktop shortcut pref now that the copied profile will not
+ // inherit it.
+ if (shortcutFileName !== "") {
+ Services.prefs.setCharPref(
+ "browser.profiles.shortcutFileName",
+ shortcutFileName
+ );
+ }
+
if (result.error) {
throw result.error;
}
diff --git a/browser/components/profiles/tests/unit/test_copy_profile.js b/browser/components/profiles/tests/unit/test_copy_profile.js
@@ -29,7 +29,13 @@ add_task(async function test_copy_profile() {
Assert.ok(SelectableProfileService.isEnabled, "Service should be enabled");
let profiles = await SelectableProfileService.getAllProfiles();
- Assert.equal(profiles.length, 1, "Only one selectable profile exist");
+ Assert.equal(profiles.length, 1, "Only one selectable profile exists");
+
+ // Simulate creating a desktop shortcut.
+ Services.prefs.setCharPref(
+ "browser.profiles.shortcutFileName",
+ "test-shortcut-name"
+ );
const backupServiceInstance = new BackupService();
@@ -60,6 +66,14 @@ add_task(async function test_copy_profile() {
SelectableProfileService.currentProfile.theme.themeId,
"Copied profile has the same theme"
);
+
+ let prefsPath = PathUtils.join(copiedProfile.path, "prefs.js");
+ let prefsFile = await IOUtils.readUTF8(prefsPath, { encoding: "utf-8" });
+ Assert.equal(
+ -1,
+ prefsFile.search("browser.profiles.shortcutFileName"),
+ "Copied profile should not have desktop shortcut pref"
+ );
});
add_task(async function test_copy_profile_with_encryption() {