diff --git a/toolkit/components/enterprisepolicies/EnterprisePolicies.js b/toolkit/components/enterprisepolicies/EnterprisePolicies.js index 45378909622c..9ef6fa193131 100644 --- a/toolkit/components/enterprisepolicies/EnterprisePolicies.js +++ b/toolkit/components/enterprisepolicies/EnterprisePolicies.js @@ -23,6 +23,9 @@ XPCOMUtils.defineLazyModuleGetters(this, { // ${InstallDir}/distribution folder. const POLICIES_FILENAME = "policies.json"; +// When true browser policy is loaded per-user from +// /run/user/$UID/appname +const PREF_PER_USER_DIR = "toolkit.policies.perUserDir"; // For easy testing, modify the helpers/sample.json file, // and set PREF_ALTERNATE_PATH in firefox.js as: // /your/repo/browser/components/enterprisepolicies/helpers/sample.json @@ -455,7 +458,12 @@ class JSONPoliciesProvider { _getConfigurationFile() { let configFile = null; try { - configFile = Services.dirsvc.get("XREAppDist", Ci.nsIFile); + let perUserPath = Services.prefs.getBoolPref(PREF_PER_USER_DIR, false); + if (perUserPath) { + configFile = Services.dirsvc.get("XREUserRunTimeDir", Ci.nsIFile); + } else { + configFile = Services.dirsvc.get("XREAppDist", Ci.nsIFile); + } configFile.append(POLICIES_FILENAME); } catch (ex) { // Getting the correct directory will fail in xpcshell tests. This should diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp index c3164f204ffd..979bd1484833 100644 --- a/toolkit/xre/nsXREDirProvider.cpp +++ b/toolkit/xre/nsXREDirProvider.cpp @@ -45,6 +45,7 @@ #include "mozilla/Omnijar.h" #include "mozilla/Preferences.h" #include "mozilla/Telemetry.h" +#include "nsPrintfCString.h" #include @@ -103,7 +104,7 @@ nsCOMPtr gDataDirProfile = nullptr; // These are required to allow nsXREDirProvider to be usable in xpcshell tests. // where gAppData is null. -#if defined(XP_MACOSX) || defined(XP_WIN) +#if defined(XP_MACOSX) || defined(XP_WIN) || defined(XP_UNIX) static const char* GetAppName() { if (gAppData) { return gAppData->name; @@ -461,6 +462,14 @@ nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent, #endif } else if (!strcmp(aProperty, XRE_USER_SYS_EXTENSION_DEV_DIR)) { return GetSysUserExtensionsDevDirectory(aFile); + } else if (!strcmp(aProperty, XRE_USER_RUNTIME_DIR)) { +#ifdef MOZ_WIDGET_GTK + nsPrintfCString path("/run/user/%d/%s/", getuid(), GetAppName()); + ToLowerCase(path); + return NS_NewNativeLocalFile(path, false, aFile); +#else + return NS_ERROR_FAILURE; +#endif } else if (!strcmp(aProperty, XRE_APP_DISTRIBUTION_DIR)) { bool persistent = false; rv = GetFile(NS_GRE_DIR, &persistent, getter_AddRefs(file)); diff --git a/xpcom/build/nsXULAppAPI.h b/xpcom/build/nsXULAppAPI.h index 121eb992812e..e1f0fd050472 100644 --- a/xpcom/build/nsXULAppAPI.h +++ b/xpcom/build/nsXULAppAPI.h @@ -141,6 +141,13 @@ */ #define XRE_ADDON_APP_DIR "XREAddonAppDir" +/** + * A directory service key which specifies the distribution specific files for + * the application unique for each user. + * It's located at /run/user/$UID// + */ +#define XRE_USER_RUNTIME_DIR "XREUserRunTimeDir" + /** * A directory service key which provides the update directory. Callers should * fall back to appDir.