0bcd21
diff -up firefox-45.0.1/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092 firefox-45.0.1/extensions/pref/autoconfig/src/nsReadConfig.cpp
0bcd21
--- firefox-45.0.1/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092	2016-03-15 23:37:54.000000000 +0100
0bcd21
+++ firefox-45.0.1/extensions/pref/autoconfig/src/nsReadConfig.cpp	2016-03-21 16:10:42.540417899 +0100
0bcd21
@@ -245,8 +245,20 @@ nsresult nsReadConfig::openAndEvaluateJS
0bcd21
             return rv;
0bcd21
 
0bcd21
         rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
0bcd21
-        if (NS_FAILED(rv)) 
0bcd21
-            return rv;
0bcd21
+        if (NS_FAILED(rv)) {
0bcd21
+          // Look for cfg file in /etc/<application>/pref
0bcd21
+          rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
0bcd21
+                                      getter_AddRefs(jsFile));
0bcd21
+          NS_ENSURE_SUCCESS(rv, rv);
0bcd21
+
0bcd21
+          rv = jsFile->AppendNative(NS_LITERAL_CSTRING("pref"));
0bcd21
+          NS_ENSURE_SUCCESS(rv, rv);
0bcd21
+          rv = jsFile->AppendNative(nsDependentCString(aFileName));
0bcd21
+          NS_ENSURE_SUCCESS(rv, rv);
0bcd21
+
0bcd21
+          rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
0bcd21
+          NS_ENSURE_SUCCESS(rv, rv);
0bcd21
+        }
0bcd21
 
0bcd21
     } else {
0bcd21
         nsAutoCString location("resource://gre/defaults/autoconfig/");
0bcd21
diff -up firefox-45.0.1/modules/libpref/Preferences.cpp.1170092 firefox-45.0.1/modules/libpref/Preferences.cpp
0bcd21
--- firefox-45.0.1/modules/libpref/Preferences.cpp.1170092	2016-03-21 16:10:42.540417899 +0100
0bcd21
+++ firefox-45.0.1/modules/libpref/Preferences.cpp	2016-03-21 16:13:29.145888710 +0100
0bcd21
@@ -1214,6 +1214,8 @@ static nsresult pref_InitInitialObjects(
0bcd21
   // - jar:$gre/omni.jar!/defaults/preferences/*.js
0bcd21
   // Thus, in omni.jar case, we always load app-specific default preferences
0bcd21
   // from omni.jar, whether or not $app == $gre.
0bcd21
+  // At very end load configuration from system config location:
0bcd21
+  // - /etc/firefox/pref/*.js
0bcd21
 
0bcd21
   nsZipFind *findPtr;
0bcd21
   nsAutoPtr<nsZipFind> find;
0bcd21
diff -up firefox-45.0.1/toolkit/xre/nsXREDirProvider.cpp.1170092 firefox-45.0.1/toolkit/xre/nsXREDirProvider.cpp
0bcd21
--- firefox-45.0.1/toolkit/xre/nsXREDirProvider.cpp.1170092	2016-03-15 23:37:46.000000000 +0100
0bcd21
+++ firefox-45.0.1/toolkit/xre/nsXREDirProvider.cpp	2016-03-21 16:12:06.498655156 +0100
0bcd21
@@ -51,6 +51,7 @@
0bcd21
 #endif
0bcd21
 #ifdef XP_UNIX
0bcd21
 #include <ctype.h>
0bcd21
+#include "nsIXULAppInfo.h"
0bcd21
 #endif
0bcd21
 #ifdef XP_IOS
0bcd21
 #include "UIKitDirProvider.h"
0bcd21
@@ -457,6 +458,20 @@ nsXREDirProvider::GetFile(const char* aP
0bcd21
       }
0bcd21
     }
0bcd21
   }
0bcd21
+#if defined(XP_UNIX)
0bcd21
+  if (!strcmp(aProperty, NS_APP_PREFS_SYSTEM_CONFIG_DIR)) {
0bcd21
+    nsCString sysConfigDir = NS_LITERAL_CSTRING("/etc/");
0bcd21
+    nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
0bcd21
+    if (!appInfo)
0bcd21
+      return NS_ERROR_NOT_AVAILABLE;
0bcd21
+    nsCString appName;
0bcd21
+    appInfo->GetName(appName);
0bcd21
+    ToLowerCase(appName);
0bcd21
+    sysConfigDir.Append(appName);
0bcd21
+    return NS_NewNativeLocalFile(sysConfigDir, false, aFile);
0bcd21
+  }
0bcd21
+#endif
0bcd21
+
0bcd21
   if (NS_FAILED(rv) || !file)
0bcd21
     return NS_ERROR_FAILURE;
0bcd21
 
0bcd21
@@ -753,6 +768,14 @@ nsXREDirProvider::GetFilesInternal(const
0bcd21
     LoadDirIntoArray(mXULAppDir, kAppendPrefDir, directories);
0bcd21
     LoadDirsIntoArray(mAppBundleDirectories,
0bcd21
                       kAppendPrefDir, directories);
0bcd21
+    // Add /etc/<application>/pref/ directory if it exists
0bcd21
+    nsCOMPtr<nsIFile> systemPrefDir;
0bcd21
+    rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR, getter_AddRefs(systemPrefDir));
0bcd21
+    if (NS_SUCCEEDED(rv)) {
0bcd21
+      rv = systemPrefDir->AppendNative(NS_LITERAL_CSTRING("pref"));
0bcd21
+      if (NS_SUCCEEDED(rv))
0bcd21
+        directories.AppendObject(systemPrefDir);
0bcd21
+    }
0bcd21
 
0bcd21
     rv = NS_NewArrayEnumerator(aResult, directories);
0bcd21
   }
0bcd21
diff -up firefox-45.0.1/xpcom/io/nsAppDirectoryServiceDefs.h.1170092 firefox-45.0.1/xpcom/io/nsAppDirectoryServiceDefs.h
0bcd21
--- firefox-45.0.1/xpcom/io/nsAppDirectoryServiceDefs.h.1170092	2016-03-15 23:37:47.000000000 +0100
0bcd21
+++ firefox-45.0.1/xpcom/io/nsAppDirectoryServiceDefs.h	2016-03-21 16:10:42.541417902 +0100
0bcd21
@@ -67,6 +67,7 @@
0bcd21
 #define NS_APP_PREFS_DEFAULTS_DIR_LIST          "PrefDL"
0bcd21
 #define NS_EXT_PREFS_DEFAULTS_DIR_LIST          "ExtPrefDL"
0bcd21
 #define NS_APP_PREFS_OVERRIDE_DIR               "PrefDOverride" // Directory for per-profile defaults
0bcd21
+#define NS_APP_PREFS_SYSTEM_CONFIG_DIR          "PrefSysConf"   // Directory with system-wide configuration
0bcd21
 
0bcd21
 #define NS_APP_USER_PROFILE_50_DIR              "ProfD"
0bcd21
 #define NS_APP_USER_PROFILE_LOCAL_50_DIR        "ProfLD"