2002-08-21 14:25:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsAppRunner.h"
|
2011-11-08 09:20:42 +04:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsXREDirProvider.h"
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
2012-03-28 14:13:30 +04:00
|
|
|
#include "nsIJSRuntimeService.h"
|
2011-11-08 09:20:42 +04:00
|
|
|
#include "nsIAppStartup.h"
|
2007-09-04 16:55:29 +04:00
|
|
|
#include "nsIDirectoryEnumerator.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2010-06-11 23:02:44 +04:00
|
|
|
#include "nsIObserver.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsIObserverService.h"
|
2006-08-08 22:18:50 +04:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2005-02-23 00:49:45 +03:00
|
|
|
#include "nsIToolkitChromeRegistry.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2002-08-21 14:25:54 +04:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2006-01-12 18:29:10 +03:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2008-08-30 00:40:05 +04:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#include "nsINIParser.h"
|
|
|
|
#include "nsDependentString.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsArrayEnumerator.h"
|
2006-01-12 18:29:10 +03:00
|
|
|
#include "nsEnumeratorUtils.h"
|
2007-09-26 22:35:21 +04:00
|
|
|
#include "nsReadableUtils.h"
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
#include "mozilla/Services.h"
|
2010-05-21 21:58:32 +04:00
|
|
|
#include "mozilla/Omnijar.h"
|
2011-11-02 18:51:39 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-03-13 02:41:26 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <shlobj.h>
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif
|
2002-11-15 05:05:19 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "nsILocalFileMac.h"
|
2012-10-26 21:21:12 +04:00
|
|
|
// for chflags()
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2002-11-15 05:05:19 +03:00
|
|
|
#endif
|
2004-06-18 01:23:51 +04:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
#include <ctype.h>
|
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-07-22 19:14:02 +04:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
#define APP_REGISTRY_NAME "Application Registry"
|
2014-02-11 02:57:01 +04:00
|
|
|
#elif defined(XP_WIN)
|
2004-07-22 19:14:02 +04:00
|
|
|
#define APP_REGISTRY_NAME "registry.dat"
|
|
|
|
#else
|
|
|
|
#define APP_REGISTRY_NAME "appreg"
|
|
|
|
#endif
|
|
|
|
|
2007-05-03 00:13:33 +04:00
|
|
|
#define PREF_OVERRIDE_DIRNAME "preferences"
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
static already_AddRefed<nsIFile>
|
2010-06-23 20:18:32 +04:00
|
|
|
CloneAndAppend(nsIFile* aFile, const char* name)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aFile->Clone(getter_AddRefs(file));
|
2012-06-06 06:08:30 +04:00
|
|
|
file->AppendNative(nsDependentCString(name));
|
|
|
|
return file.forget();
|
2010-06-23 20:18:32 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsXREDirProvider* gDirServiceProvider = nullptr;
|
2002-08-26 14:18:41 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsXREDirProvider::nsXREDirProvider() :
|
2011-10-17 18:59:28 +04:00
|
|
|
mProfileNotified(false)
|
2004-06-18 01:23:51 +04:00
|
|
|
{
|
|
|
|
gDirServiceProvider = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXREDirProvider::~nsXREDirProvider()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
gDirServiceProvider = nullptr;
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:50:04 +04:00
|
|
|
nsXREDirProvider*
|
|
|
|
nsXREDirProvider::GetSingleton()
|
|
|
|
{
|
|
|
|
return gDirServiceProvider;
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult
|
2006-01-12 18:29:10 +03:00
|
|
|
nsXREDirProvider::Initialize(nsIFile *aXULAppDir,
|
2012-06-06 06:08:30 +04:00
|
|
|
nsIFile *aGREDir,
|
2006-01-12 18:29:10 +03:00
|
|
|
nsIDirectoryServiceProvider* aAppProvider)
|
2006-08-17 18:22:04 +04:00
|
|
|
{
|
2009-11-05 00:34:16 +03:00
|
|
|
NS_ENSURE_ARG(aXULAppDir);
|
2006-08-17 18:22:04 +04:00
|
|
|
NS_ENSURE_ARG(aGREDir);
|
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
mAppProvider = aAppProvider;
|
2004-09-07 22:59:07 +04:00
|
|
|
mXULAppDir = aXULAppDir;
|
2006-08-17 18:22:04 +04:00
|
|
|
mGREDir = aGREDir;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2008-08-16 19:20:35 +04:00
|
|
|
if (!mProfileDir) {
|
|
|
|
nsCOMPtr<nsIDirectoryServiceProvider> app(do_QueryInterface(mAppProvider));
|
|
|
|
if (app) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool per = false;
|
2008-08-16 19:20:35 +04:00
|
|
|
app->GetFile(NS_APP_USER_PROFILE_50_DIR, &per, getter_AddRefs(mProfileDir));
|
2009-04-13 21:34:01 +04:00
|
|
|
NS_ASSERTION(per, "NS_APP_USER_PROFILE_50_DIR must be persistent!");
|
|
|
|
NS_ASSERTION(mProfileDir, "NS_APP_USER_PROFILE_50_DIR not defined! This shouldn't happen!");
|
2008-08-16 19:20:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 20:18:32 +04:00
|
|
|
LoadAppBundleDirs();
|
2005-06-13 20:45:22 +04:00
|
|
|
return NS_OK;
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2002-08-26 14:18:41 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult
|
2005-04-26 04:37:23 +04:00
|
|
|
nsXREDirProvider::SetProfile(nsIFile* aDir, nsIFile* aLocalDir)
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
2005-04-26 04:37:23 +04:00
|
|
|
NS_ASSERTION(aDir && aLocalDir, "We don't support no-profile apps yet!");
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
nsresult rv;
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
rv = EnsureDirectoryExists(aDir);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = EnsureDirectoryExists(aLocalDir);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-10-26 21:21:12 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
bool same;
|
|
|
|
if (NS_SUCCEEDED(aDir->Equals(aLocalDir, &same)) && !same) {
|
|
|
|
// Ensure that the cache directory is not indexed by Spotlight
|
|
|
|
// (bug 718910). At least on OS X, the cache directory (under
|
|
|
|
// ~/Library/Caches/) is always the "local" user profile
|
|
|
|
// directory. This is confusing, since *both* user profile
|
|
|
|
// directories are "local" (they both exist under the user's
|
|
|
|
// home directory). But this usage dates back at least as far
|
|
|
|
// as the patch for bug 291033, where "local" seems to mean
|
|
|
|
// "suitable for temporary storage". Don't hide the cache
|
|
|
|
// directory if by some chance it and the "non-local" profile
|
|
|
|
// directory are the same -- there are bad side effects from
|
|
|
|
// hiding a profile directory under /Library/Application Support/
|
|
|
|
// (see bug 801883).
|
|
|
|
nsAutoCString cacheDir;
|
|
|
|
if (NS_SUCCEEDED(aLocalDir->GetNativePath(cacheDir))) {
|
|
|
|
if (chflags(cacheDir.get(), UF_HIDDEN)) {
|
|
|
|
NS_WARNING("Failed to set Cache directory to HIDDEN.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
mProfileDir = aDir;
|
2005-04-26 04:37:23 +04:00
|
|
|
mProfileLocalDir = aLocalDir;
|
2004-06-18 01:23:51 +04:00
|
|
|
return NS_OK;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_QUERY_INTERFACE(nsXREDirProvider,
|
|
|
|
nsIDirectoryServiceProvider,
|
|
|
|
nsIDirectoryServiceProvider2,
|
|
|
|
nsIProfileStartup)
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2004-06-18 01:23:51 +04:00
|
|
|
nsXREDirProvider::AddRef()
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
2004-06-18 01:23:51 +04:00
|
|
|
return 1;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2004-06-18 01:23:51 +04:00
|
|
|
nsXREDirProvider::Release()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2012-05-24 18:29:52 +04:00
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetUserProfilesRootDir(nsIFile** aResult,
|
|
|
|
const nsACString* aProfileName,
|
|
|
|
const nsACString* aAppName,
|
|
|
|
const nsACString* aVendorName)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
2012-06-06 06:08:30 +04:00
|
|
|
nsresult rv = GetUserDataDirectory(getter_AddRefs(file),
|
2012-05-24 18:29:52 +04:00
|
|
|
false,
|
|
|
|
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.
|
2012-07-27 18:03:08 +04:00
|
|
|
nsresult tmp = EnsureDirectoryExists(file);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2012-05-24 18:29:52 +04:00
|
|
|
}
|
|
|
|
file.swap(*aResult);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetUserProfilesLocalDir(nsIFile** aResult,
|
|
|
|
const nsACString* aProfileName,
|
|
|
|
const nsACString* aAppName,
|
|
|
|
const nsACString* aVendorName)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
2012-06-06 06:08:30 +04:00
|
|
|
nsresult rv = GetUserDataDirectory(getter_AddRefs(file),
|
2012-05-24 18:29:52 +04:00
|
|
|
true,
|
|
|
|
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.
|
2012-07-27 18:03:08 +04:00
|
|
|
nsresult tmp = EnsureDirectoryExists(file);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2012-05-24 18:29:52 +04:00
|
|
|
}
|
|
|
|
file.swap(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-08-21 14:25:54 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
|
2002-08-21 14:25:54 +04:00
|
|
|
nsIFile** aFile)
|
|
|
|
{
|
2006-01-12 18:29:10 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool gettingProfile = false;
|
2006-01-12 18:29:10 +03:00
|
|
|
|
|
|
|
if (!strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR)) {
|
|
|
|
// If XRE_NotifyProfile hasn't been called, don't fall through to
|
|
|
|
// mAppProvider on the profile keys.
|
|
|
|
if (!mProfileNotified)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mProfileLocalDir)
|
|
|
|
return mProfileLocalDir->Clone(aFile);
|
|
|
|
|
|
|
|
if (mAppProvider)
|
|
|
|
return mAppProvider->GetFile(aProperty, aPersistent, aFile);
|
|
|
|
|
|
|
|
// This falls through to the case below
|
2011-10-17 18:59:28 +04:00
|
|
|
gettingProfile = true;
|
2006-01-12 18:29:10 +03:00
|
|
|
}
|
|
|
|
if (!strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR) || gettingProfile) {
|
|
|
|
if (!mProfileNotified)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mProfileDir)
|
|
|
|
return mProfileDir->Clone(aFile);
|
|
|
|
|
|
|
|
if (mAppProvider)
|
|
|
|
return mAppProvider->GetFile(aProperty, aPersistent, aFile);
|
|
|
|
|
|
|
|
// If we don't succeed here, bail early so that we aren't reentrant
|
|
|
|
// through the "GetProfileDir" call below.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAppProvider) {
|
|
|
|
rv = mAppProvider->GetFile(aProperty, aPersistent, aFile);
|
|
|
|
if (NS_SUCCEEDED(rv) && *aFile)
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aPersistent = true;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2005-12-23 17:51:39 +03:00
|
|
|
if (!strcmp(aProperty, NS_GRE_DIR)) {
|
|
|
|
return mGREDir->Clone(aFile);
|
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
else if (!strcmp(aProperty, NS_OS_CURRENT_PROCESS_DIR) ||
|
2004-06-18 01:23:51 +04:00
|
|
|
!strcmp(aProperty, NS_APP_INSTALL_CLEANUP_DIR)) {
|
2005-12-23 17:51:39 +03:00
|
|
|
return GetAppDir()->Clone(aFile);
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2005-09-01 17:21:55 +04:00
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2005-09-01 17:21:55 +04:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
|
|
|
|
if (!strcmp(aProperty, NS_APP_PROFILE_DEFAULTS_50_DIR) ||
|
2004-06-18 01:23:51 +04:00
|
|
|
!strcmp(aProperty, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR)) {
|
|
|
|
return GetProfileDefaultsDir(aFile);
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_PREF_DEFAULTS_50_DIR))
|
|
|
|
{
|
2005-12-23 17:51:39 +03:00
|
|
|
// return the GRE default prefs directory here, and the app default prefs
|
|
|
|
// directory (if applicable) in NS_APP_PREFS_DEFAULTS_DIR_LIST.
|
|
|
|
rv = mGREDir->Clone(getter_AddRefs(file));
|
2004-06-18 01:23:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-09-07 22:59:07 +04:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("defaults"));
|
2004-06-18 01:23:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2004-09-07 22:59:07 +04:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("pref"));
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2002-08-26 14:18:41 +04:00
|
|
|
}
|
2005-07-23 18:00:07 +04:00
|
|
|
else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_DIR) ||
|
|
|
|
!strcmp(aProperty, XRE_USER_APP_DATA_DIR)) {
|
2012-06-06 06:08:30 +04:00
|
|
|
rv = GetUserAppDataDirectory(getter_AddRefs(file));
|
2004-07-22 19:14:02 +04:00
|
|
|
}
|
2007-04-20 19:22:17 +04:00
|
|
|
else if (!strcmp(aProperty, XRE_UPDATE_ROOT_DIR)) {
|
|
|
|
rv = GetUpdateRootDir(getter_AddRefs(file));
|
2008-01-10 09:01:38 +03:00
|
|
|
}
|
2004-07-22 19:14:02 +04:00
|
|
|
else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE)) {
|
2012-06-06 06:08:30 +04:00
|
|
|
rv = GetUserAppDataDirectory(getter_AddRefs(file));
|
2006-01-12 18:29:10 +03:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING(APP_REGISTRY_NAME));
|
2004-07-22 19:14:02 +04:00
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
else if (!strcmp(aProperty, NS_APP_USER_PROFILES_ROOT_DIR)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = GetUserProfilesRootDir(getter_AddRefs(file), nullptr, nullptr, nullptr);
|
2005-04-26 04:37:23 +04:00
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_USER_PROFILES_LOCAL_ROOT_DIR)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = GetUserProfilesLocalDir(getter_AddRefs(file), nullptr, nullptr, nullptr);
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE) && gArgv[0]) {
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> lf;
|
2005-10-04 22:06:26 +04:00
|
|
|
rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
file = lf;
|
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
|
|
|
|
else if (!strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP) && mProfileDir) {
|
|
|
|
return mProfileDir->Clone(aFile);
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP)) {
|
|
|
|
if (mProfileLocalDir)
|
|
|
|
return mProfileLocalDir->Clone(aFile);
|
|
|
|
|
|
|
|
if (mProfileDir)
|
|
|
|
return mProfileDir->Clone(aFile);
|
|
|
|
|
|
|
|
if (mAppProvider)
|
|
|
|
return mAppProvider->GetFile(NS_APP_PROFILE_DIR_STARTUP, aPersistent,
|
|
|
|
aFile);
|
|
|
|
}
|
2008-03-07 04:58:18 +03:00
|
|
|
#if defined(XP_UNIX) || defined(XP_MACOSX)
|
2008-01-15 18:13:59 +03:00
|
|
|
else if (!strcmp(aProperty, XRE_SYS_LOCAL_EXTENSION_PARENT_DIR)) {
|
2010-07-23 22:00:16 +04:00
|
|
|
#ifdef ENABLE_SYSTEM_EXTENSION_DIRS
|
2012-06-06 06:08:30 +04:00
|
|
|
return GetSystemExtensionsDirectory(aFile);
|
2010-07-23 22:00:16 +04:00
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2008-01-15 18:13:59 +03:00
|
|
|
}
|
2008-03-07 04:58:18 +03:00
|
|
|
#endif
|
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
2008-01-15 18:13:59 +03:00
|
|
|
else if (!strcmp(aProperty, XRE_SYS_SHARE_EXTENSION_PARENT_DIR)) {
|
2010-07-23 22:00:16 +04:00
|
|
|
#ifdef ENABLE_SYSTEM_EXTENSION_DIRS
|
2012-11-14 23:02:07 +04:00
|
|
|
#if defined(__OpenBSD__) || defined(__FreeBSD__)
|
|
|
|
static const char *const sysLExtDir = "/usr/local/share/mozilla/extensions";
|
|
|
|
#else
|
2008-01-15 18:13:59 +03:00
|
|
|
static const char *const sysLExtDir = "/usr/share/mozilla/extensions";
|
2012-11-14 23:02:07 +04:00
|
|
|
#endif
|
2008-01-15 18:13:59 +03:00
|
|
|
return NS_NewNativeLocalFile(nsDependentCString(sysLExtDir),
|
2012-06-06 06:08:30 +04:00
|
|
|
false, aFile);
|
2010-07-23 22:00:16 +04:00
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2008-01-15 18:13:59 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (!strcmp(aProperty, XRE_USER_SYS_EXTENSION_DIR)) {
|
2010-07-23 22:00:16 +04:00
|
|
|
#ifdef ENABLE_SYSTEM_EXTENSION_DIRS
|
2012-06-06 06:08:30 +04:00
|
|
|
return GetSysUserExtensionsDirectory(aFile);
|
2010-07-23 22:00:16 +04:00
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2008-01-15 18:13:59 +03:00
|
|
|
}
|
2011-01-20 01:37:24 +03:00
|
|
|
else if (!strcmp(aProperty, XRE_APP_DISTRIBUTION_DIR)) {
|
2013-05-11 22:14:58 +04:00
|
|
|
bool persistent = false;
|
|
|
|
rv = GetFile(XRE_EXECUTABLE_FILE, &persistent, getter_AddRefs(file));
|
2011-01-20 01:37:24 +03:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2013-05-11 22:14:58 +04:00
|
|
|
rv = file->SetNativeLeafName(NS_LITERAL_CSTRING("distribution"));
|
2011-01-20 01:37:24 +03:00
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
else if (NS_SUCCEEDED(GetProfileStartupDir(getter_AddRefs(file)))) {
|
2004-09-09 00:25:45 +04:00
|
|
|
// We need to allow component, xpt, and chrome registration to
|
|
|
|
// occur prior to the profile-after-change notification.
|
2010-06-21 20:46:26 +04:00
|
|
|
if (!strcmp(aProperty, NS_APP_USER_CHROME_DIR)) {
|
2006-01-12 18:29:10 +03:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("chrome"));
|
2004-09-09 00:25:45 +04:00
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
}
|
|
|
|
|
2006-01-12 20:16:15 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && file) {
|
|
|
|
NS_ADDREF(*aFile = file);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ensureFilePermissions = false;
|
2007-01-11 00:48:07 +03:00
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
if (NS_SUCCEEDED(GetProfileDir(getter_AddRefs(file)))) {
|
|
|
|
if (!strcmp(aProperty, NS_APP_PREFS_50_DIR)) {
|
|
|
|
rv = NS_OK;
|
2005-02-23 00:49:45 +03:00
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
else if (!strcmp(aProperty, NS_APP_PREFS_50_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("prefs.js"));
|
2005-10-20 20:39:24 +04:00
|
|
|
}
|
2013-11-05 22:20:39 +04:00
|
|
|
else if (!strcmp(aProperty, NS_METRO_APP_PREFS_50_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("metro-prefs.js"));
|
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
else if (!strcmp(aProperty, NS_LOCALSTORE_UNSAFE_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_LOCALSTORE_50_FILE)) {
|
|
|
|
if (gSafeMode) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("localstore-safe.rdf"));
|
2011-10-17 18:59:28 +04:00
|
|
|
file->Remove(false);
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
else {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
|
2004-06-18 01:23:51 +04:00
|
|
|
EnsureProfileFileExists(file);
|
2011-10-17 18:59:28 +04:00
|
|
|
ensureFilePermissions = true;
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_USER_MIMETYPES_50_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("mimeTypes.rdf"));
|
|
|
|
EnsureProfileFileExists(file);
|
2011-10-17 18:59:28 +04:00
|
|
|
ensureFilePermissions = true;
|
2006-01-12 18:29:10 +03:00
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_DOWNLOADS_50_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("downloads.rdf"));
|
|
|
|
}
|
2007-05-03 00:13:33 +04:00
|
|
|
else if (!strcmp(aProperty, NS_APP_PREFS_OVERRIDE_DIR)) {
|
|
|
|
rv = mProfileDir->Clone(getter_AddRefs(file));
|
2012-07-27 18:03:08 +04:00
|
|
|
nsresult tmp = file->AppendNative(NS_LITERAL_CSTRING(PREF_OVERRIDE_DIRNAME));
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
tmp = EnsureDirectoryExists(file);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-05-03 00:13:33 +04:00
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2006-01-12 18:29:10 +03:00
|
|
|
if (NS_FAILED(rv) || !file)
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2007-01-11 00:48:07 +03:00
|
|
|
if (ensureFilePermissions) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool fileToEnsureExists;
|
|
|
|
bool isWritable;
|
2007-01-11 00:48:07 +03:00
|
|
|
if (NS_SUCCEEDED(file->Exists(&fileToEnsureExists)) && fileToEnsureExists
|
|
|
|
&& NS_SUCCEEDED(file->IsWritable(&isWritable)) && !isWritable) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t permissions;
|
2007-01-19 06:21:40 +03:00
|
|
|
if (NS_SUCCEEDED(file->GetPermissions(&permissions))) {
|
|
|
|
rv = file->SetPermissions(permissions | 0600);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to ensure file permissions");
|
2007-01-11 00:48:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_ADDREF(*aFile = file);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-04 18:29:14 +04:00
|
|
|
static void
|
2012-04-17 18:11:53 +04:00
|
|
|
LoadDirIntoArray(nsIFile* dir,
|
|
|
|
const char *const *aAppendList,
|
|
|
|
nsCOMArray<nsIFile>& aDirectories)
|
2007-09-04 18:29:14 +04:00
|
|
|
{
|
2012-04-17 18:11:53 +04:00
|
|
|
if (!dir)
|
2007-09-04 18:29:14 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> subdir;
|
2012-04-17 18:11:53 +04:00
|
|
|
dir->Clone(getter_AddRefs(subdir));
|
2007-09-04 18:29:14 +04:00
|
|
|
if (!subdir)
|
|
|
|
return;
|
|
|
|
|
2012-04-17 18:11:53 +04:00
|
|
|
for (const char *const *a = aAppendList; *a; ++a) {
|
|
|
|
subdir->AppendNative(nsDependentCString(*a));
|
|
|
|
}
|
2007-09-04 18:29:14 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool exists;
|
2012-04-17 18:11:53 +04:00
|
|
|
if (NS_SUCCEEDED(subdir->Exists(&exists)) && exists) {
|
2007-09-04 18:29:14 +04:00
|
|
|
aDirectories.AppendObject(subdir);
|
2012-04-17 18:11:53 +04:00
|
|
|
}
|
2007-09-04 18:29:14 +04:00
|
|
|
}
|
|
|
|
|
2007-08-06 23:54:09 +04:00
|
|
|
static void
|
2007-09-04 16:55:29 +04:00
|
|
|
LoadDirsIntoArray(nsCOMArray<nsIFile>& aSourceDirs,
|
2007-08-06 23:54:09 +04:00
|
|
|
const char *const* aAppendList,
|
|
|
|
nsCOMArray<nsIFile>& aDirectories)
|
|
|
|
{
|
2007-09-04 16:55:29 +04:00
|
|
|
nsCOMPtr<nsIFile> appended;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool exists;
|
2007-08-06 23:54:09 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < aSourceDirs.Count(); ++i) {
|
2007-09-04 16:55:29 +04:00
|
|
|
aSourceDirs[i]->Clone(getter_AddRefs(appended));
|
|
|
|
if (!appended)
|
|
|
|
continue;
|
2007-09-01 01:47:46 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString leaf;
|
2012-02-13 22:57:28 +04:00
|
|
|
appended->GetNativeLeafName(leaf);
|
2014-05-22 07:48:51 +04:00
|
|
|
if (!Substring(leaf, leaf.Length() - 4).EqualsLiteral(".xpi")) {
|
2012-04-17 18:11:53 +04:00
|
|
|
LoadDirIntoArray(appended,
|
|
|
|
aAppendList,
|
|
|
|
aDirectories);
|
2012-02-13 22:57:28 +04:00
|
|
|
}
|
2012-04-18 12:03:42 +04:00
|
|
|
else if (NS_SUCCEEDED(appended->Exists(&exists)) && exists)
|
2012-04-18 10:58:12 +04:00
|
|
|
aDirectories.AppendObject(appended);
|
2007-08-06 23:54:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXREDirProvider::GetFiles(const char* aProperty, nsISimpleEnumerator** aResult)
|
2006-01-12 18:29:10 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> appEnum;
|
|
|
|
nsCOMPtr<nsIDirectoryServiceProvider2>
|
|
|
|
appP2(do_QueryInterface(mAppProvider));
|
|
|
|
if (appP2) {
|
|
|
|
rv = appP2->GetFiles(aProperty, getter_AddRefs(appEnum));
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
appEnum = nullptr;
|
2006-01-12 18:29:10 +03:00
|
|
|
}
|
|
|
|
else if (rv != NS_SUCCESS_AGGREGATE_RESULT) {
|
|
|
|
NS_ADDREF(*aResult = appEnum);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> xreEnum;
|
|
|
|
rv = GetFilesInternal(aProperty, getter_AddRefs(xreEnum));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (appEnum) {
|
|
|
|
NS_ADDREF(*aResult = appEnum);
|
|
|
|
return NS_SUCCESS_AGGREGATE_RESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewUnionEnumerator(aResult, appEnum, xreEnum);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return NS_SUCCESS_AGGREGATE_RESULT;
|
|
|
|
}
|
|
|
|
|
2007-09-04 16:55:29 +04:00
|
|
|
static void
|
|
|
|
LoadExtensionDirectories(nsINIParser &parser,
|
2007-09-26 22:35:21 +04:00
|
|
|
const char *aSection,
|
2010-06-23 20:18:32 +04:00
|
|
|
nsCOMArray<nsIFile> &aDirectories,
|
|
|
|
NSLocationType aType)
|
2007-09-04 16:55:29 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i = 0;
|
2007-09-04 16:55:29 +04:00
|
|
|
do {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buf("Extension");
|
2007-09-04 16:55:29 +04:00
|
|
|
buf.AppendInt(i++);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2007-09-04 16:55:29 +04:00
|
|
|
rv = parser.GetString(aSection, buf.get(), path);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> dir = do_CreateInstance("@mozilla.org/file/local;1", &rv);
|
2007-09-04 16:55:29 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rv = dir->SetPersistentDescriptor(path);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
|
2012-02-13 22:57:28 +04:00
|
|
|
aDirectories.AppendObject(dir);
|
2014-05-22 07:48:51 +04:00
|
|
|
if (Substring(path, path.Length() - 4).EqualsLiteral(".xpi")) {
|
2010-09-11 02:54:37 +04:00
|
|
|
XRE_AddJarManifestLocation(aType, dir);
|
|
|
|
}
|
|
|
|
else {
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> manifest =
|
2010-09-11 02:54:37 +04:00
|
|
|
CloneAndAppend(dir, "chrome.manifest");
|
|
|
|
XRE_AddManifestLocation(aType, manifest);
|
|
|
|
}
|
2007-09-04 16:55:29 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
while (true);
|
2007-09-04 16:55:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-23 20:18:32 +04:00
|
|
|
nsXREDirProvider::LoadExtensionBundleDirectories()
|
2007-09-04 16:55:29 +04:00
|
|
|
{
|
2014-03-04 01:41:24 +04:00
|
|
|
if (!mozilla::Preferences::GetBool("extensions.defaultProviders.enabled", true))
|
|
|
|
return;
|
|
|
|
|
2007-09-04 16:55:29 +04:00
|
|
|
if (mProfileDir && !gSafeMode) {
|
|
|
|
nsCOMPtr<nsIFile> extensionsINI;
|
|
|
|
mProfileDir->Clone(getter_AddRefs(extensionsINI));
|
|
|
|
if (!extensionsINI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
extensionsINI->AppendNative(NS_LITERAL_CSTRING("extensions.ini"));
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> extensionsINILF =
|
2007-09-04 16:55:29 +04:00
|
|
|
do_QueryInterface(extensionsINI);
|
|
|
|
if (!extensionsINILF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsINIParser parser;
|
|
|
|
nsresult rv = parser.Init(extensionsINILF);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
2010-06-23 20:18:32 +04:00
|
|
|
LoadExtensionDirectories(parser, "ExtensionDirs", mExtensionDirectories,
|
|
|
|
NS_COMPONENT_LOCATION);
|
|
|
|
LoadExtensionDirectories(parser, "ThemeDirs", mThemeDirectories,
|
|
|
|
NS_SKIN_LOCATION);
|
2007-09-04 16:55:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXREDirProvider::LoadAppBundleDirs()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> dir;
|
2013-05-11 22:14:58 +04:00
|
|
|
bool persistent = false;
|
|
|
|
nsresult rv = GetFile(XRE_EXECUTABLE_FILE, &persistent, getter_AddRefs(dir));
|
2007-09-04 16:55:29 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2013-05-11 22:14:58 +04:00
|
|
|
dir->SetNativeLeafName(NS_LITERAL_CSTRING("distribution"));
|
2007-09-04 16:55:29 +04:00
|
|
|
dir->AppendNative(NS_LITERAL_CSTRING("bundles"));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> e;
|
|
|
|
rv = dir->GetDirectoryEntries(getter_AddRefs(e));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDirectoryEnumerator> files = do_QueryInterface(e);
|
|
|
|
if (!files)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> subdir;
|
|
|
|
while (NS_SUCCEEDED(files->GetNextFile(getter_AddRefs(subdir))) && subdir) {
|
|
|
|
mAppBundleDirectories.AppendObject(subdir);
|
2010-06-23 20:18:32 +04:00
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> manifest =
|
2010-06-23 20:18:32 +04:00
|
|
|
CloneAndAppend(subdir, "chrome.manifest");
|
2010-06-28 05:26:38 +04:00
|
|
|
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, manifest);
|
2007-09-04 16:55:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static const char *const kAppendPrefDir[] = { "defaults", "preferences", nullptr };
|
2007-09-04 16:55:29 +04:00
|
|
|
|
2007-09-04 18:29:14 +04:00
|
|
|
#ifdef DEBUG_bsmedberg
|
|
|
|
static void
|
|
|
|
DumpFileArray(const char *key,
|
|
|
|
nsCOMArray<nsIFile> dirs)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "nsXREDirProvider::GetFilesInternal(%s)\n", key);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < dirs.Count(); ++i) {
|
2007-09-04 18:29:14 +04:00
|
|
|
dirs[i]->GetNativePath(path);
|
|
|
|
fprintf(stderr, " %s\n", path.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // DEBUG_bsmedberg
|
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetFilesInternal(const char* aProperty,
|
|
|
|
nsISimpleEnumerator** aResult)
|
2004-06-18 01:23:51 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-06-07 23:45:11 +04:00
|
|
|
if (!strcmp(aProperty, XRE_EXTENSIONS_DIR_LIST)) {
|
|
|
|
nsCOMArray<nsIFile> directories;
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static const char *const kAppendNothing[] = { nullptr };
|
2007-08-27 21:57:15 +04:00
|
|
|
|
2007-09-04 16:55:29 +04:00
|
|
|
LoadDirsIntoArray(mAppBundleDirectories,
|
|
|
|
kAppendNothing, directories);
|
|
|
|
LoadDirsIntoArray(mExtensionDirectories,
|
|
|
|
kAppendNothing, directories);
|
2005-06-07 23:45:11 +04:00
|
|
|
|
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
else if (!strcmp(aProperty, NS_APP_PREFS_DEFAULTS_DIR_LIST)) {
|
|
|
|
nsCOMArray<nsIFile> directories;
|
2005-05-12 17:23:30 +04:00
|
|
|
|
2012-04-17 18:11:53 +04:00
|
|
|
LoadDirIntoArray(mXULAppDir, kAppendPrefDir, directories);
|
2007-09-04 16:55:29 +04:00
|
|
|
LoadDirsIntoArray(mAppBundleDirectories,
|
|
|
|
kAppendPrefDir, directories);
|
2007-09-01 06:16:47 +04:00
|
|
|
|
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_EXT_PREFS_DEFAULTS_DIR_LIST)) {
|
|
|
|
nsCOMArray<nsIFile> directories;
|
2007-09-04 16:55:29 +04:00
|
|
|
|
|
|
|
LoadDirsIntoArray(mExtensionDirectories,
|
|
|
|
kAppendPrefDir, directories);
|
2007-09-01 06:16:47 +04:00
|
|
|
|
2007-05-03 00:13:33 +04:00
|
|
|
if (mProfileDir) {
|
|
|
|
nsCOMPtr<nsIFile> overrideFile;
|
|
|
|
mProfileDir->Clone(getter_AddRefs(overrideFile));
|
|
|
|
overrideFile->AppendNative(NS_LITERAL_CSTRING(PREF_OVERRIDE_DIRNAME));
|
2007-09-04 16:55:29 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool exists;
|
2007-05-03 00:13:33 +04:00
|
|
|
if (NS_SUCCEEDED(overrideFile->Exists(&exists)) && exists)
|
|
|
|
directories.AppendObject(overrideFile);
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
|
|
|
}
|
2004-09-07 22:59:07 +04:00
|
|
|
else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) {
|
2005-04-11 16:43:42 +04:00
|
|
|
// NS_APP_CHROME_DIR_LIST is only used to get default (native) icons
|
|
|
|
// for OS window decoration.
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static const char *const kAppendChromeDir[] = { "chrome", nullptr };
|
2004-09-07 22:59:07 +04:00
|
|
|
nsCOMArray<nsIFile> directories;
|
2012-04-17 18:11:53 +04:00
|
|
|
LoadDirIntoArray(mXULAppDir,
|
|
|
|
kAppendChromeDir,
|
|
|
|
directories);
|
2007-09-04 16:55:29 +04:00
|
|
|
LoadDirsIntoArray(mAppBundleDirectories,
|
|
|
|
kAppendChromeDir,
|
|
|
|
directories);
|
|
|
|
LoadDirsIntoArray(mExtensionDirectories,
|
|
|
|
kAppendChromeDir,
|
|
|
|
directories);
|
2005-04-11 16:43:42 +04:00
|
|
|
|
2004-09-07 22:59:07 +04:00
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
|
|
|
}
|
2005-06-02 17:33:07 +04:00
|
|
|
else if (!strcmp(aProperty, NS_APP_PLUGINS_DIR_LIST)) {
|
|
|
|
nsCOMArray<nsIFile> directories;
|
|
|
|
|
2013-03-05 18:45:28 +04:00
|
|
|
if (mozilla::Preferences::GetBool("plugins.load_appdir_plugins", false)) {
|
|
|
|
nsCOMPtr<nsIFile> appdir;
|
|
|
|
rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(appdir));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
appdir->SetNativeLeafName(NS_LITERAL_CSTRING("plugins"));
|
|
|
|
directories.AppendObject(appdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *const kAppendPlugins[] = { "plugins", nullptr };
|
|
|
|
|
2005-06-02 17:33:07 +04:00
|
|
|
// The root dirserviceprovider does quite a bit for us: we're mainly
|
|
|
|
// interested in xulapp and extension-provided plugins.
|
2007-09-04 16:55:29 +04:00
|
|
|
LoadDirsIntoArray(mAppBundleDirectories,
|
|
|
|
kAppendPlugins,
|
|
|
|
directories);
|
|
|
|
LoadDirsIntoArray(mExtensionDirectories,
|
|
|
|
kAppendPlugins,
|
|
|
|
directories);
|
2005-06-02 17:33:07 +04:00
|
|
|
|
2009-02-02 16:53:24 +03:00
|
|
|
if (mProfileDir) {
|
|
|
|
nsCOMArray<nsIFile> profileDir;
|
|
|
|
profileDir.AppendObject(mProfileDir);
|
|
|
|
LoadDirsIntoArray(profileDir,
|
|
|
|
kAppendPlugins,
|
|
|
|
directories);
|
|
|
|
}
|
|
|
|
|
2005-06-02 17:33:07 +04:00
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = NS_SUCCESS_AGGREGATE_RESULT;
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
else
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXREDirProvider::GetDirectory(nsIFile* *aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mProfileDir, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
return mProfileDir->Clone(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXREDirProvider::DoStartup()
|
|
|
|
{
|
|
|
|
if (!mProfileNotified) {
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
|
|
mozilla::services::GetObserverService();
|
2004-06-18 01:23:51 +04:00
|
|
|
if (!obsSvc) return NS_ERROR_FAILURE;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mProfileNotified = true;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2011-11-08 09:20:42 +04:00
|
|
|
/*
|
|
|
|
Setup prefs before profile-do-change to be able to use them to track
|
|
|
|
crashes and because we want to begin crash tracking before other code run
|
|
|
|
from this notification since they may cause crashes.
|
|
|
|
*/
|
|
|
|
nsresult rv = mozilla::Preferences::ResetAndReadUserPrefs();
|
|
|
|
if (NS_FAILED(rv)) NS_WARNING("Failed to setup pref service.");
|
|
|
|
|
|
|
|
bool safeModeNecessary = false;
|
|
|
|
nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
if (appStartup) {
|
|
|
|
rv = appStartup->TrackStartupCrashBegin(&safeModeNecessary);
|
2012-02-14 05:04:30 +04:00
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE)
|
|
|
|
NS_WARNING("Error while beginning startup crash tracking");
|
2011-11-08 09:20:42 +04:00
|
|
|
|
|
|
|
if (!gSafeMode && safeModeNecessary) {
|
|
|
|
appStartup->RestartInSafeMode(nsIAppStartup::eForceQuit);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
static const char16_t kStartup[] = {'s','t','a','r','t','u','p','\0'};
|
2012-07-30 18:20:58 +04:00
|
|
|
obsSvc->NotifyObservers(nullptr, "profile-do-change", kStartup);
|
2010-06-11 23:02:44 +04:00
|
|
|
// Init the Extension Manager
|
|
|
|
nsCOMPtr<nsIObserver> em = do_GetService("@mozilla.org/addons/integration;1");
|
2010-06-22 21:23:01 +04:00
|
|
|
if (em) {
|
2012-07-30 18:20:58 +04:00
|
|
|
em->Observe(nullptr, "addons-startup", nullptr);
|
2010-06-22 21:23:01 +04:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Failed to create Addons Manager.");
|
|
|
|
}
|
2010-06-23 20:18:32 +04:00
|
|
|
|
|
|
|
LoadExtensionBundleDirectories();
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
obsSvc->NotifyObservers(nullptr, "load-extension-defaults", nullptr);
|
|
|
|
obsSvc->NotifyObservers(nullptr, "profile-after-change", kStartup);
|
2008-08-30 00:40:05 +04:00
|
|
|
|
|
|
|
// Any component that has registered for the profile-after-change category
|
|
|
|
// should also be created at this time.
|
2012-07-30 18:20:58 +04:00
|
|
|
(void)NS_CreateServicesFromCategory("profile-after-change", nullptr,
|
2008-08-30 00:40:05 +04:00
|
|
|
"profile-after-change");
|
2009-11-02 21:04:45 +03:00
|
|
|
|
2011-11-08 09:20:42 +04:00
|
|
|
if (gSafeMode && safeModeNecessary) {
|
2014-01-04 19:02:17 +04:00
|
|
|
static const char16_t kCrashed[] = {'c','r','a','s','h','e','d','\0'};
|
2012-07-30 18:20:58 +04:00
|
|
|
obsSvc->NotifyObservers(nullptr, "safemode-forced", kCrashed);
|
2011-11-08 09:20:42 +04:00
|
|
|
}
|
|
|
|
|
2012-03-13 02:41:26 +04:00
|
|
|
// 1 = Regular mode, 2 = Safe mode, 3 = Safe mode forced
|
|
|
|
int mode = 1;
|
|
|
|
if (gSafeMode) {
|
|
|
|
if (safeModeNecessary)
|
|
|
|
mode = 3;
|
|
|
|
else
|
|
|
|
mode = 2;
|
|
|
|
}
|
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::SAFE_MODE_USAGE, mode);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
obsSvc->NotifyObservers(nullptr, "profile-initial-state", nullptr);
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXREDirProvider::DoShutdown()
|
|
|
|
{
|
|
|
|
if (mProfileNotified) {
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
NS_ASSERTION(obsSvc, "No observer service?");
|
|
|
|
if (obsSvc) {
|
2014-01-04 19:02:17 +04:00
|
|
|
static const char16_t kShutdownPersist[] =
|
2004-06-18 01:23:51 +04:00
|
|
|
{'s','h','u','t','d','o','w','n','-','p','e','r','s','i','s','t','\0'};
|
2012-12-13 21:20:56 +04:00
|
|
|
obsSvc->NotifyObservers(nullptr, "profile-change-net-teardown", kShutdownPersist);
|
|
|
|
obsSvc->NotifyObservers(nullptr, "profile-change-teardown", kShutdownPersist);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2013-02-05 04:25:09 +04:00
|
|
|
// Phase 2c: Now that things are torn down, force JS GC so that things which depend on
|
|
|
|
// resources which are about to go away in "profile-before-change" are destroyed first.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJSRuntimeService> rtsvc
|
|
|
|
(do_GetService("@mozilla.org/js/xpc/RuntimeService;1"));
|
|
|
|
if (rtsvc)
|
|
|
|
{
|
|
|
|
JSRuntime *rt = nullptr;
|
|
|
|
rtsvc->GetRuntime(&rt);
|
|
|
|
if (rt)
|
|
|
|
::JS_GC(rt);
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
// Phase 3: Notify observers of a profile change
|
2012-12-13 21:20:56 +04:00
|
|
|
obsSvc->NotifyObservers(nullptr, "profile-before-change", kShutdownPersist);
|
2013-03-02 00:11:21 +04:00
|
|
|
obsSvc->NotifyObservers(nullptr, "profile-before-change2", kShutdownPersist);
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mProfileNotified = false;
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-15 21:33:14 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
static nsresult
|
2007-09-26 22:35:21 +04:00
|
|
|
GetShellFolderPath(int folder, nsAString& _retval)
|
2005-05-15 21:33:14 +04:00
|
|
|
{
|
2013-12-03 19:07:22 +04:00
|
|
|
wchar_t* buf;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t bufLength = _retval.GetMutableData(&buf, MAXPATHLEN + 3);
|
2009-07-18 03:04:56 +04:00
|
|
|
NS_ENSURE_TRUE(bufLength >= (MAXPATHLEN + 3), NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2013-10-11 00:36:42 +04:00
|
|
|
LPITEMIDLIST pItemIDList = nullptr;
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2013-10-11 00:36:42 +04:00
|
|
|
if (SUCCEEDED(SHGetSpecialFolderLocation(nullptr, folder, &pItemIDList)) &&
|
2007-09-26 22:35:21 +04:00
|
|
|
SHGetPathFromIDListW(pItemIDList, buf)) {
|
|
|
|
// We're going to use wcslen (wcsnlen not available in msvc7.1) so make
|
|
|
|
// sure to null terminate.
|
|
|
|
buf[bufLength - 1] = L'\0';
|
|
|
|
_retval.SetLength(wcslen(buf));
|
2005-05-15 21:33:14 +04:00
|
|
|
} else {
|
2007-09-26 22:35:21 +04:00
|
|
|
_retval.SetLength(0);
|
2005-05-15 21:33:14 +04:00
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2005-10-07 04:49:05 +04:00
|
|
|
CoTaskMemFree(pItemIDList);
|
|
|
|
|
2005-05-15 21:33:14 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2007-04-20 19:22:17 +04:00
|
|
|
|
2009-10-09 07:03:09 +04:00
|
|
|
/**
|
|
|
|
* Provides a fallback for getting the path to APPDATA or LOCALAPPDATA by
|
|
|
|
* querying the registry when the call to SHGetSpecialFolderLocation or
|
|
|
|
* SHGetPathFromIDListW is unable to provide these paths (Bug 513958).
|
|
|
|
*/
|
|
|
|
static nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
GetRegWindowsAppDataFolder(bool aLocal, nsAString& _retval)
|
2009-10-09 07:03:09 +04:00
|
|
|
{
|
|
|
|
HKEY key;
|
|
|
|
NS_NAMED_LITERAL_STRING(keyName,
|
|
|
|
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
|
|
|
|
DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName.get(), 0, KEY_READ,
|
|
|
|
&key);
|
|
|
|
if (res != ERROR_SUCCESS) {
|
|
|
|
_retval.SetLength(0);
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD type, size;
|
2013-10-11 00:36:42 +04:00
|
|
|
res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"),
|
|
|
|
nullptr, &type, nullptr, &size);
|
2009-10-09 07:03:09 +04:00
|
|
|
// The call to RegQueryValueExW must succeed, the type must be REG_SZ, the
|
|
|
|
// buffer size must not equal 0, and the buffer size be a multiple of 2.
|
|
|
|
if (res != ERROR_SUCCESS || type != REG_SZ || size == 0 || size % 2 != 0) {
|
|
|
|
::RegCloseKey(key);
|
|
|
|
_retval.SetLength(0);
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2014-04-24 03:03:00 +04:00
|
|
|
// |size| may or may not include room for the terminating null character
|
|
|
|
DWORD resultLen = size / 2;
|
2009-10-09 07:03:09 +04:00
|
|
|
|
|
|
|
_retval.SetLength(resultLen);
|
|
|
|
nsAString::iterator begin;
|
|
|
|
_retval.BeginWriting(begin);
|
|
|
|
if (begin.size_forward() != resultLen) {
|
|
|
|
::RegCloseKey(key);
|
|
|
|
_retval.SetLength(0);
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2013-10-11 00:36:42 +04:00
|
|
|
res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"),
|
|
|
|
nullptr, nullptr, (LPBYTE) begin.get(), &size);
|
2009-10-09 07:03:09 +04:00
|
|
|
::RegCloseKey(key);
|
|
|
|
if (res != ERROR_SUCCESS) {
|
|
|
|
_retval.SetLength(0);
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2014-04-24 03:03:00 +04:00
|
|
|
if (!_retval.CharAt(resultLen - 1)) {
|
|
|
|
// It was already null terminated.
|
|
|
|
_retval.Truncate(resultLen - 1);
|
|
|
|
}
|
|
|
|
|
2009-10-09 07:03:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-05-15 21:58:09 +04:00
|
|
|
|
|
|
|
static bool
|
|
|
|
GetCachedHash(HKEY rootKey, const nsAString ®Path, const nsAString &path,
|
|
|
|
nsAString &cachedHash)
|
|
|
|
{
|
|
|
|
HKEY baseKey;
|
2013-12-03 19:07:22 +04:00
|
|
|
if (RegOpenKeyExW(rootKey, reinterpret_cast<const wchar_t*>(regPath.BeginReading()), 0, KEY_READ, &baseKey) !=
|
2013-05-15 21:58:09 +04:00
|
|
|
ERROR_SUCCESS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar_t cachedHashRaw[512];
|
|
|
|
DWORD bufferSize = sizeof(cachedHashRaw);
|
2013-12-03 19:07:22 +04:00
|
|
|
LONG result = RegQueryValueExW(baseKey, reinterpret_cast<const wchar_t*>(path.BeginReading()), 0, nullptr,
|
2013-05-15 21:58:09 +04:00
|
|
|
(LPBYTE)cachedHashRaw, &bufferSize);
|
|
|
|
RegCloseKey(baseKey);
|
|
|
|
if (result == ERROR_SUCCESS) {
|
|
|
|
cachedHash.Assign(cachedHashRaw);
|
|
|
|
}
|
|
|
|
return ERROR_SUCCESS == result;
|
|
|
|
}
|
|
|
|
|
2013-02-08 18:58:52 +04:00
|
|
|
#endif
|
2009-10-09 07:03:09 +04:00
|
|
|
|
2007-04-20 19:22:17 +04:00
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult)
|
|
|
|
{
|
2013-02-08 18:58:52 +04:00
|
|
|
nsCOMPtr<nsIFile> updRoot;
|
|
|
|
#if defined(MOZ_WIDGET_GONK)
|
|
|
|
|
|
|
|
nsresult rv = NS_NewNativeLocalFile(nsDependentCString("/data/local"),
|
|
|
|
true,
|
|
|
|
getter_AddRefs(updRoot));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2013-02-08 18:58:52 +04:00
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIFile> appFile;
|
|
|
|
bool per = false;
|
|
|
|
nsresult rv = GetFile(XRE_EXECUTABLE_FILE, &per, getter_AddRefs(appFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = appFile->GetParent(getter_AddRefs(updRoot));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2013-05-15 21:58:09 +04:00
|
|
|
|
|
|
|
nsAutoString pathHash;
|
|
|
|
bool pathHashResult = false;
|
2014-01-13 01:45:41 +04:00
|
|
|
bool hasVendor = gAppData->vendor && strlen(gAppData->vendor) != 0;
|
2013-05-15 21:58:09 +04:00
|
|
|
|
|
|
|
nsAutoString appDirPath;
|
2014-01-13 01:45:41 +04:00
|
|
|
if (SUCCEEDED(updRoot->GetPath(appDirPath))) {
|
2013-05-15 21:58:09 +04:00
|
|
|
|
2014-01-13 01:45:41 +04:00
|
|
|
// Figure out where we should check for a cached hash value. If the
|
|
|
|
// application doesn't have the nsXREAppData vendor value defined check
|
|
|
|
// under SOFTWARE\Mozilla.
|
2013-05-15 21:58:09 +04:00
|
|
|
wchar_t regPath[1024] = { L'\0' };
|
|
|
|
swprintf_s(regPath, mozilla::ArrayLength(regPath), L"SOFTWARE\\%S\\%S\\TaskBarIDs",
|
2014-01-13 01:45:41 +04:00
|
|
|
(hasVendor ? gAppData->vendor : "Mozilla"), MOZ_APP_BASENAME);
|
2013-05-15 21:58:09 +04:00
|
|
|
|
|
|
|
// If we pre-computed the hash, grab it from the registry.
|
|
|
|
pathHashResult = GetCachedHash(HKEY_LOCAL_MACHINE,
|
|
|
|
nsDependentString(regPath), appDirPath,
|
|
|
|
pathHash);
|
|
|
|
if (!pathHashResult) {
|
|
|
|
pathHashResult = GetCachedHash(HKEY_CURRENT_USER,
|
|
|
|
nsDependentString(regPath), appDirPath,
|
|
|
|
pathHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the local app data directory and if a vendor name exists append it.
|
|
|
|
// If only a product name exists, append it. If neither exist fallback to
|
|
|
|
// old handling. We don't use the product name on purpose because we want a
|
|
|
|
// shared update directory for different apps run from the same path (like
|
|
|
|
// Metro & Desktop).
|
|
|
|
nsCOMPtr<nsIFile> localDir;
|
2014-01-13 01:45:41 +04:00
|
|
|
if (pathHashResult && (hasVendor || gAppData->name) &&
|
2013-05-15 21:58:09 +04:00
|
|
|
NS_SUCCEEDED(GetUserDataDirectoryHome(getter_AddRefs(localDir), true)) &&
|
2014-01-13 01:45:41 +04:00
|
|
|
NS_SUCCEEDED(localDir->AppendNative(nsDependentCString(hasVendor ?
|
2013-05-15 21:58:09 +04:00
|
|
|
gAppData->vendor : gAppData->name))) &&
|
|
|
|
NS_SUCCEEDED(localDir->Append(NS_LITERAL_STRING("updates"))) &&
|
|
|
|
NS_SUCCEEDED(localDir->Append(pathHash))) {
|
|
|
|
NS_ADDREF(*aResult = localDir);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-26 22:35:21 +04:00
|
|
|
nsAutoString appPath;
|
2013-02-08 18:58:52 +04:00
|
|
|
rv = updRoot->GetPath(appPath);
|
2007-04-20 19:22:17 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// AppDir may be a short path. Convert to long path to make sure
|
|
|
|
// the consistency of the update folder location
|
2007-09-26 22:35:21 +04:00
|
|
|
nsString longPath;
|
2013-12-03 19:07:22 +04:00
|
|
|
wchar_t* buf;
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t bufLength = longPath.GetMutableData(&buf, MAXPATHLEN);
|
2007-09-26 22:35:21 +04:00
|
|
|
NS_ENSURE_TRUE(bufLength >= MAXPATHLEN, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
DWORD len = GetLongPathNameW(appPath.get(), buf, bufLength);
|
|
|
|
|
2007-04-20 19:22:17 +04:00
|
|
|
// Failing GetLongPathName() is not fatal.
|
2007-09-26 22:35:21 +04:00
|
|
|
if (len <= 0 || len >= bufLength)
|
2007-04-20 19:22:17 +04:00
|
|
|
longPath.Assign(appPath);
|
|
|
|
else
|
|
|
|
longPath.SetLength(len);
|
2011-04-29 14:38:26 +04:00
|
|
|
|
2007-04-20 19:22:17 +04:00
|
|
|
// Use <UserLocalDataDir>\updates\<relative path to app dir from
|
|
|
|
// Program Files> if app dir is under Program Files to avoid the
|
|
|
|
// folder virtualization mess on Windows Vista
|
2007-09-26 22:35:21 +04:00
|
|
|
nsAutoString programFiles;
|
2007-04-20 19:22:17 +04:00
|
|
|
rv = GetShellFolderPath(CSIDL_PROGRAM_FILES, programFiles);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-26 22:35:21 +04:00
|
|
|
programFiles.AppendLiteral("\\");
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t programFilesLen = programFiles.Length();
|
2007-04-20 19:22:17 +04:00
|
|
|
|
2012-05-22 18:50:04 +04:00
|
|
|
nsAutoString programName;
|
|
|
|
if (_wcsnicmp(programFiles.get(), longPath.get(), programFilesLen) == 0) {
|
|
|
|
programName = Substring(longPath, programFilesLen);
|
|
|
|
} else {
|
|
|
|
// We need the update root directory to live outside of the installation
|
|
|
|
// directory, because otherwise the updater writing the log file can cause
|
|
|
|
// the directory to be locked, which prevents it from being replaced after
|
|
|
|
// background updates.
|
|
|
|
programName.AssignASCII(MOZ_APP_NAME);
|
|
|
|
}
|
2007-04-20 19:22:17 +04:00
|
|
|
|
|
|
|
rv = GetUserLocalDataDirectory(getter_AddRefs(updRoot));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-05-22 18:50:04 +04:00
|
|
|
rv = updRoot->AppendRelativePath(programName);
|
2007-04-20 19:22:17 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-05-15 21:33:14 +04:00
|
|
|
#endif
|
2013-02-08 18:58:52 +04:00
|
|
|
#endif
|
|
|
|
NS_ADDREF(*aResult = updRoot);
|
2012-08-27 19:27:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetProfileStartupDir(nsIFile* *aResult)
|
|
|
|
{
|
|
|
|
if (mProfileDir)
|
|
|
|
return mProfileDir->Clone(aResult);
|
|
|
|
|
|
|
|
if (mAppProvider) {
|
|
|
|
nsCOMPtr<nsIFile> needsclone;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dummy;
|
2006-01-12 18:29:10 +03:00
|
|
|
nsresult rv = mAppProvider->GetFile(NS_APP_PROFILE_DIR_STARTUP,
|
|
|
|
&dummy,
|
|
|
|
getter_AddRefs(needsclone));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return needsclone->Clone(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetProfileDir(nsIFile* *aResult)
|
|
|
|
{
|
|
|
|
if (mProfileDir) {
|
|
|
|
if (!mProfileNotified)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return mProfileDir->Clone(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAppProvider) {
|
|
|
|
nsCOMPtr<nsIFile> needsclone;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dummy;
|
2006-01-12 18:29:10 +03:00
|
|
|
nsresult rv = mAppProvider->GetFile(NS_APP_USER_PROFILE_50_DIR,
|
|
|
|
&dummy,
|
|
|
|
getter_AddRefs(needsclone));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return needsclone->Clone(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, aResult);
|
|
|
|
}
|
|
|
|
|
2002-08-21 14:25:54 +04:00
|
|
|
nsresult
|
2012-06-06 06:08:30 +04:00
|
|
|
nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal)
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
|
|
|
// Copied from nsAppFileLocationProvider (more or less)
|
|
|
|
nsresult rv;
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> localDir;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#if defined(XP_MACOSX)
|
2005-04-26 04:37:23 +04:00
|
|
|
FSRef fsRef;
|
|
|
|
OSType folderType;
|
|
|
|
if (aLocal) {
|
|
|
|
folderType = kCachedDataFolderType;
|
|
|
|
} else {
|
2007-09-26 22:35:21 +04:00
|
|
|
#ifdef MOZ_THUNDERBIRD
|
2005-04-26 04:37:23 +04:00
|
|
|
folderType = kDomainLibraryFolderType;
|
2004-06-18 11:38:59 +04:00
|
|
|
#else
|
2005-04-26 04:37:23 +04:00
|
|
|
folderType = kApplicationSupportFolderType;
|
2007-09-26 22:35:21 +04:00
|
|
|
#endif
|
2005-04-26 04:37:23 +04:00
|
|
|
}
|
|
|
|
OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
|
2005-04-26 05:38:00 +04:00
|
|
|
NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NS_NewNativeLocalFile(EmptyCString(), true, getter_AddRefs(localDir));
|
2002-08-21 14:25:54 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir);
|
|
|
|
NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
rv = dirFileMac->InitWithFSRef(&fsRef);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-26 22:35:21 +04:00
|
|
|
localDir = do_QueryInterface(dirFileMac, &rv);
|
2002-08-21 14:25:54 +04:00
|
|
|
#elif defined(XP_WIN)
|
2007-09-26 22:35:21 +04:00
|
|
|
nsString path;
|
2009-10-09 07:03:09 +04:00
|
|
|
if (aLocal) {
|
2005-05-15 21:33:14 +04:00
|
|
|
rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path);
|
2009-10-09 07:03:09 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = GetRegWindowsAppDataFolder(aLocal, path);
|
|
|
|
}
|
|
|
|
if (!aLocal || NS_FAILED(rv)) {
|
2005-05-15 21:33:14 +04:00
|
|
|
rv = GetShellFolderPath(CSIDL_APPDATA, path);
|
2009-10-09 07:03:09 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (!aLocal)
|
|
|
|
rv = GetRegWindowsAppDataFolder(aLocal, path);
|
|
|
|
}
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir));
|
2011-11-11 04:17:46 +04:00
|
|
|
#elif defined(MOZ_WIDGET_GONK)
|
2012-04-04 13:15:10 +04:00
|
|
|
rv = NS_NewNativeLocalFile(NS_LITERAL_CSTRING("/data/b2g"), true,
|
2011-11-11 04:17:46 +04:00
|
|
|
getter_AddRefs(localDir));
|
2004-06-18 01:23:51 +04:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
const char* homeDir = getenv("HOME");
|
|
|
|
if (!homeDir || !*homeDir)
|
2002-08-21 14:25:54 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2013-03-01 01:31:35 +04:00
|
|
|
#ifdef ANDROID /* We want (ProfD == ProfLD) on Android. */
|
|
|
|
aLocal = false;
|
|
|
|
#endif
|
|
|
|
|
2013-02-11 18:47:21 +04:00
|
|
|
if (aLocal) {
|
|
|
|
// If $XDG_CACHE_HOME is defined use it, otherwise use $HOME/.cache.
|
|
|
|
const char* cacheHome = getenv("XDG_CACHE_HOME");
|
|
|
|
if (cacheHome && *cacheHome) {
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(cacheHome), true,
|
|
|
|
getter_AddRefs(localDir));
|
|
|
|
} else {
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
|
|
|
|
getter_AddRefs(localDir));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = localDir->AppendNative(NS_LITERAL_CSTRING(".cache"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
|
|
|
|
getter_AddRefs(localDir));
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
#else
|
2007-09-26 22:35:21 +04:00
|
|
|
#error "Don't know how to get product dir on your platform"
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif
|
2008-01-15 18:13:59 +03:00
|
|
|
|
|
|
|
NS_IF_ADDREF(*aFile = localDir);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-06-06 06:08:30 +04:00
|
|
|
nsXREDirProvider::GetSysUserExtensionsDirectory(nsIFile** aFile)
|
2008-01-15 18:13:59 +03:00
|
|
|
{
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> localDir;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsresult rv = GetUserDataDirectoryHome(getter_AddRefs(localDir), false);
|
2008-01-15 18:13:59 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = AppendSysUserExtensionPath(localDir);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = EnsureDirectoryExists(localDir);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ADDREF(*aFile = localDir);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-07 04:58:18 +03:00
|
|
|
#if defined(XP_UNIX) || defined(XP_MACOSX)
|
|
|
|
nsresult
|
2012-06-06 06:08:30 +04:00
|
|
|
nsXREDirProvider::GetSystemExtensionsDirectory(nsIFile** aFile)
|
2008-03-07 04:58:18 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> localDir;
|
2008-03-07 04:58:18 +03:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
FSRef fsRef;
|
|
|
|
OSErr err = ::FSFindFolder(kOnSystemDisk, kApplicationSupportFolderType, kCreateFolder, &fsRef);
|
|
|
|
NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NS_NewNativeLocalFile(EmptyCString(), true, getter_AddRefs(localDir));
|
2008-03-07 04:58:18 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir);
|
|
|
|
NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
rv = dirFileMac->InitWithFSRef(&fsRef);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
localDir = do_QueryInterface(dirFileMac, &rv);
|
|
|
|
|
|
|
|
static const char* const sXR = "Mozilla";
|
|
|
|
rv = localDir->AppendNative(nsDependentCString(sXR));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
static const char* const sExtensions = "Extensions";
|
|
|
|
rv = localDir->AppendNative(nsDependentCString(sExtensions));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
static const char *const sysSExtDir =
|
|
|
|
#ifdef HAVE_USR_LIB64_DIR
|
|
|
|
"/usr/lib64/mozilla/extensions";
|
2012-11-15 23:07:09 +04:00
|
|
|
#elif defined(__OpenBSD__) || defined(__FreeBSD__)
|
2012-11-14 23:02:07 +04:00
|
|
|
"/usr/local/lib/mozilla/extensions";
|
2008-03-07 04:58:18 +03:00
|
|
|
#else
|
|
|
|
"/usr/lib/mozilla/extensions";
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(sysSExtDir), false,
|
2008-03-07 04:58:18 +03:00
|
|
|
getter_AddRefs(localDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ADDREF(*aFile = localDir);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-15 18:13:59 +03:00
|
|
|
nsresult
|
2012-06-06 06:08:30 +04:00
|
|
|
nsXREDirProvider::GetUserDataDirectory(nsIFile** aFile, bool aLocal,
|
2012-05-24 18:29:52 +04:00
|
|
|
const nsACString* aProfileName,
|
|
|
|
const nsACString* aAppName,
|
|
|
|
const nsACString* aVendorName)
|
2008-01-15 18:13:59 +03:00
|
|
|
{
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> localDir;
|
2008-01-15 18:13:59 +03:00
|
|
|
nsresult rv = GetUserDataDirectoryHome(getter_AddRefs(localDir), aLocal);
|
2007-09-26 22:35:21 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-11 18:47:21 +04:00
|
|
|
rv = AppendProfilePath(localDir, aProfileName, aAppName, aVendorName, aLocal);
|
2007-09-26 22:35:21 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2006-03-22 07:26:30 +03:00
|
|
|
#ifdef DEBUG_jungshik
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString cwd;
|
2006-03-22 07:26:30 +03:00
|
|
|
localDir->GetNativePath(cwd);
|
|
|
|
printf("nsXREDirProvider::GetUserDataDirectory: %s\n", cwd.get());
|
|
|
|
#endif
|
2002-08-26 14:18:41 +04:00
|
|
|
rv = EnsureDirectoryExists(localDir);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-26 22:35:21 +04:00
|
|
|
NS_ADDREF(*aFile = localDir);
|
2002-08-21 14:25:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-08-26 14:18:41 +04:00
|
|
|
|
|
|
|
nsresult
|
2004-06-18 01:23:51 +04:00
|
|
|
nsXREDirProvider::EnsureDirectoryExists(nsIFile* aDirectory)
|
2002-08-26 14:18:41 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool exists;
|
2002-08-26 14:18:41 +04:00
|
|
|
nsresult rv = aDirectory->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-03-22 07:26:30 +03:00
|
|
|
#ifdef DEBUG_jungshik
|
|
|
|
if (!exists) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString cwd;
|
2006-03-22 07:26:30 +03:00
|
|
|
aDirectory->GetNativePath(cwd);
|
|
|
|
printf("nsXREDirProvider::EnsureDirectoryExists: %s does not\n", cwd.get());
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-26 14:18:41 +04:00
|
|
|
if (!exists)
|
2005-04-26 04:37:23 +04:00
|
|
|
rv = aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
2006-03-22 07:26:30 +03:00
|
|
|
#ifdef DEBUG_jungshik
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
NS_WARNING("nsXREDirProvider::EnsureDirectoryExists: create failed");
|
|
|
|
#endif
|
2002-08-26 14:18:41 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsXREDirProvider::EnsureProfileFileExists(nsIFile *aFile)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool exists;
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
rv = aFile->Exists(&exists);
|
|
|
|
if (NS_FAILED(rv) || exists) return;
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString leafName;
|
2004-06-18 01:23:51 +04:00
|
|
|
rv = aFile->GetNativeLeafName(leafName);
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> defaultsFile;
|
|
|
|
rv = GetProfileDefaultsDir(getter_AddRefs(defaultsFile));
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
rv = defaultsFile->AppendNative(leafName);
|
|
|
|
if (NS_FAILED(rv)) return;
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
defaultsFile->CopyToNative(mProfileDir, EmptyCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetProfileDefaultsDir(nsIFile* *aResult)
|
|
|
|
{
|
2005-12-23 17:51:39 +03:00
|
|
|
NS_ASSERTION(mGREDir, "nsXREDirProvider not initialized.");
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_PRECONDITION(aResult, "Null out-param");
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFile> defaultsDir;
|
|
|
|
|
2005-12-23 17:51:39 +03:00
|
|
|
rv = GetAppDir()->Clone(getter_AddRefs(defaultsDir));
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-09-07 22:59:07 +04:00
|
|
|
rv = defaultsDir->AppendNative(NS_LITERAL_CSTRING("defaults"));
|
2007-09-26 22:35:21 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = defaultsDir->AppendNative(NS_LITERAL_CSTRING("profile"));
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult = defaultsDir);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-15 18:13:59 +03:00
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::AppendSysUserExtensionPath(nsIFile* aFile)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFile, "Null pointer!");
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined (XP_MACOSX) || defined(XP_WIN)
|
2008-01-15 18:13:59 +03:00
|
|
|
|
|
|
|
static const char* const sXR = "Mozilla";
|
|
|
|
rv = aFile->AppendNative(nsDependentCString(sXR));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
static const char* const sExtensions = "Extensions";
|
|
|
|
rv = aFile->AppendNative(nsDependentCString(sExtensions));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
|
|
|
|
static const char* const sXR = ".mozilla";
|
|
|
|
rv = aFile->AppendNative(nsDependentCString(sXR));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
static const char* const sExtensions = "extensions";
|
|
|
|
rv = aFile->AppendNative(nsDependentCString(sExtensions));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "Don't know how to get XRE user extension path on your platform"
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-26 22:35:21 +04:00
|
|
|
nsresult
|
2012-05-24 18:29:52 +04:00
|
|
|
nsXREDirProvider::AppendProfilePath(nsIFile* aFile,
|
|
|
|
const nsACString* aProfileName,
|
|
|
|
const nsACString* aAppName,
|
2013-02-11 18:47:21 +04:00
|
|
|
const nsACString* aVendorName,
|
2013-02-14 18:11:07 +04:00
|
|
|
bool aLocal)
|
2007-09-26 22:35:21 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aFile, "Null pointer!");
|
2012-05-24 18:29:52 +04:00
|
|
|
|
|
|
|
if (!gAppData) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString profile;
|
|
|
|
nsAutoCString appName;
|
|
|
|
nsAutoCString vendor;
|
2012-05-24 18:29:52 +04:00
|
|
|
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;
|
|
|
|
}
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2012-05-24 18:29:52 +04:00
|
|
|
nsresult rv;
|
2008-09-20 11:59:55 +04:00
|
|
|
|
2007-09-26 22:35:21 +04:00
|
|
|
#if defined (XP_MACOSX)
|
2012-05-24 18:29:52 +04:00
|
|
|
if (!profile.IsEmpty()) {
|
|
|
|
rv = AppendProfileString(aFile, profile.get());
|
2007-09-26 22:35:21 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Note that MacOS ignores the vendor when creating the profile hierarchy -
|
|
|
|
// all application preferences directories live alongside one another in
|
|
|
|
// ~/Library/Application Support/
|
2012-05-24 18:29:52 +04:00
|
|
|
rv = aFile->AppendNative(appName);
|
2007-09-26 22:35:21 +04:00
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-02-11 02:57:01 +04:00
|
|
|
#elif defined(XP_WIN)
|
2012-05-24 18:29:52 +04:00
|
|
|
if (!profile.IsEmpty()) {
|
|
|
|
rv = AppendProfileString(aFile, profile.get());
|
2007-09-26 22:35:21 +04:00
|
|
|
}
|
|
|
|
else {
|
2012-05-24 18:29:52 +04:00
|
|
|
if (!vendor.IsEmpty()) {
|
|
|
|
rv = aFile->AppendNative(vendor);
|
2007-09-26 22:35:21 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2012-05-24 18:29:52 +04:00
|
|
|
rv = aFile->AppendNative(appName);
|
2007-09-26 22:35:21 +04:00
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-04 05:16:20 +04:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
// The directory used for storing profiles
|
|
|
|
// The parent of this directory is set in GetUserDataDirectoryHome
|
|
|
|
// XXX: handle gAppData->profile properly
|
2012-05-24 18:29:52 +04:00
|
|
|
// XXXsmaug ...and the rest of the profile creation!
|
|
|
|
MOZ_ASSERT(!aAppName,
|
|
|
|
"Profile creation for external applications is not implemented!");
|
2010-06-04 05:16:20 +04:00
|
|
|
rv = aFile->AppendNative(nsDependentCString("mozilla"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-09-26 22:35:21 +04:00
|
|
|
#elif defined(XP_UNIX)
|
2013-02-11 18:47:21 +04:00
|
|
|
nsAutoCString folder;
|
|
|
|
// Make it hidden (by starting with "."), except when local (the
|
|
|
|
// profile is already under ~/.cache or XDG_CACHE_HOME).
|
|
|
|
if (!aLocal)
|
|
|
|
folder.Assign('.');
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2012-05-24 18:29:52 +04:00
|
|
|
if (!profile.IsEmpty()) {
|
2007-09-26 22:35:21 +04:00
|
|
|
// Skip any leading path characters
|
2012-05-24 18:29:52 +04:00
|
|
|
const char* profileStart = profile.get();
|
2007-09-26 22:35:21 +04:00
|
|
|
while (*profileStart == '/' || *profileStart == '\\')
|
|
|
|
profileStart++;
|
|
|
|
|
|
|
|
// On the off chance that someone wanted their folder to be hidden don't
|
|
|
|
// let it become ".."
|
2013-02-11 18:47:21 +04:00
|
|
|
if (*profileStart == '.' && !aLocal)
|
2007-09-26 22:35:21 +04:00
|
|
|
profileStart++;
|
|
|
|
|
|
|
|
folder.Append(profileStart);
|
|
|
|
ToLowerCase(folder);
|
|
|
|
|
|
|
|
rv = AppendProfileString(aFile, folder.BeginReading());
|
|
|
|
}
|
|
|
|
else {
|
2012-05-24 18:29:52 +04:00
|
|
|
if (!vendor.IsEmpty()) {
|
|
|
|
folder.Append(vendor);
|
2007-09-26 22:35:21 +04:00
|
|
|
ToLowerCase(folder);
|
|
|
|
|
|
|
|
rv = aFile->AppendNative(folder);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
folder.Truncate();
|
|
|
|
}
|
|
|
|
|
2012-05-24 18:29:52 +04:00
|
|
|
folder.Append(appName);
|
2007-09-26 22:35:21 +04:00
|
|
|
ToLowerCase(folder);
|
|
|
|
|
|
|
|
rv = aFile->AppendNative(folder);
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "Don't know how to get profile path on your platform"
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::AppendProfileString(nsIFile* aFile, const char* aPath)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFile, "Null file!");
|
|
|
|
NS_ASSERTION(aPath, "Null path!");
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString pathDup(aPath);
|
2007-09-26 22:35:21 +04:00
|
|
|
|
|
|
|
char* path = pathDup.BeginWriting();
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
char* subdir;
|
|
|
|
while ((subdir = NS_strtok("/\\", &path))) {
|
|
|
|
rv = aFile->AppendNative(nsDependentCString(subdir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|