TaskbarTabsChrome.sys.mjs (2984B)
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 https://mozilla.org/MPL/2.0/. */ 4 5 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; 6 7 let lazy = {}; 8 9 XPCOMUtils.defineLazyServiceGetters(lazy, { 10 Favicons: ["@mozilla.org/browser/favicon-service;1", Ci.nsIFaviconService], 11 }); 12 13 // Set up Taskbar Tabs Window Chrome. 14 export const TaskbarTabsChrome = { 15 /** 16 * Modifies the window chrome for Taskbar Tabs styling (mostly hiding elements). 17 * 18 * @param {Window} aWindow 19 */ 20 init(aWindow) { 21 let document = aWindow.document; 22 if (!document.documentElement.hasAttribute("taskbartab")) { 23 return; 24 } 25 26 // Ensure tab strip is hidden 27 aWindow.TabBarVisibility.update(); 28 29 // Hide bookmark star 30 document.getElementById("star-button-box").style.display = "none"; 31 32 // Hide fxa in the hamburger menu 33 document.documentElement.setAttribute("fxadisabled", true); 34 35 // Create the decorative corner icon 36 initCornerIcon(aWindow); 37 38 // Add a button to control muting/unmuting 39 initAudioButton(aWindow); 40 }, 41 }; 42 43 function initCornerIcon(aWindow) { 44 const favicon = aWindow.document.getElementById("taskbar-tabs-favicon"); 45 const tab = aWindow.gBrowser.tabs[0]; 46 47 function updateCornerIcon() { 48 const icon = aWindow.gBrowser.getIcon(tab); 49 if (icon && icon === favicon.src) { 50 return; 51 } 52 53 if (icon) { 54 favicon.src = icon; 55 } else { 56 favicon.src = lazy.Favicons.defaultFavicon.spec; 57 } 58 59 if (tab.hasAttribute("triggeringprincipal")) { 60 favicon.setAttribute( 61 "triggeringprincipal", 62 tab.getAttribute("iconloadingprincipal") 63 ); 64 } else { 65 favicon.removeAttribute("triggeringprincipal"); 66 } 67 } 68 69 tab.addEventListener("TabAttrModified", e => { 70 if ( 71 !e.detail.changed.includes("image") && 72 !e.detail.changed.includes("busy") 73 ) { 74 return; 75 } 76 77 // This holds the icon until the next page completely finishes loading; 78 // this is a bit long, but without a throbber is probably the best that 79 // can be done. 80 if (tab.hasAttribute("iconpending")) { 81 return; 82 } 83 84 updateCornerIcon(); 85 }); 86 updateCornerIcon(); 87 } 88 89 function initAudioButton(aWindow) { 90 const audioButton = aWindow.document.getElementById("taskbar-tabs-audio"); 91 const tab = aWindow.gBrowser.tabs[0]; 92 93 tab.addEventListener("TabAttrModified", _ => { 94 audioButton.toggleAttribute( 95 "soundplaying", 96 tab.hasAttribute("soundplaying") 97 ); 98 99 const muted = tab.hasAttribute("muted"); 100 audioButton.toggleAttribute("muted", muted); 101 audioButton.toggleAttribute("checked", muted); 102 audioButton.setAttribute( 103 "data-l10n-id", 104 muted ? "taskbar-tab-audio-unmute" : "taskbar-tab-audio-mute" 105 ); 106 }); 107 108 audioButton.addEventListener("command", _ => { 109 tab.toggleMuteAudio(); 110 }); 111 }