2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef _nsXREDirProvider_h__
|
|
|
|
#define _nsXREDirProvider_h__
|
|
|
|
|
|
|
|
#include "nsIDirectoryService.h"
|
|
|
|
#include "nsIProfileMigrator.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-04 05:55:29 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
2012-06-19 20:49:05 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-09-04 05:55:29 -07:00
|
|
|
|
2012-06-19 20:49:05 -07:00
|
|
|
class nsXREDirProvider MOZ_FINAL : public nsIDirectoryServiceProvider2,
|
|
|
|
public nsIProfileStartup
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// we use a custom isupports implementation (no refcount)
|
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
|
|
|
|
|
|
|
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
|
|
|
|
NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
|
|
|
|
NS_DECL_NSIPROFILESTARTUP
|
|
|
|
|
|
|
|
nsXREDirProvider();
|
|
|
|
|
|
|
|
// if aXULAppDir is null, use gArgv[0]
|
|
|
|
nsresult Initialize(nsIFile *aXULAppDir,
|
2012-06-05 19:08:30 -07:00
|
|
|
nsIFile *aGREDir,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIDirectoryServiceProvider* aAppProvider = nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
~nsXREDirProvider();
|
|
|
|
|
2012-05-22 07:50:04 -07:00
|
|
|
static nsXREDirProvider* GetSingleton();
|
|
|
|
|
2012-05-24 07:29:52 -07:00
|
|
|
nsresult GetUserProfilesRootDir(nsIFile** aResult,
|
|
|
|
const nsACString* aProfileName,
|
|
|
|
const nsACString* aAppName,
|
|
|
|
const nsACString* aVendorName);
|
|
|
|
nsresult GetUserProfilesLocalDir(nsIFile** aResult,
|
|
|
|
const nsACString* aProfileName,
|
|
|
|
const nsACString* aAppName,
|
|
|
|
const nsACString* aVendorName);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// We only set the profile dir, we don't ensure that it exists;
|
|
|
|
// that is the responsibility of the toolkit profile service.
|
|
|
|
// We also don't fire profile-changed notifications... that is
|
|
|
|
// the responsibility of the apprunner.
|
|
|
|
nsresult SetProfile(nsIFile* aProfileDir, nsIFile* aProfileLocalDir);
|
|
|
|
|
|
|
|
void DoShutdown();
|
|
|
|
|
|
|
|
nsresult GetProfileDefaultsDir(nsIFile* *aResult);
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
static nsresult GetUserAppDataDirectory(nsIFile* *aFile) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return GetUserDataDirectory(aFile, false, nullptr, nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-06-05 19:08:30 -07:00
|
|
|
static nsresult GetUserLocalDataDirectory(nsIFile* *aFile) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return GetUserDataDirectory(aFile, true, nullptr, nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-24 07:29:52 -07:00
|
|
|
// By default GetUserDataDirectory gets profile path from gAppData,
|
|
|
|
// but that can be overridden by using aProfileName/aAppName/aVendorName.
|
2012-06-05 19:08:30 -07:00
|
|
|
static nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal,
|
2012-05-24 07:29:52 -07:00
|
|
|
const nsACString* aProfileName,
|
|
|
|
const nsACString* aAppName,
|
|
|
|
const nsACString* aVendorName);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* make sure you clone it, if you need to do stuff to it */
|
|
|
|
nsIFile* GetGREDir() { return mGREDir; }
|
2007-09-26 11:35:21 -07:00
|
|
|
nsIFile* GetAppDir() {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mXULAppDir)
|
|
|
|
return mXULAppDir;
|
|
|
|
return mGREDir;
|
|
|
|
}
|
|
|
|
|
2007-04-20 08:22:17 -07:00
|
|
|
/**
|
|
|
|
* Get the directory under which update directory is created.
|
|
|
|
* This method may be called before XPCOM is started. aResult
|
|
|
|
* is a clone, it may be modified.
|
|
|
|
*/
|
|
|
|
nsresult GetUpdateRootDir(nsIFile* *aResult);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the profile startup directory as determined by this class or by
|
|
|
|
* mAppProvider. This method may be called before XPCOM is started. aResult
|
|
|
|
* is a clone, it may be modified.
|
|
|
|
*/
|
2007-04-20 08:22:17 -07:00
|
|
|
nsresult GetProfileStartupDir(nsIFile* *aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the profile directory as determined by this class or by an
|
|
|
|
* embedder-provided XPCOM directory provider. Only call this method
|
|
|
|
* when XPCOM is initialized! aResult is a clone, it may be modified.
|
|
|
|
*/
|
|
|
|
nsresult GetProfileDir(nsIFile* *aResult);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult);
|
2012-06-05 19:08:30 -07:00
|
|
|
static nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal);
|
|
|
|
static nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile);
|
2008-03-06 17:58:18 -08:00
|
|
|
#if defined(XP_UNIX) || defined(XP_MACOSX)
|
2012-06-05 19:08:30 -07:00
|
|
|
static nsresult GetSystemExtensionsDirectory(nsIFile** aFile);
|
2008-03-06 17:58:18 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult EnsureDirectoryExists(nsIFile* aDirectory);
|
|
|
|
void EnsureProfileFileExists(nsIFile* aFile);
|
|
|
|
|
2007-09-26 11:35:21 -07:00
|
|
|
// Determine the profile path within the UAppData directory. This is different
|
|
|
|
// on every major platform.
|
2012-05-24 07:29:52 -07:00
|
|
|
static nsresult AppendProfilePath(nsIFile* aFile,
|
|
|
|
const nsACString* aProfileName,
|
|
|
|
const nsACString* aAppName,
|
|
|
|
const nsACString* aVendorName);
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2008-01-15 07:13:59 -08:00
|
|
|
static nsresult AppendSysUserExtensionPath(nsIFile* aFile);
|
|
|
|
|
2007-09-26 11:35:21 -07:00
|
|
|
// Internal helper that splits a path into components using the '/' and '\\'
|
|
|
|
// delimiters.
|
|
|
|
static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath);
|
|
|
|
|
2010-06-23 09:18:32 -07:00
|
|
|
// Calculate and register extension and theme bundle directories.
|
|
|
|
void LoadExtensionBundleDirectories();
|
|
|
|
|
|
|
|
// Calculate and register app-bundled extension directories.
|
2007-09-04 05:55:29 -07:00
|
|
|
void LoadAppBundleDirs();
|
|
|
|
|
|
|
|
void Append(nsIFile* aDirectory);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDirectoryServiceProvider> mAppProvider;
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> mGREDir;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIFile> mXULAppDir;
|
|
|
|
nsCOMPtr<nsIFile> mProfileDir;
|
|
|
|
nsCOMPtr<nsIFile> mProfileLocalDir;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mProfileNotified;
|
2007-09-04 05:55:29 -07:00
|
|
|
nsCOMArray<nsIFile> mAppBundleDirectories;
|
|
|
|
nsCOMArray<nsIFile> mExtensionDirectories;
|
|
|
|
nsCOMArray<nsIFile> mThemeDirectories;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|