File: | var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp |
Warning: | line 242, column 7 Value stored to 'rv' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | #include "nsAppRunner.h" |
7 | #include "nsXREDirProvider.h" |
8 | #ifndef ANDROID |
9 | # include "commonupdatedir.h" |
10 | #endif |
11 | |
12 | #include "jsapi.h" |
13 | #include "xpcpublic.h" |
14 | #include "prprf.h" |
15 | |
16 | #include "nsIAppStartup.h" |
17 | #include "nsIFile.h" |
18 | #include "nsIObserver.h" |
19 | #include "nsIObserverService.h" |
20 | #include "nsISimpleEnumerator.h" |
21 | #include "nsIToolkitProfileService.h" |
22 | #include "nsIXULRuntime.h" |
23 | #include "commonupdatedir.h" |
24 | |
25 | #include "nsAppDirectoryServiceDefs.h" |
26 | #include "nsDirectoryServiceDefs.h" |
27 | #include "nsDirectoryServiceUtils.h" |
28 | #include "nsXULAppAPI.h" |
29 | #include "nsCategoryManagerUtils.h" |
30 | |
31 | #include "nsDependentString.h" |
32 | #include "nsCOMArray.h" |
33 | #include "nsArrayEnumerator.h" |
34 | #include "nsEnumeratorUtils.h" |
35 | #include "nsReadableUtils.h" |
36 | |
37 | #include "SpecialSystemDirectory.h" |
38 | |
39 | #include "mozilla/dom/ScriptSettings.h" |
40 | |
41 | #include "mozilla/AppShutdown.h" |
42 | #include "mozilla/AutoRestore.h" |
43 | #ifdef MOZ_BACKGROUNDTASKS1 |
44 | # include "mozilla/BackgroundTasks.h" |
45 | #endif |
46 | #include "mozilla/Components.h" |
47 | #include "mozilla/Services.h" |
48 | #include "mozilla/Omnijar.h" |
49 | #include "mozilla/Preferences.h" |
50 | #include "mozilla/ProfilerLabels.h" |
51 | #include "mozilla/Telemetry.h" |
52 | #include "mozilla/XREAppData.h" |
53 | #include "nsPrintfCString.h" |
54 | |
55 | #ifdef MOZ_THUNDERBIRD |
56 | # include "nsIPK11TokenDB.h" |
57 | # include "nsIPK11Token.h" |
58 | # ifdef XP_MACOSX |
59 | # include "MacApplicationDelegate.h" |
60 | # endif |
61 | #endif |
62 | |
63 | #include <stdlib.h> |
64 | |
65 | #ifdef XP_WIN |
66 | # include <windows.h> |
67 | # include <shlobj.h> |
68 | # include "WinUtils.h" |
69 | #endif |
70 | #ifdef XP_MACOSX |
71 | # include "nsILocalFileMac.h" |
72 | // for chflags() |
73 | # include <sys/stat.h> |
74 | # include <unistd.h> |
75 | #endif |
76 | #ifdef XP_UNIX1 |
77 | # include <ctype.h> |
78 | #endif |
79 | #ifdef XP_IOS |
80 | # include "UIKitDirProvider.h" |
81 | #endif |
82 | |
83 | #if defined(XP_MACOSX) |
84 | # define APP_REGISTRY_NAME"appreg" "Application Registry" |
85 | #elif defined(XP_WIN) |
86 | # define APP_REGISTRY_NAME"appreg" "registry.dat" |
87 | #else |
88 | # define APP_REGISTRY_NAME"appreg" "appreg" |
89 | #endif |
90 | |
91 | #define PREF_OVERRIDE_DIRNAME"preferences" "preferences" |
92 | |
93 | nsXREDirProvider* gDirServiceProvider = nullptr; |
94 | nsIFile* gDataDirHomeLocal = nullptr; |
95 | nsIFile* gDataDirHome = nullptr; |
96 | nsCOMPtr<nsIFile> gDataDirProfileLocal = nullptr; |
97 | nsCOMPtr<nsIFile> gDataDirProfile = nullptr; |
98 | |
99 | // These are required to allow nsXREDirProvider to be usable in xpcshell tests. |
100 | // where gAppData is null. |
101 | #if defined(XP_MACOSX) || defined(XP_UNIX1) |
102 | static const char* GetAppName() { |
103 | if (gAppData) { |
104 | return gAppData->name; |
105 | } |
106 | return nullptr; |
107 | } |
108 | #endif |
109 | |
110 | #ifdef XP_MACOSX |
111 | static const char* GetAppVendor() { |
112 | if (gAppData) { |
113 | return gAppData->vendor; |
114 | } |
115 | return nullptr; |
116 | } |
117 | #endif |
118 | |
119 | nsXREDirProvider::nsXREDirProvider() { gDirServiceProvider = this; } |
120 | |
121 | nsXREDirProvider::~nsXREDirProvider() { |
122 | gDirServiceProvider = nullptr; |
123 | gDataDirHomeLocal = nullptr; |
124 | gDataDirHome = nullptr; |
125 | } |
126 | |
127 | already_AddRefed<nsXREDirProvider> nsXREDirProvider::GetSingleton() { |
128 | if (!gDirServiceProvider) { |
129 | new nsXREDirProvider(); // This sets gDirServiceProvider |
130 | } |
131 | return do_AddRef(gDirServiceProvider); |
132 | } |
133 | |
134 | nsresult nsXREDirProvider::Initialize(nsIFile* aXULAppDir, nsIFile* aGREDir) { |
135 | NS_ENSURE_ARG(aXULAppDir)do { if ((__builtin_expect(!!(!(aXULAppDir)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aXULAppDir" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 135); return NS_ERROR_INVALID_ARG; } } while (false); |
136 | NS_ENSURE_ARG(aGREDir)do { if ((__builtin_expect(!!(!(aGREDir)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aGREDir" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 136); return NS_ERROR_INVALID_ARG; } } while (false); |
137 | |
138 | mXULAppDir = aXULAppDir; |
139 | mGREDir = aGREDir; |
140 | nsCOMPtr<nsIFile> binaryPath; |
141 | nsresult rv = XRE_GetBinaryPath(getter_AddRefs(binaryPath)); |
142 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 142); return rv; } } while (false); |
143 | return binaryPath->GetParent(getter_AddRefs(mGREBinDir)); |
144 | } |
145 | |
146 | nsresult nsXREDirProvider::SetProfile(nsIFile* aDir, nsIFile* aLocalDir) { |
147 | MOZ_ASSERT(aDir && aLocalDir, "We don't support no-profile apps!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(aDir && aLocalDir)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aDir && aLocalDir))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("aDir && aLocalDir" " (" "We don't support no-profile apps!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 147); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDir && aLocalDir" ") (" "We don't support no-profile apps!" ")"); do { *((volatile int*)__null) = 147; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
148 | MOZ_ASSERT(!mProfileDir && !mProfileLocalDir,do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mProfileDir && !mProfileLocalDir)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(!mProfileDir && !mProfileLocalDir))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mProfileDir && !mProfileLocalDir" " (" "You may only set the profile directories once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 149); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mProfileDir && !mProfileLocalDir" ") (" "You may only set the profile directories once" ")"); do { *((volatile int*)__null) = 149; __attribute__((nomerge)) :: abort(); } while (false); } } while (false) |
149 | "You may only set the profile directories once")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mProfileDir && !mProfileLocalDir)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(!mProfileDir && !mProfileLocalDir))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mProfileDir && !mProfileLocalDir" " (" "You may only set the profile directories once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 149); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mProfileDir && !mProfileLocalDir" ") (" "You may only set the profile directories once" ")"); do { *((volatile int*)__null) = 149; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
150 | |
151 | nsresult rv = EnsureDirectoryExists(aDir); |
152 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 152); return rv; } } while (false); |
153 | |
154 | rv = EnsureDirectoryExists(aLocalDir); |
155 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 155); return rv; } } while (false); |
156 | |
157 | #ifndef XP_WIN |
158 | nsAutoCString profilePath; |
159 | rv = aDir->GetNativePath(profilePath); |
160 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 160); return rv; } } while (false); |
161 | |
162 | nsAutoCString localProfilePath; |
163 | rv = aLocalDir->GetNativePath(localProfilePath); |
164 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 164); return rv; } } while (false); |
165 | |
166 | if (!mozilla::IsUtf8(profilePath) || !mozilla::IsUtf8(localProfilePath)) { |
167 | PR_fprintf( |
168 | PR_STDERRPR_GetSpecialFD(PR_StandardError), |
169 | "Error: The profile path is not valid UTF-8. Unable to continue.\n"); |
170 | return NS_ERROR_FAILURE; |
171 | } |
172 | #endif |
173 | |
174 | #ifdef XP_MACOSX |
175 | bool same; |
176 | if (NS_SUCCEEDED(aDir->Equals(aLocalDir, &same))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aDir->Equals(aLocalDir , &same))), 1))) && !same) { |
177 | // Ensure that the cache directory is not indexed by Spotlight |
178 | // (bug 718910). At least on OS X, the cache directory (under |
179 | // ~/Library/Caches/) is always the "local" user profile |
180 | // directory. This is confusing, since *both* user profile |
181 | // directories are "local" (they both exist under the user's |
182 | // home directory). But this usage dates back at least as far |
183 | // as the patch for bug 291033, where "local" seems to mean |
184 | // "suitable for temporary storage". Don't hide the cache |
185 | // directory if by some chance it and the "non-local" profile |
186 | // directory are the same -- there are bad side effects from |
187 | // hiding a profile directory under /Library/Application Support/ |
188 | // (see bug 801883). |
189 | nsAutoCString cacheDir; |
190 | if (NS_SUCCEEDED(aLocalDir->GetNativePath(cacheDir))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aLocalDir->GetNativePath (cacheDir))), 1)))) { |
191 | if (chflags(cacheDir.get(), UF_HIDDEN)) { |
192 | NS_WARNING("Failed to set Cache directory to HIDDEN.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to set Cache directory to HIDDEN." , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 192); |
193 | } |
194 | } |
195 | } |
196 | #endif |
197 | |
198 | mProfileDir = aDir; |
199 | mProfileLocalDir = aLocalDir; |
200 | return NS_OK; |
201 | } |
202 | |
203 | NS_IMPL_QUERY_INTERFACE(nsXREDirProvider, nsIDirectoryServiceProvider,nsresult nsXREDirProvider::QueryInterface(const nsIID& aIID , void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 205); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<nsXREDirProvider, nsIDirectoryServiceProvider >, int32_t( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider *>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char* >((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID <nsXREDirProvider, nsIDirectoryServiceProvider2>, int32_t ( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider2 *>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char* >((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID <nsXREDirProvider, nsIXREDirProvider>, int32_t( reinterpret_cast <char*>(static_cast<nsIXREDirProvider*>((nsXREDirProvider *)0x1000)) - reinterpret_cast<char*>((nsXREDirProvider* )0x1000))}, {&mozilla::detail::kImplementedIID<nsXREDirProvider , nsIProfileStartup>, int32_t( reinterpret_cast<char*> (static_cast<nsIProfileStartup*>((nsXREDirProvider*)0x1000 )) - reinterpret_cast<char*>((nsXREDirProvider*)0x1000) )}, {&mozilla::detail::kImplementedIID<nsXREDirProvider , nsISupports>, int32_t(reinterpret_cast<char*>(static_cast <nsISupports*>( static_cast<nsIDirectoryServiceProvider *>((nsXREDirProvider*)0x1000))) - reinterpret_cast<char *>((nsXREDirProvider*)0x1000))}, { nullptr, 0 } } ; static_assert ((sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface" ); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID , aInstancePtr, table); return rv; } |
204 | nsIDirectoryServiceProvider2, nsIXREDirProvider,nsresult nsXREDirProvider::QueryInterface(const nsIID& aIID , void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 205); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<nsXREDirProvider, nsIDirectoryServiceProvider >, int32_t( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider *>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char* >((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID <nsXREDirProvider, nsIDirectoryServiceProvider2>, int32_t ( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider2 *>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char* >((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID <nsXREDirProvider, nsIXREDirProvider>, int32_t( reinterpret_cast <char*>(static_cast<nsIXREDirProvider*>((nsXREDirProvider *)0x1000)) - reinterpret_cast<char*>((nsXREDirProvider* )0x1000))}, {&mozilla::detail::kImplementedIID<nsXREDirProvider , nsIProfileStartup>, int32_t( reinterpret_cast<char*> (static_cast<nsIProfileStartup*>((nsXREDirProvider*)0x1000 )) - reinterpret_cast<char*>((nsXREDirProvider*)0x1000) )}, {&mozilla::detail::kImplementedIID<nsXREDirProvider , nsISupports>, int32_t(reinterpret_cast<char*>(static_cast <nsISupports*>( static_cast<nsIDirectoryServiceProvider *>((nsXREDirProvider*)0x1000))) - reinterpret_cast<char *>((nsXREDirProvider*)0x1000))}, { nullptr, 0 } } ; static_assert ((sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface" ); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID , aInstancePtr, table); return rv; } |
205 | nsIProfileStartup)nsresult nsXREDirProvider::QueryInterface(const nsIID& aIID , void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 205); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<nsXREDirProvider, nsIDirectoryServiceProvider >, int32_t( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider *>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char* >((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID <nsXREDirProvider, nsIDirectoryServiceProvider2>, int32_t ( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider2 *>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char* >((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID <nsXREDirProvider, nsIXREDirProvider>, int32_t( reinterpret_cast <char*>(static_cast<nsIXREDirProvider*>((nsXREDirProvider *)0x1000)) - reinterpret_cast<char*>((nsXREDirProvider* )0x1000))}, {&mozilla::detail::kImplementedIID<nsXREDirProvider , nsIProfileStartup>, int32_t( reinterpret_cast<char*> (static_cast<nsIProfileStartup*>((nsXREDirProvider*)0x1000 )) - reinterpret_cast<char*>((nsXREDirProvider*)0x1000) )}, {&mozilla::detail::kImplementedIID<nsXREDirProvider , nsISupports>, int32_t(reinterpret_cast<char*>(static_cast <nsISupports*>( static_cast<nsIDirectoryServiceProvider *>((nsXREDirProvider*)0x1000))) - reinterpret_cast<char *>((nsXREDirProvider*)0x1000))}, { nullptr, 0 } } ; static_assert ((sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface" ); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID , aInstancePtr, table); return rv; } |
206 | |
207 | NS_IMETHODIMP_(MozExternalRefCountType)MozExternalRefCountType |
208 | nsXREDirProvider::AddRef() { return 1; } |
209 | |
210 | NS_IMETHODIMP_(MozExternalRefCountType)MozExternalRefCountType |
211 | nsXREDirProvider::Release() { return 0; } |
212 | |
213 | nsresult nsXREDirProvider::GetUserProfilesRootDir(nsIFile** aResult) { |
214 | nsCOMPtr<nsIFile> file; |
215 | nsresult rv = GetUserDataDirectory(getter_AddRefs(file), false); |
216 | |
217 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
218 | #if !defined(XP_UNIX1) || defined(XP_MACOSX) |
219 | rv = file->AppendNative("Profiles"_ns); |
220 | #endif |
221 | // We must create the profile directory here if it does not exist. |
222 | nsresult tmp = EnsureDirectoryExists(file); |
223 | if (NS_FAILED(tmp)((bool)(__builtin_expect(!!(NS_FAILED_impl(tmp)), 0)))) { |
224 | rv = tmp; |
225 | } |
226 | } |
227 | file.swap(*aResult); |
228 | return rv; |
229 | } |
230 | |
231 | nsresult nsXREDirProvider::GetUserProfilesLocalDir(nsIFile** aResult) { |
232 | nsCOMPtr<nsIFile> file; |
233 | nsresult rv = GetUserDataDirectory(getter_AddRefs(file), true); |
234 | |
235 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
236 | #if !defined(XP_UNIX1) || defined(XP_MACOSX) |
237 | rv = file->AppendNative("Profiles"_ns); |
238 | #endif |
239 | // We must create the profile directory here if it does not exist. |
240 | nsresult tmp = EnsureDirectoryExists(file); |
241 | if (NS_FAILED(tmp)((bool)(__builtin_expect(!!(NS_FAILED_impl(tmp)), 0)))) { |
242 | rv = tmp; |
Value stored to 'rv' is never read | |
243 | } |
244 | } |
245 | file.swap(*aResult); |
246 | return NS_OK; |
247 | } |
248 | |
249 | #ifdef MOZ_BACKGROUNDTASKS1 |
250 | nsresult nsXREDirProvider::GetBackgroundTasksProfilesRootDir( |
251 | nsIFile** aResult) { |
252 | nsCOMPtr<nsIFile> file; |
253 | nsresult rv = GetUserDataDirectory(getter_AddRefs(file), false); |
254 | |
255 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
256 | # if !defined(XP_UNIX1) || defined(XP_MACOSX) |
257 | // Sibling to regular user "Profiles" directory. |
258 | rv = file->AppendNative("Background Tasks Profiles"_ns); |
259 | # endif |
260 | // We must create the directory here if it does not exist. |
261 | nsresult tmp = EnsureDirectoryExists(file); |
262 | if (NS_FAILED(tmp)((bool)(__builtin_expect(!!(NS_FAILED_impl(tmp)), 0)))) { |
263 | rv = tmp; |
264 | } |
265 | } |
266 | file.swap(*aResult); |
267 | return rv; |
268 | } |
269 | #endif |
270 | |
271 | #if defined(XP_UNIX1) || defined(XP_MACOSX) |
272 | /** |
273 | * Get the directory that is the parent of the system-wide directories |
274 | * for extensions and native manifests. |
275 | * |
276 | * On OSX this is /Library/Application Support/Mozilla |
277 | * On Linux this is /usr/{lib,lib64}/mozilla |
278 | * (for 32- and 64-bit systems respsectively) |
279 | */ |
280 | static nsresult GetSystemParentDirectory(nsIFile** aFile) { |
281 | nsresult rv; |
282 | nsCOMPtr<nsIFile> localDir; |
283 | # if defined(XP_MACOSX) |
284 | rv = GetOSXFolderType(kOnSystemDisk, kApplicationSupportFolderType, |
285 | getter_AddRefs(localDir)); |
286 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
287 | rv = localDir->AppendNative("Mozilla"_ns); |
288 | } |
289 | # else |
290 | constexpr auto dirname = |
291 | # ifdef HAVE_USR_LIB64_DIR |
292 | "/usr/lib64/mozilla"_ns |
293 | # elif defined(__OpenBSD__) || defined(__FreeBSD__) |
294 | "/usr/local/lib/mozilla"_ns |
295 | # else |
296 | "/usr/lib/mozilla"_ns |
297 | # endif |
298 | ; |
299 | rv = NS_NewNativeLocalFile(dirname, false, getter_AddRefs(localDir)); |
300 | # endif |
301 | |
302 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
303 | localDir.forget(aFile); |
304 | } |
305 | return rv; |
306 | } |
307 | #endif |
308 | |
309 | NS_IMETHODIMPnsresult |
310 | nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent, |
311 | nsIFile** aFile) { |
312 | *aPersistent = true; |
313 | nsresult rv = NS_ERROR_FAILURE; |
314 | |
315 | nsCOMPtr<nsIFile> file; |
316 | |
317 | if (!strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR"ProfLD") || |
318 | !strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP"ProfLDS")) { |
319 | if (mProfileLocalDir) { |
320 | rv = mProfileLocalDir->Clone(getter_AddRefs(file)); |
321 | } else { |
322 | // Profile directories are only set up in the parent process. |
323 | // We don't expect every caller to check if they are in the right process, |
324 | // so fail immediately to avoid warning spam. |
325 | NS_WARNING_ASSERTION(!XRE_IsParentProcess(),do { if (!(!XRE_IsParentProcess())) { NS_DebugBreak(NS_DEBUG_WARNING , "tried to get profile in parent too early", "!XRE_IsParentProcess()" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 326); } } while (false) |
326 | "tried to get profile in parent too early")do { if (!(!XRE_IsParentProcess())) { NS_DebugBreak(NS_DEBUG_WARNING , "tried to get profile in parent too early", "!XRE_IsParentProcess()" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 326); } } while (false); |
327 | return NS_ERROR_FAILURE; |
328 | } |
329 | } else if (!strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR"ProfD") || |
330 | !strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP"ProfDS")) { |
331 | rv = GetProfileStartupDir(getter_AddRefs(file)); |
332 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
333 | return rv; |
334 | } |
335 | } else if (!strcmp(aProperty, NS_GRE_DIR"GreD")) { |
336 | // On Android, internal files are inside the APK, a zip file, so this |
337 | // folder doesn't really make sense. |
338 | #if !defined(MOZ_WIDGET_ANDROID) |
339 | rv = mGREDir->Clone(getter_AddRefs(file)); |
340 | #endif // !defined(MOZ_WIDGET_ANDROID) |
341 | } else if (!strcmp(aProperty, NS_GRE_BIN_DIR"GreBinD")) { |
342 | rv = mGREBinDir->Clone(getter_AddRefs(file)); |
343 | } else if (!strcmp(aProperty, NS_OS_CURRENT_PROCESS_DIR"CurProcD") || |
344 | !strcmp(aProperty, NS_APP_INSTALL_CLEANUP_DIR"XPIClnupD")) { |
345 | rv = GetAppDir()->Clone(getter_AddRefs(file)); |
346 | } else if (!strcmp(aProperty, NS_APP_PREF_DEFAULTS_50_DIR"PrfDef")) { |
347 | // Same as NS_GRE_DIR |
348 | #if !defined(MOZ_WIDGET_ANDROID) |
349 | // return the GRE default prefs directory here, and the app default prefs |
350 | // directory (if applicable) in NS_APP_PREFS_DEFAULTS_DIR_LIST. |
351 | rv = mGREDir->Clone(getter_AddRefs(file)); |
352 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 352); return rv; } } while (false); |
353 | rv = file->AppendNative("defaults"_ns); |
354 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 354); return rv; } } while (false); |
355 | rv = file->AppendNative("pref"_ns); |
356 | #endif // !defined(MOZ_WIDGET_ANDROID) |
357 | } else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_DIR"AppRegD") || |
358 | !strcmp(aProperty, XRE_USER_APP_DATA_DIR"UAppData")) { |
359 | rv = GetUserAppDataDirectory(getter_AddRefs(file)); |
360 | } |
361 | #if defined(XP_UNIX1) || defined(XP_MACOSX) |
362 | else if (!strcmp(aProperty, XRE_SYS_NATIVE_MANIFESTS"XRESysNativeManifests")) { |
363 | rv = ::GetSystemParentDirectory(getter_AddRefs(file)); |
364 | } else if (!strcmp(aProperty, XRE_USER_NATIVE_MANIFESTS"XREUserNativeManifests")) { |
365 | rv = GetUserDataDirectoryHome(getter_AddRefs(file), false); |
366 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 366); return rv; } } while (false); |
367 | # if defined(XP_MACOSX) |
368 | rv = file->AppendNative("Mozilla"_ns); |
369 | # else // defined(XP_MACOSX) |
370 | rv = file->AppendNative(".mozilla"_ns); |
371 | # endif // defined(XP_MACOSX) |
372 | } |
373 | #endif // defined(XP_UNIX) || defined(XP_MACOSX) |
374 | else if (!strcmp(aProperty, XRE_UPDATE_ROOT_DIR"UpdRootD")) { |
375 | rv = GetUpdateRootDir(getter_AddRefs(file)); |
376 | } else if (!strcmp(aProperty, XRE_OLD_UPDATE_ROOT_DIR"OldUpdRootD")) { |
377 | rv = GetUpdateRootDir(getter_AddRefs(file), true); |
378 | } else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE"AppRegF")) { |
379 | rv = GetUserAppDataDirectory(getter_AddRefs(file)); |
380 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 380); return rv; } } while (false); |
381 | rv = file->AppendNative(nsLiteralCString(APP_REGISTRY_NAME"appreg")); |
382 | } else if (!strcmp(aProperty, NS_APP_USER_PROFILES_ROOT_DIR"DefProfRt")) { |
383 | rv = GetUserProfilesRootDir(getter_AddRefs(file)); |
384 | } else if (!strcmp(aProperty, NS_APP_USER_PROFILES_LOCAL_ROOT_DIR"DefProfLRt")) { |
385 | rv = GetUserProfilesLocalDir(getter_AddRefs(file)); |
386 | } else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE"XREExeF")) { |
387 | rv = XRE_GetBinaryPath(getter_AddRefs(file)); |
388 | } |
389 | #if defined(XP_UNIX1) || defined(XP_MACOSX) |
390 | else if (!strcmp(aProperty, XRE_SYS_LOCAL_EXTENSION_PARENT_DIR"XRESysLExtPD")) { |
391 | # ifdef ENABLE_SYSTEM_EXTENSION_DIRS1 |
392 | rv = GetSystemExtensionsDirectory(getter_AddRefs(file)); |
393 | # endif |
394 | } |
395 | #endif // defined(XP_UNIX) || defined(XP_MACOSX) |
396 | #if defined(XP_UNIX1) && !defined(XP_MACOSX) |
397 | else if (!strcmp(aProperty, XRE_SYS_SHARE_EXTENSION_PARENT_DIR"XRESysSExtPD")) { |
398 | # ifdef ENABLE_SYSTEM_EXTENSION_DIRS1 |
399 | # if defined(__OpenBSD__) || defined(__FreeBSD__) |
400 | static const char* const sysLExtDir = "/usr/local/share/mozilla/extensions"; |
401 | # else |
402 | static const char* const sysLExtDir = "/usr/share/mozilla/extensions"; |
403 | # endif |
404 | rv = NS_NewNativeLocalFile(nsDependentCString(sysLExtDir), false, |
405 | getter_AddRefs(file)); |
406 | # endif |
407 | } |
408 | #endif // defined(XP_UNIX) && !defined(XP_MACOSX) |
409 | else if (!strcmp(aProperty, XRE_USER_SYS_EXTENSION_DIR"XREUSysExt")) { |
410 | #ifdef ENABLE_SYSTEM_EXTENSION_DIRS1 |
411 | rv = GetSysUserExtensionsDirectory(getter_AddRefs(file)); |
412 | #endif |
413 | } else if (!strcmp(aProperty, XRE_USER_RUNTIME_DIR"XREUserRunTimeDir")) { |
414 | #if defined(XP_UNIX1) |
415 | nsPrintfCString path("/run/user/%d/%s/", getuid(), GetAppName()); |
416 | ToLowerCase(path); |
417 | rv = NS_NewNativeLocalFile(path, false, getter_AddRefs(file)); |
418 | #endif |
419 | } else if (!strcmp(aProperty, XRE_APP_DISTRIBUTION_DIR"XREAppDist")) { |
420 | bool persistent = false; |
421 | rv = GetFile(NS_GRE_DIR"GreD", &persistent, getter_AddRefs(file)); |
422 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 422); return rv; } } while (false); |
423 | rv = file->AppendNative("distribution"_ns); |
424 | } else if (!strcmp(aProperty, XRE_APP_FEATURES_DIR"XREAppFeat")) { |
425 | rv = GetAppDir()->Clone(getter_AddRefs(file)); |
426 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 426); return rv; } } while (false); |
427 | rv = file->AppendNative("features"_ns); |
428 | } else if (!strcmp(aProperty, XRE_ADDON_APP_DIR"XREAddonAppDir")) { |
429 | nsCOMPtr<nsIDirectoryServiceProvider> dirsvc( |
430 | do_GetService("@mozilla.org/file/directory_service;1", &rv)); |
431 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 431); return rv; } } while (false); |
432 | bool unused; |
433 | rv = dirsvc->GetFile("XCurProcD", &unused, getter_AddRefs(file)); |
434 | } else if (!strcmp(aProperty, NS_APP_USER_CHROME_DIR"UChrm")) { |
435 | // It isn't clear why this uses GetProfileStartupDir instead of |
436 | // GetProfileDir. It could theoretically matter in a non-main |
437 | // process where some other directory provider has defined |
438 | // NS_APP_USER_PROFILE_50_DIR. In that scenario, using |
439 | // GetProfileStartupDir means this will fail instead of succeed. |
440 | rv = GetProfileStartupDir(getter_AddRefs(file)); |
441 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
442 | return rv; |
443 | } |
444 | rv = file->AppendNative("chrome"_ns); |
445 | } else if (!strcmp(aProperty, NS_APP_PREFS_50_DIR"PrefD")) { |
446 | rv = GetProfileDir(getter_AddRefs(file)); |
447 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
448 | return rv; |
449 | } |
450 | } else if (!strcmp(aProperty, NS_APP_PREFS_50_FILE"PrefF")) { |
451 | rv = GetProfileDir(getter_AddRefs(file)); |
452 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
453 | return rv; |
454 | } |
455 | rv = file->AppendNative("prefs.js"_ns); |
456 | } else if (!strcmp(aProperty, NS_APP_PREFS_OVERRIDE_DIR"PrefDOverride")) { |
457 | rv = GetProfileDir(getter_AddRefs(file)); |
458 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
459 | return rv; |
460 | } |
461 | rv = file->AppendNative(nsLiteralCString(PREF_OVERRIDE_DIRNAME"preferences")); |
462 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 462); return rv; } } while (false); |
463 | rv = EnsureDirectoryExists(file); |
464 | } else { |
465 | // We don't know anything about this property. Fail without warning, because |
466 | // otherwise we'll get too much warning spam due to |
467 | // nsDirectoryService::Get() trying everything it gets with every provider. |
468 | return NS_ERROR_FAILURE; |
469 | } |
470 | |
471 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 471); return rv; } } while (false); |
472 | NS_ENSURE_TRUE(file, NS_ERROR_FAILURE)do { if ((__builtin_expect(!!(!(file)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "file" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 472); return NS_ERROR_FAILURE; } } while (false); |
473 | |
474 | file.forget(aFile); |
475 | return NS_OK; |
476 | } |
477 | |
478 | static void LoadDirIntoArray(nsIFile* dir, const char* const* aAppendList, |
479 | nsCOMArray<nsIFile>& aDirectories) { |
480 | if (!dir) return; |
481 | |
482 | nsCOMPtr<nsIFile> subdir; |
483 | dir->Clone(getter_AddRefs(subdir)); |
484 | if (!subdir) return; |
485 | |
486 | for (const char* const* a = aAppendList; *a; ++a) { |
487 | subdir->AppendNative(nsDependentCString(*a)); |
488 | } |
489 | |
490 | bool exists; |
491 | if (NS_SUCCEEDED(subdir->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(subdir->Exists (&exists))), 1))) && exists) { |
492 | aDirectories.AppendObject(subdir); |
493 | } |
494 | } |
495 | |
496 | static const char* const kAppendPrefDir[] = {"defaults", "preferences", |
497 | nullptr}; |
498 | #ifdef MOZ_BACKGROUNDTASKS1 |
499 | static const char* const kAppendBackgroundTasksPrefDir[] = { |
500 | "defaults", "backgroundtasks", nullptr}; |
501 | #endif |
502 | |
503 | NS_IMETHODIMPnsresult |
504 | nsXREDirProvider::GetFiles(const char* aProperty, |
505 | nsISimpleEnumerator** aResult) { |
506 | nsresult rv = NS_ERROR_FAILURE; |
507 | *aResult = nullptr; |
508 | |
509 | if (!strcmp(aProperty, NS_APP_PREFS_DEFAULTS_DIR_LIST"PrefDL")) { |
510 | nsCOMArray<nsIFile> directories; |
511 | |
512 | LoadDirIntoArray(mXULAppDir, kAppendPrefDir, directories); |
513 | #ifdef MOZ_BACKGROUNDTASKS1 |
514 | if (mozilla::BackgroundTasks::IsBackgroundTaskMode()) { |
515 | LoadDirIntoArray(mGREDir, kAppendBackgroundTasksPrefDir, directories); |
516 | LoadDirIntoArray(mXULAppDir, kAppendBackgroundTasksPrefDir, directories); |
517 | } |
518 | #endif |
519 | |
520 | rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile)(nsIFile::COMTypeInfo<nsIFile, void>::kIID)); |
521 | } else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST"AChromDL")) { |
522 | // NS_APP_CHROME_DIR_LIST is only used to get default (native) icons |
523 | // for OS window decoration. |
524 | |
525 | static const char* const kAppendChromeDir[] = {"chrome", nullptr}; |
526 | nsCOMArray<nsIFile> directories; |
527 | LoadDirIntoArray(mXULAppDir, kAppendChromeDir, directories); |
528 | |
529 | rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile)(nsIFile::COMTypeInfo<nsIFile, void>::kIID)); |
530 | } |
531 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 531); return rv; } } while (false); |
532 | |
533 | return NS_SUCCESS_AGGREGATE_RESULT; |
534 | } |
535 | |
536 | NS_IMETHODIMPnsresult |
537 | nsXREDirProvider::GetDirectory(nsIFile** aResult) { |
538 | NS_ENSURE_TRUE(mProfileDir, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(mProfileDir)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "mProfileDir" ") failed" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 538); return NS_ERROR_NOT_INITIALIZED; } } while (false); |
539 | return mProfileDir->Clone(aResult); |
540 | } |
541 | |
542 | void nsXREDirProvider::InitializeUserPrefs() { |
543 | if (!mPrefsInitialized) { |
544 | mozilla::Preferences::InitializeUserPrefs(); |
545 | } |
546 | } |
547 | |
548 | void nsXREDirProvider::FinishInitializingUserPrefs() { |
549 | if (!mPrefsInitialized) { |
550 | mozilla::Preferences::FinishInitializingUserPrefs(); |
551 | mPrefsInitialized = true; |
552 | } |
553 | } |
554 | |
555 | NS_IMETHODIMPnsresult |
556 | nsXREDirProvider::DoStartup() { |
557 | nsresult rv; |
558 | |
559 | if (!mAppStarted) { |
560 | nsCOMPtr<nsIObserverService> obsSvc = |
561 | mozilla::services::GetObserverService(); |
562 | if (!obsSvc) return NS_ERROR_FAILURE; |
563 | |
564 | mAppStarted = true; |
565 | |
566 | /* |
567 | Make sure we've setup prefs before profile-do-change to be able to use |
568 | them to track crashes and because we want to begin crash tracking before |
569 | other code run from this notification since they may cause crashes. |
570 | */ |
571 | MOZ_ASSERT(mPrefsInitialized)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mPrefsInitialized)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mPrefsInitialized))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mPrefsInitialized" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 571); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPrefsInitialized" ")"); do { *((volatile int*)__null) = 571; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
572 | |
573 | bool safeModeNecessary = false; |
574 | nsCOMPtr<nsIAppStartup> appStartup( |
575 | mozilla::components::AppStartup::Service()); |
576 | if (appStartup) { |
577 | rv = appStartup->TrackStartupCrashBegin(&safeModeNecessary); |
578 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && rv != NS_ERROR_NOT_AVAILABLE) |
579 | NS_WARNING("Error while beginning startup crash tracking")NS_DebugBreak(NS_DEBUG_WARNING, "Error while beginning startup crash tracking" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 579); |
580 | |
581 | if (!gSafeMode && safeModeNecessary) { |
582 | appStartup->RestartInSafeMode(nsIAppStartup::eForceQuit); |
583 | return NS_OK; |
584 | } |
585 | } |
586 | |
587 | static const char16_t kStartup[] = {'s', 't', 'a', 'r', |
588 | 't', 'u', 'p', '\0'}; |
589 | obsSvc->NotifyObservers(nullptr, "profile-do-change", kStartup); |
590 | |
591 | // Initialize the Enterprise Policies service in the parent process |
592 | // In the content process it's loaded on demand when needed |
593 | if (XRE_IsParentProcess()) { |
594 | nsCOMPtr<nsIObserver> policies( |
595 | do_GetService("@mozilla.org/enterprisepolicies;1")); |
596 | if (policies) { |
597 | policies->Observe(nullptr, "policies-startup", nullptr); |
598 | } |
599 | } |
600 | |
601 | #ifdef MOZ_THUNDERBIRD |
602 | bool bgtaskMode = false; |
603 | # ifdef MOZ_BACKGROUNDTASKS1 |
604 | bgtaskMode = mozilla::BackgroundTasks::IsBackgroundTaskMode(); |
605 | # endif |
606 | if (!bgtaskMode && |
607 | mozilla::Preferences::GetBool( |
608 | "security.prompt_for_master_password_on_startup", false)) { |
609 | # ifdef XP_MACOSX |
610 | // Ensure the application is initialized before the prompt is triggered. |
611 | // Note: calling InitializeMacApp more than once does nothing. |
612 | InitializeMacApp(); |
613 | # endif |
614 | // Prompt for the master password prior to opening application windows, |
615 | // to avoid the race that triggers multiple prompts (see bug 177175). |
616 | // We use this code until we have a better solution, possibly as |
617 | // described in bug 177175 comment 384. |
618 | nsCOMPtr<nsIPK11TokenDB> db = |
619 | do_GetService("@mozilla.org/security/pk11tokendb;1"); |
620 | if (db) { |
621 | nsCOMPtr<nsIPK11Token> token; |
622 | if (NS_SUCCEEDED(db->GetInternalKeyToken(getter_AddRefs(token)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(db->GetInternalKeyToken (getter_AddRefs(token)))), 1)))) { |
623 | mozilla::Unused << token->Login(false); |
624 | } |
625 | } else { |
626 | NS_WARNING("Failed to get nsIPK11TokenDB service.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to get nsIPK11TokenDB service." , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 626); |
627 | } |
628 | } |
629 | #endif |
630 | |
631 | bool initExtensionManager = |
632 | #ifdef MOZ_BACKGROUNDTASKS1 |
633 | !mozilla::BackgroundTasks::IsBackgroundTaskMode(); |
634 | #else |
635 | true; |
636 | #endif |
637 | if (initExtensionManager) { |
638 | // Init the Extension Manager |
639 | nsCOMPtr<nsIObserver> em = |
640 | do_GetService("@mozilla.org/addons/integration;1"); |
641 | if (em) { |
642 | em->Observe(nullptr, "addons-startup", nullptr); |
643 | } else { |
644 | NS_WARNING("Failed to create Addons Manager.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to create Addons Manager." , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 644); |
645 | } |
646 | } |
647 | |
648 | obsSvc->NotifyObservers(nullptr, "profile-after-change", kStartup); |
649 | |
650 | // Any component that has registered for the profile-after-change category |
651 | // should also be created at this time. |
652 | (void)NS_CreateServicesFromCategory("profile-after-change", nullptr, |
653 | "profile-after-change"); |
654 | |
655 | if (gSafeMode && safeModeNecessary) { |
656 | static const char16_t kCrashed[] = {'c', 'r', 'a', 's', |
657 | 'h', 'e', 'd', '\0'}; |
658 | obsSvc->NotifyObservers(nullptr, "safemode-forced", kCrashed); |
659 | } |
660 | |
661 | // 1 = Regular mode, 2 = Safe mode, 3 = Safe mode forced |
662 | int mode = 1; |
663 | if (gSafeMode) { |
664 | if (safeModeNecessary) |
665 | mode = 3; |
666 | else |
667 | mode = 2; |
668 | } |
669 | mozilla::Telemetry::Accumulate(mozilla::Telemetry::SAFE_MODE_USAGE, mode); |
670 | |
671 | obsSvc->NotifyObservers(nullptr, "profile-initial-state", nullptr); |
672 | } |
673 | return NS_OK; |
674 | } |
675 | |
676 | void nsXREDirProvider::DoShutdown() { |
677 | AUTO_PROFILER_LABEL("nsXREDirProvider::DoShutdown", OTHER)mozilla::AutoProfilerLabel raiiObject677( "nsXREDirProvider::DoShutdown" , nullptr, JS::ProfilingCategoryPair::OTHER); |
678 | |
679 | if (mAppStarted) { |
680 | mozilla::AppShutdown::AdvanceShutdownPhase( |
681 | mozilla::ShutdownPhase::AppShutdownNetTeardown, nullptr); |
682 | mozilla::AppShutdown::AdvanceShutdownPhase( |
683 | mozilla::ShutdownPhase::AppShutdownTeardown, nullptr); |
684 | |
685 | #ifdef DEBUG1 |
686 | // Not having this causes large intermittent leaks. See bug 1340425. |
687 | if (JSContext* cx = mozilla::dom::danger::GetJSContext()) { |
688 | JS_GC(cx); |
689 | } |
690 | #endif |
691 | |
692 | mozilla::AppShutdown::AdvanceShutdownPhase( |
693 | mozilla::ShutdownPhase::AppShutdown, nullptr); |
694 | mozilla::AppShutdown::AdvanceShutdownPhase( |
695 | mozilla::ShutdownPhase::AppShutdownQM, nullptr); |
696 | mozilla::AppShutdown::AdvanceShutdownPhase( |
697 | mozilla::ShutdownPhase::AppShutdownTelemetry, nullptr); |
698 | mAppStarted = false; |
699 | } |
700 | |
701 | gDataDirProfileLocal = nullptr; |
702 | gDataDirProfile = nullptr; |
703 | } |
704 | |
705 | #ifdef XP_WIN |
706 | static nsresult GetShellFolderPath(KNOWNFOLDERID folder, nsAString& _retval) { |
707 | DWORD flags = KF_FLAG_SIMPLE_IDLIST | KF_FLAG_DONT_VERIFY | KF_FLAG_NO_ALIAS; |
708 | PWSTR path = nullptr; |
709 | |
710 | if (!SUCCEEDED(SHGetKnownFolderPath(folder, flags, NULL__null, &path))) { |
711 | return NS_ERROR_NOT_AVAILABLE; |
712 | } |
713 | |
714 | _retval = nsDependentString(path); |
715 | CoTaskMemFree(path); |
716 | return NS_OK; |
717 | } |
718 | |
719 | /** |
720 | * Provides a fallback for getting the path to APPDATA or LOCALAPPDATA by |
721 | * querying the registry when the call to SHGetSpecialFolderLocation or |
722 | * SHGetPathFromIDListW is unable to provide these paths (Bug 513958). |
723 | */ |
724 | static nsresult GetRegWindowsAppDataFolder(bool aLocal, nsAString& _retval) { |
725 | HKEY key; |
726 | LPCWSTR keyName = |
727 | L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; |
728 | DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName, 0, KEY_READ, &key); |
729 | if (res != ERROR_SUCCESS) { |
730 | _retval.SetLength(0); |
731 | return NS_ERROR_NOT_AVAILABLE; |
732 | } |
733 | |
734 | DWORD type, size; |
735 | res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"), nullptr, |
736 | &type, nullptr, &size); |
737 | // The call to RegQueryValueExW must succeed, the type must be REG_SZ, the |
738 | // buffer size must not equal 0, and the buffer size be a multiple of 2. |
739 | if (res != ERROR_SUCCESS || type != REG_SZ || size == 0 || size % 2 != 0) { |
740 | ::RegCloseKey(key); |
741 | _retval.SetLength(0); |
742 | return NS_ERROR_NOT_AVAILABLE; |
743 | } |
744 | |
745 | // |size| may or may not include room for the terminating null character |
746 | DWORD resultLen = size / 2; |
747 | |
748 | if (!_retval.SetLength(resultLen, mozilla::fallible)) { |
749 | ::RegCloseKey(key); |
750 | _retval.SetLength(0); |
751 | return NS_ERROR_NOT_AVAILABLE; |
752 | } |
753 | |
754 | auto begin = _retval.BeginWriting(); |
755 | |
756 | res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"), nullptr, |
757 | nullptr, (LPBYTE)begin, &size); |
758 | ::RegCloseKey(key); |
759 | if (res != ERROR_SUCCESS) { |
760 | _retval.SetLength(0); |
761 | return NS_ERROR_NOT_AVAILABLE; |
762 | } |
763 | |
764 | if (!_retval.CharAt(resultLen - 1)) { |
765 | // It was already null terminated. |
766 | _retval.Truncate(resultLen - 1); |
767 | } |
768 | |
769 | return NS_OK; |
770 | } |
771 | #endif |
772 | |
773 | static nsresult HashInstallPath(nsAString& aInstallPath, nsAString& aPathHash) { |
774 | mozilla::UniquePtr<NS_tchar[]> hash; |
775 | bool success = ::GetInstallHash(PromiseFlatStringTPromiseFlatString<char16_t>(aInstallPath).get(), hash); |
776 | if (!success) { |
777 | return NS_ERROR_FAILURE; |
778 | } |
779 | |
780 | // The hash string is a NS_tchar*, which is wchar* in Windows and char* |
781 | // elsewhere. |
782 | #ifdef XP_WIN |
783 | aPathHash.Assign(hash.get()); |
784 | #else |
785 | aPathHash.AssignASCII(hash.get()); |
786 | #endif |
787 | return NS_OK; |
788 | } |
789 | |
790 | /** |
791 | * Gets a hash of the installation directory. |
792 | */ |
793 | nsresult nsXREDirProvider::GetInstallHash(nsAString& aPathHash) { |
794 | nsAutoString stringToHash; |
795 | |
796 | #ifdef XP_WIN |
797 | if (mozilla::widget::WinUtils::HasPackageIdentity()) { |
798 | // For packages, the install path includes the version number, so it isn't |
799 | // a stable or consistent identifier for the installation. The package |
800 | // family name is though, so use that instead of the path. |
801 | stringToHash = mozilla::widget::WinUtils::GetPackageFamilyName(); |
802 | } else |
803 | #endif |
804 | { |
805 | nsCOMPtr<nsIFile> installDir; |
806 | nsCOMPtr<nsIFile> appFile; |
807 | bool per = false; |
808 | nsresult rv = GetFile(XRE_EXECUTABLE_FILE"XREExeF", &per, getter_AddRefs(appFile)); |
809 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 809); return rv; } } while (false); |
810 | rv = appFile->GetParent(getter_AddRefs(installDir)); |
811 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 811); return rv; } } while (false); |
812 | |
813 | // It is possible that the path we have is on a case insensitive |
814 | // filesystem in which case the path may vary depending on how the |
815 | // application is called. We want to normalize the case somehow. |
816 | #ifdef XP_WIN |
817 | // Windows provides a way to get the correct case. |
818 | if (!mozilla::widget::WinUtils::ResolveJunctionPointsAndSymLinks( |
819 | installDir)) { |
820 | NS_WARNING("Failed to resolve install directory.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to resolve install directory." , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 820); |
821 | } |
822 | #elif defined(MOZ_WIDGET_COCOA) |
823 | // On OSX roundtripping through an FSRef fixes the case. |
824 | FSRef ref; |
825 | nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(installDir); |
826 | rv = macFile->GetFSRef(&ref); |
827 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 827); return rv; } } while (false); |
828 | rv = NS_NewLocalFileWithFSRef(&ref, true, getter_AddRefs(macFile)); |
829 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 829); return rv; } } while (false); |
830 | installDir = static_cast<nsIFile*>(macFile); |
831 | #endif |
832 | // On linux XRE_EXECUTABLE_FILE already seems to be set to the correct path. |
833 | |
834 | rv = installDir->GetPath(stringToHash); |
835 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 835); return rv; } } while (false); |
836 | } |
837 | |
838 | // If we somehow failed to get an actual value, hashing an empty string could |
839 | // potentially cause some serious problems given all the things this hash is |
840 | // used for. So we don't allow that. |
841 | if (stringToHash.IsEmpty()) { |
842 | return NS_ERROR_FAILURE; |
843 | } |
844 | |
845 | return HashInstallPath(stringToHash, aPathHash); |
846 | } |
847 | |
848 | /** |
849 | * Before bug 1555319 the directory hashed can have had an incorrect case. |
850 | * Access to that hash is still available through this function. It is needed so |
851 | * we can migrate users who may have an incorrect hash in profiles.ini. This |
852 | * support can probably be removed in a few releases time. |
853 | */ |
854 | nsresult nsXREDirProvider::GetLegacyInstallHash(nsAString& aPathHash) { |
855 | nsCOMPtr<nsIFile> installDir; |
856 | nsCOMPtr<nsIFile> appFile; |
857 | bool per = false; |
858 | nsresult rv = GetFile(XRE_EXECUTABLE_FILE"XREExeF", &per, getter_AddRefs(appFile)); |
859 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 859); return rv; } } while (false); |
860 | rv = appFile->GetParent(getter_AddRefs(installDir)); |
861 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 861); return rv; } } while (false); |
862 | |
863 | nsAutoString installPath; |
864 | rv = installDir->GetPath(installPath); |
865 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 865); return rv; } } while (false); |
866 | |
867 | #ifdef XP_WIN |
868 | # if defined(MOZ_THUNDERBIRD) || defined(MOZ_SUITE) |
869 | // Convert a 64-bit install path to what would have been the 32-bit install |
870 | // path to allow users to migrate their profiles from one to the other. |
871 | PWSTR pathX86 = nullptr; |
872 | HRESULT hres = |
873 | SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, 0, nullptr, &pathX86); |
874 | if (SUCCEEDED(hres)) { |
875 | nsDependentString strPathX86(pathX86); |
876 | if (!StringBeginsWith(installPath, strPathX86, |
877 | nsCaseInsensitiveStringComparator)) { |
878 | PWSTR path = nullptr; |
879 | hres = SHGetKnownFolderPath(FOLDERID_ProgramFiles, 0, nullptr, &path); |
880 | if (SUCCEEDED(hres)) { |
881 | if (StringBeginsWith(installPath, nsDependentString(path), |
882 | nsCaseInsensitiveStringComparator)) { |
883 | installPath.Replace(0, wcslen(path), strPathX86); |
884 | } |
885 | } |
886 | CoTaskMemFree(path); |
887 | } |
888 | } |
889 | CoTaskMemFree(pathX86); |
890 | # endif |
891 | #endif |
892 | return HashInstallPath(installPath, aPathHash); |
893 | } |
894 | |
895 | nsresult nsXREDirProvider::GetUpdateRootDir(nsIFile** aResult, |
896 | bool aGetOldLocation) { |
897 | #ifndef XP_WIN |
898 | // There is no old update location on platforms other than Windows. Windows is |
899 | // the only platform for which we migrated the update directory. |
900 | if (aGetOldLocation) { |
901 | return NS_ERROR_NOT_IMPLEMENTED; |
902 | } |
903 | #endif |
904 | nsCOMPtr<nsIFile> updRoot; |
905 | nsCOMPtr<nsIFile> appFile; |
906 | bool per = false; |
907 | nsresult rv = GetFile(XRE_EXECUTABLE_FILE"XREExeF", &per, getter_AddRefs(appFile)); |
908 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 908); return rv; } } while (false); |
909 | rv = appFile->GetParent(getter_AddRefs(updRoot)); |
910 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 910); return rv; } } while (false); |
911 | |
912 | #ifdef XP_MACOSX |
913 | nsCOMPtr<nsIFile> appRootDirFile; |
914 | nsCOMPtr<nsIFile> localDir; |
915 | nsAutoString appDirPath; |
916 | if (NS_FAILED(appFile->GetParent(getter_AddRefs(appRootDirFile)))((bool)(__builtin_expect(!!(NS_FAILED_impl(appFile->GetParent (getter_AddRefs(appRootDirFile)))), 0))) || |
917 | NS_FAILED(appRootDirFile->GetPath(appDirPath))((bool)(__builtin_expect(!!(NS_FAILED_impl(appRootDirFile-> GetPath(appDirPath))), 0))) || |
918 | NS_FAILED(GetUserDataDirectoryHome(getter_AddRefs(localDir), true))((bool)(__builtin_expect(!!(NS_FAILED_impl(GetUserDataDirectoryHome (getter_AddRefs(localDir), true))), 0)))) { |
919 | return NS_ERROR_FAILURE; |
920 | } |
921 | |
922 | int32_t dotIndex = appDirPath.RFind(u".app"); |
923 | if (dotIndex == kNotFound) { |
924 | dotIndex = appDirPath.Length(); |
925 | } |
926 | appDirPath = Substring(appDirPath, 1, dotIndex - 1); |
927 | |
928 | bool hasVendor = GetAppVendor() && strlen(GetAppVendor()) != 0; |
929 | if (hasVendor || GetAppName()) { |
930 | if (NS_FAILED(localDir->AppendNative(((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->AppendNative ( nsDependentCString(hasVendor ? GetAppVendor() : GetAppName( ))))), 0))) |
931 | nsDependentCString(hasVendor ? GetAppVendor() : GetAppName())))((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->AppendNative ( nsDependentCString(hasVendor ? GetAppVendor() : GetAppName( ))))), 0)))) { |
932 | return NS_ERROR_FAILURE; |
933 | } |
934 | } else if (NS_FAILED(localDir->AppendNative("Mozilla"_ns))((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->AppendNative ("Mozilla"_ns))), 0)))) { |
935 | return NS_ERROR_FAILURE; |
936 | } |
937 | |
938 | if (NS_FAILED(localDir->Append(u"updates"_ns))((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->Append (u"updates"_ns))), 0))) || |
939 | NS_FAILED(localDir->AppendRelativePath(appDirPath))((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->AppendRelativePath (appDirPath))), 0)))) { |
940 | return NS_ERROR_FAILURE; |
941 | } |
942 | |
943 | localDir.forget(aResult); |
944 | return NS_OK; |
945 | |
946 | #elif XP_WIN |
947 | nsAutoString installPath; |
948 | rv = updRoot->GetPath(installPath); |
949 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 949); return rv; } } while (false); |
950 | |
951 | mozilla::UniquePtr<wchar_t[]> updatePath; |
952 | HRESULT hrv; |
953 | if (aGetOldLocation) { |
954 | hrv = |
955 | GetOldUpdateDirectory(PromiseFlatStringTPromiseFlatString<char16_t>(installPath).get(), updatePath); |
956 | } else { |
957 | hrv = GetCommonUpdateDirectory(PromiseFlatStringTPromiseFlatString<char16_t>(installPath).get(), |
958 | updatePath); |
959 | } |
960 | if (FAILED(hrv)) { |
961 | return NS_ERROR_FAILURE; |
962 | } |
963 | nsAutoString updatePathStr; |
964 | updatePathStr.Assign(updatePath.get()); |
965 | updRoot->InitWithPath(updatePathStr); |
966 | updRoot.forget(aResult); |
967 | return NS_OK; |
968 | #else |
969 | updRoot.forget(aResult); |
970 | return NS_OK; |
971 | #endif // XP_WIN |
972 | } |
973 | |
974 | nsresult nsXREDirProvider::GetProfileStartupDir(nsIFile** aResult) { |
975 | if (mProfileDir) { |
976 | return mProfileDir->Clone(aResult); |
977 | } |
978 | |
979 | // Profile directories are only set up in the parent process. |
980 | // We don't expect every caller to check if they are in the right process, |
981 | // so fail immediately to avoid warning spam. |
982 | NS_WARNING_ASSERTION(!XRE_IsParentProcess(),do { if (!(!XRE_IsParentProcess())) { NS_DebugBreak(NS_DEBUG_WARNING , "tried to get profile in parent too early", "!XRE_IsParentProcess()" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 983); } } while (false) |
983 | "tried to get profile in parent too early")do { if (!(!XRE_IsParentProcess())) { NS_DebugBreak(NS_DEBUG_WARNING , "tried to get profile in parent too early", "!XRE_IsParentProcess()" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 983); } } while (false); |
984 | return NS_ERROR_FAILURE; |
985 | } |
986 | |
987 | nsresult nsXREDirProvider::GetProfileDir(nsIFile** aResult) { |
988 | if (!mProfileDir) { |
989 | nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR"ProfD", |
990 | getter_AddRefs(mProfileDir)); |
991 | // Guard against potential buggy directory providers that fail while also |
992 | // returning something. |
993 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
994 | MOZ_ASSERT(!mProfileDir,do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mProfileDir)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mProfileDir))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mProfileDir" " (" "Directory provider failed but returned a value" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 995); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mProfileDir" ") (" "Directory provider failed but returned a value" ")"); do { *((volatile int*)__null) = 995; __attribute__((nomerge) ) ::abort(); } while (false); } } while (false) |
995 | "Directory provider failed but returned a value")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mProfileDir)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mProfileDir))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mProfileDir" " (" "Directory provider failed but returned a value" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 995); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mProfileDir" ") (" "Directory provider failed but returned a value" ")"); do { *((volatile int*)__null) = 995; __attribute__((nomerge) ) ::abort(); } while (false); } } while (false); |
996 | mProfileDir = nullptr; |
997 | } |
998 | } |
999 | // If we failed to get mProfileDir, this will warn for us if appropriate. |
1000 | return GetProfileStartupDir(aResult); |
1001 | } |
1002 | |
1003 | NS_IMETHODIMPnsresult |
1004 | nsXREDirProvider::SetUserDataDirectory(nsIFile* aFile, bool aLocal) { |
1005 | if (aLocal) { |
1006 | NS_IF_RELEASE(gDataDirHomeLocal)do { if (gDataDirHomeLocal) { (gDataDirHomeLocal)->Release (); (gDataDirHomeLocal) = 0; } } while (0); |
1007 | NS_IF_ADDREF(gDataDirHomeLocal = aFile)ns_if_addref(gDataDirHomeLocal = aFile); |
1008 | } else { |
1009 | NS_IF_RELEASE(gDataDirHome)do { if (gDataDirHome) { (gDataDirHome)->Release(); (gDataDirHome ) = 0; } } while (0); |
1010 | NS_IF_ADDREF(gDataDirHome = aFile)ns_if_addref(gDataDirHome = aFile); |
1011 | } |
1012 | |
1013 | return NS_OK; |
1014 | } |
1015 | |
1016 | /* static */ |
1017 | nsresult nsXREDirProvider::SetUserDataProfileDirectory(nsCOMPtr<nsIFile>& aFile, |
1018 | bool aLocal) { |
1019 | if (aLocal) { |
1020 | gDataDirProfileLocal = aFile; |
1021 | } else { |
1022 | gDataDirProfile = aFile; |
1023 | } |
1024 | |
1025 | return NS_OK; |
1026 | } |
1027 | |
1028 | nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, |
1029 | bool aLocal) { |
1030 | // Copied from nsAppFileLocationProvider (more or less) |
1031 | nsresult rv; |
1032 | nsCOMPtr<nsIFile> localDir; |
1033 | |
1034 | if (aLocal && gDataDirHomeLocal) { |
1035 | return gDataDirHomeLocal->Clone(aFile); |
1036 | } |
1037 | if (!aLocal && gDataDirHome) { |
1038 | return gDataDirHome->Clone(aFile); |
1039 | } |
1040 | |
1041 | #if defined(XP_MACOSX) |
1042 | FSRef fsRef; |
1043 | OSType folderType; |
1044 | if (aLocal) { |
1045 | folderType = kCachedDataFolderType; |
1046 | } else { |
1047 | # ifdef MOZ_THUNDERBIRD |
1048 | folderType = kDomainLibraryFolderType; |
1049 | # else |
1050 | folderType = kApplicationSupportFolderType; |
1051 | # endif |
1052 | } |
1053 | OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef); |
1054 | NS_ENSURE_FALSE(err, NS_ERROR_FAILURE)do { if ((__builtin_expect(!!(!(!(err))), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "!(err)" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1054); return NS_ERROR_FAILURE; } } while (false); |
1055 | |
1056 | rv = NS_NewNativeLocalFile(""_ns, true, getter_AddRefs(localDir)); |
1057 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1057); return rv; } } while (false); |
1058 | |
1059 | nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir); |
1060 | NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(dirFileMac)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "dirFileMac" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1060); return NS_ERROR_UNEXPECTED; } } while (false); |
1061 | |
1062 | rv = dirFileMac->InitWithFSRef(&fsRef); |
1063 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1063); return rv; } } while (false); |
1064 | |
1065 | localDir = dirFileMac; |
1066 | #elif defined(XP_IOS) |
1067 | nsAutoCString userDir; |
1068 | if (GetUIKitDirectory(aLocal, userDir)) { |
1069 | rv = NS_NewNativeLocalFile(userDir, true, getter_AddRefs(localDir)); |
1070 | } else { |
1071 | rv = NS_ERROR_FAILURE; |
1072 | } |
1073 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1073); return rv; } } while (false); |
1074 | #elif defined(XP_WIN) |
1075 | nsString path; |
1076 | if (aLocal) { |
1077 | rv = GetShellFolderPath(FOLDERID_LocalAppData, path); |
1078 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) rv = GetRegWindowsAppDataFolder(aLocal, path); |
1079 | } |
1080 | if (!aLocal || NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1081 | rv = GetShellFolderPath(FOLDERID_RoamingAppData, path); |
1082 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1083 | if (!aLocal) rv = GetRegWindowsAppDataFolder(aLocal, path); |
1084 | } |
1085 | } |
1086 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1086); return rv; } } while (false); |
1087 | |
1088 | rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir)); |
1089 | #elif defined(XP_UNIX1) |
1090 | const char* homeDir = getenv("HOME"); |
1091 | if (!homeDir || !*homeDir) return NS_ERROR_FAILURE; |
1092 | |
1093 | # ifdef ANDROID /* We want (ProfD == ProfLD) on Android. */ |
1094 | aLocal = false; |
1095 | # endif |
1096 | |
1097 | if (aLocal) { |
1098 | // If $XDG_CACHE_HOME is defined use it, otherwise use $HOME/.cache. |
1099 | const char* cacheHome = getenv("XDG_CACHE_HOME"); |
1100 | if (cacheHome && *cacheHome) { |
1101 | rv = NS_NewNativeLocalFile(nsDependentCString(cacheHome), true, |
1102 | getter_AddRefs(localDir)); |
1103 | } else { |
1104 | rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true, |
1105 | getter_AddRefs(localDir)); |
1106 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) rv = localDir->AppendNative(".cache"_ns); |
1107 | } |
1108 | } else { |
1109 | rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true, |
1110 | getter_AddRefs(localDir)); |
1111 | } |
1112 | #else |
1113 | # error "Don't know how to get product dir on your platform" |
1114 | #endif |
1115 | |
1116 | NS_IF_ADDREF(*aFile = localDir)ns_if_addref(*aFile = localDir); |
1117 | return rv; |
1118 | } |
1119 | |
1120 | nsresult nsXREDirProvider::GetSysUserExtensionsDirectory(nsIFile** aFile) { |
1121 | nsCOMPtr<nsIFile> localDir; |
1122 | nsresult rv = GetUserDataDirectoryHome(getter_AddRefs(localDir), false); |
1123 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1123); return rv; } } while (false); |
1124 | |
1125 | rv = AppendSysUserExtensionPath(localDir); |
1126 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1126); return rv; } } while (false); |
1127 | |
1128 | rv = EnsureDirectoryExists(localDir); |
1129 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1129); return rv; } } while (false); |
1130 | |
1131 | localDir.forget(aFile); |
1132 | return NS_OK; |
1133 | } |
1134 | |
1135 | #if defined(XP_UNIX1) || defined(XP_MACOSX) |
1136 | nsresult nsXREDirProvider::GetSystemExtensionsDirectory(nsIFile** aFile) { |
1137 | nsresult rv; |
1138 | nsCOMPtr<nsIFile> localDir; |
1139 | |
1140 | rv = GetSystemParentDirectory(getter_AddRefs(localDir)); |
1141 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
1142 | constexpr auto sExtensions = |
1143 | # if defined(XP_MACOSX) |
1144 | "Extensions"_ns |
1145 | # else |
1146 | "extensions"_ns |
1147 | # endif |
1148 | ; |
1149 | |
1150 | rv = localDir->AppendNative(sExtensions); |
1151 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
1152 | localDir.forget(aFile); |
1153 | } |
1154 | } |
1155 | return rv; |
1156 | } |
1157 | #endif |
1158 | |
1159 | nsresult nsXREDirProvider::GetUserDataDirectory(nsIFile** aFile, bool aLocal) { |
1160 | nsCOMPtr<nsIFile> localDir; |
1161 | |
1162 | if (aLocal && gDataDirProfileLocal) { |
1163 | return gDataDirProfileLocal->Clone(aFile); |
1164 | } |
1165 | if (!aLocal && gDataDirProfile) { |
1166 | return gDataDirProfile->Clone(aFile); |
1167 | } |
1168 | |
1169 | nsresult rv = GetUserDataDirectoryHome(getter_AddRefs(localDir), aLocal); |
1170 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1170); return rv; } } while (false); |
1171 | |
1172 | rv = AppendProfilePath(localDir, aLocal); |
1173 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1173); return rv; } } while (false); |
1174 | |
1175 | rv = EnsureDirectoryExists(localDir); |
1176 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1176); return rv; } } while (false); |
1177 | |
1178 | nsXREDirProvider::SetUserDataProfileDirectory(localDir, aLocal); |
1179 | |
1180 | localDir.forget(aFile); |
1181 | return NS_OK; |
1182 | } |
1183 | |
1184 | nsresult nsXREDirProvider::EnsureDirectoryExists(nsIFile* aDirectory) { |
1185 | nsresult rv = aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0700); |
1186 | |
1187 | if (rv == NS_ERROR_FILE_ALREADY_EXISTS) { |
1188 | rv = NS_OK; |
1189 | } |
1190 | return rv; |
1191 | } |
1192 | |
1193 | nsresult nsXREDirProvider::AppendSysUserExtensionPath(nsIFile* aFile) { |
1194 | NS_ASSERTION(aFile, "Null pointer!")do { if (!(aFile)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Null pointer!" , "aFile", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1194); MOZ_PretendNoReturn(); } } while (0); |
1195 | |
1196 | nsresult rv; |
1197 | |
1198 | #if defined(XP_MACOSX) || defined(XP_WIN) |
1199 | |
1200 | static const char* const sXR = "Mozilla"; |
1201 | rv = aFile->AppendNative(nsDependentCString(sXR)); |
1202 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1202); return rv; } } while (false); |
1203 | |
1204 | static const char* const sExtensions = "Extensions"; |
1205 | rv = aFile->AppendNative(nsDependentCString(sExtensions)); |
1206 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1206); return rv; } } while (false); |
1207 | |
1208 | #elif defined(XP_UNIX1) |
1209 | |
1210 | static const char* const sXR = ".mozilla"; |
1211 | rv = aFile->AppendNative(nsDependentCString(sXR)); |
1212 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1212); return rv; } } while (false); |
1213 | |
1214 | static const char* const sExtensions = "extensions"; |
1215 | rv = aFile->AppendNative(nsDependentCString(sExtensions)); |
1216 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1216); return rv; } } while (false); |
1217 | |
1218 | #else |
1219 | # error "Don't know how to get XRE user extension path on your platform" |
1220 | #endif |
1221 | return NS_OK; |
1222 | } |
1223 | |
1224 | nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal) { |
1225 | NS_ASSERTION(aFile, "Null pointer!")do { if (!(aFile)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Null pointer!" , "aFile", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1225); MOZ_PretendNoReturn(); } } while (0); |
1226 | |
1227 | // If there is no XREAppData then there is no information to use to build |
1228 | // the profile path so just do nothing. This should only happen in xpcshell |
1229 | // tests. |
1230 | if (!gAppData) { |
1231 | return NS_OK; |
1232 | } |
1233 | |
1234 | nsAutoCString profile; |
1235 | nsAutoCString appName; |
1236 | nsAutoCString vendor; |
1237 | if (gAppData->profile) { |
1238 | profile = gAppData->profile; |
1239 | } else { |
1240 | appName = gAppData->name; |
1241 | vendor = gAppData->vendor; |
1242 | } |
1243 | |
1244 | nsresult rv = NS_OK; |
1245 | |
1246 | #if defined(XP_MACOSX) |
1247 | if (!profile.IsEmpty()) { |
1248 | rv = AppendProfileString(aFile, profile.get()); |
1249 | } else { |
1250 | // Note that MacOS ignores the vendor when creating the profile hierarchy - |
1251 | // all application preferences directories live alongside one another in |
1252 | // ~/Library/Application Support/ |
1253 | rv = aFile->AppendNative(appName); |
1254 | } |
1255 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1255); return rv; } } while (false); |
1256 | |
1257 | #elif defined(XP_WIN) |
1258 | if (!profile.IsEmpty()) { |
1259 | rv = AppendProfileString(aFile, profile.get()); |
1260 | } else { |
1261 | if (!vendor.IsEmpty()) { |
1262 | rv = aFile->AppendNative(vendor); |
1263 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1263); return rv; } } while (false); |
1264 | } |
1265 | rv = aFile->AppendNative(appName); |
1266 | } |
1267 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1267); return rv; } } while (false); |
1268 | |
1269 | #elif defined(ANDROID) |
1270 | // The directory used for storing profiles |
1271 | // The parent of this directory is set in GetUserDataDirectoryHome |
1272 | // XXX: handle gAppData->profile properly |
1273 | // XXXsmaug ...and the rest of the profile creation! |
1274 | rv = aFile->AppendNative(nsDependentCString("mozilla")); |
1275 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1275); return rv; } } while (false); |
1276 | #elif defined(XP_UNIX1) |
1277 | nsAutoCString folder; |
1278 | // Make it hidden (by starting with "."), except when local (the |
1279 | // profile is already under ~/.cache or XDG_CACHE_HOME). |
1280 | if (!aLocal) folder.Assign('.'); |
1281 | |
1282 | if (!profile.IsEmpty()) { |
1283 | // Skip any leading path characters |
1284 | const char* profileStart = profile.get(); |
1285 | while (*profileStart == '/' || *profileStart == '\\') profileStart++; |
1286 | |
1287 | // On the off chance that someone wanted their folder to be hidden don't |
1288 | // let it become ".." |
1289 | if (*profileStart == '.' && !aLocal) profileStart++; |
1290 | |
1291 | folder.Append(profileStart); |
1292 | ToLowerCase(folder); |
1293 | |
1294 | rv = AppendProfileString(aFile, folder.BeginReading()); |
1295 | } else { |
1296 | if (!vendor.IsEmpty()) { |
1297 | folder.Append(vendor); |
1298 | ToLowerCase(folder); |
1299 | |
1300 | rv = aFile->AppendNative(folder); |
1301 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1301); return rv; } } while (false); |
1302 | |
1303 | folder.Truncate(); |
1304 | } |
1305 | |
1306 | // This can be the case in tests. |
1307 | if (!appName.IsEmpty()) { |
1308 | folder.Append(appName); |
1309 | ToLowerCase(folder); |
1310 | |
1311 | rv = aFile->AppendNative(folder); |
1312 | } |
1313 | } |
1314 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1314); return rv; } } while (false); |
1315 | |
1316 | #else |
1317 | # error "Don't know how to get profile path on your platform" |
1318 | #endif |
1319 | return NS_OK; |
1320 | } |
1321 | |
1322 | nsresult nsXREDirProvider::AppendProfileString(nsIFile* aFile, |
1323 | const char* aPath) { |
1324 | NS_ASSERTION(aFile, "Null file!")do { if (!(aFile)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Null file!" , "aFile", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1324); MOZ_PretendNoReturn(); } } while (0); |
1325 | NS_ASSERTION(aPath, "Null path!")do { if (!(aPath)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Null path!" , "aPath", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1325); MOZ_PretendNoReturn(); } } while (0); |
1326 | |
1327 | nsAutoCString pathDup(aPath); |
1328 | |
1329 | char* path = pathDup.BeginWriting(); |
1330 | |
1331 | nsresult rv; |
1332 | char* subdir; |
1333 | while ((subdir = NS_strtok("/\\", &path))) { |
1334 | rv = aFile->AppendNative(nsDependentCString(subdir)); |
1335 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp" , 1335); return rv; } } while (false); |
1336 | } |
1337 | |
1338 | return NS_OK; |
1339 | } |