Bug 1880230 - Added support for private browsing only widgets in CustomizableUI. r=hsohaney,firefox-desktop-core-reviewers ,Gijs,desktop-theme-reviewers,dao

Differential Revision: https://phabricator.services.mozilla.com/D209857
This commit is contained in:
William Wen
2024-06-29 03:13:43 +00:00
parent a999a9f30b
commit cf7cd2418a
5 changed files with 220 additions and 6 deletions

View File

@@ -1178,6 +1178,10 @@ var CustomizableUIInternal = {
continue;
}
if (!inPrivateWindow && widget?.hideInNonPrivateBrowsing) {
continue;
}
this.ensureButtonContextMenu(node, aAreaNode);
// This needs updating in case we're resetting / undoing a reset.
@@ -1410,6 +1414,8 @@ var CustomizableUIInternal = {
let showInPrivateBrowsing = gPalette.has(aWidgetId)
? gPalette.get(aWidgetId).showInPrivateBrowsing
: true;
let hideInNonPrivateBrowsing =
gPalette.get(aWidgetId)?.hideInNonPrivateBrowsing ?? false;
for (let areaNode of areaNodes) {
let window = areaNode.ownerGlobal;
@@ -1420,6 +1426,13 @@ var CustomizableUIInternal = {
continue;
}
if (
hideInNonPrivateBrowsing &&
!lazy.PrivateBrowsingUtils.isWindowPrivate(window)
) {
continue;
}
let container = this.getCustomizationTarget(areaNode);
let widgetNode = window.document.getElementById(aWidgetId);
if (widgetNode && isOverflowable) {
@@ -1597,6 +1610,8 @@ var CustomizableUIInternal = {
let showInPrivateBrowsing = gPalette.has(aWidgetId)
? gPalette.get(aWidgetId).showInPrivateBrowsing
: true;
let hideInNonPrivateBrowsing =
gPalette.get(aWidgetId)?.hideInNonPrivateBrowsing ?? false;
if (
!showInPrivateBrowsing &&
@@ -1605,6 +1620,13 @@ var CustomizableUIInternal = {
return;
}
if (
hideInNonPrivateBrowsing &&
!lazy.PrivateBrowsingUtils.isWindowPrivate(window)
) {
return;
}
let [, widgetNode] = this.getWidgetNode(aWidgetId, window);
if (!widgetNode) {
lazy.log.error("Widget '" + aWidgetId + "' not found, unable to move");
@@ -1866,6 +1888,12 @@ var CustomizableUIInternal = {
) {
return null;
}
if (
aWidget.hideInNonPrivateBrowsing &&
!lazy.PrivateBrowsingUtils.isWindowPrivate(aDocument.defaultView)
) {
return null;
}
lazy.log.debug("Building " + aWidget.id + " of type " + aWidget.type);
@@ -2364,7 +2392,10 @@ var CustomizableUIInternal = {
// gPalette.
for (let [id, widget] of gPalette) {
if (!widget.currentArea) {
if (widget.showInPrivateBrowsing || !isWindowPrivate) {
if (
(isWindowPrivate && widget.showInPrivateBrowsing) ||
(!isWindowPrivate && !widget.hideInNonPrivateBrowsing)
) {
widgets.add(id);
}
}
@@ -2991,6 +3022,7 @@ var CustomizableUIInternal = {
tooltiptext: null,
l10nId: null,
showInPrivateBrowsing: true,
hideInNonPrivateBrowsing: false,
_introducedInVersion: -1,
_introducedByPref: null,
keepBroadcastAttributesWhenCustomizing: false,
@@ -3033,6 +3065,7 @@ var CustomizableUIInternal = {
const kOptBoolProps = [
"removable",
"showInPrivateBrowsing",
"hideInNonPrivateBrowsing",
"overflows",
"tabSpecific",
"locationSpecific",
@@ -3567,7 +3600,12 @@ var CustomizableUIInternal = {
// that are present. This avoids including items that don't exist (e.g. ids
// of add-on items that the user has uninstalled).
let orderedPlacements = CustomizableUI.getWidgetIdsInArea(container.id);
return orderedPlacements.filter(w => currentWidgets.has(w));
return orderedPlacements.filter(w => {
return (
currentWidgets.has(w) ||
this.getWidgetProvider(w) == CustomizableUI.PROVIDER_API
);
});
},
get inDefaultState() {
@@ -4209,6 +4247,8 @@ export var CustomizableUI = {
* as the "$shortcut" variable to the fluent message.
* - showInPrivateBrowsing: whether to show the widget in private browsing
* mode (optional, default: true)
* - hideInNonPrivateBrowsing: whether to hide the widget in non private
* browsing mode windows (optional, default: false)
* - tabSpecific: If true, closes the panel if the tab changes.
* - locationSpecific: If true, closes the panel if the location changes.
* This is similar to tabSpecific, but also if the location
@@ -4263,6 +4303,8 @@ export var CustomizableUI = {
* - tooltiptext: for API-provided widgets, the tooltip of the widget;
* - showInPrivateBrowsing: for API-provided widgets, whether the widget is
* visible in private browsing;
* - hideInNonPrivateBrowsing: for API-provided widgets, whether the widget is
* hidden in non-private browsing;
*
* Single window wrappers obtained through forWindow(someWindow) or from the
* instances array have the following properties
@@ -4969,6 +5011,7 @@ function WidgetGroupWrapper(aWidget) {
"label",
"tooltiptext",
"showInPrivateBrowsing",
"hideInNonPrivateBrowsing",
"viewId",
"disallowSubView",
"webExtension",