Commit f7c6e20b authored by henry's avatar henry Committed by brizental
Browse files

MB 419: Mullvad Browser migration procedures.

This commit implements the the Mullvad Browser's version of _migrateUI.
parent c4990bf8
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
@@ -388,6 +388,9 @@ BrowserGlue.prototype = {
    this._migrateUI();
    lazy.ProfileDataUpgrader.upgradeBB(this._isNewProfile);

    // Mullvad Browser-specific version of _migrateUI.
    this._migrateUIMB();

    if (!Services.prefs.prefHasUserValue(PREF_PDFJS_ISDEFAULT_CACHE_STATE)) {
      lazy.PdfJs.checkIsDefault(this._isNewProfile);
    }
@@ -1603,6 +1606,58 @@ BrowserGlue.prototype = {
    }
  },

  // Use this method for any MB migration that can be run just before showing
  // the UI.
  // Anything that critically needs to be migrated earlier should not use this.
  async _migrateUIMB() {
    // Version 1: Mullvad Browser 14.5a6: Clear home page update url preference
    //            (mullvad-browser#411).
    // Version 2: Mullvad Browser 15.0a2: Remove legacy search addons
    //            (tor-browser#43111).
    const MB_MIGRATION_VERSION = 2;
    const MIGRATION_PREF = "mullvadbrowser.migration.version";

    // If we decide to force updating users to pass through any version
    // following 14.5, we can remove this check, and check only whether
    // MIGRATION_PREF has a user value, like Mozilla does.
    if (this._isNewProfile) {
      // Do not migrate fresh profiles
      Services.prefs.setIntPref(MIGRATION_PREF, MB_MIGRATION_VERSION);
      return;
    } else if (this._isNewProfile === undefined) {
      // If this happens, check if upstream updated their function and do not
      // set this member anymore!
      console.error("_migrateUIMB: this._isNewProfile is undefined.");
    }

    const currentVersion = Services.prefs.getIntPref(MIGRATION_PREF, 0);

    if (currentVersion < 1) {
      Services.prefs.clearUserPref("mullvadbrowser.post_update.url");
    }
    const dropAddons = async list => {
      for (const id of list) {
        try {
          const engine = await lazy.AddonManager.getAddonByID(id);
          await engine?.uninstall();
        } catch {}
      }
    };
    if (currentVersion < 2) {
      await dropAddons([
        "brave@search.mozilla.org",
        "ddg@search.mozilla.org",
        "ddg-html@search.mozilla.org",
        "metager@search.mozilla.org",
        "mojeek@search.mozilla.org",
        "mullvad-leta@search.mozilla.org",
        "startpage@search.mozilla.org",
      ]);
    }

    Services.prefs.setIntPref(MIGRATION_PREF, MB_MIGRATION_VERSION);
  },

  async _showUpgradeDialog() {
    const data = await lazy.OnboardingMessageProvider.getUpgradeMessage();
    const { gBrowser } = lazy.BrowserWindowTracker.getTopWindow();