Bug 1893693 - Create SelectableProfile and SelectableProfileService. r=mossop

Differential Revision: https://phabricator.services.mozilla.com/D210201
This commit is contained in:
Niklas Baumgardner 2024-05-27 16:36:43 +00:00
parent 30fdfcf7c3
commit 16de0305a2
7 changed files with 322 additions and 3 deletions

View File

@ -51,7 +51,6 @@ DIRS += [
"pocket",
"preferences",
"privatebrowsing",
"profiles",
"prompts",
"protections",
"protocolhandler",
@ -75,6 +74,8 @@ DIRS += [
DIRS += ["build"]
if CONFIG["MOZ_SELECTABLE_PROFILES"]:
DIRS += ["profiles"]
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
DIRS += ["touchbar"]

View File

@ -2,4 +2,4 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
export class ProfilesChild extends JSWindowActorParent {}
export class ProfilesChild extends JSWindowActorChild {}

View File

@ -0,0 +1,117 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* The selectable profile
*/
export class SelectableProfile {
// DB internal autoincremented integer ID.
// eslint-disable-next-line no-unused-private-class-members
#id;
// Path to profile on disk.
#path;
// The user-editable name
#name;
// Name of the user's chosen avatar, which corresponds to a list of built-in
// SVG avatars.
#avatar;
// Cached theme properties, used to allow displaying a SelectableProfile
// without loading the AddonManager to get theme info.
#themeL10nID;
#themeFG;
#themeBG;
// Note: setters update the object, then ask the SelectableProfileService to save it.
/**
* Get the user-editable name for the profile.
*
* @returns {string} Name of profile
*/
get name() {
return this.#name;
}
/**
* Update the user-editable name for the profile, then trigger saving the profile,
* which will notify() other running instances.
*
* @param {string} aName The new name of the profile
*/
set name(aName) {
this.#name = aName;
this.saveUpdatesToDB();
}
/**
* Get the path to the profile on disk.
*
* @returns {string} Path of profile
*/
get path() {
return this.#path;
}
/**
* Get the name of the avatar for the profile.
*
* @returns {string} Name of the avatar
*/
get avatar() {
return this.#avatar;
}
/**
* Update the avatar, then trigger saving the profile, which will notify()
* other running instances.
*
* @param {string} aAvatar Name of the avatar
*/
set avatar(aAvatar) {
this.avatar = aAvatar;
this.saveUpdatesToDB();
}
// Note, theme properties are set and returned as a group.
/**
* Get the theme l10n-id as a string, like "theme-foo-name".
* the theme foreground color as CSS style string, like "rgb(1,1,1)",
* the theme background color as CSS style string, like "rgb(0,0,0)".
*
* @returns {object} an object of the form { l10nID, fgColor, bgColor }.
*/
get theme() {
return {
l10nID: this.#themeL10nID,
fgColor: this.#themeFG,
bgColor: this.#themeBG,
};
}
/**
* Update the theme (all three properties are required), then trigger saving
* the profile, which will notify() other running instances.
*
* @param {object} param0 The theme object
* @param {string} param0.l10nID L10n id of the theme
* @param {string} param0.fgColor Foreground color of theme as CSS style string, like "rgb(1,1,1)",
* @param {string} param0.bgColor Background color of theme as CSS style string, like "rgb(0,0,0)".
*/
set theme({ l10nID, fgColor, bgColor }) {
this.#themeL10nID = l10nID;
this.#themeFG = fgColor;
this.#themeBG = bgColor;
this.saveUpdatesToDB();
}
saveUpdatesToDB() {}
}

View File

@ -0,0 +1,166 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// TDOD: Remove this line once methods are updated. See bug 1896727
/* eslint-disable no-unused-vars */
/**
* The service that manages selectable profiles
*/
export class SelectableProfileService {
/**
* At startup, store the nsToolkitProfile for the group.
* Get the groupDBPath from the nsToolkitProfile, and connect to it.
*
* @param {nsToolkitProfile} groupProfile The current toolkit profile
*/
init(groupProfile) {}
/**
* Create the SQLite DB for the profile group.
* Init shared prefs for the group and add to DB.
* Create the Group DB path to aNamedProfile entry in profiles.ini.
* Import aNamedProfile into DB.
*
* @param {nsToolkitProfile} groupProfile The current toolkit profile
*/
createProfileGroup(groupProfile) {}
/**
* When the last selectable profile in a group is deleted,
* also remove the profile group's named profile entry from profiles.ini
* and delete the group DB.
*/
deleteProfileGroup() {}
// App session lifecycle methods and multi-process support
/**
* When the group DB has been updated, either changes to prefs or profiles,
* ask the remoting service to notify other running instances that they should
* check for updates and refresh their UI accordingly.
*/
notify() {}
/**
* Invoked when the remoting service has notified this instance that another
* instance has updated the database. Triggers refreshProfiles() and refreshPrefs().
*/
observe() {}
/**
* Init or update the current SelectableProfiles from the DB.
*/
refreshProfiles() {}
/**
* Fetch all prefs from the DB and write to the current instance.
*/
refreshPrefs() {}
/**
* Update the current default profile by setting its path as the Path
* of the nsToolkitProfile for the group.
*
* @param {SelectableProfile} aSelectableProfile The new default SelectableProfile
*/
setDefault(aSelectableProfile) {}
/**
* Update whether to show the selectable profile selector window at startup.
* Set on the nsToolkitProfile instance for the group.
*
* @param {boolean} shouldShow Whether or not we should show the profile selector
*/
setShowProfileChooser(shouldShow) {}
/**
* Update the path to the group DB. Set on the nsToolkitProfile instance
* for the group.
*
* @param {string} aPath The path to the group DB
*/
setGroupDBPath(aPath) {}
// SelectableProfile lifecycle
/**
* Create an empty SelectableProfile and add it to the group DB.
* This is an unmanaged profile from the nsToolkitProfile perspective.
*/
createProfile() {}
/**
* Delete a SelectableProfile from the group DB.
* If it was the last profile in the group, also call deleteProfileGroup().
*/
deleteProfile() {}
/**
* Schedule deletion of the current SelectableProfile as a background task, then exit.
*/
deleteCurrentProfile() {}
/**
* Write an updated profile to the DB.
*
* @param {SelectableProfile} aSelectableProfile The SelectableProfile to be update
*/
updateProfile(aSelectableProfile) {}
/**
* Get the complete list of profiles in the group.
*/
getProfiles() {}
/**
* Get a specific profile by its internal ID.
*
* @param {number} aProfileID The internal id of the profile
*/
getProfile(aProfileID) {}
// Shared Prefs management
/**
* Get all shared prefs as a list.
*/
getAllPrefs() {}
/**
* Get the value of a specific shared pref.
*
* @param {string} aPrefName The name of the pref to get
*/
getPref(aPrefName) {}
/**
* Insert or update a pref value, then notify() other running instances.
*
* @param {string} aPrefName The name of the pref
* @param {string} aPrefType The type of the pref
* @param {any} aPrefValue The value of the pref
*/
createOrUpdatePref(aPrefName, aPrefType, aPrefValue) {}
/**
* Remove a shared pref, then notify() other running instances.
*
* @param {string} aPrefName The name of the pref to delete
*/
deletePref(aPrefName) {}
// DB lifecycle
/**
* Create the SQLite DB for the profile group at groupDBPath.
* Init shared prefs for the group and add to DB.
*/
createGroupDB() {}
/**
* Delete the SQLite DB when the last selectable profile is deleted.
*/
deleteGroupDB() {}
}

View File

@ -4,6 +4,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
XPCSHELL_TESTS_MANIFESTS += ["tests/unit/xpcshell.toml"]
JAR_MANIFESTS += ["jar.mn"]
FINAL_TARGET_FILES.actors += [
@ -11,5 +13,10 @@ FINAL_TARGET_FILES.actors += [
"ProfilesParent.sys.mjs",
]
EXTRA_JS_MODULES.profiles += [
"SelectableProfile.sys.mjs",
"SelectableProfileService.sys.mjs",
]
with Files("**"):
BUG_COMPONENT = ("Firefox", "Profiles")
BUG_COMPONENT = ("Toolkit", "Startup and Profile System")

View File

@ -0,0 +1,24 @@
/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const { SelectableProfile } = ChromeUtils.importESModule(
"resource:///modules/profiles/SelectableProfile.sys.mjs"
);
const { SelectableProfileService } = ChromeUtils.importESModule(
"resource:///modules/profiles/SelectableProfileService.sys.mjs"
);
add_task(
{
skip_if: () => !AppConstants.MOZ_SELECTABLE_PROFILES,
},
async function test_SelectableProfileAndServiceExist() {
ok(SelectableProfile, "SelectableProfile exists");
ok(SelectableProfileService, "SelectableProfileService exists");
}
);

View File

@ -0,0 +1,4 @@
[DEFAULT]
firefox-appdir = "browser"
["test_selectable_profile_service_exists.js"]