1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef _nsXREDirProvider_h__
7 #define _nsXREDirProvider_h__
9 #include "nsIDirectoryService.h"
10 #include "nsIProfileMigrator.h"
14 #include "nsCOMArray.h"
15 #include "mozilla/Attributes.h"
17 class nsXREDirProvider MOZ_FINAL
: public nsIDirectoryServiceProvider2
,
18 public nsIProfileStartup
21 // we use a custom isupports implementation (no refcount)
22 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
);
23 NS_IMETHOD_(nsrefcnt
) AddRef(void);
24 NS_IMETHOD_(nsrefcnt
) Release(void);
26 NS_DECL_NSIDIRECTORYSERVICEPROVIDER
27 NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
28 NS_DECL_NSIPROFILESTARTUP
32 // if aXULAppDir is null, use gArgv[0]
33 nsresult
Initialize(nsIFile
*aXULAppDir
,
35 nsIDirectoryServiceProvider
* aAppProvider
= nullptr);
38 static nsXREDirProvider
* GetSingleton();
40 nsresult
GetUserProfilesRootDir(nsIFile
** aResult
,
41 const nsACString
* aProfileName
,
42 const nsACString
* aAppName
,
43 const nsACString
* aVendorName
);
44 nsresult
GetUserProfilesLocalDir(nsIFile
** aResult
,
45 const nsACString
* aProfileName
,
46 const nsACString
* aAppName
,
47 const nsACString
* aVendorName
);
49 // We only set the profile dir, we don't ensure that it exists;
50 // that is the responsibility of the toolkit profile service.
51 // We also don't fire profile-changed notifications... that is
52 // the responsibility of the apprunner.
53 nsresult
SetProfile(nsIFile
* aProfileDir
, nsIFile
* aProfileLocalDir
);
57 nsresult
GetProfileDefaultsDir(nsIFile
* *aResult
);
59 static nsresult
GetUserAppDataDirectory(nsIFile
* *aFile
) {
60 return GetUserDataDirectory(aFile
, false, nullptr, nullptr, nullptr);
62 static nsresult
GetUserLocalDataDirectory(nsIFile
* *aFile
) {
63 return GetUserDataDirectory(aFile
, true, nullptr, nullptr, nullptr);
66 // By default GetUserDataDirectory gets profile path from gAppData,
67 // but that can be overridden by using aProfileName/aAppName/aVendorName.
68 static nsresult
GetUserDataDirectory(nsIFile
** aFile
, bool aLocal
,
69 const nsACString
* aProfileName
,
70 const nsACString
* aAppName
,
71 const nsACString
* aVendorName
);
73 /* make sure you clone it, if you need to do stuff to it */
74 nsIFile
* GetGREDir() { return mGREDir
; }
75 nsIFile
* GetAppDir() {
82 * Get the directory under which update directory is created.
83 * This method may be called before XPCOM is started. aResult
84 * is a clone, it may be modified.
86 nsresult
GetUpdateRootDir(nsIFile
* *aResult
);
89 * Get the profile startup directory as determined by this class or by
90 * mAppProvider. This method may be called before XPCOM is started. aResult
91 * is a clone, it may be modified.
93 nsresult
GetProfileStartupDir(nsIFile
* *aResult
);
96 * Get the profile directory as determined by this class or by an
97 * embedder-provided XPCOM directory provider. Only call this method
98 * when XPCOM is initialized! aResult is a clone, it may be modified.
100 nsresult
GetProfileDir(nsIFile
* *aResult
);
103 nsresult
GetFilesInternal(const char* aProperty
, nsISimpleEnumerator
** aResult
);
104 static nsresult
GetUserDataDirectoryHome(nsIFile
* *aFile
, bool aLocal
);
105 static nsresult
GetSysUserExtensionsDirectory(nsIFile
* *aFile
);
106 #if defined(XP_UNIX) || defined(XP_MACOSX)
107 static nsresult
GetSystemExtensionsDirectory(nsIFile
** aFile
);
109 static nsresult
EnsureDirectoryExists(nsIFile
* aDirectory
);
110 void EnsureProfileFileExists(nsIFile
* aFile
);
112 // Determine the profile path within the UAppData directory. This is different
113 // on every major platform.
114 static nsresult
AppendProfilePath(nsIFile
* aFile
,
115 const nsACString
* aProfileName
,
116 const nsACString
* aAppName
,
117 const nsACString
* aVendorName
);
119 static nsresult
AppendSysUserExtensionPath(nsIFile
* aFile
);
121 // Internal helper that splits a path into components using the '/' and '\\'
123 static inline nsresult
AppendProfileString(nsIFile
* aFile
, const char* aPath
);
125 // Calculate and register extension and theme bundle directories.
126 void LoadExtensionBundleDirectories();
128 // Calculate and register app-bundled extension directories.
129 void LoadAppBundleDirs();
131 void Append(nsIFile
* aDirectory
);
133 nsCOMPtr
<nsIDirectoryServiceProvider
> mAppProvider
;
134 nsCOMPtr
<nsIFile
> mGREDir
;
135 nsCOMPtr
<nsIFile
> mXULAppDir
;
136 nsCOMPtr
<nsIFile
> mProfileDir
;
137 nsCOMPtr
<nsIFile
> mProfileLocalDir
;
138 bool mProfileNotified
;
139 nsCOMArray
<nsIFile
> mAppBundleDirectories
;
140 nsCOMArray
<nsIFile
> mExtensionDirectories
;
141 nsCOMArray
<nsIFile
> mThemeDirectories
;