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