| ... | ... | @@ -65,6 +65,11 @@ const kSubviewEvents = ["ViewShowing", "ViewHiding"]; | 
| 65 | 65 |   */
 | 
| 66 | 66 |  var kVersion = 17;
 | 
| 67 | 67 |  
 | 
|  | 68 | +/**
 | 
|  | 69 | + * The current version for base browser.
 | 
|  | 70 | + */
 | 
|  | 71 | +var kVersionBaseBrowser = 1;
 | 
|  | 72 | +
 | 
| 68 | 73 |  /**
 | 
| 69 | 74 |   * Buttons removed from built-ins by version they were removed. kVersion must be
 | 
| 70 | 75 |   * bumped any time a new id is added to this. Use the button id as key, and
 | 
| ... | ... | @@ -218,6 +223,7 @@ var CustomizableUIInternal = { | 
| 218 | 223 |      this._updateForNewVersion();
 | 
| 219 | 224 |      this._updateForNewProtonVersion();
 | 
| 220 | 225 |      this._markObsoleteBuiltinButtonsSeen();
 | 
|  | 226 | +    this._updateForBaseBrowser();
 | 
| 221 | 227 |  
 | 
| 222 | 228 |      this.registerArea(
 | 
| 223 | 229 |        CustomizableUI.AREA_FIXED_OVERFLOW_PANEL,
 | 
| ... | ... | @@ -236,10 +242,15 @@ var CustomizableUIInternal = { | 
| 236 | 242 |        Services.policies.isAllowed("removeHomeButtonByDefault")
 | 
| 237 | 243 |          ? null
 | 
| 238 | 244 |          : "home-button",
 | 
| 239 |  | -      "spring",
 | 
|  | 245 | +      // Don't want springs either side of the urlbar. tor-browser#41736
 | 
| 240 | 246 |        "urlbar-container",
 | 
| 241 |  | -      "spring",
 | 
| 242 |  | -      "save-to-pocket-button",
 | 
|  | 247 | +      // save-to-pocket-button is entirely disabled. See tor-browser#18886 and
 | 
|  | 248 | +      // tor-browser#31602.
 | 
|  | 249 | +      // Base-browser additions tor-browser#41736. If you want to add to, remove
 | 
|  | 250 | +      // from, or rearrange this list, then bump the kVersionBaseBrowser and
 | 
|  | 251 | +      // update existing saved states in _updateForBaseBrowser.
 | 
|  | 252 | +      "security-level-button",
 | 
|  | 253 | +      "new-identity-button",
 | 
| 243 | 254 |        "downloads-button",
 | 
| 244 | 255 |        AppConstants.MOZ_DEV_EDITION ? "developer-button" : null,
 | 
| 245 | 256 |        "fxa-toolbar-menu-button",
 | 
| ... | ... | @@ -255,6 +266,10 @@ var CustomizableUIInternal = { | 
| 255 | 266 |        },
 | 
| 256 | 267 |        true
 | 
| 257 | 268 |      );
 | 
|  | 269 | +    // navbarPlacements does not match the initial default XHTML layout.
 | 
|  | 270 | +    // Therefore we always need to rebuild the navbar area when
 | 
|  | 271 | +    // registerToolbarNode is called. tor-browser#41736
 | 
|  | 272 | +    gDirtyAreaCache.add(CustomizableUI.AREA_NAVBAR);
 | 
| 258 | 273 |  
 | 
| 259 | 274 |      if (AppConstants.MENUBAR_CAN_AUTOHIDE) {
 | 
| 260 | 275 |        this.registerArea(
 | 
| ... | ... | @@ -687,6 +702,104 @@ var CustomizableUIInternal = { | 
| 687 | 702 |      }
 | 
| 688 | 703 |    },
 | 
| 689 | 704 |  
 | 
|  | 705 | +  _updateForBaseBrowser() {
 | 
|  | 706 | +    if (!gSavedState) {
 | 
|  | 707 | +      // Use the defaults.
 | 
|  | 708 | +      return;
 | 
|  | 709 | +    }
 | 
|  | 710 | +
 | 
|  | 711 | +    const currentVersion = gSavedState.currentVersionBaseBrowser;
 | 
|  | 712 | +
 | 
|  | 713 | +    if (currentVersion < 1) {
 | 
|  | 714 | +      // NOTE: In base-browser/tor-browser version 12.5a5, and earlier, the
 | 
|  | 715 | +      // toolbar was configured by setting the full JSON string for the default
 | 
|  | 716 | +      // "browser.uiCustomization.state" preference value. The disadvantage is
 | 
|  | 717 | +      // that we could not update this value in a way that existing users (who
 | 
|  | 718 | +      // would have non-default preference values) would also get the desired
 | 
|  | 719 | +      // change (e.g. for adding or removing a button).
 | 
|  | 720 | +      //
 | 
|  | 721 | +      // With tor-browser#41736 we want to switch to changing the toolbar
 | 
|  | 722 | +      // dynamically like firefox. Therefore, this first version transfer simply
 | 
|  | 723 | +      // gets the toolbar into the same state we wanted before, away from the
 | 
|  | 724 | +      // default firefox state.
 | 
|  | 725 | +      //
 | 
|  | 726 | +      // If an existing user state aligned with the previous default
 | 
|  | 727 | +      // "browser.uiCustomization.state" then this shouldn't visibly change
 | 
|  | 728 | +      // anything.
 | 
|  | 729 | +      // If a user explicitly customized the toolbar to go back to the firefox
 | 
|  | 730 | +      // default, then this may undo those changes.
 | 
|  | 731 | +      const navbarPlacements =
 | 
|  | 732 | +        gSavedState.placements[CustomizableUI.AREA_NAVBAR];
 | 
|  | 733 | +      if (navbarPlacements) {
 | 
|  | 734 | +        const getBeforeAfterUrlbar = () => {
 | 
|  | 735 | +          // NOTE: The urlbar is non-removable from the navbar, so should have
 | 
|  | 736 | +          // an index.
 | 
|  | 737 | +          const index = navbarPlacements.indexOf("urlbar-container");
 | 
|  | 738 | +          let after = index + 1;
 | 
|  | 739 | +          if (
 | 
|  | 740 | +            after < navbarPlacements.length &&
 | 
|  | 741 | +            navbarPlacements[after] === "search-container"
 | 
|  | 742 | +          ) {
 | 
|  | 743 | +            // Skip past the search-container.
 | 
|  | 744 | +            after++;
 | 
|  | 745 | +          }
 | 
|  | 746 | +          return { before: index - 1, after };
 | 
|  | 747 | +        };
 | 
|  | 748 | +
 | 
|  | 749 | +        // Remove the urlbar springs either side of the urlbar.
 | 
|  | 750 | +        const { before, after } = getBeforeAfterUrlbar();
 | 
|  | 751 | +        if (
 | 
|  | 752 | +          after < navbarPlacements.length &&
 | 
|  | 753 | +          this.matchingSpecials(navbarPlacements[after], "spring")
 | 
|  | 754 | +        ) {
 | 
|  | 755 | +          // Remove the spring after.
 | 
|  | 756 | +          navbarPlacements.splice(after, 1);
 | 
|  | 757 | +          // NOTE: The `before` index does not change.
 | 
|  | 758 | +        }
 | 
|  | 759 | +        if (
 | 
|  | 760 | +          before >= 0 &&
 | 
|  | 761 | +          this.matchingSpecials(navbarPlacements[before], "spring")
 | 
|  | 762 | +        ) {
 | 
|  | 763 | +          // Remove the spring before.
 | 
|  | 764 | +          navbarPlacements.splice(before, 1);
 | 
|  | 765 | +        }
 | 
|  | 766 | +
 | 
|  | 767 | +        // Make sure the security-level-button and new-identity-button appears
 | 
|  | 768 | +        // in the toolbar.
 | 
|  | 769 | +        for (const id of ["new-identity-button", "security-level-button"]) {
 | 
|  | 770 | +          let alreadyAdded = false;
 | 
|  | 771 | +          for (const placements of Object.values(gSavedState.placements)) {
 | 
|  | 772 | +            if (placements.includes(id)) {
 | 
|  | 773 | +              alreadyAdded = true;
 | 
|  | 774 | +              break;
 | 
|  | 775 | +            }
 | 
|  | 776 | +          }
 | 
|  | 777 | +          if (alreadyAdded) {
 | 
|  | 778 | +            continue;
 | 
|  | 779 | +          }
 | 
|  | 780 | +
 | 
|  | 781 | +          // Add to the nav-bar, after the urlbar-container.
 | 
|  | 782 | +          // NOTE: We have already removed the spring after the urlbar.
 | 
|  | 783 | +          navbarPlacements.splice(getBeforeAfterUrlbar().after, 0, id);
 | 
|  | 784 | +        }
 | 
|  | 785 | +      }
 | 
|  | 786 | +
 | 
|  | 787 | +      // Remove save-to-pocket-button. See tor-browser#18886 and
 | 
|  | 788 | +      // tor-browser#31602.
 | 
|  | 789 | +      for (const placements of Object.values(gSavedState.placements)) {
 | 
|  | 790 | +        let buttonIndex = placements.indexOf("save-to-pocket-button");
 | 
|  | 791 | +        if (buttonIndex != -1) {
 | 
|  | 792 | +          placements.splice(buttonIndex, 1);
 | 
|  | 793 | +        }
 | 
|  | 794 | +      }
 | 
|  | 795 | +
 | 
|  | 796 | +      // Remove unused fields that used to be part of
 | 
|  | 797 | +      // "browser.uiCustomization.state".
 | 
|  | 798 | +      delete gSavedState.placements["PanelUI-contents"];
 | 
|  | 799 | +      delete gSavedState.placements["addon-bar"];
 | 
|  | 800 | +    }
 | 
|  | 801 | +  },
 | 
|  | 802 | +
 | 
| 690 | 803 |    _placeNewDefaultWidgetsInArea(aArea) {
 | 
| 691 | 804 |      let futurePlacedWidgets = gFuturePlacements.get(aArea);
 | 
| 692 | 805 |      let savedPlacements =
 | 
| ... | ... | @@ -2501,6 +2614,10 @@ var CustomizableUIInternal = { | 
| 2501 | 2614 |        gSavedState.currentVersion = 0;
 | 
| 2502 | 2615 |      }
 | 
| 2503 | 2616 |  
 | 
|  | 2617 | +    if (!("currentVersionBaseBrowser" in gSavedState)) {
 | 
|  | 2618 | +      gSavedState.currentVersionBaseBrowser = 0;
 | 
|  | 2619 | +    }
 | 
|  | 2620 | +
 | 
| 2504 | 2621 |      gSeenWidgets = new Set(gSavedState.seen || []);
 | 
| 2505 | 2622 |      gDirtyAreaCache = new Set(gSavedState.dirtyAreaCache || []);
 | 
| 2506 | 2623 |      gNewElementCount = gSavedState.newElementCount || 0;
 | 
| ... | ... | @@ -2579,6 +2696,7 @@ var CustomizableUIInternal = { | 
| 2579 | 2696 |        seen: gSeenWidgets,
 | 
| 2580 | 2697 |        dirtyAreaCache: gDirtyAreaCache,
 | 
| 2581 | 2698 |        currentVersion: kVersion,
 | 
|  | 2699 | +      currentVersionBaseBrowser: kVersionBaseBrowser,
 | 
| 2582 | 2700 |        newElementCount: gNewElementCount,
 | 
| 2583 | 2701 |      };
 | 
| 2584 | 2702 |  
 |