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/. */
7 loader.lazyRequireGetter(
10 "resource://devtools/client/shared/widgets/tooltip/HTMLTooltip.js",
17 "Enable fission in Firefox. When navigating between two domains, you " +
18 "will switch between two distinct processes. And if an iframe is " +
19 "hosted from another domain, it will run in another process",
22 "devtools.every-frame-target.enabled",
23 "When enabled, targets will be created for all iframes, no matter if " +
24 "they are remote or not, independently of Fission being enabled or not",
27 "fission.bfcacheInParent",
28 "Enable bfcache navigation in parent process (requires Fission and involve " +
29 "more top level target switching",
34 * Temporary module to show a Tooltip with the currently enabled preferences
35 * relevant for DevTools ongoing architectural work (e.g. Fission, EFT, …).
37 * This module should be deleted once all experimental prefs are preffed on in Nightly.
39 function showTooltip(toolbox) {
40 if (!toolbox._experimentalPrefsTooltip) {
41 toolbox._experimentalPrefsTooltip = new HTMLTooltip(toolbox.doc, {
45 toolbox.once("destroy", () => toolbox._experimentalPrefsTooltip.destroy());
48 // Terrible hack to allow to toggle using the command button.
49 if (toolbox._experimentalPrefsTooltip.preventShow) {
53 updateTooltipContent(toolbox);
55 const commandId = "command-button-experimental-prefs";
56 toolbox._experimentalPrefsTooltip.show(toolbox.doc.getElementById(commandId));
58 // Follows a hack to be able to close the tooltip when clicking on the
59 // command button. Otherwise it will flicker and reopen.
60 toolbox._experimentalPrefsTooltip.preventShow = true;
61 toolbox._experimentalPrefsTooltip.once("hidden", () => {
62 toolbox.win.setTimeout(
63 () => (toolbox._experimentalPrefsTooltip.preventShow = false),
68 exports.showTooltip = showTooltip;
69 function updateTooltipContent(toolbox) {
70 const container = toolbox.doc.createElement("div");
73 * This is the grid we want to have:
74 * +--------------------------------------------+---------------+
75 * | Header text | Reset button |
76 * +------+-----------------------------+-------+---------------+
77 * | Icon | Preference name | Value | Toggle button |
78 * +------+-----------------------------+-------+---------------+
79 * | Icon | Preference name | Value | Toggle button |
80 * +------+-----------------------------+-------+---------------+
83 Object.assign(container.style, {
86 "max-content minmax(300px, auto) max-content max-content",
88 gridTemplateRows: `repeat(${PREFERENCES.length + 1}, auto)`,
94 container.classList.add("theme-body");
96 const headerContainer = toolbox.doc.createElement("header");
98 * The grid layout of the header container is as follows:
100 * +-------------------------+--------------+
101 * | Header text | Reset button |
102 * +-------------------------+--------------+
105 Object.assign(headerContainer.style, {
107 gridTemplateColumns: "subgrid",
108 gridColumn: "1 / -1",
111 const header = toolbox.doc.createElement("h1");
113 Object.assign(header.style, {
114 gridColumn: "1 / -2",
120 header.textContent = "DevTools Experimental preferences";
122 const resetButton = toolbox.doc.createElement("button");
123 resetButton.addEventListener("click", () => {
124 for (const [name] of PREFERENCES) {
125 Services.prefs.clearUserPref(name);
127 updateTooltipContent(toolbox);
129 resetButton.textContent = "reset all";
131 headerContainer.append(header, resetButton);
133 const prefList = toolbox.doc.createElement("ul");
134 Object.assign(prefList.style, {
136 gridTemplateColumns: "subgrid",
137 gridTemplateRows: "subgrid",
138 // Subgrid should span all grid columns
139 gridColumn: "1 / -1",
146 for (const [name, desc] of PREFERENCES) {
147 const prefEl = createPreferenceListItem(toolbox, name, desc);
148 prefList.appendChild(prefEl);
151 container.append(headerContainer, prefList);
153 toolbox._experimentalPrefsTooltip.panel.innerHTML = "";
154 // There is a hardcoded 320px max width for doorhanger tooltips,
156 toolbox._experimentalPrefsTooltip.panel.style.maxWidth = "unset";
157 toolbox._experimentalPrefsTooltip.panel.appendChild(container);
160 function createPreferenceListItem(toolbox, name, desc) {
161 const isPrefEnabled = Services.prefs.getBoolPref(name, false);
163 const prefEl = toolbox.doc.createElement("li");
166 * The grid layout of a preference line is as follows:
168 * +------+-----------------------------+-------+---------------+
169 * | Icon | Preference name | Value | Toggle button |
170 * +------+-----------------------------+-------+---------------+
173 Object.assign(prefEl.style, {
177 alignItems: "center",
178 gridTemplateColumns: "subgrid",
179 gridColumn: "1 / -1",
182 prefEl.classList.toggle("theme-comment", !isPrefEnabled);
185 const prefInfo = toolbox.doc.createElement("div");
186 prefInfo.title = desc;
188 Object.assign(prefInfo.style, {
193 prefInfo.classList.add("experimental-pref-icon");
196 const prefTitle = toolbox.doc.createElement("span");
198 Object.assign(prefTitle.style, {
200 fontWeight: isPrefEnabled ? "bold" : "normal",
203 prefTitle.textContent = name;
206 const prefValue = toolbox.doc.createElement("span");
207 prefValue.textContent = isPrefEnabled;
210 const toggleButton = toolbox.doc.createElement("button");
211 toggleButton.addEventListener("click", () => {
212 Services.prefs.setBoolPref(name, !isPrefEnabled);
213 updateTooltipContent(toolbox);
215 toggleButton.textContent = "toggle";
217 prefEl.append(prefInfo, prefTitle, prefValue, toggleButton);
221 function isAnyPreferenceEnabled() {
222 for (const [name] of PREFERENCES) {
223 const isPrefEnabled = Services.prefs.getBoolPref(name, false);
230 exports.isAnyPreferenceEnabled = isAnyPreferenceEnabled;