diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /browser/components/extensions/parent/ext-sidebarAction.js | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/extensions/parent/ext-sidebarAction.js')
-rw-r--r-- | browser/components/extensions/parent/ext-sidebarAction.js | 169 |
1 files changed, 51 insertions, 118 deletions
diff --git a/browser/components/extensions/parent/ext-sidebarAction.js b/browser/components/extensions/parent/ext-sidebarAction.js index 197456abd9..b2c009014e 100644 --- a/browser/components/extensions/parent/ext-sidebarAction.js +++ b/browser/components/extensions/parent/ext-sidebarAction.js @@ -17,8 +17,6 @@ var { IconDetails } = ExtensionParent; // WeakMap[Extension -> SidebarAction] let sidebarActionMap = new WeakMap(); -const sidebarURL = "chrome://browser/content/webext-panels.xhtml"; - /** * Responsible for the sidebar_action section of the manifest as well * as the associated sidebar browser. @@ -40,7 +38,6 @@ this.sidebarAction = class extends ExtensionAPI { let widgetId = makeWidgetId(extension.id); this.id = `${widgetId}-sidebar-action`; this.menuId = `menubar_menu_${this.id}`; - this.switcherMenuId = `sidebarswitcher_menu_${this.id}`; this.browserStyle = options.browser_style; @@ -66,23 +63,6 @@ this.sidebarAction = class extends ExtensionAPI { }; windowTracker.addOpenListener(this.windowOpenListener); - this.updateHeader = event => { - let window = event.target.ownerGlobal; - let details = this.tabContext.get(window.gBrowser.selectedTab); - let header = window.document.getElementById("sidebar-switcher-target"); - if (window.SidebarUI.currentID === this.id) { - this.setMenuIcon(header, details); - } - }; - - this.windowCloseListener = window => { - let header = window.document.getElementById("sidebar-switcher-target"); - if (header) { - header.removeEventListener("SidebarShown", this.updateHeader); - } - }; - windowTracker.addCloseListener(this.windowCloseListener); - sidebarActionMap.set(extension, this); } @@ -91,7 +71,7 @@ this.sidebarAction = class extends ExtensionAPI { } onShutdown(isAppShutdown) { - sidebarActionMap.delete(this.this); + sidebarActionMap.delete(this.extension); this.tabContext.shutdown(); @@ -102,26 +82,18 @@ this.sidebarAction = class extends ExtensionAPI { } for (let window of windowTracker.browserWindows()) { - let { document, SidebarUI } = window; - if (SidebarUI.currentID === this.id) { - SidebarUI.hide(); - } - document.getElementById(this.menuId)?.remove(); - document.getElementById(this.switcherMenuId)?.remove(); - let header = document.getElementById("sidebar-switcher-target"); - header.removeEventListener("SidebarShown", this.updateHeader); - SidebarUI.sidebars.delete(this.id); + let { SidebarController } = window; + SidebarController.removeExtension(this.id); } windowTracker.removeOpenListener(this.windowOpenListener); - windowTracker.removeCloseListener(this.windowCloseListener); } static onUninstall(id) { const sidebarId = `${makeWidgetId(id)}-sidebar-action`; for (let window of windowTracker.browserWindows()) { - let { SidebarUI } = window; - if (SidebarUI.lastOpenedId === sidebarId) { - SidebarUI.lastOpenedId = null; + let { SidebarController } = window; + if (SidebarController.lastOpenedId === sidebarId) { + SidebarController.lastOpenedId = null; } } } @@ -135,12 +107,12 @@ this.sidebarAction = class extends ExtensionAPI { let install = this.extension.startupReason === "ADDON_INSTALL"; for (let window of windowTracker.browserWindows()) { this.updateWindow(window); - let { SidebarUI } = window; + let { SidebarController } = window; if ( (install && this.extension.manifest.sidebar_action.open_at_install) || - SidebarUI.lastOpenedId == this.id + SidebarController.lastOpenedId == this.id ) { - SidebarUI.show(this.id); + SidebarController.show(this.id); } } } @@ -149,60 +121,29 @@ this.sidebarAction = class extends ExtensionAPI { if (!this.extension.canAccessWindow(window)) { return; } - let { document, SidebarUI } = window; - let keyId = `ext-key-id-${this.id}`; - - SidebarUI.sidebars.set(this.id, { - title: details.title, - url: sidebarURL, + this.panel = details.panel; + let { SidebarController } = window; + SidebarController.registerExtension(this.id, { + icon: this.getMenuIcon(details), menuId: this.menuId, - switcherMenuId: this.switcherMenuId, - // The following properties are specific to extensions + title: details.title, extensionId: this.extension.id, - panel: details.panel, - browserStyle: this.browserStyle, + onload: () => + SidebarController.browser.contentWindow.loadPanel( + this.extension.id, + this.panel, + this.browserStyle + ), }); - - let header = document.getElementById("sidebar-switcher-target"); - header.addEventListener("SidebarShown", this.updateHeader); - - // Insert a menuitem for View->Show Sidebars. - let menuitem = document.createXULElement("menuitem"); - menuitem.setAttribute("id", this.menuId); - menuitem.setAttribute("type", "checkbox"); - menuitem.setAttribute("label", details.title); - menuitem.setAttribute("oncommand", `SidebarUI.toggle("${this.id}");`); - menuitem.setAttribute("class", "menuitem-iconic webextension-menuitem"); - menuitem.setAttribute("key", keyId); - this.setMenuIcon(menuitem, details); - - // Insert a toolbarbutton for the sidebar dropdown selector. - let switcherMenuitem = menuitem.cloneNode(); - switcherMenuitem.setAttribute("id", this.switcherMenuId); - switcherMenuitem.removeAttribute("type"); - - document.getElementById("viewSidebarMenu").appendChild(menuitem); - let separator = document.getElementById("sidebar-extensions-separator"); - separator.parentNode.insertBefore(switcherMenuitem, separator); - - return menuitem; } - setMenuIcon(menuitem, details) { + getMenuIcon(details) { let getIcon = size => IconDetails.escapeUrl( IconDetails.getPreferredIcon(details.icon, this.extension, size).icon ); - menuitem.setAttribute( - "style", - ` - --webextension-menuitem-image: image-set( - url("${getIcon(16)}"), - url("${getIcon(32)}") 2x - ); - ` - ); + return `image-set(url("${getIcon(16)}"), url("${getIcon(32)}") 2x)`; } /** @@ -214,34 +155,26 @@ this.sidebarAction = class extends ExtensionAPI { * Tab specific sidebar configuration. */ updateButton(window, tabData) { - let { document, SidebarUI } = window; + let { document, SidebarController } = window; let title = tabData.title || this.extension.name; - let menu = document.getElementById(this.menuId); - if (!menu) { - menu = this.createMenuItem(window, tabData); + if (!document.getElementById(this.menuId)) { + // Menu items are added when new windows are opened, or from onReady (when + // an extension has fully started). The menu item may be missing at this + // point if the extension updates the sidebar during its startup. + this.createMenuItem(window, tabData); } - - let urlChanged = tabData.panel !== SidebarUI.sidebars.get(this.id).panel; + let urlChanged = tabData.panel !== this.panel; if (urlChanged) { - SidebarUI.sidebars.get(this.id).panel = tabData.panel; - } - - menu.setAttribute("label", title); - this.setMenuIcon(menu, tabData); - - let button = document.getElementById(this.switcherMenuId); - button.setAttribute("label", title); - this.setMenuIcon(button, tabData); - - // Update the sidebar if this extension is the current sidebar. - if (SidebarUI.currentID === this.id) { - SidebarUI.title = title; - let header = document.getElementById("sidebar-switcher-target"); - this.setMenuIcon(header, tabData); - if (SidebarUI.isOpen && urlChanged) { - SidebarUI.show(this.id); - } + this.panel = tabData.panel; } + SidebarController.setExtensionAttributes( + this.id, + { + icon: this.getMenuIcon(tabData), + label: title, + }, + urlChanged + ); } /** @@ -382,9 +315,9 @@ this.sidebarAction = class extends ExtensionAPI { * @param {ChromeWindow} window */ triggerAction(window) { - let { SidebarUI } = window; - if (SidebarUI && this.extension.canAccessWindow(window)) { - SidebarUI.toggle(this.id); + let { SidebarController } = window; + if (SidebarController && this.extension.canAccessWindow(window)) { + SidebarController.toggle(this.id); } } @@ -394,9 +327,9 @@ this.sidebarAction = class extends ExtensionAPI { * @param {ChromeWindow} window */ open(window) { - let { SidebarUI } = window; - if (SidebarUI && this.extension.canAccessWindow(window)) { - SidebarUI.show(this.id); + let { SidebarController } = window; + if (SidebarController && this.extension.canAccessWindow(window)) { + SidebarController.show(this.id); } } @@ -407,7 +340,7 @@ this.sidebarAction = class extends ExtensionAPI { */ close(window) { if (this.isOpen(window)) { - window.SidebarUI.hide(); + window.SidebarController.hide(); } } @@ -417,15 +350,15 @@ this.sidebarAction = class extends ExtensionAPI { * @param {ChromeWindow} window */ toggle(window) { - let { SidebarUI } = window; - if (!SidebarUI || !this.extension.canAccessWindow(window)) { + let { SidebarController } = window; + if (!SidebarController || !this.extension.canAccessWindow(window)) { return; } if (!this.isOpen(window)) { - SidebarUI.show(this.id); + SidebarController.show(this.id); } else { - SidebarUI.hide(); + SidebarController.hide(); } } @@ -436,8 +369,8 @@ this.sidebarAction = class extends ExtensionAPI { * @returns {boolean} */ isOpen(window) { - let { SidebarUI } = window; - return SidebarUI.isOpen && this.id == SidebarUI.currentID; + let { SidebarController } = window; + return SidebarController.isOpen && this.id == SidebarController.currentID; } getAPI(context) { |