Bug 1759009 - Update distribution config. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D140898
This commit is contained in:
Mike Kaply
2022-03-14 10:52:39 +00:00
parent 3ca06fb79e
commit 8d17321488

View File

@@ -24,6 +24,11 @@ ChromeUtils.defineModuleGetter(
"PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"AddonManager",
"resource://gre/modules/AddonManager.jsm"
);
function DistributionCustomizer() {}
@@ -114,6 +119,19 @@ DistributionCustomizer.prototype = {
return this._language;
},
async _removeDistributionBookmarks() {
await PlacesUtils.bookmarks.fetch(
{ guidPrefix: this.BOOKMARK_GUID_PREFIX },
bookmark => PlacesUtils.bookmarks.remove(bookmark).catch()
);
await PlacesUtils.bookmarks.fetch(
{ guidPrefix: this.FOLDER_GUID_PREFIX },
folder => {
PlacesUtils.bookmarks.remove(folder).catch();
}
);
},
async _parseBookmarksSection(parentGuid, section) {
let keys = Array.from(this._ini.getKeys(section)).sort();
let re = /^item\.(\d+)\.(\w+)\.?(\w*)/;
@@ -278,7 +296,30 @@ DistributionCustomizer.prototype = {
_bookmarksApplied: false,
async applyBookmarks() {
await this._doApplyBookmarks();
let prefs = Services.prefs
.getChildList("distribution.yandex")
.concat(Services.prefs.getChildList("distribution.mailru"))
.concat(Services.prefs.getChildList("distribution.okru"));
if (prefs.length) {
let extensionIDs = [
"sovetnik-yandex@yandex.ru",
"vb@yandex.ru",
"ntp-mail@corp.mail.ru",
"ntp-okru@corp.mail.ru",
];
for (let extensionID of extensionIDs) {
let addon = await AddonManager.getAddonByID(extensionID);
if (addon) {
await addon.disable();
}
}
for (let pref of prefs) {
Services.prefs.clearUserPref(pref);
}
await this._removeDistributionBookmarks();
} else {
await this._doApplyBookmarks();
}
this._bookmarksApplied = true;
this._checkCustomizationComplete();
},
@@ -371,6 +412,16 @@ DistributionCustomizer.prototype = {
// separate because they are "special" (read: required)
defaults.set("distribution.id", distroID);
if (
distroID.startsWith("yandex") ||
distroID.startsWith("mailru") ||
distroID.startsWith("okru")
) {
this.__defineGetter__("_ini", () => null);
return this._checkCustomizationComplete();
}
defaults.set(
"distribution.version",
this._ini.getString("Global", "version")