Bumping manifests a=b2g-bump
[gecko.git] / toolkit / xre / nsXREDirProvider.h
blobd8ffe512c9bb0b175296677330ca3830076fc22f
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"
11 #include "nsIFile.h"
13 #include "nsCOMPtr.h"
14 #include "nsCOMArray.h"
15 #include "mozilla/Attributes.h"
17 class nsXREDirProvider MOZ_FINAL : public nsIDirectoryServiceProvider2,
18 public nsIProfileStartup
20 public:
21 // we use a custom isupports implementation (no refcount)
22 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
23 NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
24 NS_IMETHOD_(MozExternalRefCountType) Release(void);
26 NS_DECL_NSIDIRECTORYSERVICEPROVIDER
27 NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
28 NS_DECL_NSIPROFILESTARTUP
30 nsXREDirProvider();
32 // if aXULAppDir is null, use gArgv[0]
33 nsresult Initialize(nsIFile *aXULAppDir,
34 nsIFile *aGREDir,
35 nsIDirectoryServiceProvider* aAppProvider = nullptr);
36 ~nsXREDirProvider();
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);
55 void DoShutdown();
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* GetGREBinDir() { return mGREBinDir; }
76 nsIFile* GetAppDir() {
77 if (mXULAppDir)
78 return mXULAppDir;
79 return mGREDir;
82 /**
83 * Get the directory under which update directory is created.
84 * This method may be called before XPCOM is started. aResult
85 * is a clone, it may be modified.
87 nsresult GetUpdateRootDir(nsIFile* *aResult);
89 /**
90 * Get the profile startup directory as determined by this class or by
91 * mAppProvider. This method may be called before XPCOM is started. aResult
92 * is a clone, it may be modified.
94 nsresult GetProfileStartupDir(nsIFile* *aResult);
96 /**
97 * Get the profile directory as determined by this class or by an
98 * embedder-provided XPCOM directory provider. Only call this method
99 * when XPCOM is initialized! aResult is a clone, it may be modified.
101 nsresult GetProfileDir(nsIFile* *aResult);
103 protected:
104 nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult);
105 static nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal);
106 static nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile);
107 #if defined(XP_UNIX) || defined(XP_MACOSX)
108 static nsresult GetSystemExtensionsDirectory(nsIFile** aFile);
109 #endif
110 static nsresult EnsureDirectoryExists(nsIFile* aDirectory);
111 void EnsureProfileFileExists(nsIFile* aFile);
113 // Determine the profile path within the UAppData directory. This is different
114 // on every major platform.
115 static nsresult AppendProfilePath(nsIFile* aFile,
116 const nsACString* aProfileName,
117 const nsACString* aAppName,
118 const nsACString* aVendorName,
119 bool aLocal);
121 static nsresult AppendSysUserExtensionPath(nsIFile* aFile);
123 // Internal helper that splits a path into components using the '/' and '\\'
124 // delimiters.
125 static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath);
127 // Calculate and register extension and theme bundle directories.
128 void LoadExtensionBundleDirectories();
130 // Calculate and register app-bundled extension directories.
131 void LoadAppBundleDirs();
133 void Append(nsIFile* aDirectory);
135 nsCOMPtr<nsIDirectoryServiceProvider> mAppProvider;
136 // On OSX, mGREDir points to .app/Contents/Resources
137 nsCOMPtr<nsIFile> mGREDir;
138 // On OSX, mGREBinDir points to .app/Contents/MacOS
139 nsCOMPtr<nsIFile> mGREBinDir;
140 // On OSX, mXULAppDir points to .app/Contents/Resources/browser
141 nsCOMPtr<nsIFile> mXULAppDir;
142 nsCOMPtr<nsIFile> mProfileDir;
143 nsCOMPtr<nsIFile> mProfileLocalDir;
144 bool mProfileNotified;
145 nsCOMArray<nsIFile> mAppBundleDirectories;
146 nsCOMArray<nsIFile> mExtensionDirectories;
147 nsCOMArray<nsIFile> mThemeDirectories;
150 #endif