Skip to content

Commit

Permalink
MB 329: Customize toolbar for mullvad-browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
henry-torproject authored and morganava committed Sep 27, 2024
1 parent 57d2cd5 commit 564c9f3
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion browser/components/customizableui/CustomizableUI.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ var kVersion = 20;
var kVersionBaseBrowser = 2;
const NoScriptId = "_73a6fe31-595d-460b-a920-fcc0f8843232_-browser-action";

/**
* The current version for mullvad browser.
*/
var kVersionMullvadBrowser = 1;

/**
* Buttons removed from built-ins by version they were removed. kVersion must be
* bumped any time a new id is added to this. Use the button id as key, and
Expand Down Expand Up @@ -228,6 +233,7 @@ var CustomizableUIInternal = {
this._updateForNewProtonVersion();
this._markObsoleteBuiltinButtonsSeen();
this._updateForBaseBrowser();
this._updateForMullvadBrowser();

this.registerArea(
CustomizableUI.AREA_FIXED_OVERFLOW_PANEL,
Expand Down Expand Up @@ -264,7 +270,11 @@ var CustomizableUIInternal = {
// Base-browser additions tor-browser#41736. If you want to add to, remove
// from, or rearrange this list, then bump the kVersionBaseBrowser and
// update existing saved states in _updateForBaseBrowser.
"security-level-button",
// Or if the change is only meant for mullvad-browser, bump
// kVersionMullvadBrowser instead and update the existing saved states in
// _updateForMullvadBrowser.
// Do not show the security-level-button by default in Mullvad Browser.
// See mullvad-browser#329
"new-identity-button",
"downloads-button",
AppConstants.MOZ_DEV_EDITION ? "developer-button" : null,
Expand Down Expand Up @@ -930,6 +940,44 @@ var CustomizableUIInternal = {
}
},

_updateForMullvadBrowser() {
if (!gSavedState) {
// Use the defaults.
return;
}

const currentVersion = gSavedState.currentVersionMullvadBrowser;

if (currentVersion < 1) {
// Remove security-level-button if:
// + it hasn't been moved out of the navbar by the user, and
// + the user does not have a custom security level.
//
// NOTE: _updateForBaseBrowser adds this button when
// currentVersionBaseBrowser < 1. This should only happen when
// currentVersionMullvadBrowser < 1, and this method runs after, so should
// reverse it.
const navbarPlacements =
gSavedState.placements[CustomizableUI.AREA_NAVBAR];
if (navbarPlacements) {
const buttonIndex = navbarPlacements.indexOf("security-level-button");
// Test if security level icon exists in the navbar.
// Even though a user may have moved the button within the navbar,
// there is no simple way to know whether the button was moved, or if
// other components were moved around it.
if (buttonIndex >= 0) {
// NOTE: We expect the SecurityLevel module to already be initialized.
const { SecurityLevelPrefs } = ChromeUtils.importESModule(
"resource://gre/modules/SecurityLevel.sys.mjs"
);
if (!SecurityLevelPrefs.securityCustom) {
navbarPlacements.splice(buttonIndex, 1);
}
}
}
}
},

_placeNewDefaultWidgetsInArea(aArea) {
let futurePlacedWidgets = gFuturePlacements.get(aArea);
let savedPlacements =
Expand Down Expand Up @@ -2773,6 +2821,10 @@ var CustomizableUIInternal = {
gSavedState.currentVersionBaseBrowser = 0;
}

if (!("currentVersionMullvadBrowser" in gSavedState)) {
gSavedState.currentVersionMullvadBrowser = 0;
}

gSeenWidgets = new Set(gSavedState.seen || []);
gDirtyAreaCache = new Set(gSavedState.dirtyAreaCache || []);
gNewElementCount = gSavedState.newElementCount || 0;
Expand Down Expand Up @@ -2856,6 +2908,7 @@ var CustomizableUIInternal = {
dirtyAreaCache: gDirtyAreaCache,
currentVersion: kVersion,
currentVersionBaseBrowser: kVersionBaseBrowser,
currentVersionMullvadBrowser: kVersionMullvadBrowser,
newElementCount: gNewElementCount,
};

Expand Down

0 comments on commit 564c9f3

Please sign in to comment.