Skip to content
Snippets Groups Projects
Verified Commit 184d4222 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame :jack_o_lantern:
Browse files

Bug 41435: Add a Tor Browser migration function

For now this function only deletes old language packs for which we are
already packaging the strings with the application.
parent 46d7eee1
Branches
Tags
1 merge request!1293Bug 43306: Rebased stable onto 128.5.0esr
......@@ -1614,6 +1614,10 @@ BrowserGlue.prototype = {
// Base Browser-specific version of _migrateUI.
this._migrateUIBB();
// Handle any TBB-specific migration before showing the UI. Keep after
// _migrateUI to make sure this._isNewProfile has been defined.
this._migrateUITBB();
if (!Services.prefs.prefHasUserValue(PREF_PDFJS_ISDEFAULT_CACHE_STATE)) {
lazy.PdfJs.checkIsDefault(this._isNewProfile);
}
......@@ -4819,6 +4823,105 @@ BrowserGlue.prototype = {
Services.prefs.setIntPref(MIGRATION_PREF, MIGRATION_VERSION);
},
// Use this method for any TBB migration that can be run just before showing
// the UI.
// Anything that critically needs to be migrated earlier should not use this.
_migrateUITBB() {
// Version 1: Tor Browser 12.0. We use it to remove langpacks, after the
// migration to packaged locales.
// Version 2: Tor Browser 13.0/13.0a1: tor-browser#41845. Also, removed some
// torbutton preferences that are not used anymore.
// Version 3: Tor Browser 13.0.7/13.5a3: Remove blockchair
// (tor-browser#42283).
// Version 4: Tor Browser 14.0a4 (2024-09-02): Remove Twitter, Yahoo and
// YouTube search engines (tor-browser#41835).
// Version 5: Tor Browser 14.0a5: Clear user preference for CFR settings
// since we hid the UI (tor-browser#43118).
const TBB_MIGRATION_VERSION = 5;
const MIGRATION_PREF = "torbrowser.migration.version";
// If we decide to force updating users to pass through any version
// following 12.0, 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, TBB_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("_migrateUITBB: this._isNewProfile is undefined.");
}
const currentVersion = Services.prefs.getIntPref(MIGRATION_PREF, 0);
const removeLangpacks = async () => {
for (const addon of await AddonManager.getAddonsByTypes(["locale"])) {
await addon.uninstall();
}
};
if (currentVersion < 1) {
removeLangpacks().catch(err => {
console.error("Could not remove langpacks", err);
});
}
if (currentVersion < 2) {
const prefToClear = [
// tor-browser#41845: We were forcing these value by check the value of
// automatic PBM. We decided not to change
"browser.cache.disk.enable",
"places.history.enabled",
"security.nocertdb",
"permissions.memory_only",
// Old torbutton preferences not used anymore.
"extensions.torbutton.loglevel",
"extensions.torbutton.logmethod",
"extensions.torbutton.pref_fixup_version",
"extensions.torbutton.resize_new_windows",
"extensions.torbutton.startup",
"extensions.torlauncher.prompt_for_locale",
"extensions.torlauncher.loglevel",
"extensions.torlauncher.logmethod",
"extensions.torlauncher.torrc_fixup_version",
];
for (const pref of prefToClear) {
if (Services.prefs.prefHasUserValue(pref)) {
Services.prefs.clearUserPref(pref);
}
}
}
const dropAddons = async list => {
for (const id of list) {
try {
const engine = await lazy.AddonManager.getAddonByID(id);
await engine?.uninstall();
} catch {}
}
};
if (currentVersion < 3) {
dropAddons([
"blockchair@search.mozilla.org",
"blockchair-onion@search.mozilla.org",
]);
}
if (currentVersion < 4) {
dropAddons([
"twitter@search.mozilla.org",
"yahoo@search.mozilla.org",
"youtube@search.mozilla.org",
]);
}
if (currentVersion < 5) {
for (const pref of [
"browser.newtabpage.activity-stream.asrouter.userprefs.cfr.addons",
"browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features",
]) {
Services.prefs.clearUserPref(pref);
}
}
Services.prefs.setIntPref(MIGRATION_PREF, TBB_MIGRATION_VERSION);
},
async _showUpgradeDialog() {
const data = await lazy.OnboardingMessageProvider.getUpgradeMessage();
const { gBrowser } = lazy.BrowserWindowTracker.getTopWindow();
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment