| ... | ... | @@ -65,6 +65,16 @@ 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 | +
 | 
|  | 73 | +/**
 | 
|  | 74 | + * The current version for tor browser.
 | 
|  | 75 | + */
 | 
|  | 76 | +var kVersionTorBrowser = 1;
 | 
|  | 77 | +
 | 
| 68 | 78 |  /**
 | 
| 69 | 79 |   * Buttons removed from built-ins by version they were removed. kVersion must be
 | 
| 70 | 80 |   * bumped any time a new id is added to this. Use the button id as key, and
 | 
| ... | ... | @@ -218,6 +228,8 @@ var CustomizableUIInternal = { | 
| 218 | 228 |      this._updateForNewVersion();
 | 
| 219 | 229 |      this._updateForNewProtonVersion();
 | 
| 220 | 230 |      this._markObsoleteBuiltinButtonsSeen();
 | 
|  | 231 | +    this._updateForBaseBrowser();
 | 
|  | 232 | +    this._updateForTorBrowser();
 | 
| 221 | 233 |  
 | 
| 222 | 234 |      this.registerArea(
 | 
| 223 | 235 |        CustomizableUI.AREA_FIXED_OVERFLOW_PANEL,
 | 
| ... | ... | @@ -236,10 +248,17 @@ var CustomizableUIInternal = { | 
| 236 | 248 |        Services.policies.isAllowed("removeHomeButtonByDefault")
 | 
| 237 | 249 |          ? null
 | 
| 238 | 250 |          : "home-button",
 | 
| 239 |  | -      "spring",
 | 
|  | 251 | +      // Don't want springs either side of the urlbar. tor-browser#41736
 | 
| 240 | 252 |        "urlbar-container",
 | 
| 241 |  | -      "spring",
 | 
| 242 |  | -      "save-to-pocket-button",
 | 
|  | 253 | +      // save-to-pocket-button is entirely disabled. See tor-browser#18886 and
 | 
|  | 254 | +      // tor-browser#31602.
 | 
|  | 255 | +      // Base-browser additions tor-browser#41736. If you want to add to, remove
 | 
|  | 256 | +      // from, or rearrange this list, then bump the kVersionBaseBrowser and
 | 
|  | 257 | +      // update existing saved states in _updateForBaseBrowser.
 | 
|  | 258 | +      // Or if the change is only meant for tor-browser, bump kVersionTorBrowser
 | 
|  | 259 | +      // instead and update the existing saved states in _updateForTorBrowser.
 | 
|  | 260 | +      "security-level-button",
 | 
|  | 261 | +      "new-identity-button",
 | 
| 243 | 262 |        "downloads-button",
 | 
| 244 | 263 |        AppConstants.MOZ_DEV_EDITION ? "developer-button" : null,
 | 
| 245 | 264 |        "fxa-toolbar-menu-button",
 | 
| ... | ... | @@ -255,6 +274,10 @@ var CustomizableUIInternal = { | 
| 255 | 274 |        },
 | 
| 256 | 275 |        true
 | 
| 257 | 276 |      );
 | 
|  | 277 | +    // navbarPlacements does not match the initial default XHTML layout.
 | 
|  | 278 | +    // Therefore we always need to rebuild the navbar area when
 | 
|  | 279 | +    // registerToolbarNode is called. tor-browser#41736
 | 
|  | 280 | +    gDirtyAreaCache.add(CustomizableUI.AREA_NAVBAR);
 | 
| 258 | 281 |  
 | 
| 259 | 282 |      if (AppConstants.MENUBAR_CAN_AUTOHIDE) {
 | 
| 260 | 283 |        this.registerArea(
 | 
| ... | ... | @@ -687,6 +710,123 @@ var CustomizableUIInternal = { | 
| 687 | 710 |      }
 | 
| 688 | 711 |    },
 | 
| 689 | 712 |  
 | 
|  | 713 | +  _updateForBaseBrowser() {
 | 
|  | 714 | +    if (!gSavedState) {
 | 
|  | 715 | +      // Use the defaults.
 | 
|  | 716 | +      return;
 | 
|  | 717 | +    }
 | 
|  | 718 | +
 | 
|  | 719 | +    const currentVersion = gSavedState.currentVersionBaseBrowser;
 | 
|  | 720 | +
 | 
|  | 721 | +    if (currentVersion < 1) {
 | 
|  | 722 | +      // NOTE: In base-browser/tor-browser version 12.5a5, and earlier, the
 | 
|  | 723 | +      // toolbar was configured by setting the full JSON string for the default
 | 
|  | 724 | +      // "browser.uiCustomization.state" preference value. The disadvantage is
 | 
|  | 725 | +      // that we could not update this value in a way that existing users (who
 | 
|  | 726 | +      // would have non-default preference values) would also get the desired
 | 
|  | 727 | +      // change (e.g. for adding or removing a button).
 | 
|  | 728 | +      //
 | 
|  | 729 | +      // With tor-browser#41736 we want to switch to changing the toolbar
 | 
|  | 730 | +      // dynamically like firefox. Therefore, this first version transfer simply
 | 
|  | 731 | +      // gets the toolbar into the same state we wanted before, away from the
 | 
|  | 732 | +      // default firefox state.
 | 
|  | 733 | +      //
 | 
|  | 734 | +      // If an existing user state aligned with the previous default
 | 
|  | 735 | +      // "browser.uiCustomization.state" then this shouldn't visibly change
 | 
|  | 736 | +      // anything.
 | 
|  | 737 | +      // If a user explicitly customized the toolbar to go back to the firefox
 | 
|  | 738 | +      // default, then this may undo those changes.
 | 
|  | 739 | +      const navbarPlacements =
 | 
|  | 740 | +        gSavedState.placements[CustomizableUI.AREA_NAVBAR];
 | 
|  | 741 | +      if (navbarPlacements) {
 | 
|  | 742 | +        const getBeforeAfterUrlbar = () => {
 | 
|  | 743 | +          // NOTE: The urlbar is non-removable from the navbar, so should have
 | 
|  | 744 | +          // an index.
 | 
|  | 745 | +          const index = navbarPlacements.indexOf("urlbar-container");
 | 
|  | 746 | +          let after = index + 1;
 | 
|  | 747 | +          if (
 | 
|  | 748 | +            after < navbarPlacements.length &&
 | 
|  | 749 | +            navbarPlacements[after] === "search-container"
 | 
|  | 750 | +          ) {
 | 
|  | 751 | +            // Skip past the search-container.
 | 
|  | 752 | +            after++;
 | 
|  | 753 | +          }
 | 
|  | 754 | +          return { before: index - 1, after };
 | 
|  | 755 | +        };
 | 
|  | 756 | +
 | 
|  | 757 | +        // Remove the urlbar springs either side of the urlbar.
 | 
|  | 758 | +        const { before, after } = getBeforeAfterUrlbar();
 | 
|  | 759 | +        if (
 | 
|  | 760 | +          after < navbarPlacements.length &&
 | 
|  | 761 | +          this.matchingSpecials(navbarPlacements[after], "spring")
 | 
|  | 762 | +        ) {
 | 
|  | 763 | +          // Remove the spring after.
 | 
|  | 764 | +          navbarPlacements.splice(after, 1);
 | 
|  | 765 | +          // NOTE: The `before` index does not change.
 | 
|  | 766 | +        }
 | 
|  | 767 | +        if (
 | 
|  | 768 | +          before >= 0 &&
 | 
|  | 769 | +          this.matchingSpecials(navbarPlacements[before], "spring")
 | 
|  | 770 | +        ) {
 | 
|  | 771 | +          // Remove the spring before.
 | 
|  | 772 | +          navbarPlacements.splice(before, 1);
 | 
|  | 773 | +        }
 | 
|  | 774 | +
 | 
|  | 775 | +        // Make sure the security-level-button and new-identity-button appears
 | 
|  | 776 | +        // in the toolbar.
 | 
|  | 777 | +        for (const id of ["new-identity-button", "security-level-button"]) {
 | 
|  | 778 | +          let alreadyAdded = false;
 | 
|  | 779 | +          for (const placements of Object.values(gSavedState.placements)) {
 | 
|  | 780 | +            if (placements.includes(id)) {
 | 
|  | 781 | +              alreadyAdded = true;
 | 
|  | 782 | +              break;
 | 
|  | 783 | +            }
 | 
|  | 784 | +          }
 | 
|  | 785 | +          if (alreadyAdded) {
 | 
|  | 786 | +            continue;
 | 
|  | 787 | +          }
 | 
|  | 788 | +
 | 
|  | 789 | +          // Add to the nav-bar, after the urlbar-container.
 | 
|  | 790 | +          // NOTE: We have already removed the spring after the urlbar.
 | 
|  | 791 | +          navbarPlacements.splice(getBeforeAfterUrlbar().after, 0, id);
 | 
|  | 792 | +        }
 | 
|  | 793 | +      }
 | 
|  | 794 | +
 | 
|  | 795 | +      // Remove save-to-pocket-button. See tor-browser#18886 and
 | 
|  | 796 | +      // tor-browser#31602.
 | 
|  | 797 | +      for (const placements of Object.values(gSavedState.placements)) {
 | 
|  | 798 | +        let buttonIndex = placements.indexOf("save-to-pocket-button");
 | 
|  | 799 | +        if (buttonIndex != -1) {
 | 
|  | 800 | +          placements.splice(buttonIndex, 1);
 | 
|  | 801 | +        }
 | 
|  | 802 | +      }
 | 
|  | 803 | +
 | 
|  | 804 | +      // Remove unused fields that used to be part of
 | 
|  | 805 | +      // "browser.uiCustomization.state".
 | 
|  | 806 | +      delete gSavedState.placements["PanelUI-contents"];
 | 
|  | 807 | +      delete gSavedState.placements["addon-bar"];
 | 
|  | 808 | +    }
 | 
|  | 809 | +  },
 | 
|  | 810 | +
 | 
|  | 811 | +  _updateForTorBrowser() {
 | 
|  | 812 | +    if (!gSavedState) {
 | 
|  | 813 | +      // Use the defaults.
 | 
|  | 814 | +      return;
 | 
|  | 815 | +    }
 | 
|  | 816 | +
 | 
|  | 817 | +    const currentVersion = gSavedState.currentVersionTorBrowser;
 | 
|  | 818 | +
 | 
|  | 819 | +    if (currentVersion < 1) {
 | 
|  | 820 | +      // Remove torbutton-button, which no longer exists.
 | 
|  | 821 | +      for (const placements of Object.values(gSavedState.placements)) {
 | 
|  | 822 | +        let buttonIndex = placements.indexOf("torbutton-button");
 | 
|  | 823 | +        if (buttonIndex != -1) {
 | 
|  | 824 | +          placements.splice(buttonIndex, 1);
 | 
|  | 825 | +        }
 | 
|  | 826 | +      }
 | 
|  | 827 | +    }
 | 
|  | 828 | +  },
 | 
|  | 829 | +
 | 
| 690 | 830 |    _placeNewDefaultWidgetsInArea(aArea) {
 | 
| 691 | 831 |      let futurePlacedWidgets = gFuturePlacements.get(aArea);
 | 
| 692 | 832 |      let savedPlacements =
 | 
| ... | ... | @@ -2501,6 +2641,14 @@ var CustomizableUIInternal = { | 
| 2501 | 2641 |        gSavedState.currentVersion = 0;
 | 
| 2502 | 2642 |      }
 | 
| 2503 | 2643 |  
 | 
|  | 2644 | +    if (!("currentVersionBaseBrowser" in gSavedState)) {
 | 
|  | 2645 | +      gSavedState.currentVersionBaseBrowser = 0;
 | 
|  | 2646 | +    }
 | 
|  | 2647 | +
 | 
|  | 2648 | +    if (!("currentVersionTorBrowser" in gSavedState)) {
 | 
|  | 2649 | +      gSavedState.currentVersionTorBrowser = 0;
 | 
|  | 2650 | +    }
 | 
|  | 2651 | +
 | 
| 2504 | 2652 |      gSeenWidgets = new Set(gSavedState.seen || []);
 | 
| 2505 | 2653 |      gDirtyAreaCache = new Set(gSavedState.dirtyAreaCache || []);
 | 
| 2506 | 2654 |      gNewElementCount = gSavedState.newElementCount || 0;
 | 
| ... | ... | @@ -2579,6 +2727,8 @@ var CustomizableUIInternal = { | 
| 2579 | 2727 |        seen: gSeenWidgets,
 | 
| 2580 | 2728 |        dirtyAreaCache: gDirtyAreaCache,
 | 
| 2581 | 2729 |        currentVersion: kVersion,
 | 
|  | 2730 | +      currentVersionBaseBrowser: kVersionBaseBrowser,
 | 
|  | 2731 | +      currentVersionTorBrowser: kVersionTorBrowser,
 | 
| 2582 | 2732 |        newElementCount: gNewElementCount,
 | 
| 2583 | 2733 |      };
 | 
| 2584 | 2734 |  
 |