/src/mozilla-central/toolkit/xre/nsXREDirProvider.h
Line | Count | Source (jump to first uncovered line) |
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 | | #include "nsIXREDirProvider.h" |
13 | | |
14 | | #include "nsCOMPtr.h" |
15 | | #include "nsCOMArray.h" |
16 | | #include "mozilla/Attributes.h" |
17 | | |
18 | | // {5573967d-f6cf-4c63-8e0e-9ac06e04d62b} |
19 | | #define NS_XREDIRPROVIDER_CID \ |
20 | | { 0x5573967d, 0xf6cf, 0x4c63, \ |
21 | | { 0x8e, 0x0e, 0x9a, 0xc0, 0x6e, 0x04, 0xd6, 0x2b } } |
22 | | #define NS_XREDIRPROVIDER_CONTRACTID "@mozilla.org/xre/directory-provider;1" |
23 | | |
24 | | class nsXREDirProvider final : public nsIDirectoryServiceProvider2, |
25 | | public nsIXREDirProvider, |
26 | | public nsIProfileStartup |
27 | | { |
28 | | public: |
29 | | // we use a custom isupports implementation (no refcount) |
30 | | NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override; |
31 | | NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override; |
32 | | NS_IMETHOD_(MozExternalRefCountType) Release(void) override; |
33 | | |
34 | | NS_DECL_NSIDIRECTORYSERVICEPROVIDER |
35 | | NS_DECL_NSIDIRECTORYSERVICEPROVIDER2 |
36 | | NS_DECL_NSIXREDIRPROVIDER |
37 | | NS_DECL_NSIPROFILESTARTUP |
38 | | |
39 | | nsXREDirProvider(); |
40 | | |
41 | | // if aXULAppDir is null, use gArgv[0] |
42 | | nsresult Initialize(nsIFile *aXULAppDir, |
43 | | nsIFile *aGREDir, |
44 | | nsIDirectoryServiceProvider* aAppProvider = nullptr); |
45 | | ~nsXREDirProvider(); |
46 | | |
47 | | static already_AddRefed<nsXREDirProvider> GetSingleton(); |
48 | | |
49 | | nsresult GetUserProfilesRootDir(nsIFile** aResult); |
50 | | nsresult GetUserProfilesLocalDir(nsIFile** aResult); |
51 | | |
52 | | // We only set the profile dir, we don't ensure that it exists; |
53 | | // that is the responsibility of the toolkit profile service. |
54 | | // We also don't fire profile-changed notifications... that is |
55 | | // the responsibility of the apprunner. |
56 | | nsresult SetProfile(nsIFile* aProfileDir, nsIFile* aProfileLocalDir); |
57 | | |
58 | | void InitializeUserPrefs(); |
59 | | |
60 | | void DoShutdown(); |
61 | | |
62 | 0 | static nsresult GetUserAppDataDirectory(nsIFile* *aFile) { |
63 | 0 | return GetUserDataDirectory(aFile, false); |
64 | 0 | } |
65 | 0 | static nsresult GetUserLocalDataDirectory(nsIFile* *aFile) { |
66 | 0 | return GetUserDataDirectory(aFile, true); |
67 | 0 | } |
68 | | |
69 | | // GetUserDataDirectory gets the profile path from gAppData. |
70 | | static nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal); |
71 | | |
72 | | /* make sure you clone it, if you need to do stuff to it */ |
73 | 0 | nsIFile* GetGREDir() { return mGREDir; } |
74 | 3 | nsIFile* GetGREBinDir() { return mGREBinDir; } |
75 | 0 | nsIFile* GetAppDir() { |
76 | 0 | if (mXULAppDir) |
77 | 0 | return mXULAppDir; |
78 | 0 | return mGREDir; |
79 | 0 | } |
80 | | |
81 | | /** |
82 | | * Get a hash for the install directory. |
83 | | */ |
84 | | nsresult GetInstallHash(nsAString & aPathHash, bool aUseCompatibilityMode); |
85 | | |
86 | | /** |
87 | | * Get the directory under which update directory is created. |
88 | | * This method may be called before XPCOM is started. aResult |
89 | | * is a clone, it may be modified. |
90 | | */ |
91 | | nsresult GetUpdateRootDir(nsIFile* *aResult); |
92 | | |
93 | | /** |
94 | | * Get the profile startup directory as determined by this class or by |
95 | | * mAppProvider. This method may be called before XPCOM is started. aResult |
96 | | * is a clone, it may be modified. |
97 | | */ |
98 | | nsresult GetProfileStartupDir(nsIFile* *aResult); |
99 | | |
100 | | /** |
101 | | * Get the profile directory as determined by this class or by an |
102 | | * embedder-provided XPCOM directory provider. Only call this method |
103 | | * when XPCOM is initialized! aResult is a clone, it may be modified. |
104 | | */ |
105 | | nsresult GetProfileDir(nsIFile* *aResult); |
106 | | |
107 | | protected: |
108 | | nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult); |
109 | | static nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal); |
110 | | static nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile); |
111 | | static nsresult GetSysUserExtensionsDevDirectory(nsIFile* *aFile); |
112 | | #if defined(XP_UNIX) || defined(XP_MACOSX) |
113 | | static nsresult GetSystemExtensionsDirectory(nsIFile** aFile); |
114 | | #endif |
115 | | static nsresult EnsureDirectoryExists(nsIFile* aDirectory); |
116 | | |
117 | | // Determine the profile path within the UAppData directory. This is different |
118 | | // on every major platform. |
119 | | static nsresult AppendProfilePath(nsIFile* aFile, bool aLocal); |
120 | | |
121 | | static nsresult AppendSysUserExtensionPath(nsIFile* aFile); |
122 | | static nsresult AppendSysUserExtensionsDevPath(nsIFile* aFile); |
123 | | |
124 | | // Internal helper that splits a path into components using the '/' and '\\' |
125 | | // delimiters. |
126 | | static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath); |
127 | | |
128 | | #if defined(MOZ_CONTENT_SANDBOX) |
129 | | // Load the temp directory for sandboxed content processes |
130 | | nsresult LoadContentProcessTempDir(); |
131 | | #endif |
132 | | |
133 | | void Append(nsIFile* aDirectory); |
134 | | |
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 | | bool mPrefsInitialized = false; |
146 | | #if defined(MOZ_CONTENT_SANDBOX) |
147 | | nsCOMPtr<nsIFile> mContentTempDir; |
148 | | nsCOMPtr<nsIFile> mContentProcessSandboxTempDir; |
149 | | #endif |
150 | | nsCOMArray<nsIFile> mAppBundleDirectories; |
151 | | }; |
152 | | |
153 | | #endif |