michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _nsXREDirProvider_h__ michael@0: #define _nsXREDirProvider_h__ michael@0: michael@0: #include "nsIDirectoryService.h" michael@0: #include "nsIProfileMigrator.h" michael@0: #include "nsIFile.h" michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCOMArray.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsXREDirProvider MOZ_FINAL : public nsIDirectoryServiceProvider2, michael@0: public nsIProfileStartup michael@0: { michael@0: public: michael@0: // we use a custom isupports implementation (no refcount) michael@0: NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); michael@0: NS_IMETHOD_(MozExternalRefCountType) AddRef(void); michael@0: NS_IMETHOD_(MozExternalRefCountType) Release(void); michael@0: michael@0: NS_DECL_NSIDIRECTORYSERVICEPROVIDER michael@0: NS_DECL_NSIDIRECTORYSERVICEPROVIDER2 michael@0: NS_DECL_NSIPROFILESTARTUP michael@0: michael@0: nsXREDirProvider(); michael@0: michael@0: // if aXULAppDir is null, use gArgv[0] michael@0: nsresult Initialize(nsIFile *aXULAppDir, michael@0: nsIFile *aGREDir, michael@0: nsIDirectoryServiceProvider* aAppProvider = nullptr); michael@0: ~nsXREDirProvider(); michael@0: michael@0: static nsXREDirProvider* GetSingleton(); michael@0: michael@0: nsresult GetUserProfilesRootDir(nsIFile** aResult, michael@0: const nsACString* aProfileName, michael@0: const nsACString* aAppName, michael@0: const nsACString* aVendorName); michael@0: nsresult GetUserProfilesLocalDir(nsIFile** aResult, michael@0: const nsACString* aProfileName, michael@0: const nsACString* aAppName, michael@0: const nsACString* aVendorName); michael@0: michael@0: // We only set the profile dir, we don't ensure that it exists; michael@0: // that is the responsibility of the toolkit profile service. michael@0: // We also don't fire profile-changed notifications... that is michael@0: // the responsibility of the apprunner. michael@0: nsresult SetProfile(nsIFile* aProfileDir, nsIFile* aProfileLocalDir); michael@0: michael@0: void DoShutdown(); michael@0: michael@0: nsresult GetProfileDefaultsDir(nsIFile* *aResult); michael@0: michael@0: nsresult GetUserAppDataDirectory(nsIFile* *aFile) { michael@0: return GetUserDataDirectory(aFile, false, nullptr, nullptr, nullptr); michael@0: } michael@0: nsresult GetUserLocalDataDirectory(nsIFile* *aFile) { michael@0: return GetUserDataDirectory(aFile, true, nullptr, nullptr, nullptr); michael@0: } michael@0: michael@0: // By default GetUserDataDirectory gets profile path from gAppData, michael@0: // but that can be overridden by using aProfileName/aAppName/aVendorName. michael@0: nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal, michael@0: const nsACString* aProfileName, michael@0: const nsACString* aAppName, michael@0: const nsACString* aVendorName); michael@0: michael@0: /* make sure you clone it, if you need to do stuff to it */ michael@0: nsIFile* GetGREDir() { return mGREDir; } michael@0: nsIFile* GetAppDir() { michael@0: if (mXULAppDir) michael@0: return mXULAppDir; michael@0: return mGREDir; michael@0: } michael@0: michael@0: /** michael@0: * Get the directory under which update directory is created. michael@0: * This method may be called before XPCOM is started. aResult michael@0: * is a clone, it may be modified. michael@0: */ michael@0: nsresult GetUpdateRootDir(nsIFile* *aResult); michael@0: michael@0: /** michael@0: * Get the profile startup directory as determined by this class or by michael@0: * mAppProvider. This method may be called before XPCOM is started. aResult michael@0: * is a clone, it may be modified. michael@0: */ michael@0: nsresult GetProfileStartupDir(nsIFile* *aResult); michael@0: michael@0: /** michael@0: * Get the profile directory as determined by this class or by an michael@0: * embedder-provided XPCOM directory provider. Only call this method michael@0: * when XPCOM is initialized! aResult is a clone, it may be modified. michael@0: */ michael@0: nsresult GetProfileDir(nsIFile* *aResult); michael@0: michael@0: protected: michael@0: nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult); michael@0: nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal); michael@0: nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile); michael@0: #if defined(XP_UNIX) || defined(XP_MACOSX) michael@0: static nsresult GetSystemExtensionsDirectory(nsIFile** aFile); michael@0: #endif michael@0: static nsresult EnsureDirectoryExists(nsIFile* aDirectory); michael@0: void EnsureProfileFileExists(nsIFile* aFile); michael@0: michael@0: // Determine the profile path within the UAppData directory. This is different michael@0: // on every major platform. michael@0: static nsresult AppendProfilePath(nsIFile* aFile, michael@0: const nsACString* aProfileName, michael@0: const nsACString* aAppName, michael@0: const nsACString* aVendorName, michael@0: bool aLocal); michael@0: michael@0: static nsresult AppendSysUserExtensionPath(nsIFile* aFile); michael@0: michael@0: // Internal helper that splits a path into components using the '/' and '\\' michael@0: // delimiters. michael@0: static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath); michael@0: michael@0: // Calculate and register extension and theme bundle directories. michael@0: void LoadExtensionBundleDirectories(); michael@0: michael@0: // Calculate and register app-bundled extension directories. michael@0: void LoadAppBundleDirs(); michael@0: michael@0: void Append(nsIFile* aDirectory); michael@0: michael@0: nsCOMPtr mAppProvider; michael@0: nsCOMPtr mGREDir; michael@0: nsCOMPtr mXULAppDir; michael@0: nsCOMPtr mProfileDir; michael@0: nsCOMPtr mProfileLocalDir; michael@0: bool mProfileNotified; michael@0: nsCOMArray mAppBundleDirectories; michael@0: nsCOMArray mExtensionDirectories; michael@0: nsCOMArray mThemeDirectories; michael@0: }; michael@0: michael@0: #endif