1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // This file is loaded into the browser window scope.
6 /* eslint-env mozilla/browser-window */
8 XPCOMUtils.defineLazyServiceGetter(
11 "@mozilla.org/toolkit/profile-service;1",
12 "nsIToolkitProfileService"
17 XPCOMUtils.defineLazyPreferenceGetter(
20 "browser.profiles.enabled",
22 this.toggleProfileButtonsVisibility.bind(this)
25 if (!this.PROFILES_ENABLED) {
29 this.toggleProfileButtonsVisibility();
32 toggleProfileButtonsVisibility() {
33 let profilesButton = PanelMultiView.getViewNode(
35 "appMenu-profiles-button"
38 profilesButton.hidden = !this.PROFILES_ENABLED;
40 if (this.PROFILES_ENABLED) {
41 document.l10n.setArgs(profilesButton, {
42 profilename: ProfileService.currentProfile?.name ?? "",
48 this.populateSubView();
49 PanelUI.showSubView("PanelUI-profiles", panel);
52 async populateSubView() {
53 let closeProfileButton = PanelMultiView.getViewNode(
55 "profiles-close-profile-button"
57 document.l10n.setArgs(closeProfileButton, {
58 profilename: ProfileService.currentProfile?.name ?? "",
61 let profileIconEl = PanelMultiView.getViewNode(
65 profileIconEl.style.listStyleImage = `url(${
66 ProfileService.currentProfile?.iconURL ??
67 "chrome://branding/content/icon64.png"
70 let profileNameEl = PanelMultiView.getViewNode(document, "profile-name");
71 profileNameEl.textContent = ProfileService.currentProfile?.name ?? "";
73 let profilesList = PanelMultiView.getViewNode(
76 ).querySelector("#profiles-list");
77 while (profilesList.lastElementChild) {
78 profilesList.lastElementChild.remove();
81 for (let profile of ProfileService.profiles) {
82 if (profile === ProfileService.currentProfile) {
86 let button = document.createXULElement("toolbarbutton");
87 button.setAttribute("label", profile.name);
88 button.className = "subviewbutton subviewbutton-iconic";
89 button.style.listStyleImage = `url(${
90 profile.iconURL ?? "chrome://branding/content/icon16.png"
92 button.onclick = () => {
93 Services.startup.createInstanceWithProfile(profile);
96 profilesList.appendChild(button);