2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.EXPORTED_SYMBOLS = [ "DistributionCustomizer" ];
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var Ci = Components.interfaces;
|
|
|
|
var Cc = Components.classes;
|
|
|
|
var Cr = Components.results;
|
|
|
|
var Cu = Components.utils;
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2009-10-05 14:13:04 +04:00
|
|
|
const DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC =
|
|
|
|
"distribution-customization-complete";
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2017-09-19 20:41:06 +03:00
|
|
|
const PREF_CACHED_FILE_EXISTENCE = "distribution.iniFile.exists.value";
|
|
|
|
const PREF_CACHED_FILE_APPVERSION = "distribution.iniFile.exists.appversion";
|
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "Preferences",
|
|
|
|
"resource://gre/modules/Preferences.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "PlacesUtils",
|
|
|
|
"resource://gre/modules/PlacesUtils.jsm");
|
2012-02-24 16:42:26 +04:00
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.DistributionCustomizer = function DistributionCustomizer() {
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2009-10-05 14:13:04 +04:00
|
|
|
DistributionCustomizer.prototype = {
|
2017-09-19 20:41:06 +03:00
|
|
|
get _iniFile() {
|
|
|
|
// For parallel xpcshell testing purposes allow loading the distribution.ini
|
|
|
|
// file from the profile folder through an hidden pref.
|
|
|
|
let loadFromProfile = Services.prefs.getBoolPref("distribution.testing.loadFromProfile", false);
|
|
|
|
|
|
|
|
let iniFile;
|
|
|
|
try {
|
2017-10-11 17:43:51 +03:00
|
|
|
iniFile = loadFromProfile ? Services.dirsvc.get("ProfD", Ci.nsIFile)
|
|
|
|
: Services.dirsvc.get("XREAppDist", Ci.nsIFile);
|
2017-09-19 20:41:06 +03:00
|
|
|
if (loadFromProfile) {
|
|
|
|
iniFile.leafName = "distribution";
|
|
|
|
}
|
|
|
|
iniFile.append("distribution.ini");
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
this.__defineGetter__("_iniFile", () => iniFile);
|
|
|
|
return iniFile;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _hasDistributionIni() {
|
|
|
|
if (Services.prefs.prefHasUserValue(PREF_CACHED_FILE_EXISTENCE)) {
|
|
|
|
let knownForVersion = Services.prefs.getStringPref(PREF_CACHED_FILE_APPVERSION, "unknown");
|
|
|
|
if (knownForVersion == AppConstants.MOZ_APP_VERSION) {
|
|
|
|
return Services.prefs.getBoolPref(PREF_CACHED_FILE_EXISTENCE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let fileExists = this._iniFile.exists();
|
|
|
|
Services.prefs.setBoolPref(PREF_CACHED_FILE_EXISTENCE, fileExists);
|
|
|
|
Services.prefs.setStringPref(PREF_CACHED_FILE_APPVERSION, AppConstants.MOZ_APP_VERSION);
|
|
|
|
|
|
|
|
this.__defineGetter__("_hasDistributionIni", () => fileExists);
|
|
|
|
return fileExists;
|
|
|
|
},
|
2009-10-05 14:13:04 +04:00
|
|
|
|
|
|
|
get _ini() {
|
2015-04-08 22:18:31 +03:00
|
|
|
let ini = null;
|
|
|
|
try {
|
2017-09-19 20:41:06 +03:00
|
|
|
if (this._hasDistributionIni) {
|
2015-04-08 22:18:31 +03:00
|
|
|
ini = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
|
2009-10-05 14:13:04 +04:00
|
|
|
getService(Ci.nsIINIParserFactory).
|
|
|
|
createINIParser(this._iniFile);
|
2015-04-08 22:18:31 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2017-09-19 20:41:06 +03:00
|
|
|
if (e.result == Cr.NS_ERROR_FILE_NOT_FOUND) {
|
|
|
|
// We probably had cached the file existence as true,
|
|
|
|
// but it no longer exists. We could set the new cache
|
|
|
|
// value here, but let's just invalidate the cache and
|
|
|
|
// let it be cached by a single code path on the next check.
|
|
|
|
Services.prefs.clearUserPref(PREF_CACHED_FILE_EXISTENCE);
|
|
|
|
} else {
|
|
|
|
// Unable to parse INI.
|
|
|
|
Cu.reportError("Unable to parse distribution.ini");
|
|
|
|
}
|
2015-04-08 22:18:31 +03:00
|
|
|
}
|
2015-09-23 12:36:20 +03:00
|
|
|
this.__defineGetter__("_ini", () => ini);
|
2009-10-05 14:13:04 +04:00
|
|
|
return this._ini;
|
|
|
|
},
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2009-10-05 14:13:04 +04:00
|
|
|
get _locale() {
|
2017-03-12 05:43:11 +03:00
|
|
|
const locale = Services.locale.getRequestedLocale() || "en-US";
|
2015-09-23 12:36:20 +03:00
|
|
|
this.__defineGetter__("_locale", () => locale);
|
2009-10-05 14:13:04 +04:00
|
|
|
return this._locale;
|
|
|
|
},
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2016-02-19 19:59:15 +03:00
|
|
|
get _language() {
|
|
|
|
let language = this._locale.split("-")[0];
|
|
|
|
this.__defineGetter__("_language", () => language);
|
|
|
|
return this._language;
|
|
|
|
},
|
|
|
|
|
2017-05-12 15:42:39 +03:00
|
|
|
async _parseBookmarksSection(parentGuid, section) {
|
2015-03-16 14:51:02 +03:00
|
|
|
let keys = Array.from(enumerate(this._ini.getKeys(section))).sort();
|
|
|
|
let re = /^item\.(\d+)\.(\w+)\.?(\w*)/;
|
2007-09-11 19:52:04 +04:00
|
|
|
let items = {};
|
2015-03-16 14:51:02 +03:00
|
|
|
let defaultIndex = -1;
|
|
|
|
let maxIndex = -1;
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2015-03-16 14:51:02 +03:00
|
|
|
for (let key of keys) {
|
|
|
|
let m = re.exec(key);
|
2007-09-11 19:52:04 +04:00
|
|
|
if (m) {
|
2016-11-03 14:51:48 +03:00
|
|
|
let [, itemIndex, iprop, ilocale] = m;
|
2015-03-16 14:51:02 +03:00
|
|
|
itemIndex = parseInt(itemIndex);
|
2007-09-11 19:52:04 +04:00
|
|
|
|
|
|
|
if (ilocale)
|
|
|
|
continue;
|
|
|
|
|
2015-03-16 14:51:02 +03:00
|
|
|
if (keys.indexOf(key + "." + this._locale) >= 0) {
|
|
|
|
key += "." + this._locale;
|
2016-02-19 19:59:15 +03:00
|
|
|
} else if (keys.indexOf(key + "." + this._language) >= 0) {
|
|
|
|
key += "." + this._language;
|
2007-09-11 19:52:04 +04:00
|
|
|
}
|
|
|
|
|
2015-03-16 14:51:02 +03:00
|
|
|
if (!items[itemIndex])
|
|
|
|
items[itemIndex] = {};
|
|
|
|
items[itemIndex][iprop] = this._ini.getString(section, key);
|
|
|
|
|
2017-07-25 21:15:41 +03:00
|
|
|
if (iprop == "type" && items[itemIndex].type == "default")
|
2015-03-16 14:51:02 +03:00
|
|
|
defaultIndex = itemIndex;
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2015-03-16 14:51:02 +03:00
|
|
|
if (maxIndex < itemIndex)
|
|
|
|
maxIndex = itemIndex;
|
2007-09-11 19:52:04 +04:00
|
|
|
} else {
|
2015-03-16 14:51:02 +03:00
|
|
|
dump(`Key did not match: ${key}\n`);
|
2007-09-11 19:52:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let prependIndex = 0;
|
2015-03-16 14:51:02 +03:00
|
|
|
for (let itemIndex = 0; itemIndex <= maxIndex; itemIndex++) {
|
|
|
|
if (!items[itemIndex])
|
2007-09-11 19:52:04 +04:00
|
|
|
continue;
|
|
|
|
|
2012-02-24 16:42:26 +04:00
|
|
|
let index = PlacesUtils.bookmarks.DEFAULT_INDEX;
|
2015-03-16 14:51:02 +03:00
|
|
|
let item = items[itemIndex];
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2015-03-16 14:51:02 +03:00
|
|
|
switch (item.type) {
|
2007-09-11 19:52:04 +04:00
|
|
|
case "default":
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "folder":
|
2015-03-16 14:51:02 +03:00
|
|
|
if (itemIndex < defaultIndex)
|
2007-09-11 19:52:04 +04:00
|
|
|
index = prependIndex++;
|
|
|
|
|
2017-05-12 15:42:39 +03:00
|
|
|
let folder = await PlacesUtils.bookmarks.insert({
|
2015-03-16 14:51:02 +03:00
|
|
|
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
|
|
|
parentGuid, index, title: item.title
|
|
|
|
});
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2017-05-12 15:42:39 +03:00
|
|
|
await this._parseBookmarksSection(folder.guid,
|
2015-03-16 14:51:02 +03:00
|
|
|
"BookmarksFolder-" + item.folderId);
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2015-03-16 14:51:02 +03:00
|
|
|
if (item.description) {
|
2017-05-12 15:42:39 +03:00
|
|
|
let folderId = await PlacesUtils.promiseItemId(folder.guid);
|
2015-03-16 14:51:02 +03:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(folderId,
|
2012-02-24 16:42:26 +04:00
|
|
|
"bookmarkProperties/description",
|
2015-03-16 14:51:02 +03:00
|
|
|
item.description, 0,
|
2012-02-24 16:42:26 +04:00
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2015-03-16 14:51:02 +03:00
|
|
|
}
|
2007-09-11 19:52:04 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "separator":
|
2015-03-16 14:51:02 +03:00
|
|
|
if (itemIndex < defaultIndex)
|
2007-09-11 19:52:04 +04:00
|
|
|
index = prependIndex++;
|
2015-03-16 14:51:02 +03:00
|
|
|
|
2017-05-12 15:42:39 +03:00
|
|
|
await PlacesUtils.bookmarks.insert({
|
2015-03-16 14:51:02 +03:00
|
|
|
type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
|
|
|
parentGuid, index
|
|
|
|
});
|
2007-09-11 19:52:04 +04:00
|
|
|
break;
|
|
|
|
|
2008-08-26 01:22:33 +04:00
|
|
|
case "livemark":
|
2015-03-16 14:51:02 +03:00
|
|
|
if (itemIndex < defaultIndex)
|
2008-08-26 01:22:33 +04:00
|
|
|
index = prependIndex++;
|
|
|
|
|
2009-10-05 14:13:04 +04:00
|
|
|
// Don't bother updating the livemark contents on creation.
|
2017-05-12 15:42:39 +03:00
|
|
|
let parentId = await PlacesUtils.promiseItemId(parentGuid);
|
|
|
|
await PlacesUtils.livemarks.addLivemark({
|
2017-10-11 17:43:51 +03:00
|
|
|
feedURI: Services.io.newURI(item.feedLink),
|
|
|
|
siteURI: Services.io.newURI(item.siteLink),
|
2015-03-16 14:51:02 +03:00
|
|
|
parentId, index, title: item.title
|
|
|
|
});
|
2008-08-26 01:22:33 +04:00
|
|
|
break;
|
|
|
|
|
2007-09-11 19:52:04 +04:00
|
|
|
case "bookmark":
|
|
|
|
default:
|
2015-03-16 14:51:02 +03:00
|
|
|
if (itemIndex < defaultIndex)
|
2007-09-11 19:52:04 +04:00
|
|
|
index = prependIndex++;
|
|
|
|
|
2017-05-12 15:42:39 +03:00
|
|
|
let bm = await PlacesUtils.bookmarks.insert({
|
2015-03-16 14:51:02 +03:00
|
|
|
parentGuid, index, title: item.title, url: item.link
|
|
|
|
});
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2015-03-16 14:51:02 +03:00
|
|
|
if (item.description) {
|
2017-05-12 15:42:39 +03:00
|
|
|
let bmId = await PlacesUtils.promiseItemId(bm.guid);
|
2015-03-16 14:51:02 +03:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(bmId,
|
2012-02-24 16:42:26 +04:00
|
|
|
"bookmarkProperties/description",
|
2015-03-16 14:51:02 +03:00
|
|
|
item.description, 0,
|
2012-02-24 16:42:26 +04:00
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2015-03-16 14:51:02 +03:00
|
|
|
}
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2015-10-30 06:22:29 +03:00
|
|
|
if (item.icon && item.iconData) {
|
|
|
|
try {
|
2017-10-11 17:43:51 +03:00
|
|
|
let faviconURI = Services.io.newURI(item.icon);
|
2015-10-30 06:22:29 +03:00
|
|
|
PlacesUtils.favicons.replaceFaviconDataFromDataURL(
|
|
|
|
faviconURI, item.iconData, 0,
|
|
|
|
Services.scriptSecurityManager.getSystemPrincipal());
|
|
|
|
|
|
|
|
PlacesUtils.favicons.setAndFetchFaviconForPage(
|
2017-10-11 17:43:51 +03:00
|
|
|
Services.io.newURI(item.link), faviconURI, false,
|
2015-10-30 06:22:29 +03:00
|
|
|
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, null,
|
|
|
|
Services.scriptSecurityManager.getSystemPrincipal());
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (e) {
|
2015-10-30 06:22:29 +03:00
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.keyword) {
|
|
|
|
try {
|
2017-05-12 15:42:39 +03:00
|
|
|
await PlacesUtils.keywords.insert({ keyword: item.keyword,
|
2015-10-30 06:22:29 +03:00
|
|
|
url: item.link });
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (e) {
|
2015-10-30 06:22:29 +03:00
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-11 19:52:04 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-05-12 15:42:39 +03:00
|
|
|
},
|
2009-10-05 14:13:04 +04:00
|
|
|
|
2016-02-24 18:47:52 +03:00
|
|
|
_newProfile: false,
|
2009-10-05 14:13:04 +04:00
|
|
|
_customizationsApplied: false,
|
2007-09-11 19:52:04 +04:00
|
|
|
applyCustomizations: function DIST_applyCustomizations() {
|
2009-10-05 14:13:04 +04:00
|
|
|
this._customizationsApplied = true;
|
2016-02-24 18:47:52 +03:00
|
|
|
|
|
|
|
if (!Services.prefs.prefHasUserValue("browser.migration.version"))
|
|
|
|
this._newProfile = true;
|
|
|
|
|
2015-04-08 22:18:31 +03:00
|
|
|
if (!this._ini)
|
2009-10-05 14:13:04 +04:00
|
|
|
return this._checkCustomizationComplete();
|
2007-09-11 19:52:04 +04:00
|
|
|
|
|
|
|
// nsPrefService loads very early. Reload prefs so we can set
|
|
|
|
// distribution defaults during the prefservice:after-app-defaults
|
|
|
|
// notification (see applyPrefDefaults below)
|
2017-10-11 17:43:51 +03:00
|
|
|
Services.prefs.QueryInterface(Ci.nsIObserver)
|
|
|
|
.observe(null, "reload-default-prefs", null);
|
2009-10-05 14:13:04 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_bookmarksApplied: false,
|
2017-05-12 15:42:39 +03:00
|
|
|
async applyBookmarks() {
|
|
|
|
await this._doApplyBookmarks();
|
2009-10-05 14:13:04 +04:00
|
|
|
this._bookmarksApplied = true;
|
2015-03-16 14:51:02 +03:00
|
|
|
this._checkCustomizationComplete();
|
2017-05-12 15:42:39 +03:00
|
|
|
},
|
2015-03-16 14:51:02 +03:00
|
|
|
|
2017-05-12 15:42:39 +03:00
|
|
|
async _doApplyBookmarks() {
|
2015-04-08 22:18:31 +03:00
|
|
|
if (!this._ini)
|
2015-03-16 14:51:02 +03:00
|
|
|
return;
|
2007-09-11 19:52:04 +04:00
|
|
|
|
|
|
|
let sections = enumToObject(this._ini.getSections());
|
|
|
|
|
|
|
|
// The global section, and several of its fields, is required
|
|
|
|
// (we also check here to be consistent with applyPrefDefaults below)
|
2017-07-25 21:15:41 +03:00
|
|
|
if (!sections.Global)
|
2015-03-16 14:51:02 +03:00
|
|
|
return;
|
|
|
|
|
2007-09-11 19:52:04 +04:00
|
|
|
let globalPrefs = enumToObject(this._ini.getKeys("Global"));
|
2017-07-25 21:15:41 +03:00
|
|
|
if (!(globalPrefs.id && globalPrefs.version && globalPrefs.about))
|
2015-03-16 14:51:02 +03:00
|
|
|
return;
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2008-08-26 01:24:03 +04:00
|
|
|
let bmProcessedPref;
|
|
|
|
try {
|
2009-10-05 14:13:04 +04:00
|
|
|
bmProcessedPref = this._ini.getString("Global",
|
|
|
|
"bookmarks.initialized.pref");
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2008-08-26 01:24:03 +04:00
|
|
|
bmProcessedPref = "distribution." +
|
|
|
|
this._ini.getString("Global", "id") + ".bookmarksProcessed";
|
|
|
|
}
|
|
|
|
|
2017-10-11 17:43:51 +03:00
|
|
|
let bmProcessed = Services.prefs.getBoolPref(bmProcessedPref, false);
|
2007-09-11 19:52:04 +04:00
|
|
|
|
|
|
|
if (!bmProcessed) {
|
2017-07-25 21:15:41 +03:00
|
|
|
if (sections.BookmarksMenu)
|
2017-05-12 15:42:39 +03:00
|
|
|
await this._parseBookmarksSection(PlacesUtils.bookmarks.menuGuid,
|
2015-03-16 14:51:02 +03:00
|
|
|
"BookmarksMenu");
|
2017-07-25 21:15:41 +03:00
|
|
|
if (sections.BookmarksToolbar)
|
2017-05-12 15:42:39 +03:00
|
|
|
await this._parseBookmarksSection(PlacesUtils.bookmarks.toolbarGuid,
|
2015-03-16 14:51:02 +03:00
|
|
|
"BookmarksToolbar");
|
2017-10-11 17:43:51 +03:00
|
|
|
Services.prefs.setBoolPref(bmProcessedPref, true);
|
2007-09-11 19:52:04 +04:00
|
|
|
}
|
2017-05-12 15:42:39 +03:00
|
|
|
},
|
2009-10-05 14:13:04 +04:00
|
|
|
|
|
|
|
_prefDefaultsApplied: false,
|
2007-09-11 19:52:04 +04:00
|
|
|
applyPrefDefaults: function DIST_applyPrefDefaults() {
|
2009-10-05 14:13:04 +04:00
|
|
|
this._prefDefaultsApplied = true;
|
2015-04-08 22:18:31 +03:00
|
|
|
if (!this._ini)
|
2009-10-05 14:13:04 +04:00
|
|
|
return this._checkCustomizationComplete();
|
2007-09-11 19:52:04 +04:00
|
|
|
|
|
|
|
let sections = enumToObject(this._ini.getSections());
|
|
|
|
|
|
|
|
// The global section, and several of its fields, is required
|
2017-07-25 21:15:41 +03:00
|
|
|
if (!sections.Global)
|
2009-10-05 14:13:04 +04:00
|
|
|
return this._checkCustomizationComplete();
|
2007-09-11 19:52:04 +04:00
|
|
|
let globalPrefs = enumToObject(this._ini.getKeys("Global"));
|
2017-07-25 21:15:41 +03:00
|
|
|
if (!(globalPrefs.id && globalPrefs.version && globalPrefs.about))
|
2009-10-05 14:13:04 +04:00
|
|
|
return this._checkCustomizationComplete();
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2016-03-01 19:58:04 +03:00
|
|
|
let defaults = new Preferences({defaultBranch: true});
|
2007-09-11 19:52:04 +04:00
|
|
|
|
|
|
|
// Global really contains info we set as prefs. They're only
|
|
|
|
// separate because they are "special" (read: required)
|
|
|
|
|
2016-03-01 19:58:04 +03:00
|
|
|
defaults.set("distribution.id", this._ini.getString("Global", "id"));
|
|
|
|
defaults.set("distribution.version", this._ini.getString("Global", "version"));
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2016-03-01 19:58:04 +03:00
|
|
|
let partnerAbout;
|
2013-07-20 00:17:29 +04:00
|
|
|
try {
|
|
|
|
if (globalPrefs["about." + this._locale]) {
|
2016-03-01 19:58:04 +03:00
|
|
|
partnerAbout = this._ini.getString("Global", "about." + this._locale);
|
2016-02-19 19:59:15 +03:00
|
|
|
} else if (globalPrefs["about." + this._language]) {
|
2016-03-01 19:58:04 +03:00
|
|
|
partnerAbout = this._ini.getString("Global", "about." + this._language);
|
2013-07-20 00:17:29 +04:00
|
|
|
} else {
|
2016-03-01 19:58:04 +03:00
|
|
|
partnerAbout = this._ini.getString("Global", "about");
|
2013-07-20 00:17:29 +04:00
|
|
|
}
|
2016-03-01 19:58:04 +03:00
|
|
|
defaults.set("distribution.about", partnerAbout);
|
2013-07-20 00:17:29 +04:00
|
|
|
} catch (e) {
|
|
|
|
/* ignore bad prefs due to bug 895473 and move on */
|
|
|
|
Cu.reportError(e);
|
2007-09-11 19:52:04 +04:00
|
|
|
}
|
|
|
|
|
2016-03-03 00:04:38 +03:00
|
|
|
var usedPreferences = [];
|
|
|
|
|
|
|
|
if (sections["Preferences-" + this._locale]) {
|
|
|
|
for (let key of enumerate(this._ini.getKeys("Preferences-" + this._locale))) {
|
|
|
|
try {
|
|
|
|
let value = this._ini.getString("Preferences-" + this._locale, key);
|
|
|
|
if (value) {
|
2016-03-08 18:39:45 +03:00
|
|
|
defaults.set(key, parseValue(value));
|
2016-03-03 00:04:38 +03:00
|
|
|
}
|
|
|
|
usedPreferences.push(key);
|
|
|
|
} catch (e) { /* ignore bad prefs and move on */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sections["Preferences-" + this._language]) {
|
|
|
|
for (let key of enumerate(this._ini.getKeys("Preferences-" + this._language))) {
|
|
|
|
if (usedPreferences.indexOf(key) > -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
let value = this._ini.getString("Preferences-" + this._language, key);
|
|
|
|
if (value) {
|
2016-03-08 18:39:45 +03:00
|
|
|
defaults.set(key, parseValue(value));
|
2016-03-03 00:04:38 +03:00
|
|
|
}
|
|
|
|
usedPreferences.push(key);
|
|
|
|
} catch (e) { /* ignore bad prefs and move on */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 21:15:41 +03:00
|
|
|
if (sections.Preferences) {
|
2015-03-16 14:51:02 +03:00
|
|
|
for (let key of enumerate(this._ini.getKeys("Preferences"))) {
|
2016-03-03 00:04:38 +03:00
|
|
|
if (usedPreferences.indexOf(key) > -1) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-09-11 19:52:04 +04:00
|
|
|
try {
|
2016-03-03 00:04:38 +03:00
|
|
|
let value = this._ini.getString("Preferences", key);
|
|
|
|
if (value) {
|
|
|
|
value = value.replace(/%LOCALE%/g, this._locale);
|
|
|
|
value = value.replace(/%LANGUAGE%/g, this._language);
|
2016-03-08 18:39:45 +03:00
|
|
|
defaults.set(key, parseValue(value));
|
2016-03-03 00:04:38 +03:00
|
|
|
}
|
2007-09-11 19:52:04 +04:00
|
|
|
} catch (e) { /* ignore bad prefs and move on */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let localizedStr = Cc["@mozilla.org/pref-localizedstring;1"].
|
|
|
|
createInstance(Ci.nsIPrefLocalizedString);
|
|
|
|
|
2016-02-26 23:47:53 +03:00
|
|
|
var usedLocalizablePreferences = [];
|
|
|
|
|
|
|
|
if (sections["LocalizablePreferences-" + this._locale]) {
|
|
|
|
for (let key of enumerate(this._ini.getKeys("LocalizablePreferences-" + this._locale))) {
|
2007-09-11 19:52:04 +04:00
|
|
|
try {
|
2016-03-03 00:04:38 +03:00
|
|
|
let value = this._ini.getString("LocalizablePreferences-" + this._locale, key);
|
|
|
|
if (value) {
|
|
|
|
value = parseValue(value);
|
2016-02-26 23:47:53 +03:00
|
|
|
localizedStr.data = "data:text/plain," + key + "=" + value;
|
2016-03-01 19:58:04 +03:00
|
|
|
defaults._prefBranch.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
|
2016-02-26 23:47:53 +03:00
|
|
|
}
|
|
|
|
usedLocalizablePreferences.push(key);
|
2016-02-19 19:59:15 +03:00
|
|
|
} catch (e) { /* ignore bad prefs and move on */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sections["LocalizablePreferences-" + this._language]) {
|
|
|
|
for (let key of enumerate(this._ini.getKeys("LocalizablePreferences-" + this._language))) {
|
2016-02-26 23:47:53 +03:00
|
|
|
if (usedLocalizablePreferences.indexOf(key) > -1) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-02-19 19:59:15 +03:00
|
|
|
try {
|
2016-03-03 00:04:38 +03:00
|
|
|
let value = this._ini.getString("LocalizablePreferences-" + this._language, key);
|
|
|
|
if (value) {
|
|
|
|
value = parseValue(value);
|
2016-02-26 23:47:53 +03:00
|
|
|
localizedStr.data = "data:text/plain," + key + "=" + value;
|
2016-03-01 19:58:04 +03:00
|
|
|
defaults._prefBranch.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
|
2016-02-26 23:47:53 +03:00
|
|
|
}
|
|
|
|
usedLocalizablePreferences.push(key);
|
2007-09-11 19:52:04 +04:00
|
|
|
} catch (e) { /* ignore bad prefs and move on */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 21:15:41 +03:00
|
|
|
if (sections.LocalizablePreferences) {
|
2016-02-26 23:47:53 +03:00
|
|
|
for (let key of enumerate(this._ini.getKeys("LocalizablePreferences"))) {
|
|
|
|
if (usedLocalizablePreferences.indexOf(key) > -1) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-09-11 19:52:04 +04:00
|
|
|
try {
|
2016-03-03 00:04:38 +03:00
|
|
|
let value = this._ini.getString("LocalizablePreferences", key);
|
|
|
|
if (value) {
|
|
|
|
value = parseValue(value);
|
2016-02-26 23:47:53 +03:00
|
|
|
value = value.replace(/%LOCALE%/g, this._locale);
|
|
|
|
value = value.replace(/%LANGUAGE%/g, this._language);
|
|
|
|
localizedStr.data = "data:text/plain," + key + "=" + value;
|
2017-01-11 00:20:18 +03:00
|
|
|
defaults._prefBranch.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
|
2016-02-26 23:47:53 +03:00
|
|
|
}
|
2007-09-11 19:52:04 +04:00
|
|
|
} catch (e) { /* ignore bad prefs and move on */ }
|
|
|
|
}
|
|
|
|
}
|
2009-10-05 14:13:04 +04:00
|
|
|
|
|
|
|
return this._checkCustomizationComplete();
|
|
|
|
},
|
|
|
|
|
|
|
|
_checkCustomizationComplete: function DIST__checkCustomizationComplete() {
|
2016-02-24 18:47:52 +03:00
|
|
|
const BROWSER_DOCURL = "chrome://browser/content/browser.xul";
|
|
|
|
|
|
|
|
if (this._newProfile) {
|
|
|
|
let xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
|
|
|
|
|
|
|
|
try {
|
|
|
|
var showPersonalToolbar = Services.prefs.getBoolPref("browser.showPersonalToolbar");
|
|
|
|
if (showPersonalToolbar) {
|
|
|
|
xulStore.setValue(BROWSER_DOCURL, "PersonalToolbar", "collapsed", "false");
|
|
|
|
}
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (e) {}
|
2016-02-24 18:47:52 +03:00
|
|
|
try {
|
|
|
|
var showMenubar = Services.prefs.getBoolPref("browser.showMenubar");
|
|
|
|
if (showMenubar) {
|
2016-10-31 19:31:58 +03:00
|
|
|
xulStore.setValue(BROWSER_DOCURL, "toolbar-menubar", "autohide", "false");
|
2016-02-24 18:47:52 +03:00
|
|
|
}
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (e) {}
|
2016-02-24 18:47:52 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 22:18:31 +03:00
|
|
|
let prefDefaultsApplied = this._prefDefaultsApplied || !this._ini;
|
2009-10-05 14:13:04 +04:00
|
|
|
if (this._customizationsApplied && this._bookmarksApplied &&
|
|
|
|
prefDefaultsApplied) {
|
2017-10-11 17:43:51 +03:00
|
|
|
Services.obs.notifyObservers(null, DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC);
|
2009-10-05 14:13:04 +04:00
|
|
|
}
|
2007-09-11 19:52:04 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-29 19:47:01 +03:00
|
|
|
function parseValue(value) {
|
|
|
|
try {
|
|
|
|
value = JSON.parse(value);
|
|
|
|
} catch (e) {
|
|
|
|
// JSON.parse catches numbers and booleans.
|
|
|
|
// Anything else, we assume is a string.
|
|
|
|
// Remove the quotes that aren't needed anymore.
|
|
|
|
value = value.replace(/^"/, "");
|
|
|
|
value = value.replace(/"$/, "");
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-03-16 14:51:02 +03:00
|
|
|
function* enumerate(UTF8Enumerator) {
|
2007-09-11 19:52:04 +04:00
|
|
|
while (UTF8Enumerator.hasMore())
|
|
|
|
yield UTF8Enumerator.getNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
function enumToObject(UTF8Enumerator) {
|
|
|
|
let ret = {};
|
2015-03-16 14:51:02 +03:00
|
|
|
for (let i of enumerate(UTF8Enumerator))
|
2007-09-11 19:52:04 +04:00
|
|
|
ret[i] = 1;
|
|
|
|
return ret;
|
|
|
|
}
|