Skip to content

Commit 006285e

Browse files
committed
Bug 1976952 - Change Taskbar Tabs page action visibility as the pref changes. r=nrishel
Differential Revision: https://phabricator.services.mozilla.com/D257056
1 parent 02c748b commit 006285e

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

browser/components/taskbartabs/TaskbarTabsPageAction.sys.mjs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,10 @@ export const TaskbarTabsPageAction = {
3535
* @param {DOMWindow} aWindow - The browser window.
3636
*/
3737
init(aWindow) {
38-
let taskbarTabsEnabled = lazy.TaskbarTabsUtils.isEnabled();
3938
let isPopupWindow = !aWindow.toolbar.visible;
4039
let isPrivate = lazy.PrivateBrowsingUtils.isWindowPrivate(aWindow);
4140

42-
if (
43-
!taskbarTabsEnabled ||
44-
isPopupWindow ||
45-
isPrivate ||
46-
AppConstants.platform != "win"
47-
) {
41+
if (isPopupWindow || isPrivate || AppConstants.platform != "win") {
4842
lazy.logConsole.info("Not initializing Taskbar Tabs Page Action.");
4943
return;
5044
}
@@ -131,7 +125,8 @@ export const TaskbarTabsPageAction = {
131125
* @param {Element} aElement - The element that makes up the page action.
132126
*/
133127
function initVisibilityChanges(aWindow, aElement) {
134-
const shouldHide = aLocation => !aLocation.scheme.startsWith("http");
128+
const shouldHide = aLocation =>
129+
!(aLocation.scheme.startsWith("http") && lazy.TaskbarTabsUtils.isEnabled());
135130
aElement.hidden = shouldHide(aWindow.gBrowser.currentURI);
136131

137132
aWindow.gBrowser.addProgressListener({
@@ -141,4 +136,13 @@ function initVisibilityChanges(aWindow, aElement) {
141136
}
142137
},
143138
});
139+
140+
const observer = () => {
141+
aElement.hidden = shouldHide(aWindow.gBrowser.currentURI);
142+
};
143+
144+
Services.prefs.addObserver("browser.taskbarTabs.enabled", observer);
145+
aWindow.addEventListener("unload", function () {
146+
Services.prefs.removeObserver("browser.taskbarTabs.enabled", observer);
147+
});
144148
}

browser/components/taskbartabs/test/browser/browser_taskbarTabs_pageAction.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,22 @@ add_task(async function testIframeNavigationIsIgnored() {
301301
function getURIScheme(uri) {
302302
return Services.io.newURI(uri).scheme;
303303
}
304+
305+
add_task(async function testPrefIsMonitored() {
306+
const element = document.getElementById("taskbar-tabs-button");
307+
308+
await BrowserTestUtils.withNewTab(BASE_URL, async () => {
309+
ok(!element.hidden, "Page action starts as visible");
310+
await testVisibilityChange(BASE_URL, HIDDEN_URI, true, false);
311+
312+
await SpecialPowers.pushPrefEnv({
313+
set: [["browser.taskbarTabs.enabled", false]],
314+
});
315+
ok(element.hidden, "Page action becomes invisible");
316+
await testVisibilityChange(BASE_URL, HIDDEN_URI, false, false);
317+
318+
await SpecialPowers.popPrefEnv();
319+
ok(!element.hidden, "Page action becomes visible again");
320+
await testVisibilityChange(BASE_URL, HIDDEN_URI, true, false);
321+
});
322+
});

0 commit comments

Comments
 (0)