Line data Source code
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/. */
5 :
6 : #ifndef _nsXREDirProvider_h__
7 : #define _nsXREDirProvider_h__
8 :
9 : #include "nsIDirectoryService.h"
10 : #include "nsIProfileMigrator.h"
11 : #include "nsIFile.h"
12 :
13 : #include "nsCOMPtr.h"
14 : #include "nsCOMArray.h"
15 : #include "mozilla/Attributes.h"
16 :
17 : class nsXREDirProvider final : public nsIDirectoryServiceProvider2,
18 : public nsIProfileStartup
19 : {
20 : public:
21 : // we use a custom isupports implementation (no refcount)
22 : NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
23 : NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
24 : NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
25 :
26 : NS_DECL_NSIDIRECTORYSERVICEPROVIDER
27 : NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
28 : NS_DECL_NSIPROFILESTARTUP
29 :
30 : nsXREDirProvider();
31 :
32 : // if aXULAppDir is null, use gArgv[0]
33 : nsresult Initialize(nsIFile *aXULAppDir,
34 : nsIFile *aGREDir,
35 : nsIDirectoryServiceProvider* aAppProvider = nullptr);
36 : ~nsXREDirProvider();
37 :
38 : static nsXREDirProvider* GetSingleton();
39 :
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);
48 :
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);
54 :
55 : void DoShutdown();
56 :
57 4 : static nsresult GetUserAppDataDirectory(nsIFile* *aFile) {
58 4 : return GetUserDataDirectory(aFile, false, nullptr, nullptr, nullptr);
59 : }
60 1 : static nsresult GetUserLocalDataDirectory(nsIFile* *aFile) {
61 1 : return GetUserDataDirectory(aFile, true, nullptr, nullptr, nullptr);
62 : }
63 :
64 : // By default GetUserDataDirectory gets profile path from gAppData,
65 : // but that can be overridden by using aProfileName/aAppName/aVendorName.
66 : static nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal,
67 : const nsACString* aProfileName,
68 : const nsACString* aAppName,
69 : const nsACString* aVendorName);
70 :
71 : /* make sure you clone it, if you need to do stuff to it */
72 2 : nsIFile* GetGREDir() { return mGREDir; }
73 1 : nsIFile* GetGREBinDir() { return mGREBinDir; }
74 3 : nsIFile* GetAppDir() {
75 3 : if (mXULAppDir)
76 3 : return mXULAppDir;
77 0 : return mGREDir;
78 : }
79 :
80 : /**
81 : * Get the directory under which update directory is created.
82 : * This method may be called before XPCOM is started. aResult
83 : * is a clone, it may be modified.
84 : */
85 : nsresult GetUpdateRootDir(nsIFile* *aResult);
86 :
87 : /**
88 : * Get the profile startup directory as determined by this class or by
89 : * mAppProvider. This method may be called before XPCOM is started. aResult
90 : * is a clone, it may be modified.
91 : */
92 : nsresult GetProfileStartupDir(nsIFile* *aResult);
93 :
94 : /**
95 : * Get the profile directory as determined by this class or by an
96 : * embedder-provided XPCOM directory provider. Only call this method
97 : * when XPCOM is initialized! aResult is a clone, it may be modified.
98 : */
99 : nsresult GetProfileDir(nsIFile* *aResult);
100 :
101 : protected:
102 : nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult);
103 : static nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal);
104 : static nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile);
105 : #if defined(XP_UNIX) || defined(XP_MACOSX)
106 : static nsresult GetSystemExtensionsDirectory(nsIFile** aFile);
107 : #endif
108 : static nsresult EnsureDirectoryExists(nsIFile* aDirectory);
109 :
110 : // Determine the profile path within the UAppData directory. This is different
111 : // on every major platform.
112 : static nsresult AppendProfilePath(nsIFile* aFile,
113 : const nsACString* aProfileName,
114 : const nsACString* aAppName,
115 : const nsACString* aVendorName,
116 : bool aLocal);
117 :
118 : static nsresult AppendSysUserExtensionPath(nsIFile* aFile);
119 :
120 : // Internal helper that splits a path into components using the '/' and '\\'
121 : // delimiters.
122 : static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath);
123 :
124 : #if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
125 : // Load the temp directory for sandboxed content processes
126 : nsresult LoadContentProcessTempDir();
127 : #endif
128 :
129 : #ifdef MOZ_B2G
130 : // Calculate and register app-bundled extension directories.
131 : void LoadAppBundleDirs();
132 : #endif
133 :
134 : void Append(nsIFile* aDirectory);
135 :
136 : nsCOMPtr<nsIDirectoryServiceProvider> mAppProvider;
137 : // On OSX, mGREDir points to .app/Contents/Resources
138 : nsCOMPtr<nsIFile> mGREDir;
139 : // On OSX, mGREBinDir points to .app/Contents/MacOS
140 : nsCOMPtr<nsIFile> mGREBinDir;
141 : // On OSX, mXULAppDir points to .app/Contents/Resources/browser
142 : nsCOMPtr<nsIFile> mXULAppDir;
143 : nsCOMPtr<nsIFile> mProfileDir;
144 : nsCOMPtr<nsIFile> mProfileLocalDir;
145 : bool mProfileNotified;
146 : #if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
147 : nsCOMPtr<nsIFile> mContentTempDir;
148 : nsCOMPtr<nsIFile> mContentProcessSandboxTempDir;
149 : #endif
150 : nsCOMArray<nsIFile> mAppBundleDirectories;
151 : };
152 :
153 : #endif
|