2014-05-05 17:30:43 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-07-16 14:20:33 +00:00
|
|
|
#include "nsAppFileLocationProvider.h"
|
2000-08-10 04:39:30 +00:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2015-09-04 09:50:49 +00:00
|
|
|
#include "nsEnumeratorUtils.h"
|
2000-07-16 14:20:33 +00:00
|
|
|
#include "nsIAtom.h"
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2000-07-19 19:58:35 +00:00
|
|
|
#include "nsString.h"
|
2001-11-02 15:29:57 +00:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2001-11-26 15:54:38 +00:00
|
|
|
#include "prenv.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2010-04-27 12:57:34 +00:00
|
|
|
#if defined(MOZ_WIDGET_COCOA)
|
2009-03-19 17:41:13 +00:00
|
|
|
#include <Carbon/Carbon.h>
|
2000-07-19 21:47:08 +00:00
|
|
|
#include "nsILocalFileMac.h"
|
2003-04-02 22:45:08 +00:00
|
|
|
#elif defined(XP_WIN)
|
2000-07-19 19:58:35 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <shlobj.h>
|
2000-07-19 21:20:35 +00:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/param.h>
|
2000-07-16 14:20:33 +00:00
|
|
|
#endif
|
2000-09-21 13:45:31 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-07-16 14:20:33 +00:00
|
|
|
// WARNING: These hard coded names need to go away. They need to
|
|
|
|
// come from localizable resources
|
|
|
|
|
2010-04-27 12:57:34 +00:00
|
|
|
#if defined(MOZ_WIDGET_COCOA)
|
2002-04-27 05:33:09 +00:00
|
|
|
#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("Application Registry")
|
|
|
|
#define ESSENTIAL_FILES NS_LITERAL_CSTRING("Essential Files")
|
2014-02-10 22:57:01 +00:00
|
|
|
#elif defined(XP_WIN)
|
2002-04-27 05:33:09 +00:00
|
|
|
#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("registry.dat")
|
2001-01-18 22:51:57 +00:00
|
|
|
#else
|
2002-04-27 05:33:09 +00:00
|
|
|
#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("appreg")
|
2001-07-31 19:05:34 +00:00
|
|
|
#endif
|
2001-01-18 22:51:57 +00:00
|
|
|
|
|
|
|
// define default product directory
|
2003-07-01 18:32:49 +00:00
|
|
|
#define DEFAULT_PRODUCT_DIR NS_LITERAL_CSTRING(MOZ_USER_DIR)
|
2001-01-18 22:51:57 +00:00
|
|
|
|
2001-11-26 15:54:38 +00:00
|
|
|
// Locally defined keys used by nsAppDirectoryEnumerator
|
|
|
|
#define NS_ENV_PLUGINS_DIR "EnvPlugins" // env var MOZ_PLUGIN_PATH
|
2002-03-07 15:24:40 +00:00
|
|
|
#define NS_USER_PLUGINS_DIR "UserPlugins"
|
2001-01-18 22:51:57 +00:00
|
|
|
|
2010-04-27 12:57:34 +00:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2002-06-14 12:30:44 +00:00
|
|
|
#define NS_MACOSX_USER_PLUGIN_DIR "OSXUserPlugins"
|
|
|
|
#define NS_MACOSX_LOCAL_PLUGIN_DIR "OSXLocalPlugins"
|
2008-10-10 15:54:33 +00:00
|
|
|
#elif XP_UNIX
|
|
|
|
#define NS_SYSTEM_PLUGINS_DIR "SysPlugins"
|
2002-06-14 12:30:44 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
#define DEFAULTS_DIR_NAME NS_LITERAL_CSTRING("defaults")
|
|
|
|
#define DEFAULTS_PREF_DIR_NAME NS_LITERAL_CSTRING("pref")
|
|
|
|
#define RES_DIR_NAME NS_LITERAL_CSTRING("res")
|
|
|
|
#define CHROME_DIR_NAME NS_LITERAL_CSTRING("chrome")
|
|
|
|
#define PLUGINS_DIR_NAME NS_LITERAL_CSTRING("plugins")
|
|
|
|
#define SEARCH_DIR_NAME NS_LITERAL_CSTRING("searchplugins")
|
2000-07-16 14:20:33 +00:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsAppFileLocationProvider::Constructor/Destructor
|
2001-07-31 19:05:34 +00:00
|
|
|
//*****************************************************************************
|
2000-07-16 14:20:33 +00:00
|
|
|
|
|
|
|
nsAppFileLocationProvider::nsAppFileLocationProvider()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsAppFileLocationProvider::nsISupports
|
2001-07-31 19:05:34 +00:00
|
|
|
//*****************************************************************************
|
2000-07-16 14:20:33 +00:00
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsAppFileLocationProvider,
|
|
|
|
nsIDirectoryServiceProvider,
|
|
|
|
nsIDirectoryServiceProvider2)
|
2000-07-16 14:20:33 +00:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsAppFileLocationProvider::nsIDirectoryServiceProvider
|
2001-07-31 19:05:34 +00:00
|
|
|
//*****************************************************************************
|
2000-07-16 14:20:33 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-14 20:15:46 +00:00
|
|
|
nsAppFileLocationProvider::GetFile(const char* aProp, bool* aPersistent,
|
|
|
|
nsIFile** aResult)
|
2001-07-31 19:05:34 +00:00
|
|
|
{
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_WARN_IF(!aProp)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2013-11-19 21:27:37 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
nsCOMPtr<nsIFile> localFile;
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2000-07-16 14:20:33 +00:00
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
*aResult = nullptr;
|
|
|
|
*aPersistent = true;
|
2002-06-14 12:30:44 +00:00
|
|
|
|
2010-04-27 12:57:34 +00:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2014-05-05 17:30:43 +00:00
|
|
|
FSRef fileRef;
|
|
|
|
nsCOMPtr<nsILocalFileMac> macFile;
|
2002-06-14 12:30:44 +00:00
|
|
|
#endif
|
2014-05-05 17:30:43 +00:00
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
if (nsCRT::strcmp(aProp, NS_APP_APPLICATION_REGISTRY_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = GetProductDirectory(getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_APPLICATION_REGISTRY_FILE) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = GetProductDirectory(getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localFile->AppendNative(APP_REGISTRY_NAME);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_DEFAULTS_50_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_PREF_DEFAULTS_50_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME);
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localFile->AppendRelativeNativePath(DEFAULTS_PREF_DIR_NAME);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2000-07-16 14:20:33 +00:00
|
|
|
}
|
2014-05-14 20:15:46 +00:00
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_USER_PROFILES_ROOT_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = GetDefaultUserProfileRoot(getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_USER_PROFILES_LOCAL_ROOT_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = GetDefaultUserProfileRoot(getter_AddRefs(localFile), true);
|
2014-05-14 20:15:46 +00:00
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_RES_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localFile->AppendRelativeNativePath(RES_DIR_NAME);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_CHROME_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localFile->AppendRelativeNativePath(CHROME_DIR_NAME);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_PLUGINS_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localFile->AppendRelativeNativePath(PLUGINS_DIR_NAME);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
}
|
2010-04-27 12:57:34 +00:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2014-05-14 20:15:46 +00:00
|
|
|
else if (nsCRT::strcmp(aProp, NS_MACOSX_USER_PLUGIN_DIR) == 0) {
|
2014-08-25 19:17:15 +00:00
|
|
|
if (::FSFindFolder(kUserDomain, kInternetPlugInFolderType, false,
|
|
|
|
&fileRef) == noErr) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = NS_NewLocalFileWithFSRef(&fileRef, true, getter_AddRefs(macFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
localFile = macFile;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2002-06-14 12:30:44 +00:00
|
|
|
}
|
2014-05-14 20:15:46 +00:00
|
|
|
} else if (nsCRT::strcmp(aProp, NS_MACOSX_LOCAL_PLUGIN_DIR) == 0) {
|
2014-08-25 19:17:15 +00:00
|
|
|
if (::FSFindFolder(kLocalDomain, kInternetPlugInFolderType, false,
|
|
|
|
&fileRef) == noErr) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = NS_NewLocalFileWithFSRef(&fileRef, true, getter_AddRefs(macFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
localFile = macFile;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2009-09-08 21:22:49 +00:00
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
}
|
2002-06-14 12:30:44 +00:00
|
|
|
#else
|
2014-05-14 20:15:46 +00:00
|
|
|
else if (nsCRT::strcmp(aProp, NS_ENV_PLUGINS_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
NS_ERROR("Don't use nsAppFileLocationProvider::GetFile(NS_ENV_PLUGINS_DIR, ...). "
|
|
|
|
"Use nsAppFileLocationProvider::GetFiles(...).");
|
2014-05-14 20:15:46 +00:00
|
|
|
const char* pathVar = PR_GetEnv("MOZ_PLUGIN_PATH");
|
2014-05-05 17:30:43 +00:00
|
|
|
if (pathVar && *pathVar)
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(pathVar), true,
|
|
|
|
getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
} else if (nsCRT::strcmp(aProp, NS_USER_PLUGINS_DIR) == 0) {
|
2010-07-23 18:00:16 +00:00
|
|
|
#ifdef ENABLE_SYSTEM_EXTENSION_DIRS
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = GetProductDirectory(getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localFile->AppendRelativeNativePath(PLUGINS_DIR_NAME);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2010-07-23 18:00:16 +00:00
|
|
|
#else
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2010-07-23 18:00:16 +00:00
|
|
|
#endif
|
2014-05-05 17:30:43 +00:00
|
|
|
}
|
2008-10-10 15:54:33 +00:00
|
|
|
#ifdef XP_UNIX
|
2014-05-14 20:15:46 +00:00
|
|
|
else if (nsCRT::strcmp(aProp, NS_SYSTEM_PLUGINS_DIR) == 0) {
|
2010-07-23 18:00:16 +00:00
|
|
|
#ifdef ENABLE_SYSTEM_EXTENSION_DIRS
|
2014-05-14 20:15:46 +00:00
|
|
|
static const char* const sysLPlgDir =
|
2009-06-24 07:21:43 +00:00
|
|
|
#if defined(HAVE_USR_LIB64_DIR) && defined(__LP64__)
|
2014-05-05 17:30:43 +00:00
|
|
|
"/usr/lib64/mozilla/plugins";
|
2012-11-14 19:02:07 +00:00
|
|
|
#elif defined(__OpenBSD__) || defined (__FreeBSD__)
|
2014-05-05 17:30:43 +00:00
|
|
|
"/usr/local/lib/mozilla/plugins";
|
2009-06-24 07:21:43 +00:00
|
|
|
#else
|
2014-05-05 17:30:43 +00:00
|
|
|
"/usr/lib/mozilla/plugins";
|
2009-06-24 07:21:43 +00:00
|
|
|
#endif
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(sysLPlgDir),
|
|
|
|
false, getter_AddRefs(localFile));
|
2010-07-23 18:00:16 +00:00
|
|
|
#else
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2010-07-23 18:00:16 +00:00
|
|
|
#endif
|
2014-05-05 17:30:43 +00:00
|
|
|
}
|
2008-10-10 15:54:33 +00:00
|
|
|
#endif
|
2002-06-14 12:30:44 +00:00
|
|
|
#endif
|
2014-05-14 20:15:46 +00:00
|
|
|
else if (nsCRT::strcmp(aProp, NS_APP_SEARCH_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localFile->AppendRelativeNativePath(SEARCH_DIR_NAME);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_USER_SEARCH_DIR) == 0) {
|
|
|
|
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, aResult);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = (*aResult)->AppendNative(SEARCH_DIR_NAME);
|
|
|
|
}
|
|
|
|
} else if (nsCRT::strcmp(aProp, NS_APP_INSTALL_CLEANUP_DIR) == 0) {
|
2014-05-05 17:30:43 +00:00
|
|
|
// This is cloned so that embeddors will have a hook to override
|
|
|
|
// with their own cleanup dir. See bugzilla bug #105087
|
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
}
|
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
if (localFile && NS_SUCCEEDED(rv)) {
|
2015-03-12 13:43:50 +00:00
|
|
|
localFile.forget(aResult);
|
|
|
|
return NS_OK;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
|
|
|
|
return rv;
|
2000-07-16 14:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-15 04:30:32 +00:00
|
|
|
nsresult
|
2014-05-14 20:15:46 +00:00
|
|
|
nsAppFileLocationProvider::CloneMozBinDirectory(nsIFile** aLocalFile)
|
2000-07-16 14:20:33 +00:00
|
|
|
{
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_WARN_IF(!aLocalFile)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
if (!mMozBinDirectory) {
|
2014-05-05 17:30:43 +00:00
|
|
|
// Get the mozilla bin directory
|
|
|
|
// 1. Check the directory service first for NS_XPCOM_CURRENT_PROCESS_DIR
|
|
|
|
// This will be set if a directory was passed to NS_InitXPCOM
|
|
|
|
// 2. If that doesn't work, set it to be the current process directory
|
|
|
|
nsCOMPtr<nsIProperties>
|
|
|
|
directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return rv;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(mMozBinDirectory));
|
2014-05-05 17:30:43 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-14 20:15:46 +00:00
|
|
|
rv = directoryService->Get(NS_OS_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(mMozBinDirectory));
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return rv;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2001-01-18 22:51:57 +00:00
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
nsCOMPtr<nsIFile> aFile;
|
|
|
|
rv = mMozBinDirectory->Clone(getter_AddRefs(aFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return rv;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2000-07-16 14:20:33 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
NS_IF_ADDREF(*aLocalFile = aFile);
|
|
|
|
return NS_OK;
|
2000-07-16 14:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
2001-01-18 22:51:57 +00:00
|
|
|
// GetProductDirectory - Gets the directory which contains the application data folder
|
2000-07-16 14:20:33 +00:00
|
|
|
//
|
|
|
|
// UNIX : ~/.mozilla/
|
2001-07-31 19:05:34 +00:00
|
|
|
// WIN : <Application Data folder on user's machine>\Mozilla
|
2001-01-18 22:51:57 +00:00
|
|
|
// Mac : :Documents:Mozilla:
|
2000-07-16 14:20:33 +00:00
|
|
|
//----------------------------------------------------------------------------------------
|
2016-08-15 04:30:32 +00:00
|
|
|
nsresult
|
2014-05-14 20:15:46 +00:00
|
|
|
nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
|
|
|
|
bool aLocal)
|
2000-07-16 14:20:33 +00:00
|
|
|
{
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_WARN_IF(!aLocalFile)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
nsresult rv;
|
|
|
|
bool exists;
|
|
|
|
nsCOMPtr<nsIFile> localDir;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2010-04-27 12:57:34 +00:00
|
|
|
#if defined(MOZ_WIDGET_COCOA)
|
2014-05-05 17:30:43 +00:00
|
|
|
FSRef fsRef;
|
2014-08-25 19:17:15 +00:00
|
|
|
OSType folderType = aLocal ? (OSType)kCachedDataFolderType :
|
|
|
|
(OSType)kDomainLibraryFolderType;
|
2014-05-05 17:30:43 +00:00
|
|
|
OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
|
2014-05-14 20:15:46 +00:00
|
|
|
if (err) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
NS_NewLocalFile(EmptyString(), true, getter_AddRefs(localDir));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (!localDir) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
nsCOMPtr<nsILocalFileMac> localDirMac(do_QueryInterface(localDir));
|
|
|
|
rv = localDirMac->InitWithFSRef(&fsRef);
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2003-04-02 22:45:08 +00:00
|
|
|
#elif defined(XP_WIN)
|
2014-05-05 17:30:43 +00:00
|
|
|
nsCOMPtr<nsIProperties> directoryService =
|
|
|
|
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
const char* prop = aLocal ? NS_WIN_LOCAL_APPDATA_DIR : NS_WIN_APPDATA_DIR;
|
|
|
|
rv = directoryService->Get(prop, NS_GET_IID(nsIFile), getter_AddRefs(localDir));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-07-16 14:20:33 +00:00
|
|
|
#elif defined(XP_UNIX)
|
2014-08-25 19:17:15 +00:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), true,
|
|
|
|
getter_AddRefs(localDir));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-01-18 22:51:57 +00:00
|
|
|
#else
|
|
|
|
#error dont_know_how_to_get_product_dir_on_your_platform
|
|
|
|
#endif
|
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR);
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localDir->Exists(&exists);
|
2005-01-30 21:33:47 +00:00
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !exists) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2005-01-30 21:33:47 +00:00
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-01-18 22:51:57 +00:00
|
|
|
|
2015-07-01 16:27:43 +00:00
|
|
|
localDir.forget(aLocalFile);
|
2001-01-18 22:51:57 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
return rv;
|
2001-01-18 22:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
// GetDefaultUserProfileRoot - Gets the directory which contains each user profile dir
|
|
|
|
//
|
|
|
|
// UNIX : ~/.mozilla/
|
2001-07-31 19:05:34 +00:00
|
|
|
// WIN : <Application Data folder on user's machine>\Mozilla\Profiles
|
2001-04-18 02:51:24 +00:00
|
|
|
// Mac : :Documents:Mozilla:Profiles:
|
2001-01-18 22:51:57 +00:00
|
|
|
//----------------------------------------------------------------------------------------
|
2016-08-15 04:30:32 +00:00
|
|
|
nsresult
|
2014-05-14 20:15:46 +00:00
|
|
|
nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsIFile** aLocalFile,
|
|
|
|
bool aLocal)
|
2001-01-18 22:51:57 +00:00
|
|
|
{
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_WARN_IF(!aLocalFile)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFile> localDir;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = GetProductDirectory(getter_AddRefs(localDir), aLocal);
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-07-16 14:20:33 +00:00
|
|
|
|
2014-02-10 22:57:01 +00:00
|
|
|
#if defined(MOZ_WIDGET_COCOA) || defined(XP_WIN)
|
2014-05-05 17:30:43 +00:00
|
|
|
// These 3 platforms share this part of the path - do them as one
|
|
|
|
rv = localDir->AppendRelativeNativePath(NS_LITERAL_CSTRING("Profiles"));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
|
|
|
|
bool exists;
|
|
|
|
rv = localDir->Exists(&exists);
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !exists) {
|
2014-05-05 17:30:43 +00:00
|
|
|
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-07-16 14:20:33 +00:00
|
|
|
#endif
|
|
|
|
|
2015-07-01 16:27:43 +00:00
|
|
|
localDir.forget(aLocalFile);
|
2000-07-16 14:20:33 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
return rv;
|
2000-07-16 14:20:33 +00:00
|
|
|
}
|
|
|
|
|
2001-11-02 15:29:57 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsAppFileLocationProvider::nsIDirectoryServiceProvider2
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
class nsAppDirectoryEnumerator : public nsISimpleEnumerator
|
|
|
|
{
|
2014-05-05 17:30:43 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* aKeyList is a null-terminated list of properties which are provided by aProvider
|
|
|
|
* They do not need to be publicly defined keys.
|
|
|
|
*/
|
2014-05-14 20:15:46 +00:00
|
|
|
nsAppDirectoryEnumerator(nsIDirectoryServiceProvider* aProvider,
|
2014-05-05 17:30:43 +00:00
|
|
|
const char* aKeyList[]) :
|
|
|
|
mProvider(aProvider),
|
|
|
|
mCurrentKey(aKeyList)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD HasMoreElements(bool* aResult) override
|
2014-05-05 17:30:43 +00:00
|
|
|
{
|
2014-05-14 20:15:46 +00:00
|
|
|
while (!mNext && *mCurrentKey) {
|
2014-05-05 17:30:43 +00:00
|
|
|
bool dontCare;
|
|
|
|
nsCOMPtr<nsIFile> testFile;
|
|
|
|
(void)mProvider->GetFile(*mCurrentKey++, &dontCare, getter_AddRefs(testFile));
|
|
|
|
// Don't return a file which does not exist.
|
|
|
|
bool exists;
|
2014-05-14 20:15:46 +00:00
|
|
|
if (testFile && NS_SUCCEEDED(testFile->Exists(&exists)) && exists) {
|
2014-05-05 17:30:43 +00:00
|
|
|
mNext = testFile;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2001-11-02 15:29:57 +00:00
|
|
|
}
|
2014-05-14 20:15:46 +00:00
|
|
|
*aResult = mNext != nullptr;
|
2014-05-05 17:30:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-11-02 15:29:57 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD GetNext(nsISupports** aResult) override
|
2014-05-05 17:30:43 +00:00
|
|
|
{
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_WARN_IF(!aResult)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
|
|
|
*aResult = nullptr;
|
2001-11-02 15:29:57 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
bool hasMore;
|
|
|
|
HasMoreElements(&hasMore);
|
2014-05-14 20:15:46 +00:00
|
|
|
if (!hasMore) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2001-11-02 15:29:57 +00:00
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
*aResult = mNext;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
2014-05-05 17:30:43 +00:00
|
|
|
mNext = nullptr;
|
2004-01-22 01:01:19 +00:00
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
return *aResult ? NS_OK : NS_ERROR_FAILURE;
|
2014-05-05 17:30:43 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 22:11:53 +00:00
|
|
|
protected:
|
2015-01-18 02:14:51 +00:00
|
|
|
nsCOMPtr<nsIDirectoryServiceProvider> mProvider;
|
2014-06-30 22:11:53 +00:00
|
|
|
const char** mCurrentKey;
|
|
|
|
nsCOMPtr<nsIFile> mNext;
|
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
// Virtual destructor since subclass nsPathsDirectoryEnumerator
|
|
|
|
// does not re-implement Release()
|
|
|
|
virtual ~nsAppDirectoryEnumerator()
|
|
|
|
{
|
|
|
|
}
|
2001-11-02 15:29:57 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsAppDirectoryEnumerator, nsISimpleEnumerator)
|
2001-11-02 15:29:57 +00:00
|
|
|
|
2002-10-25 13:08:44 +00:00
|
|
|
/* nsPathsDirectoryEnumerator and PATH_SEPARATOR
|
|
|
|
* are not used on MacOS/X. */
|
|
|
|
|
2014-02-10 22:57:01 +00:00
|
|
|
#if defined(XP_WIN) /* Win32 */
|
2002-10-25 13:08:44 +00:00
|
|
|
#define PATH_SEPARATOR ';'
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 19:10:24 +00:00
|
|
|
#else
|
2002-10-25 13:08:44 +00:00
|
|
|
#define PATH_SEPARATOR ':'
|
|
|
|
#endif
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsPathsDirectoryEnumerator final
|
2014-06-30 22:11:53 +00:00
|
|
|
: public nsAppDirectoryEnumerator
|
2002-10-25 13:08:44 +00:00
|
|
|
{
|
2014-06-30 22:11:53 +00:00
|
|
|
~nsPathsDirectoryEnumerator() {}
|
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* aKeyList is a null-terminated list.
|
|
|
|
* The first element is a path list.
|
|
|
|
* The remainder are properties provided by aProvider.
|
|
|
|
* They do not need to be publicly defined keys.
|
|
|
|
*/
|
2014-05-14 20:15:46 +00:00
|
|
|
nsPathsDirectoryEnumerator(nsIDirectoryServiceProvider* aProvider,
|
2014-05-05 17:30:43 +00:00
|
|
|
const char* aKeyList[]) :
|
2014-05-14 20:15:46 +00:00
|
|
|
nsAppDirectoryEnumerator(aProvider, aKeyList + 1),
|
2002-10-25 13:08:44 +00:00
|
|
|
mEndPath(aKeyList[0])
|
2014-05-05 17:30:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
NS_IMETHOD HasMoreElements(bool* aResult)
|
2014-05-05 17:30:43 +00:00
|
|
|
{
|
|
|
|
if (mEndPath)
|
2014-05-14 20:15:46 +00:00
|
|
|
while (!mNext && *mEndPath) {
|
|
|
|
const char* pathVar = mEndPath;
|
2014-05-05 17:30:43 +00:00
|
|
|
|
|
|
|
// skip PATH_SEPARATORs at the begining of the mEndPath
|
2014-05-14 20:15:46 +00:00
|
|
|
while (*pathVar == PATH_SEPARATOR) {
|
|
|
|
++pathVar;
|
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
do {
|
|
|
|
++mEndPath;
|
|
|
|
} while (*mEndPath && *mEndPath != PATH_SEPARATOR);
|
2014-05-05 17:30:43 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> localFile;
|
|
|
|
NS_NewNativeLocalFile(Substring(pathVar, mEndPath),
|
|
|
|
true,
|
|
|
|
getter_AddRefs(localFile));
|
2014-05-14 20:15:46 +00:00
|
|
|
if (*mEndPath == PATH_SEPARATOR) {
|
2014-05-05 17:30:43 +00:00
|
|
|
++mEndPath;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
// Don't return a "file" (directory) which does not exist.
|
|
|
|
bool exists;
|
|
|
|
if (localFile &&
|
|
|
|
NS_SUCCEEDED(localFile->Exists(&exists)) &&
|
2014-05-14 20:15:46 +00:00
|
|
|
exists) {
|
2014-05-05 17:30:43 +00:00
|
|
|
mNext = localFile;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
}
|
2014-05-14 20:15:46 +00:00
|
|
|
if (mNext) {
|
|
|
|
*aResult = true;
|
|
|
|
} else {
|
|
|
|
nsAppDirectoryEnumerator::HasMoreElements(aResult);
|
|
|
|
}
|
2002-10-25 13:08:44 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-10-25 13:08:44 +00:00
|
|
|
|
2014-05-05 17:30:43 +00:00
|
|
|
protected:
|
2014-05-14 20:15:46 +00:00
|
|
|
const char* mEndPath;
|
2002-10-25 13:08:44 +00:00
|
|
|
};
|
|
|
|
|
2001-11-02 15:29:57 +00:00
|
|
|
NS_IMETHODIMP
|
2014-05-14 20:15:46 +00:00
|
|
|
nsAppFileLocationProvider::GetFiles(const char* aProp,
|
|
|
|
nsISimpleEnumerator** aResult)
|
2001-11-02 15:29:57 +00:00
|
|
|
{
|
2014-05-14 20:15:46 +00:00
|
|
|
if (NS_WARN_IF(!aResult)) {
|
2014-05-05 17:30:43 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-14 20:15:46 +00:00
|
|
|
}
|
|
|
|
*aResult = nullptr;
|
2014-05-05 17:30:43 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2014-05-14 20:15:46 +00:00
|
|
|
if (!nsCRT::strcmp(aProp, NS_APP_PLUGINS_DIR_LIST)) {
|
2010-04-27 12:57:34 +00:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2014-05-14 20:15:46 +00:00
|
|
|
static const char* keys[] = {
|
|
|
|
NS_APP_PLUGINS_DIR,
|
|
|
|
NS_MACOSX_USER_PLUGIN_DIR,
|
|
|
|
NS_MACOSX_LOCAL_PLUGIN_DIR,
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
*aResult = new nsAppDirectoryEnumerator(this, keys);
|
2008-10-10 15:54:33 +00:00
|
|
|
#else
|
|
|
|
#ifdef XP_UNIX
|
2014-05-05 17:30:43 +00:00
|
|
|
static const char* keys[] = { nullptr, NS_USER_PLUGINS_DIR, NS_APP_PLUGINS_DIR, NS_SYSTEM_PLUGINS_DIR, nullptr };
|
2002-10-25 13:08:44 +00:00
|
|
|
#else
|
2014-05-05 17:30:43 +00:00
|
|
|
static const char* keys[] = { nullptr, NS_USER_PLUGINS_DIR, NS_APP_PLUGINS_DIR, nullptr };
|
2002-10-25 13:08:44 +00:00
|
|
|
#endif
|
2014-05-05 17:30:43 +00:00
|
|
|
if (!keys[0] && !(keys[0] = PR_GetEnv("MOZ_PLUGIN_PATH"))) {
|
|
|
|
static const char nullstr = 0;
|
|
|
|
keys[0] = &nullstr;
|
2001-11-02 15:29:57 +00:00
|
|
|
}
|
2014-05-14 20:15:46 +00:00
|
|
|
*aResult = new nsPathsDirectoryEnumerator(this, keys);
|
2014-05-05 17:30:43 +00:00
|
|
|
#endif
|
2015-03-02 10:59:36 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
rv = NS_OK;
|
2014-05-05 17:30:43 +00:00
|
|
|
}
|
2014-05-14 20:15:46 +00:00
|
|
|
if (!nsCRT::strcmp(aProp, NS_APP_SEARCH_DIR_LIST)) {
|
2015-09-04 09:50:49 +00:00
|
|
|
static const char* keys[] = { nullptr, NS_APP_USER_SEARCH_DIR, nullptr };
|
2014-05-05 17:30:43 +00:00
|
|
|
if (!keys[0] && !(keys[0] = PR_GetEnv("MOZ_SEARCH_ENGINE_PATH"))) {
|
|
|
|
static const char nullstr = 0;
|
|
|
|
keys[0] = &nullstr;
|
2005-06-29 15:55:57 +00:00
|
|
|
}
|
2014-05-14 20:15:46 +00:00
|
|
|
*aResult = new nsPathsDirectoryEnumerator(this, keys);
|
2015-03-02 10:59:36 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
rv = NS_OK;
|
2014-05-05 17:30:43 +00:00
|
|
|
}
|
2015-09-04 09:50:49 +00:00
|
|
|
if (!strcmp(aProp, NS_APP_DISTRIBUTION_SEARCH_DIR_LIST)) {
|
|
|
|
return NS_NewEmptyEnumerator(aResult);
|
|
|
|
}
|
2014-05-05 17:30:43 +00:00
|
|
|
return rv;
|
2001-11-02 15:29:57 +00:00
|
|
|
}
|