commit cb7d6e60469b7f2f43610132a19453b5a86dc8c7
parent 4a77334ea34cf7c066f5c63b6aaf216e7eb3a532
Author: Rob Wu <rob@robwu.nl>
Date: Thu, 9 Oct 2025 01:59:34 +0000
Bug 1814871 - Refactor gUnifiedExtensions.getActivePolicies r=rpl
- Remove `policy.active` check because getActiveExtensions() only
returns entries that are active, by definition.
- Drop `all` parameter and move the `hasBrowserActionUI` check to the
only caller that cared (and already had a comment that explains why
we skip extensions that have a browser action).
- Move sorting to the only place that relies on the order (the place
that renders the extensions in a list). All other callers only care
about the items within, not their order.
- Replace `!!.filter(...).length` in `hasExtensionsInPanel` with
`.some(...)` to capture the intended outcome more clearly.
Differential Revision: https://phabricator.services.mozilla.com/D265130
Diffstat:
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/browser/base/content/browser-addons.js b/browser/base/content/browser-addons.js
@@ -2233,20 +2233,17 @@ var gUnifiedExtensions = {
/**
* Gets a list of active WebExtensionPolicy instances of type "extension",
- * sorted alphabetically based on add-on's names. Optionally, filter out
- * extensions with browser action.
+ * excluding hidden extensions, available to this window.
*
- * @param {bool} all When set to true (the default), return the list of all
- * active policies, including the ones that have a
- * browser action. Otherwise, extensions with browser
- * action are filtered out.
* @returns {Array<WebExtensionPolicy>} An array of active policies.
*/
- getActivePolicies(all = true) {
+ getActivePolicies() {
let policies = WebExtensionPolicy.getActiveExtensions();
policies = policies.filter(policy => {
let { extension } = policy;
- if (!policy.active || extension?.type !== "extension") {
+ if (extension?.type !== "extension") {
+ // extension can only be null due to bugs (bug 1642012).
+ // Exclude non-extension types such as themes, dictionaries, etc.
return false;
}
@@ -2257,10 +2254,9 @@ var gUnifiedExtensions = {
return false;
}
- return all || !extension.hasBrowserActionUI;
+ return true;
});
- policies.sort((a, b) => a.name.localeCompare(b.name));
return policies;
},
@@ -2273,16 +2269,14 @@ var gUnifiedExtensions = {
*/
hasExtensionsInPanel() {
const policies = this.getActivePolicies();
-
- return !!policies
- .map(policy => this.browserActionFor(policy)?.widget)
- .filter(widget => {
- return (
- !widget ||
- widget?.areaType !== CustomizableUI.TYPE_TOOLBAR ||
- widget?.forWindow(window).overflowed
- );
- }).length;
+ return policies.some(policy => {
+ let widget = this.browserActionFor(policy)?.widget;
+ return (
+ !widget ||
+ widget.areaType !== CustomizableUI.TYPE_TOOLBAR ||
+ widget.forWindow(window).overflowed
+ );
+ });
},
handleEvent(event) {
@@ -2343,11 +2337,18 @@ var gUnifiedExtensions = {
},
onPanelViewShowing(panelview) {
- const list = panelview.querySelector(".unified-extensions-list");
+ const policies = this.getActivePolicies();
+
// Only add extensions that do not have a browser action in this list since
// the extensions with browser action have CUI widgets and will appear in
// the panel (or toolbar) via the CUI mechanism.
- for (const policy of this.getActivePolicies(/* all */ false)) {
+ const policiesForList = policies.filter(
+ p => !p.extension.hasBrowserActionUI
+ );
+ policiesForList.sort((a, b) => a.name.localeCompare(b.name));
+
+ const list = panelview.querySelector(".unified-extensions-list");
+ for (const policy of policiesForList) {
const item = document.createElement("unified-extensions-item");
item.setExtension(policy.extension);
list.appendChild(item);