summaryrefslogtreecommitdiffstats
path: root/browser/base/content/browser-profiles.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /browser/base/content/browser-profiles.js
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-adbda400be353e676059e335c3c0aaf99e719475.tar.xz
firefox-adbda400be353e676059e335c3c0aaf99e719475.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/browser-profiles.js')
-rw-r--r--browser/base/content/browser-profiles.js99
1 files changed, 99 insertions, 0 deletions
diff --git a/browser/base/content/browser-profiles.js b/browser/base/content/browser-profiles.js
new file mode 100644
index 0000000000..72eca39e44
--- /dev/null
+++ b/browser/base/content/browser-profiles.js
@@ -0,0 +1,99 @@
+/* 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/. */
+
+// This file is loaded into the browser window scope.
+/* eslint-env mozilla/browser-window */
+
+XPCOMUtils.defineLazyServiceGetter(
+ this,
+ "ProfileService",
+ "@mozilla.org/toolkit/profile-service;1",
+ "nsIToolkitProfileService"
+);
+
+var gProfiles = {
+ init() {
+ XPCOMUtils.defineLazyPreferenceGetter(
+ this,
+ "PROFILES_ENABLED",
+ "browser.profiles.enabled",
+ false,
+ this.toggleProfileButtonsVisibility.bind(this)
+ );
+
+ if (!this.PROFILES_ENABLED) {
+ return;
+ }
+
+ this.toggleProfileButtonsVisibility();
+ },
+
+ toggleProfileButtonsVisibility() {
+ let profilesButton = PanelMultiView.getViewNode(
+ document,
+ "appMenu-profiles-button"
+ );
+
+ profilesButton.hidden = !this.PROFILES_ENABLED;
+
+ if (this.PROFILES_ENABLED) {
+ document.l10n.setArgs(profilesButton, {
+ profilename: ProfileService.currentProfile?.name ?? "",
+ });
+ }
+ },
+
+ updateView(panel) {
+ this.populateSubView();
+ PanelUI.showSubView("PanelUI-profiles", panel);
+ },
+
+ async populateSubView() {
+ let closeProfileButton = PanelMultiView.getViewNode(
+ document,
+ "profiles-close-profile-button"
+ );
+ document.l10n.setArgs(closeProfileButton, {
+ profilename: ProfileService.currentProfile?.name ?? "",
+ });
+
+ let profileIconEl = PanelMultiView.getViewNode(
+ document,
+ "profile-icon-image"
+ );
+ profileIconEl.style.listStyleImage = `url(${
+ ProfileService.currentProfile?.iconURL ??
+ "chrome://branding/content/icon64.png"
+ })`;
+
+ let profileNameEl = PanelMultiView.getViewNode(document, "profile-name");
+ profileNameEl.textContent = ProfileService.currentProfile?.name ?? "";
+
+ let profilesList = PanelMultiView.getViewNode(
+ document,
+ "PanelUI-profiles"
+ ).querySelector("#profiles-list");
+ while (profilesList.lastElementChild) {
+ profilesList.lastElementChild.remove();
+ }
+
+ for (let profile of ProfileService.profiles) {
+ if (profile === ProfileService.currentProfile) {
+ continue;
+ }
+
+ let button = document.createXULElement("toolbarbutton");
+ button.setAttribute("label", profile.name);
+ button.className = "subviewbutton subviewbutton-iconic";
+ button.style.listStyleImage = `url(${
+ profile.iconURL ?? "chrome://branding/content/icon16.png"
+ })`;
+ button.onclick = () => {
+ Services.startup.createInstanceWithProfile(profile);
+ };
+
+ profilesList.appendChild(button);
+ }
+ },
+};