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",
32 "devtools.debugger.features.javascript-tracing",
33 "Enable the JavaScript tracer. (You need to restart Firefox / the Browser Toolbox to apply this setting)",
38 * Temporary module to show a Tooltip with the currently enabled preferences
39 * relevant for DevTools ongoing architectural work (e.g. Fission, EFT, …).
41 * This module should be deleted once all experimental prefs are preffed on in Nightly.
43 function showTooltip(toolbox
) {
44 if (!toolbox
._experimentalPrefsTooltip
) {
45 toolbox
._experimentalPrefsTooltip
= new HTMLTooltip(toolbox
.doc
, {
49 toolbox
.once("destroy", () => toolbox
._experimentalPrefsTooltip
.destroy());
52 // Terrible hack to allow to toggle using the command button.
53 if (toolbox
._experimentalPrefsTooltip
.preventShow
) {
57 updateTooltipContent(toolbox
);
59 const commandId
= "command-button-experimental-prefs";
60 toolbox
._experimentalPrefsTooltip
.show(toolbox
.doc
.getElementById(commandId
));
62 // Follows a hack to be able to close the tooltip when clicking on the
63 // command button. Otherwise it will flicker and reopen.
64 toolbox
._experimentalPrefsTooltip
.preventShow
= true;
65 toolbox
._experimentalPrefsTooltip
.once("hidden", () => {
66 toolbox
.win
.setTimeout(
67 () => (toolbox
._experimentalPrefsTooltip
.preventShow
= false),
72 exports
.showTooltip
= showTooltip
;
73 function updateTooltipContent(toolbox
) {
74 const container
= toolbox
.doc
.createElement("div");
77 * This is the grid we want to have:
78 * +--------------------------------------------+---------------+
79 * | Header text | Reset button |
80 * +------+-----------------------------+-------+---------------+
81 * | Icon | Preference name | Value | Toggle button |
82 * +------+-----------------------------+-------+---------------+
83 * | Icon | Preference name | Value | Toggle button |
84 * +------+-----------------------------+-------+---------------+
87 Object
.assign(container
.style
, {
90 "max-content minmax(300px, auto) max-content max-content",
92 gridTemplateRows
: `repeat(${PREFERENCES.length + 1}, auto)`,
98 container
.classList
.add("theme-body");
100 const headerContainer
= toolbox
.doc
.createElement("header");
102 * The grid layout of the header container is as follows:
104 * +-------------------------+--------------+
105 * | Header text | Reset button |
106 * +-------------------------+--------------+
109 Object
.assign(headerContainer
.style
, {
111 gridTemplateColumns
: "subgrid",
112 gridColumn
: "1 / -1",
115 const header
= toolbox
.doc
.createElement("h1");
117 Object
.assign(header
.style
, {
118 gridColumn
: "1 / -2",
124 header
.textContent
= "DevTools Experimental preferences";
126 const resetButton
= toolbox
.doc
.createElement("button");
127 resetButton
.addEventListener("click", () => {
128 for (const [name
] of PREFERENCES
) {
129 Services
.prefs
.clearUserPref(name
);
131 updateTooltipContent(toolbox
);
133 resetButton
.textContent
= "reset all";
135 headerContainer
.append(header
, resetButton
);
137 const prefList
= toolbox
.doc
.createElement("ul");
138 Object
.assign(prefList
.style
, {
140 gridTemplateColumns
: "subgrid",
141 gridTemplateRows
: "subgrid",
142 // Subgrid should span all grid columns
143 gridColumn
: "1 / -1",
150 for (const [name
, desc
] of PREFERENCES
) {
151 const prefEl
= createPreferenceListItem(toolbox
, name
, desc
);
152 prefList
.appendChild(prefEl
);
155 container
.append(headerContainer
, prefList
);
157 toolbox
._experimentalPrefsTooltip
.panel
.innerHTML
= "";
158 // There is a hardcoded 320px max width for doorhanger tooltips,
160 toolbox
._experimentalPrefsTooltip
.panel
.style
.maxWidth
= "unset";
161 toolbox
._experimentalPrefsTooltip
.panel
.appendChild(container
);
164 function createPreferenceListItem(toolbox
, name
, desc
) {
165 const isPrefEnabled
= Services
.prefs
.getBoolPref(name
, false);
167 const prefEl
= toolbox
.doc
.createElement("li");
170 * The grid layout of a preference line is as follows:
172 * +------+-----------------------------+-------+---------------+
173 * | Icon | Preference name | Value | Toggle button |
174 * +------+-----------------------------+-------+---------------+
177 Object
.assign(prefEl
.style
, {
181 alignItems
: "center",
182 gridTemplateColumns
: "subgrid",
183 gridColumn
: "1 / -1",
186 prefEl
.classList
.toggle("theme-comment", !isPrefEnabled
);
189 const prefInfo
= toolbox
.doc
.createElement("div");
190 prefInfo
.title
= desc
;
192 Object
.assign(prefInfo
.style
, {
197 prefInfo
.classList
.add("experimental-pref-icon");
200 const prefTitle
= toolbox
.doc
.createElement("span");
202 Object
.assign(prefTitle
.style
, {
204 fontWeight
: isPrefEnabled
? "bold" : "normal",
207 prefTitle
.textContent
= name
;
210 const prefValue
= toolbox
.doc
.createElement("span");
211 prefValue
.textContent
= isPrefEnabled
;
214 const toggleButton
= toolbox
.doc
.createElement("button");
215 toggleButton
.addEventListener("click", () => {
216 Services
.prefs
.setBoolPref(name
, !isPrefEnabled
);
217 updateTooltipContent(toolbox
);
219 toggleButton
.textContent
= "toggle";
221 prefEl
.append(prefInfo
, prefTitle
, prefValue
, toggleButton
);
225 function isAnyPreferenceEnabled() {
226 for (const [name
] of PREFERENCES
) {
227 const isPrefEnabled
= Services
.prefs
.getBoolPref(name
, false);
234 exports
.isAnyPreferenceEnabled
= isAnyPreferenceEnabled
;