Bug 1170092 Load preferences from /etc/firefox/defaults/pref on Linux; r=mkaply

Preferences from /etc/firefox/defaults/pref overwrites preferences set in omni.jar
and firefox/defaults/pref. The code was used for flatpak and snap only, but it could
be used also for regular Linux builds.

Differential Revision: https://phabricator.services.mozilla.com/D168799
This commit is contained in:
Jan Horak 2023-03-02 14:41:56 +00:00
parent 7bc36fb361
commit bddcbe8678
3 changed files with 24 additions and 17 deletions

View File

@ -11,6 +11,9 @@ function run_test() {
updateAppInfo();
try {
Services.dirsvc.undefine("SysConfD");
} catch (e) {}
let customSysConfD = Services.dirsvc.get("SysConfD", Ci.nsIFile);
let parent = customSysConfD.parent;
let child = customSysConfD.leafName;

View File

@ -8,6 +8,9 @@ const { updateAppInfo } = ChromeUtils.importESModule(
function run_test() {
updateAppInfo();
try {
Services.dirsvc.undefine("SysConfD");
} catch (e) {}
let defaultSysConfD = Services.dirsvc.get("SysConfD", Ci.nsIFile);
equal("/etc/xpcshell", defaultSysConfD.path, "SysConfD is in /etc");
}

View File

@ -4919,23 +4919,6 @@ nsresult Preferences::InitInitialObjects(bool aIsStartup) {
NS_WARNING("Error parsing application default preferences.");
}
#if defined(MOZ_WIDGET_GTK)
// Under Flatpak/Snap package, load /etc/firefox/defaults/pref/*.js.
if (mozilla::widget::IsRunningUnderFlatpakOrSnap()) {
nsCOMPtr<nsIFile> defaultSnapPrefDir;
rv = NS_GetSpecialDirectory(NS_OS_SYSTEM_CONFIG_DIR,
getter_AddRefs(defaultSnapPrefDir));
NS_ENSURE_SUCCESS(rv, rv);
defaultSnapPrefDir->AppendNative("defaults"_ns);
defaultSnapPrefDir->AppendNative("pref"_ns);
rv = pref_LoadPrefsInDir(defaultSnapPrefDir, nullptr, 0);
if (NS_FAILED(rv)) {
NS_WARNING("Error parsing application default preferences under Snap.");
}
}
#endif
// Load jar:$app/omni.jar!/defaults/preferences/*.js
// or jar:$gre/omni.jar!/defaults/preferences/*.js.
RefPtr<nsZipArchive> appJarReader = Omnijar::GetReader(Omnijar::APP);
@ -5008,6 +4991,24 @@ nsresult Preferences::InitInitialObjects(bool aIsStartup) {
}
}
#if defined(MOZ_WIDGET_GTK)
// To ensure the system-wide preferences are not overwritten by
// firefox/browser/defauts/preferences/*.js we need to load
// the /etc/firefox/defaults/pref/*.js settings as last.
// Under Flatpak, the NS_OS_SYSTEM_CONFIG_DIR points to /app/etc/firefox
nsCOMPtr<nsIFile> defaultSystemPrefDir;
rv = NS_GetSpecialDirectory(NS_OS_SYSTEM_CONFIG_DIR,
getter_AddRefs(defaultSystemPrefDir));
NS_ENSURE_SUCCESS(rv, rv);
defaultSystemPrefDir->AppendNative("defaults"_ns);
defaultSystemPrefDir->AppendNative("pref"_ns);
rv = pref_LoadPrefsInDir(defaultSystemPrefDir, nullptr, 0);
if (NS_FAILED(rv)) {
NS_WARNING("Error parsing application default preferences.");
}
#endif
if (XRE_IsParentProcess()) {
SetupTelemetryPref();
}