commit 87849bd0e5940d1973bf697a84e6b8ac2b4072aa Author: Kathleen Brade brade@pearlcrescent.com Date: Mon Sep 30 15:26:22 2013 -0700
Change the default Firefox profile directory to be TBB-relative.
This should eliminate our need to rely on a wrapper script that sets $HOME and launches Firefox with -profile.
See https://trac.torproject.org/projects/tor/ticket/9173. --- toolkit/xre/nsXREDirProvider.cpp | 104 ++++++-------------------------- toolkit/xre/nsXREDirProvider.h | 10 +-- xpcom/io/Makefile.in | 4 +- xpcom/io/nsAppFileLocationProvider.cpp | 77 +++++++++-------------- 4 files changed, 55 insertions(+), 140 deletions(-)
diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp index ecf56c2..8432cca 100644 --- a/toolkit/xre/nsXREDirProvider.cpp +++ b/toolkit/xre/nsXREDirProvider.cpp @@ -31,6 +31,7 @@ #include "nsArrayEnumerator.h" #include "nsEnumeratorUtils.h" #include "nsReadableUtils.h" +#include "nsXPCOMPrivate.h" // for XPCOM_FILE_PATH_SEPARATOR #include "mozilla/Services.h" #include "mozilla/Omnijar.h" #include "mozilla/Preferences.h" @@ -166,9 +167,6 @@ nsXREDirProvider::GetUserProfilesRootDir(nsIFile** aResult, aProfileName, aAppName, aVendorName);
if (NS_SUCCEEDED(rv)) { -#if !defined(XP_UNIX) || defined(XP_MACOSX) - rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles")); -#endif // We must create the profile directory here if it does not exist. nsresult tmp = EnsureDirectoryExists(file); if (NS_FAILED(tmp)) { @@ -191,9 +189,6 @@ nsXREDirProvider::GetUserProfilesLocalDir(nsIFile** aResult, aProfileName, aAppName, aVendorName);
if (NS_SUCCEEDED(rv)) { -#if !defined(XP_UNIX) || defined(XP_MACOSX) - rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles")); -#endif // We must create the profile directory here if it does not exist. nsresult tmp = EnsureDirectoryExists(file); if (NS_FAILED(tmp)) { @@ -1051,88 +1046,35 @@ nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal) { // Copied from nsAppFileLocationProvider (more or less) - nsresult rv; + NS_ENSURE_ARG_POINTER(aFile); nsCOMPtr<nsIFile> localDir;
+ nsresult rv = GetAppDir()->Clone(getter_AddRefs(localDir)); + NS_ENSURE_SUCCESS(rv, rv); + + int levelsToRemove = 1; #if defined(XP_MACOSX) - FSRef fsRef; - OSType folderType; - if (aLocal) { - folderType = kCachedDataFolderType; - } else { -#ifdef MOZ_THUNDERBIRD - folderType = kDomainLibraryFolderType; -#else - folderType = kApplicationSupportFolderType; + levelsToRemove += 4; #endif + while (localDir && (levelsToRemove > 0)) { + nsCOMPtr<nsIFile> parentDir; + rv = localDir->GetParent(getter_AddRefs(parentDir)); + NS_ENSURE_SUCCESS(rv, rv); + localDir = parentDir; + --levelsToRemove; } - OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef); - NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
- rv = NS_NewNativeLocalFile(EmptyCString(), true, getter_AddRefs(localDir)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir); - NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED); + if (!localDir) + return NS_ERROR_FAILURE;
- rv = dirFileMac->InitWithFSRef(&fsRef); + rv = localDir->AppendRelativeNativePath(NS_LITERAL_CSTRING("Data" + XPCOM_FILE_PATH_SEPARATOR "Browser")); NS_ENSURE_SUCCESS(rv, rv);
- localDir = do_QueryInterface(dirFileMac, &rv); -#elif defined(XP_WIN) - nsString path; if (aLocal) { - rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path); - if (NS_FAILED(rv)) - rv = GetRegWindowsAppDataFolder(aLocal, path); - } - if (!aLocal || NS_FAILED(rv)) { - rv = GetShellFolderPath(CSIDL_APPDATA, path); - if (NS_FAILED(rv)) { - if (!aLocal) - rv = GetRegWindowsAppDataFolder(aLocal, path); - } + rv = localDir->AppendNative(NS_LITERAL_CSTRING("Caches")); + NS_ENSURE_SUCCESS(rv, rv); } - NS_ENSURE_SUCCESS(rv, rv); - - rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir)); -#elif defined(XP_OS2) -#if 0 /* For OS/2 we want to always use MOZILLA_HOME */ - // we want an environment variable of the form - // FIREFOX_HOME, etc - if (!gAppData) - return NS_ERROR_FAILURE; - nsDependentCString envVar(nsDependentCString(gAppData->name)); - envVar.Append("_HOME"); - char *pHome = getenv(envVar.get()); -#endif - char *pHome = getenv("MOZILLA_HOME"); - if (pHome && *pHome) { - rv = NS_NewNativeLocalFile(nsDependentCString(pHome), true, - getter_AddRefs(localDir)); - } else { - PPIB ppib; - PTIB ptib; - char appDir[CCHMAXPATH]; - - DosGetInfoBlocks(&ptib, &ppib); - DosQueryModuleName(ppib->pib_hmte, CCHMAXPATH, appDir); - *strrchr(appDir, '\') = '\0'; - rv = NS_NewNativeLocalFile(nsDependentCString(appDir), true, getter_AddRefs(localDir)); - } -#elif defined(MOZ_WIDGET_GONK) - rv = NS_NewNativeLocalFile(NS_LITERAL_CSTRING("/data/b2g"), true, - getter_AddRefs(localDir)); -#elif defined(XP_UNIX) - const char* homeDir = getenv("HOME"); - if (!homeDir || !*homeDir) - return NS_ERROR_FAILURE; - - rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true, - getter_AddRefs(localDir)); -#else -#error "Don't know how to get product dir on your platform" -#endif
NS_IF_ADDREF(*aFile = localDir); return rv; @@ -1346,16 +1288,8 @@ nsXREDirProvider::AppendProfilePath(nsIFile* aFile, nsCAutoString vendor; if (aProfileName && !aProfileName->IsEmpty()) { profile = *aProfileName; - } else if (aAppName) { - appName = *aAppName; - if (aVendorName) { - vendor = *aVendorName; - } } else if (gAppData->profile) { profile = gAppData->profile; - } else { - appName = gAppData->name; - vendor = gAppData->vendor; }
nsresult rv; diff --git a/toolkit/xre/nsXREDirProvider.h b/toolkit/xre/nsXREDirProvider.h index 77d109f..d574f59 100644 --- a/toolkit/xre/nsXREDirProvider.h +++ b/toolkit/xre/nsXREDirProvider.h @@ -56,16 +56,16 @@ public:
nsresult GetProfileDefaultsDir(nsIFile* *aResult);
- static nsresult GetUserAppDataDirectory(nsIFile* *aFile) { + nsresult GetUserAppDataDirectory(nsIFile* *aFile) { return GetUserDataDirectory(aFile, false, nullptr, nullptr, nullptr); } - static nsresult GetUserLocalDataDirectory(nsIFile* *aFile) { + nsresult GetUserLocalDataDirectory(nsIFile* *aFile) { return GetUserDataDirectory(aFile, true, nullptr, nullptr, nullptr); }
// By default GetUserDataDirectory gets profile path from gAppData, // but that can be overridden by using aProfileName/aAppName/aVendorName. - static nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal, + nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal, const nsACString* aProfileName, const nsACString* aAppName, const nsACString* aVendorName); @@ -101,8 +101,8 @@ public:
protected: nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult); - static nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal); - static nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile); + nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal); + nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile); #if defined(XP_UNIX) || defined(XP_MACOSX) static nsresult GetSystemExtensionsDirectory(nsIFile** aFile); #endif diff --git a/xpcom/io/Makefile.in b/xpcom/io/Makefile.in index 79ad5de..3fba891 100644 --- a/xpcom/io/Makefile.in +++ b/xpcom/io/Makefile.in @@ -162,7 +162,9 @@ DEFINES += -DHAVE_USR_LIB64_DIR endif endif
-LOCAL_INCLUDES += -I.. +LOCAL_INCLUDES += \ + -I.. \ + -I$(srcdir)/../build
ifeq ($(MOZ_PLATFORM_MAEMO),5) CFLAGS += $(MOZ_DBUS_CFLAGS) diff --git a/xpcom/io/nsAppFileLocationProvider.cpp b/xpcom/io/nsAppFileLocationProvider.cpp index 1e667b8..3828eed 100644 --- a/xpcom/io/nsAppFileLocationProvider.cpp +++ b/xpcom/io/nsAppFileLocationProvider.cpp @@ -13,6 +13,7 @@ #include "nsISimpleEnumerator.h" #include "prenv.h" #include "nsCRT.h" +#include "nsXPCOMPrivate.h" // for XPCOM_FILE_PATH_SEPARATOR
#if defined(MOZ_WIDGET_COCOA) #include <Carbon/Carbon.h> @@ -283,9 +284,8 @@ NS_METHOD nsAppFileLocationProvider::CloneMozBinDirectory(nsIFile **aLocalFile) //---------------------------------------------------------------------------------------- // GetProductDirectory - Gets the directory which contains the application data folder // -// UNIX : ~/.mozilla/ -// WIN : <Application Data folder on user's machine>\Mozilla -// Mac : :Documents:Mozilla: +// UNIX and WIN : <App Folder>/../Data/Browser +// Mac : <App Folder>/../../../../../Data/Browser //---------------------------------------------------------------------------------------- NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsIFile **aLocalFile, bool aLocal) { @@ -295,38 +295,33 @@ NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsIFile **aLocalFile, b bool exists; nsCOMPtr<nsIFile> localDir;
-#if defined(MOZ_WIDGET_COCOA) - FSRef fsRef; - OSType folderType = aLocal ? (OSType) kCachedDataFolderType : (OSType) kDomainLibraryFolderType; - OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef); - if (err) return NS_ERROR_FAILURE; - NS_NewLocalFile(EmptyString(), true, getter_AddRefs(localDir)); - if (!localDir) return NS_ERROR_FAILURE; - nsCOMPtr<nsILocalFileMac> localDirMac(do_QueryInterface(localDir)); - rv = localDirMac->InitWithFSRef(&fsRef); - if (NS_FAILED(rv)) return rv; -#elif defined(XP_OS2) - nsCOMPtr<nsIProperties> directoryService = - do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - rv = directoryService->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsIFile), getter_AddRefs(localDir)); - if (NS_FAILED(rv)) return rv; -#elif defined(XP_WIN) - nsCOMPtr<nsIProperties> directoryService = - do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - const char* prop = aLocal ? NS_WIN_LOCAL_APPDATA_DIR : NS_WIN_APPDATA_DIR; - rv = directoryService->Get(prop, NS_GET_IID(nsIFile), getter_AddRefs(localDir)); - if (NS_FAILED(rv)) return rv; -#elif defined(XP_UNIX) - rv = NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), true, getter_AddRefs(localDir)); - if (NS_FAILED(rv)) return rv; -#else -#error dont_know_how_to_get_product_dir_on_your_platform + rv = CloneMozBinDirectory(getter_AddRefs(localDir)); + NS_ENSURE_SUCCESS(rv, rv); + + int levelsToRemove = 1; +#if defined(XP_MACOSX) + levelsToRemove += 4; #endif + while (localDir && (levelsToRemove > 0)) { + nsCOMPtr<nsIFile> parentDir; + rv = localDir->GetParent(getter_AddRefs(parentDir)); + NS_ENSURE_SUCCESS(rv, rv); + localDir = parentDir; + --levelsToRemove; + } + + if (!localDir) + return NS_ERROR_FAILURE; + + rv = localDir->AppendRelativeNativePath(NS_LITERAL_CSTRING("Data" + XPCOM_FILE_PATH_SEPARATOR "Browser")); + NS_ENSURE_SUCCESS(rv, rv); + + if (aLocal) { + rv = localDir->AppendNative(NS_LITERAL_CSTRING("Caches")); + NS_ENSURE_SUCCESS(rv, rv); + }
- rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR); - if (NS_FAILED(rv)) return rv; rv = localDir->Exists(&exists);
if (NS_SUCCEEDED(rv) && !exists) @@ -343,10 +338,6 @@ NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsIFile **aLocalFile, b
//---------------------------------------------------------------------------------------- // GetDefaultUserProfileRoot - Gets the directory which contains each user profile dir -// -// UNIX : ~/.mozilla/ -// WIN : <Application Data folder on user's machine>\Mozilla\Profiles -// Mac : :Documents:Mozilla:Profiles: //---------------------------------------------------------------------------------------- NS_METHOD nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsIFile **aLocalFile, bool aLocal) { @@ -358,18 +349,6 @@ NS_METHOD nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsIFile **aLocalF rv = GetProductDirectory(getter_AddRefs(localDir), aLocal); if (NS_FAILED(rv)) return rv;
-#if defined(MOZ_WIDGET_COCOA) || defined(XP_OS2) || defined(XP_WIN) - // These 3 platforms share this part of the path - do them as one - rv = localDir->AppendRelativeNativePath(NS_LITERAL_CSTRING("Profiles")); - if (NS_FAILED(rv)) return rv; - - bool exists; - rv = localDir->Exists(&exists); - if (NS_SUCCEEDED(rv) && !exists) - rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775); - if (NS_FAILED(rv)) return rv; -#endif - *aLocalFile = localDir; NS_ADDREF(*aLocalFile);