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
|
|
|
|
|
|
|
#ifndef _nsXREDirProvider_h__
|
|
|
|
#define _nsXREDirProvider_h__
|
|
|
|
|
|
|
|
#include "nsIDirectoryService.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsIProfileMigrator.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2007-09-04 16:55:29 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
2012-06-20 07:49:05 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-09-04 16:55:29 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXREDirProvider final : public nsIDirectoryServiceProvider2,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIProfileStartup
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
|
|
|
public:
|
2004-06-18 01:23:51 +04:00
|
|
|
// we use a custom isupports implementation (no refcount)
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2002-09-29 10:51:54 +04:00
|
|
|
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
|
|
|
|
NS_DECL_NSIPROFILESTARTUP
|
|
|
|
|
|
|
|
nsXREDirProvider();
|
2006-01-12 18:29:10 +03:00
|
|
|
|
|
|
|
// if aXULAppDir is null, use gArgv[0]
|
|
|
|
nsresult Initialize(nsIFile *aXULAppDir,
|
2012-06-06 06:08:30 +04:00
|
|
|
nsIFile *aGREDir,
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIDirectoryServiceProvider* aAppProvider = nullptr);
|
2004-06-18 01:23:51 +04:00
|
|
|
~nsXREDirProvider();
|
|
|
|
|
2012-05-22 18:50:04 +04:00
|
|
|
static nsXREDirProvider* GetSingleton();
|
|
|
|
|
2017-11-08 19:36:51 +03:00
|
|
|
nsresult GetUserProfilesRootDir(nsIFile** aResult);
|
|
|
|
nsresult GetUserProfilesLocalDir(nsIFile** aResult);
|
2012-05-24 18:29:52 +04:00
|
|
|
|
2004-06-18 01:23:51 +04: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.
|
2005-04-26 04:37:23 +04:00
|
|
|
nsresult SetProfile(nsIFile* aProfileDir, nsIFile* aProfileLocalDir);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2017-09-14 21:35:01 +03:00
|
|
|
void InitializeUserPrefs();
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
void DoShutdown();
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
static nsresult GetUserAppDataDirectory(nsIFile* *aFile) {
|
2017-11-08 19:36:51 +03:00
|
|
|
return GetUserDataDirectory(aFile, false);
|
2005-04-26 04:37:23 +04:00
|
|
|
}
|
2012-06-06 06:08:30 +04:00
|
|
|
static nsresult GetUserLocalDataDirectory(nsIFile* *aFile) {
|
2017-11-08 19:36:51 +03:00
|
|
|
return GetUserDataDirectory(aFile, true);
|
2005-04-26 04:37:23 +04:00
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2017-11-08 19:36:51 +03:00
|
|
|
// GetUserDataDirectory gets the profile path from gAppData.
|
|
|
|
static nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal);
|
2012-05-24 18:29:52 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
/* make sure you clone it, if you need to do stuff to it */
|
2005-12-23 17:51:39 +03:00
|
|
|
nsIFile* GetGREDir() { return mGREDir; }
|
2014-10-04 00:48:49 +04:00
|
|
|
nsIFile* GetGREBinDir() { return mGREBinDir; }
|
2007-09-26 22:35:21 +04:00
|
|
|
nsIFile* GetAppDir() {
|
2005-12-23 17:51:39 +03:00
|
|
|
if (mXULAppDir)
|
|
|
|
return mXULAppDir;
|
|
|
|
return mGREDir;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2018-08-21 17:53:03 +03:00
|
|
|
/**
|
|
|
|
* Get a hash for the install directory.
|
|
|
|
*/
|
2018-09-10 20:35:23 +03:00
|
|
|
nsresult GetInstallHash(nsAString & aPathHash,
|
|
|
|
bool aUseCompatibilityMode = false);
|
2018-08-21 17:53:03 +03:00
|
|
|
|
2007-04-20 19:22:17 +04: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);
|
|
|
|
|
2006-01-12 18:29:10 +03: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 19:22:17 +04:00
|
|
|
nsresult GetProfileStartupDir(nsIFile* *aResult);
|
2006-01-12 18:29:10 +03: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);
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
protected:
|
2006-01-12 18:29:10 +03:00
|
|
|
nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult);
|
2012-06-06 06:08:30 +04:00
|
|
|
static nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal);
|
|
|
|
static nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile);
|
2017-10-04 20:43:49 +03:00
|
|
|
static nsresult GetSysUserExtensionsDevDirectory(nsIFile* *aFile);
|
2008-03-07 04:58:18 +03:00
|
|
|
#if defined(XP_UNIX) || defined(XP_MACOSX)
|
2012-06-06 06:08:30 +04:00
|
|
|
static nsresult GetSystemExtensionsDirectory(nsIFile** aFile);
|
2008-03-07 04:58:18 +03:00
|
|
|
#endif
|
2004-06-18 01:23:51 +04:00
|
|
|
static nsresult EnsureDirectoryExists(nsIFile* aDirectory);
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2007-09-26 22:35:21 +04:00
|
|
|
// Determine the profile path within the UAppData directory. This is different
|
|
|
|
// on every major platform.
|
2017-11-08 19:36:51 +03:00
|
|
|
static nsresult AppendProfilePath(nsIFile* aFile, bool aLocal);
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2008-01-15 18:13:59 +03:00
|
|
|
static nsresult AppendSysUserExtensionPath(nsIFile* aFile);
|
2017-10-04 20:43:49 +03:00
|
|
|
static nsresult AppendSysUserExtensionsDevPath(nsIFile* aFile);
|
2008-01-15 18:13:59 +03:00
|
|
|
|
2007-09-26 22:35:21 +04:00
|
|
|
// Internal helper that splits a path into components using the '/' and '\\'
|
|
|
|
// delimiters.
|
|
|
|
static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath);
|
|
|
|
|
2018-01-09 18:29:40 +03:00
|
|
|
#if defined(MOZ_CONTENT_SANDBOX)
|
2016-03-07 22:26:35 +03:00
|
|
|
// Load the temp directory for sandboxed content processes
|
|
|
|
nsresult LoadContentProcessTempDir();
|
|
|
|
#endif
|
|
|
|
|
2007-09-04 16:55:29 +04:00
|
|
|
void Append(nsIFile* aDirectory);
|
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
nsCOMPtr<nsIDirectoryServiceProvider> mAppProvider;
|
2014-09-29 22:51:04 +04:00
|
|
|
// On OSX, mGREDir points to .app/Contents/Resources
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> mGREDir;
|
2014-10-04 00:48:49 +04:00
|
|
|
// On OSX, mGREBinDir points to .app/Contents/MacOS
|
|
|
|
nsCOMPtr<nsIFile> mGREBinDir;
|
2014-09-29 22:51:04 +04:00
|
|
|
// On OSX, mXULAppDir points to .app/Contents/Resources/browser
|
2004-09-07 22:59:07 +04:00
|
|
|
nsCOMPtr<nsIFile> mXULAppDir;
|
2004-06-18 01:23:51 +04:00
|
|
|
nsCOMPtr<nsIFile> mProfileDir;
|
2005-04-26 04:37:23 +04:00
|
|
|
nsCOMPtr<nsIFile> mProfileLocalDir;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mProfileNotified;
|
2017-09-14 21:35:01 +03:00
|
|
|
bool mPrefsInitialized = false;
|
2018-01-09 18:29:40 +03:00
|
|
|
#if defined(MOZ_CONTENT_SANDBOX)
|
2016-03-07 22:26:35 +03:00
|
|
|
nsCOMPtr<nsIFile> mContentTempDir;
|
2016-07-06 00:48:25 +03:00
|
|
|
nsCOMPtr<nsIFile> mContentProcessSandboxTempDir;
|
2016-03-07 22:26:35 +03:00
|
|
|
#endif
|
2007-09-04 16:55:29 +04:00
|
|
|
nsCOMArray<nsIFile> mAppBundleDirectories;
|
2002-08-21 14:25:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|