Pier Angelo Vendrame pushed to branch tor-browser-102.7.0esr-12.5-1 at The Tor Project / Applications / Tor Browser
Commits:
-
fbc46b57
by Pier Angelo Vendrame at 2023-02-08T12:22:33+01:00
-
8029d2b1
by Pier Angelo Vendrame at 2023-02-08T12:22:34+01:00
-
1dafa91c
by Pier Angelo Vendrame at 2023-02-08T12:22:34+01:00
-
4595d824
by Pier Angelo Vendrame at 2023-02-08T12:22:35+01:00
-
cb3d5136
by Pier Angelo Vendrame at 2023-02-08T12:22:36+01:00
-
7e272b9d
by Pier Angelo Vendrame at 2023-02-08T12:22:36+01:00
-
f210d8ca
by Pier Angelo Vendrame at 2023-02-08T12:22:37+01:00
8 changed files:
- mozconfig-macos-x86_64
- toolkit/xre/nsAppRunner.cpp
- toolkit/xre/nsXREDirProvider.cpp
- toolkit/xre/nsXREDirProvider.h
- − xpcom/io/TorFileUtils.cpp
- − xpcom/io/TorFileUtils.h
- xpcom/io/moz.build
- xpcom/io/nsAppFileLocationProvider.cpp
Changes:
| ... | ... | @@ -5,4 +5,5 @@ ac_add_options --enable-strip |
| 5 | 5 | # See bug #41131
|
| 6 | 6 | ac_add_options --disable-update-agent
|
| 7 | 7 | |
| 8 | +ac_add_options --with-relative-data-dir=../TorBrowser-Data/Browser
|
|
| 8 | 9 | ac_add_options --enable-tor-browser-data-outside-app-dir |
| ... | ... | @@ -3099,13 +3099,16 @@ static ReturnAbortOnError ShowProfileManager( |
| 3099 | 3099 | return LaunchChild(false, true);
|
| 3100 | 3100 | }
|
| 3101 | 3101 | |
| 3102 | -#ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
|
|
| 3103 | -static ProfileStatus CheckTorBrowserDataWriteAccess(nsIFile* aAppDir) {
|
|
| 3102 | +#ifdef XP_MACOSX
|
|
| 3103 | +static ProfileStatus CheckTorBrowserDataWriteAccess() {
|
|
| 3104 | 3104 | // Check whether we can write to the directory that will contain
|
| 3105 | 3105 | // TorBrowser-Data.
|
| 3106 | + RefPtr<nsXREDirProvider> singleton = nsXREDirProvider::GetSingleton();
|
|
| 3107 | + if (!singleton) {
|
|
| 3108 | + return PROFILE_STATUS_OTHER_ERROR;
|
|
| 3109 | + }
|
|
| 3106 | 3110 | nsCOMPtr<nsIFile> tbDataDir;
|
| 3107 | - nsresult rv =
|
|
| 3108 | - nsXREDirProvider::GetTorBrowserUserDataDir(getter_AddRefs(tbDataDir));
|
|
| 3111 | + nsresult rv = singleton->GetTorBrowserUserDataDir(getter_AddRefs(tbDataDir));
|
|
| 3109 | 3112 | NS_ENSURE_SUCCESS(rv, PROFILE_STATUS_OTHER_ERROR);
|
| 3110 | 3113 | nsCOMPtr<nsIFile> tbDataDirParent;
|
| 3111 | 3114 | rv = tbDataDir->GetParent(getter_AddRefs(tbDataDirParent));
|
| ... | ... | @@ -5081,25 +5084,14 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) { |
| 5081 | 5084 | }
|
| 5082 | 5085 | #endif
|
| 5083 | 5086 | |
| 5084 | -#if (defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)) || \
|
|
| 5085 | - defined(TOR_BROWSER_DATA_OUTSIDE_APP_DIR)
|
|
| 5086 | - nsCOMPtr<nsIFile> exeFile, exeDir;
|
|
| 5087 | - bool persistent;
|
|
| 5088 | - rv = mDirProvider.GetFile(XRE_EXECUTABLE_FILE, &persistent,
|
|
| 5089 | - getter_AddRefs(exeFile));
|
|
| 5090 | - NS_ENSURE_SUCCESS(rv, 1);
|
|
| 5091 | - rv = exeFile->GetParent(getter_AddRefs(exeDir));
|
|
| 5092 | - NS_ENSURE_SUCCESS(rv, 1);
|
|
| 5093 | -#endif
|
|
| 5094 | - |
|
| 5095 | 5087 | rv = NS_NewToolkitProfileService(getter_AddRefs(mProfileSvc));
|
| 5096 | -#ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
|
|
| 5088 | +#ifdef XP_MACOSX
|
|
| 5097 | 5089 | if (NS_FAILED(rv)) {
|
| 5098 | 5090 | // NS_NewToolkitProfileService() returns a generic NS_ERROR_FAILURE error
|
| 5099 | 5091 | // if creation of the TorBrowser-Data directory fails due to access denied
|
| 5100 | 5092 | // or because of a read-only disk volume. Do an extra check here to detect
|
| 5101 | 5093 | // these errors so we can display an informative error message.
|
| 5102 | - ProfileStatus status = CheckTorBrowserDataWriteAccess(exeDir);
|
|
| 5094 | + ProfileStatus status = CheckTorBrowserDataWriteAccess();
|
|
| 5103 | 5095 | if ((PROFILE_STATUS_ACCESS_DENIED == status) ||
|
| 5104 | 5096 | (PROFILE_STATUS_READ_ONLY == status)) {
|
| 5105 | 5097 | ProfileErrorDialog(nullptr, nullptr, status, nullptr, mNativeApp,
|
| ... | ... | @@ -5216,14 +5208,12 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) { |
| 5216 | 5208 | if (CheckArg("test-process-updates")) {
|
| 5217 | 5209 | SaveToEnv("MOZ_TEST_PROCESS_UPDATES=1");
|
| 5218 | 5210 | }
|
| 5219 | -# ifndef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
|
|
| 5220 | 5211 | nsCOMPtr<nsIFile> exeFile, exeDir;
|
| 5221 | 5212 | rv = mDirProvider.GetFile(XRE_EXECUTABLE_FILE, &persistent,
|
| 5222 | 5213 | getter_AddRefs(exeFile));
|
| 5223 | 5214 | NS_ENSURE_SUCCESS(rv, 1);
|
| 5224 | 5215 | rv = exeFile->GetParent(getter_AddRefs(exeDir));
|
| 5225 | 5216 | NS_ENSURE_SUCCESS(rv, 1);
|
| 5226 | -# endif
|
|
| 5227 | 5217 | |
| 5228 | 5218 | # ifdef TOR_BROWSER_UPDATE
|
| 5229 | 5219 | nsAutoCString compatVersion(TOR_BROWSER_VERSION_QUOTED);
|
| ... | ... | @@ -56,8 +56,6 @@ |
| 56 | 56 | # include "nsIPK11Token.h"
|
| 57 | 57 | #endif
|
| 58 | 58 | |
| 59 | -#include "TorFileUtils.h"
|
|
| 60 | - |
|
| 61 | 59 | #include <stdlib.h>
|
| 62 | 60 | |
| 63 | 61 | #ifdef XP_WIN
|
| ... | ... | @@ -113,6 +111,10 @@ nsIFile* gDataDirHome = nullptr; |
| 113 | 111 | nsCOMPtr<nsIFile> gDataDirProfileLocal = nullptr;
|
| 114 | 112 | nsCOMPtr<nsIFile> gDataDirProfile = nullptr;
|
| 115 | 113 | |
| 114 | +#if defined(RELATIVE_DATA_DIR)
|
|
| 115 | +mozilla::Maybe<nsCOMPtr<nsIFile>> gDataDirPortable;
|
|
| 116 | +#endif
|
|
| 117 | + |
|
| 116 | 118 | // These are required to allow nsXREDirProvider to be usable in xpcshell tests.
|
| 117 | 119 | // where gAppData is null.
|
| 118 | 120 | #if defined(XP_MACOSX) || defined(XP_UNIX)
|
| ... | ... | @@ -1205,14 +1207,19 @@ nsresult nsXREDirProvider::GetUpdateRootDir(nsIFile** aResult, |
| 1205 | 1207 | }
|
| 1206 | 1208 | #endif
|
| 1207 | 1209 | nsCOMPtr<nsIFile> updRoot;
|
| 1210 | + nsCOMPtr<nsIFile> appFile;
|
|
| 1211 | + bool per = false;
|
|
| 1212 | + nsresult rv = GetFile(XRE_EXECUTABLE_FILE, &per, getter_AddRefs(appFile));
|
|
| 1213 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1214 | + |
|
| 1208 | 1215 | #if defined(TOR_BROWSER_UPDATE)
|
| 1209 | 1216 | // For Tor Browser, we store update history, etc. within the UpdateInfo
|
| 1210 | 1217 | // directory under the user data directory.
|
| 1211 | - nsresult rv = GetTorBrowserUserDataDir(getter_AddRefs(updRoot));
|
|
| 1218 | + rv = GetTorBrowserUserDataDir(getter_AddRefs(updRoot));
|
|
| 1212 | 1219 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1213 | 1220 | rv = updRoot->AppendNative("UpdateInfo"_ns);
|
| 1214 | 1221 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1215 | -# if defined(XP_MACOSX) && defined(TOR_BROWSER_DATA_OUTSIDE_APP_DIR)
|
|
| 1222 | +# if defined(XP_MACOSX)
|
|
| 1216 | 1223 | // Since the TorBrowser-Data directory may be shared among different
|
| 1217 | 1224 | // installations of the application, embed the app path in the update dir
|
| 1218 | 1225 | // so that the update history is partitioned. This is much less likely to
|
| ... | ... | @@ -1220,29 +1227,20 @@ nsresult nsXREDirProvider::GetUpdateRootDir(nsIFile** aResult, |
| 1220 | 1227 | // those platforms include a "container" folder that provides partitioning
|
| 1221 | 1228 | // by default, and we do not support use of a shared, OS-recommended area
|
| 1222 | 1229 | // for user data on those platforms.
|
| 1223 | - nsAutoString appDirPath;
|
|
| 1224 | - nsCOMPtr<nsIFile> appRootDir;
|
|
| 1225 | - rv = GetAppRootDir(getter_AddRefs(appRootDir));
|
|
| 1230 | + nsAutoString appPath;
|
|
| 1231 | + rv = appFile->GetPath(appPath);
|
|
| 1226 | 1232 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1227 | - rv = appRootDir->GetPath(appDirPath);
|
|
| 1228 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1229 | - |
|
| 1230 | - int32_t dotIndex = appDirPath.RFind(".app");
|
|
| 1233 | + int32_t dotIndex = appPath.RFind(".app");
|
|
| 1231 | 1234 | if (dotIndex == kNotFound) {
|
| 1232 | - dotIndex = appDirPath.Length();
|
|
| 1235 | + dotIndex = appPath.Length();
|
|
| 1233 | 1236 | }
|
| 1234 | - appDirPath = Substring(appDirPath, 1, dotIndex - 1);
|
|
| 1235 | - rv = updRoot->AppendRelativePath(appDirPath);
|
|
| 1237 | + appPath = Substring(appPath, 1, dotIndex - 1);
|
|
| 1238 | + rv = updRoot->AppendRelativePath(appPath);
|
|
| 1236 | 1239 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1237 | 1240 | # endif
|
| 1238 | 1241 | #else // ! TOR_BROWSER_UPDATE
|
| 1239 | - nsCOMPtr<nsIFile> appFile;
|
|
| 1240 | - bool per = false;
|
|
| 1241 | - nsresult rv = GetFile(XRE_EXECUTABLE_FILE, &per, getter_AddRefs(appFile));
|
|
| 1242 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1243 | 1242 | rv = appFile->GetParent(getter_AddRefs(updRoot));
|
| 1244 | 1243 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1245 | - |
|
| 1246 | 1244 | # ifdef XP_MACOSX
|
| 1247 | 1245 | nsCOMPtr<nsIFile> appRootDirFile;
|
| 1248 | 1246 | nsCOMPtr<nsIFile> localDir;
|
| ... | ... | @@ -1360,6 +1358,91 @@ nsresult nsXREDirProvider::SetUserDataProfileDirectory(nsCOMPtr<nsIFile>& aFile, |
| 1360 | 1358 | return NS_OK;
|
| 1361 | 1359 | }
|
| 1362 | 1360 | |
| 1361 | +#if defined(RELATIVE_DATA_DIR)
|
|
| 1362 | +nsresult nsXREDirProvider::GetPortableDataDir(nsIFile** aFile,
|
|
| 1363 | + bool& aIsPortable) {
|
|
| 1364 | + if (gDataDirPortable) {
|
|
| 1365 | + if (*gDataDirPortable) {
|
|
| 1366 | + nsresult rv = (*gDataDirPortable)->Clone(aFile);
|
|
| 1367 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1368 | + aIsPortable = true;
|
|
| 1369 | + } else {
|
|
| 1370 | + aIsPortable = false;
|
|
| 1371 | + }
|
|
| 1372 | + return NS_OK;
|
|
| 1373 | + }
|
|
| 1374 | + |
|
| 1375 | + nsCOMPtr<nsIFile> exeFile, exeDir;
|
|
| 1376 | + bool persistent = false;
|
|
| 1377 | + nsresult rv =
|
|
| 1378 | + GetFile(XRE_EXECUTABLE_FILE, &persistent, getter_AddRefs(exeFile));
|
|
| 1379 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1380 | + rv = exeFile->Normalize();
|
|
| 1381 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1382 | + rv = exeFile->GetParent(getter_AddRefs(exeDir));
|
|
| 1383 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1384 | + |
|
| 1385 | +# if defined(XP_MACOSX)
|
|
| 1386 | + nsAutoString exeDirPath;
|
|
| 1387 | + rv = exeDir->GetPath(exeDirPath);
|
|
| 1388 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1389 | + // When the browser is installed in /Applications, we never run in portable
|
|
| 1390 | + // mode.
|
|
| 1391 | + if (exeDirPath.Find("/Applications/", true /* ignore case */) == 0) {
|
|
| 1392 | + aIsPortable = false;
|
|
| 1393 | + return NS_OK;
|
|
| 1394 | + }
|
|
| 1395 | +# endif
|
|
| 1396 | + |
|
| 1397 | + nsCOMPtr<nsIFile> systemInstallFile;
|
|
| 1398 | + rv = exeDir->Clone(getter_AddRefs(systemInstallFile));
|
|
| 1399 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1400 | + rv = systemInstallFile->AppendNative("system-install"_ns);
|
|
| 1401 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1402 | + |
|
| 1403 | + bool exists = false;
|
|
| 1404 | + rv = systemInstallFile->Exists(&exists);
|
|
| 1405 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1406 | + if (exists) {
|
|
| 1407 | + aIsPortable = false;
|
|
| 1408 | + gDataDirPortable.emplace(nullptr);
|
|
| 1409 | + return NS_OK;
|
|
| 1410 | + }
|
|
| 1411 | + |
|
| 1412 | + nsCOMPtr<nsIFile> localDir = exeDir;
|
|
| 1413 | +# if defined(XP_MACOSX)
|
|
| 1414 | + rv = exeDir->GetParent(getter_AddRefs(localDir));
|
|
| 1415 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1416 | + exeDir = localDir;
|
|
| 1417 | + rv = exeDir->GetParent(getter_AddRefs(localDir));
|
|
| 1418 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1419 | +# endif
|
|
| 1420 | + rv = localDir->SetRelativePath(localDir.get(),
|
|
| 1421 | + nsLiteralCString(RELATIVE_DATA_DIR));
|
|
| 1422 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1423 | + |
|
| 1424 | +# if defined(XP_MACOSX)
|
|
| 1425 | + // On macOS we try to create the directory immediately to switch to
|
|
| 1426 | + // system-install mode if needed (e.g., when running from the DMG).
|
|
| 1427 | + rv = localDir->Exists(&exists);
|
|
| 1428 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1429 | + if (!exists) {
|
|
| 1430 | + rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
|
| 1431 | + if (NS_FAILED(rv)) {
|
|
| 1432 | + aIsPortable = false;
|
|
| 1433 | + return NS_OK;
|
|
| 1434 | + }
|
|
| 1435 | + }
|
|
| 1436 | +# endif
|
|
| 1437 | + |
|
| 1438 | + gDataDirPortable.emplace(localDir);
|
|
| 1439 | + rv = (*gDataDirPortable)->Clone(aFile);
|
|
| 1440 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1441 | + aIsPortable = true;
|
|
| 1442 | + return rv;
|
|
| 1443 | +}
|
|
| 1444 | +#endif
|
|
| 1445 | + |
|
| 1363 | 1446 | nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile,
|
| 1364 | 1447 | bool aLocal) {
|
| 1365 | 1448 | // Copied from nsAppFileLocationProvider (more or less)
|
| ... | ... | @@ -1374,38 +1457,40 @@ nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, |
| 1374 | 1457 | return gDataDirHome->Clone(aFile);
|
| 1375 | 1458 | }
|
| 1376 | 1459 | |
| 1377 | -#if defined(RELATIVE_DATA_DIR) || defined(TOR_BROWSER_DATA_OUTSIDE_APP_DIR)
|
|
| 1378 | -# ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
|
|
| 1379 | - rv = GetTorBrowserUserDataDir(getter_AddRefs(localDir));
|
|
| 1380 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1381 | - rv = localDir->AppendNative("Browser"_ns);
|
|
| 1382 | -# else
|
|
| 1460 | +#if defined(RELATIVE_DATA_DIR)
|
|
| 1383 | 1461 | RefPtr<nsXREDirProvider> singleton = GetSingleton();
|
| 1384 | 1462 | if (!singleton) {
|
| 1385 | 1463 | return NS_ERROR_OUT_OF_MEMORY;
|
| 1386 | 1464 | }
|
| 1387 | - rv = singleton->GetAppRootDir(getter_AddRefs(localDir));
|
|
| 1465 | + bool isPortable = false;
|
|
| 1466 | + rv = singleton->GetPortableDataDir(getter_AddRefs(localDir), isPortable);
|
|
| 1388 | 1467 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1389 | - nsAutoCString profileDir(RELATIVE_DATA_DIR);
|
|
| 1390 | - rv = localDir->SetRelativePath(localDir.get(), profileDir);
|
|
| 1391 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1392 | -# endif
|
|
| 1393 | - if (aLocal) {
|
|
| 1394 | - rv = localDir->AppendNative("Caches"_ns);
|
|
| 1395 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1468 | + if (isPortable) {
|
|
| 1469 | + if (aLocal) {
|
|
| 1470 | + rv = localDir->AppendNative("Caches"_ns);
|
|
| 1471 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1472 | + }
|
|
| 1473 | + NS_IF_ADDREF(*aFile = localDir);
|
|
| 1474 | + return rv;
|
|
| 1396 | 1475 | }
|
| 1397 | -#elif defined(XP_MACOSX)
|
|
| 1476 | +#endif
|
|
| 1477 | + |
|
| 1478 | +#if defined(XP_MACOSX)
|
|
| 1398 | 1479 | FSRef fsRef;
|
| 1480 | +# if defined(TOR_BROWSER_VERSION)
|
|
| 1481 | + OSType folderType = kApplicationSupportFolderType;
|
|
| 1482 | +# else
|
|
| 1399 | 1483 | OSType folderType;
|
| 1400 | 1484 | if (aLocal) {
|
| 1401 | 1485 | folderType = kCachedDataFolderType;
|
| 1402 | 1486 | } else {
|
| 1403 | -# ifdef MOZ_THUNDERBIRD
|
|
| 1487 | +# ifdef MOZ_THUNDERBIRD
|
|
| 1404 | 1488 | folderType = kDomainLibraryFolderType;
|
| 1405 | -# else
|
|
| 1489 | +# else
|
|
| 1406 | 1490 | folderType = kApplicationSupportFolderType;
|
| 1407 | -# endif
|
|
| 1491 | +# endif
|
|
| 1408 | 1492 | }
|
| 1493 | +# endif
|
|
| 1409 | 1494 | OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
|
| 1410 | 1495 | NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
|
| 1411 | 1496 | |
| ... | ... | @@ -1418,6 +1503,17 @@ nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, |
| 1418 | 1503 | rv = dirFileMac->InitWithFSRef(&fsRef);
|
| 1419 | 1504 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1420 | 1505 | |
| 1506 | +# if defined(TOR_BROWSER_VERSION)
|
|
| 1507 | + rv = dirFileMac->AppendNative("TorBrowser-Data"_ns);
|
|
| 1508 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1509 | + rv = dirFileMac->AppendNative("Browser"_ns);
|
|
| 1510 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1511 | + if (aLocal) {
|
|
| 1512 | + rv = dirFileMac->AppendNative("Caches"_ns);
|
|
| 1513 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1514 | + }
|
|
| 1515 | +# endif
|
|
| 1516 | + |
|
| 1421 | 1517 | localDir = dirFileMac;
|
| 1422 | 1518 | #elif defined(XP_IOS)
|
| 1423 | 1519 | nsAutoCString userDir;
|
| ... | ... | @@ -1537,37 +1633,6 @@ nsresult nsXREDirProvider::GetUserDataDirectory(nsIFile** aFile, bool aLocal) { |
| 1537 | 1633 | return NS_OK;
|
| 1538 | 1634 | }
|
| 1539 | 1635 | |
| 1540 | -nsresult nsXREDirProvider::GetTorBrowserUserDataDir(nsIFile** aFile) {
|
|
| 1541 | - NS_ENSURE_ARG_POINTER(aFile);
|
|
| 1542 | - nsCOMPtr<nsIFile> appRootDir;
|
|
| 1543 | - RefPtr<nsXREDirProvider> singleton = GetSingleton();
|
|
| 1544 | - if (!singleton) {
|
|
| 1545 | - return NS_ERROR_OUT_OF_MEMORY;
|
|
| 1546 | - }
|
|
| 1547 | - nsresult rv = singleton->GetAppRootDir(getter_AddRefs(appRootDir));
|
|
| 1548 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1549 | - return TorBrowser_GetUserDataDir(appRootDir, aFile);
|
|
| 1550 | -}
|
|
| 1551 | - |
|
| 1552 | -nsresult nsXREDirProvider::GetAppRootDir(nsIFile** aFile) {
|
|
| 1553 | - bool persistent = false;
|
|
| 1554 | - nsCOMPtr<nsIFile> file, appRootDir;
|
|
| 1555 | - nsresult rv = GetFile(XRE_EXECUTABLE_FILE, &persistent, getter_AddRefs(file));
|
|
| 1556 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1557 | - rv = file->Normalize();
|
|
| 1558 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1559 | - int levelsToRemove = 1;
|
|
| 1560 | -#if defined(XP_MACOSX)
|
|
| 1561 | - levelsToRemove += 2;
|
|
| 1562 | -#endif
|
|
| 1563 | - while (levelsToRemove-- > 0) {
|
|
| 1564 | - rv = file->GetParent(getter_AddRefs(appRootDir));
|
|
| 1565 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1566 | - file = appRootDir;
|
|
| 1567 | - }
|
|
| 1568 | - return appRootDir->Clone(aFile);
|
|
| 1569 | -}
|
|
| 1570 | - |
|
| 1571 | 1636 | nsresult nsXREDirProvider::EnsureDirectoryExists(nsIFile* aDirectory) {
|
| 1572 | 1637 | nsresult rv = aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
| 1573 | 1638 | |
| ... | ... | @@ -1618,6 +1683,13 @@ nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal) { |
| 1618 | 1683 | return NS_OK;
|
| 1619 | 1684 | }
|
| 1620 | 1685 | |
| 1686 | +#if defined(RELATIVE_DATA_DIR)
|
|
| 1687 | + if (gDataDirPortable && *gDataDirPortable) {
|
|
| 1688 | + // Do nothing in portable mode
|
|
| 1689 | + return NS_OK;
|
|
| 1690 | + }
|
|
| 1691 | +#endif
|
|
| 1692 | + |
|
| 1621 | 1693 | nsAutoCString profile;
|
| 1622 | 1694 | nsAutoCString appName;
|
| 1623 | 1695 | nsAutoCString vendor;
|
| ... | ... | @@ -1631,29 +1703,29 @@ nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal) { |
| 1631 | 1703 | nsresult rv = NS_OK;
|
| 1632 | 1704 | |
| 1633 | 1705 | #if defined(XP_MACOSX)
|
| 1706 | +# ifndef TOR_BROWSER_VERSION
|
|
| 1707 | + // For Tor Browser we already prepare the data directory as we need it, even
|
|
| 1708 | + // when we are running a system install.
|
|
| 1634 | 1709 | if (!profile.IsEmpty()) {
|
| 1635 | 1710 | rv = AppendProfileString(aFile, profile.get());
|
| 1636 | -# ifndef RELATIVE_DATA_DIR
|
|
| 1637 | 1711 | } else {
|
| 1638 | 1712 | // Note that MacOS ignores the vendor when creating the profile hierarchy -
|
| 1639 | 1713 | // all application preferences directories live alongside one another in
|
| 1640 | 1714 | // ~/Library/Application Support/
|
| 1641 | 1715 | rv = aFile->AppendNative(appName);
|
| 1642 | -# endif
|
|
| 1643 | 1716 | }
|
| 1644 | 1717 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1718 | +# endif
|
|
| 1645 | 1719 | |
| 1646 | 1720 | #elif defined(XP_WIN)
|
| 1647 | 1721 | if (!profile.IsEmpty()) {
|
| 1648 | 1722 | rv = AppendProfileString(aFile, profile.get());
|
| 1649 | -# ifndef RELATIVE_DATA_DIR
|
|
| 1650 | 1723 | } else {
|
| 1651 | 1724 | if (!vendor.IsEmpty()) {
|
| 1652 | 1725 | rv = aFile->AppendNative(vendor);
|
| 1653 | 1726 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1654 | 1727 | }
|
| 1655 | 1728 | rv = aFile->AppendNative(appName);
|
| 1656 | -# endif
|
|
| 1657 | 1729 | }
|
| 1658 | 1730 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1659 | 1731 | |
| ... | ... | @@ -1668,26 +1740,21 @@ nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal) { |
| 1668 | 1740 | nsAutoCString folder;
|
| 1669 | 1741 | // Make it hidden (by starting with "."), except when local (the
|
| 1670 | 1742 | // profile is already under ~/.cache or XDG_CACHE_HOME).
|
| 1671 | -# ifndef RELATIVE_DATA_DIR
|
|
| 1672 | 1743 | if (!aLocal) folder.Assign('.');
|
| 1673 | -# endif
|
|
| 1674 | 1744 | |
| 1675 | 1745 | if (!profile.IsEmpty()) {
|
| 1676 | 1746 | // Skip any leading path characters
|
| 1677 | 1747 | const char* profileStart = profile.get();
|
| 1678 | 1748 | while (*profileStart == '/' || *profileStart == '\\') profileStart++;
|
| 1679 | 1749 | |
| 1680 | -# ifndef RELATIVE_DATA_DIR
|
|
| 1681 | 1750 | // On the off chance that someone wanted their folder to be hidden don't
|
| 1682 | 1751 | // let it become ".."
|
| 1683 | 1752 | if (*profileStart == '.' && !aLocal) profileStart++;
|
| 1684 | -# endif
|
|
| 1685 | 1753 | |
| 1686 | 1754 | folder.Append(profileStart);
|
| 1687 | 1755 | ToLowerCase(folder);
|
| 1688 | 1756 | |
| 1689 | 1757 | rv = AppendProfileString(aFile, folder.BeginReading());
|
| 1690 | -# ifndef RELATIVE_DATA_DIR
|
|
| 1691 | 1758 | } else {
|
| 1692 | 1759 | if (!vendor.IsEmpty()) {
|
| 1693 | 1760 | folder.Append(vendor);
|
| ... | ... | @@ -1706,7 +1773,6 @@ nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal) { |
| 1706 | 1773 | |
| 1707 | 1774 | rv = aFile->AppendNative(folder);
|
| 1708 | 1775 | }
|
| 1709 | -# endif
|
|
| 1710 | 1776 | }
|
| 1711 | 1777 | NS_ENSURE_SUCCESS(rv, rv);
|
| 1712 | 1778 | |
| ... | ... | @@ -1734,3 +1800,21 @@ nsresult nsXREDirProvider::AppendProfileString(nsIFile* aFile, |
| 1734 | 1800 | |
| 1735 | 1801 | return NS_OK;
|
| 1736 | 1802 | }
|
| 1803 | + |
|
| 1804 | +nsresult nsXREDirProvider::GetTorBrowserUserDataDir(nsIFile** aFile) {
|
|
| 1805 | +#ifdef ANDROID
|
|
| 1806 | + // We expect this function not to be called on Android.
|
|
| 1807 | + // But, for sake of completeness, we handle also this case.
|
|
| 1808 | + const char* homeDir = getenv("HOME");
|
|
| 1809 | + if (!homeDir || !*homeDir) {
|
|
| 1810 | + return NS_ERROR_FAILURE;
|
|
| 1811 | + }
|
|
| 1812 | + return NS_NewNativeLocalFile(nsDependentCString(homeDir), true, aFile);
|
|
| 1813 | +#endif
|
|
| 1814 | + |
|
| 1815 | + NS_ENSURE_ARG_POINTER(aFile);
|
|
| 1816 | + nsCOMPtr<nsIFile> dataDir;
|
|
| 1817 | + nsresult rv = GetUserDataDirectoryHome(getter_AddRefs(dataDir), false);
|
|
| 1818 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 1819 | + return dataDir->GetParent(aFile);
|
|
| 1820 | +} |
| ... | ... | @@ -110,18 +110,11 @@ class nsXREDirProvider final : public nsIDirectoryServiceProvider2, |
| 110 | 110 | nsresult GetProfileDir(nsIFile** aResult);
|
| 111 | 111 | |
| 112 | 112 | /**
|
| 113 | - * Get the TorBrowser user data directory by calling the
|
|
| 114 | - * TorBrowser_GetUserDataDir() utility function.
|
|
| 113 | + * Get the Tor Browser user data directory.
|
|
| 114 | + * We take for granted that for Tor Browser we can take the parent directory
|
|
| 115 | + * of the one returned by GetUserDataDirectoryHome (with aLocal = false).
|
|
| 115 | 116 | */
|
| 116 | - static nsresult GetTorBrowserUserDataDir(nsIFile** aFile);
|
|
| 117 | - |
|
| 118 | - /**
|
|
| 119 | - * Get the path to the base application directory.
|
|
| 120 | - *
|
|
| 121 | - * In almost all platforms it is the directory that contains the Firefox
|
|
| 122 | - * executable; on macOS we remove also Contents/MacOS from it.
|
|
| 123 | - */
|
|
| 124 | - nsresult GetAppRootDir(nsIFile** aFile);
|
|
| 117 | + nsresult GetTorBrowserUserDataDir(nsIFile** aFile);
|
|
| 125 | 118 | |
| 126 | 119 | protected:
|
| 127 | 120 | nsresult GetFilesInternal(const char* aProperty,
|
| ... | ... | @@ -169,6 +162,14 @@ class nsXREDirProvider final : public nsIDirectoryServiceProvider2, |
| 169 | 162 | private:
|
| 170 | 163 | static nsresult SetUserDataProfileDirectory(nsCOMPtr<nsIFile>& aFile,
|
| 171 | 164 | bool aLocal);
|
| 165 | + |
|
| 166 | +#if defined(RELATIVE_DATA_DIR)
|
|
| 167 | + /**
|
|
| 168 | + * Get the path to the portable data dir, if the application is running in
|
|
| 169 | + * portable mode.
|
|
| 170 | + */
|
|
| 171 | + nsresult GetPortableDataDir(nsIFile** aFile, bool& aIsPortable);
|
|
| 172 | +#endif
|
|
| 172 | 173 | };
|
| 173 | 174 | |
| 174 | 175 | #endif |
| 1 | -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
| 2 | -/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
| 3 | -/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
| 4 | - * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
| 5 | - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
| 6 | - |
|
| 7 | -#include "TorFileUtils.h"
|
|
| 8 | -#include "nsString.h"
|
|
| 9 | -#ifdef MOZ_WIDGET_COCOA
|
|
| 10 | -# include <Carbon/Carbon.h>
|
|
| 11 | -# include "nsILocalFileMac.h"
|
|
| 12 | -#endif
|
|
| 13 | - |
|
| 14 | -nsresult TorBrowser_GetUserDataDir(nsIFile* aAppDir, nsIFile** aFile) {
|
|
| 15 | - NS_ENSURE_ARG_POINTER(aFile);
|
|
| 16 | - nsCOMPtr<nsIFile> tbDataDir;
|
|
| 17 | - |
|
| 18 | -#ifdef ANDROID
|
|
| 19 | - const char* homeDir = getenv("HOME");
|
|
| 20 | - if (!homeDir || !*homeDir) return NS_ERROR_FAILURE;
|
|
| 21 | - nsresult rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
|
|
| 22 | - getter_AddRefs(tbDataDir));
|
|
| 23 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 24 | -#elif defined(TOR_BROWSER_DATA_OUTSIDE_APP_DIR)
|
|
| 25 | - nsAutoCString tbDataLeafName("TorBrowser-Data"_ns);
|
|
| 26 | -# ifndef XP_MACOSX
|
|
| 27 | - // On all platforms except Mac OS, we always operate in a "portable" mode
|
|
| 28 | - // where the TorBrowser-Data directory is located next to the application.
|
|
| 29 | - nsresult rv = aAppDir->GetParent(getter_AddRefs(tbDataDir));
|
|
| 30 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 31 | - rv = tbDataDir->AppendNative(tbDataLeafName);
|
|
| 32 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 33 | -# else
|
|
| 34 | - // For Mac OS, determine whether we should store user data in the OS's
|
|
| 35 | - // standard location (i.e., under ~/Library/Application Support). We use
|
|
| 36 | - // the OS location if (1) the application is installed in a directory whose
|
|
| 37 | - // path contains "/Applications" or (2) the TorBrowser-Data directory does
|
|
| 38 | - // not exist and cannot be created (which probably means we lack write
|
|
| 39 | - // permission to the directory that contains the application).
|
|
| 40 | - nsAutoString appRootPath;
|
|
| 41 | - nsresult rv = aAppDir->GetPath(appRootPath);
|
|
| 42 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 43 | - bool useOSLocation =
|
|
| 44 | - (appRootPath.Find("/Applications", true /* ignore case */) >= 0);
|
|
| 45 | - if (!useOSLocation) {
|
|
| 46 | - // We hope to use the portable (aka side-by-side) approach, but before we
|
|
| 47 | - // commit to that, let's ensure that we can create the TorBrowser-Data
|
|
| 48 | - // directory. If it already exists, we will try to use it; if not and we
|
|
| 49 | - // fail to create it, we will switch to ~/Library/Application Support.
|
|
| 50 | - rv = aAppDir->GetParent(getter_AddRefs(tbDataDir));
|
|
| 51 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 52 | - rv = tbDataDir->AppendNative(tbDataLeafName);
|
|
| 53 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 54 | - bool exists = false;
|
|
| 55 | - rv = tbDataDir->Exists(&exists);
|
|
| 56 | - if (NS_SUCCEEDED(rv) && !exists)
|
|
| 57 | - rv = tbDataDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
|
| 58 | - useOSLocation = NS_FAILED(rv);
|
|
| 59 | - }
|
|
| 60 | - |
|
| 61 | - if (useOSLocation) {
|
|
| 62 | - // We are using ~/Library/Application Support/TorBrowser-Data. We do not
|
|
| 63 | - // need to create that directory here because the code in nsXREDirProvider
|
|
| 64 | - // will do so (and the user should always have write permission for
|
|
| 65 | - // ~/Library/Application Support; if they do not we have no more options).
|
|
| 66 | - FSRef fsRef;
|
|
| 67 | - OSErr err = ::FSFindFolder(kUserDomain, kApplicationSupportFolderType,
|
|
| 68 | - kCreateFolder, &fsRef);
|
|
| 69 | - NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
|
|
| 70 | - // To convert the FSRef returned by FSFindFolder() into an nsIFile that
|
|
| 71 | - // points to ~/Library/Application Support, we first create an empty
|
|
| 72 | - // nsIFile object (no path) and then use InitWithFSRef() to set the
|
|
| 73 | - // path.
|
|
| 74 | - rv = NS_NewNativeLocalFile(""_ns, true, getter_AddRefs(tbDataDir));
|
|
| 75 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 76 | - nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(tbDataDir);
|
|
| 77 | - if (!dirFileMac) return NS_ERROR_UNEXPECTED;
|
|
| 78 | - rv = dirFileMac->InitWithFSRef(&fsRef);
|
|
| 79 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 80 | - rv = tbDataDir->AppendNative(tbDataLeafName);
|
|
| 81 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 82 | - }
|
|
| 83 | -# endif
|
|
| 84 | - |
|
| 85 | -#else
|
|
| 86 | - // User data is embedded within the application directory (i.e.,
|
|
| 87 | - // TOR_BROWSER_DATA_OUTSIDE_APP_DIR is not defined).
|
|
| 88 | - nsresult rv = aAppDir->Clone(getter_AddRefs(tbDataDir));
|
|
| 89 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 90 | - rv = tbDataDir->AppendNative("TorBrowser"_ns);
|
|
| 91 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 92 | -#endif
|
|
| 93 | - |
|
| 94 | - tbDataDir.forget(aFile);
|
|
| 95 | - return NS_OK;
|
|
| 96 | -} |
| 1 | -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
| 2 | -/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
| 3 | -/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
| 4 | - * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
| 5 | - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
| 6 | - |
|
| 7 | -#ifndef TorFileUtils_h__
|
|
| 8 | -#define TorFileUtils_h__
|
|
| 9 | - |
|
| 10 | -#include "nsIFile.h"
|
|
| 11 | - |
|
| 12 | -/**
|
|
| 13 | - * TorBrowser_GetUserDataDir
|
|
| 14 | - *
|
|
| 15 | - * Retrieve the Tor Browser user data directory.
|
|
| 16 | - * When built with --enable-tor-browser-data-outside-app-dir, the directory
|
|
| 17 | - * is next to the application directory, except on Mac OS where it may be
|
|
| 18 | - * there or it may be at ~/Library/Application Support/TorBrowser-Data (the
|
|
| 19 | - * latter location is used if the .app bundle is in a directory whose path
|
|
| 20 | - * contains /Applications or if we lack write access to the directory that
|
|
| 21 | - * contains the .app).
|
|
| 22 | - * When built without --enable-tor-browser-data-outside-app-dir, this
|
|
| 23 | - * directory is TorBrowser.app/TorBrowser.
|
|
| 24 | - *
|
|
| 25 | - * @param aAppDir The path to Tor Browser directory
|
|
| 26 | - * @param aFile Out parameter that is set to the Tor Browser user data
|
|
| 27 | - * directory.
|
|
| 28 | - * @return NS_OK on success. Error otherwise.
|
|
| 29 | - */
|
|
| 30 | -extern nsresult TorBrowser_GetUserDataDir(nsIFile* aAppDir, nsIFile** aFile);
|
|
| 31 | - |
|
| 32 | -#endif // !TorFileUtils_h__ |
| ... | ... | @@ -86,7 +86,6 @@ EXPORTS += [ |
| 86 | 86 | "nsUnicharInputStream.h",
|
| 87 | 87 | "nsWildCard.h",
|
| 88 | 88 | "SpecialSystemDirectory.h",
|
| 89 | - "TorFileUtils.h",
|
|
| 90 | 89 | ]
|
| 91 | 90 | |
| 92 | 91 | EXPORTS.mozilla += [
|
| ... | ... | @@ -137,10 +136,6 @@ UNIFIED_SOURCES += [ |
| 137 | 136 | "SpecialSystemDirectory.cpp",
|
| 138 | 137 | ]
|
| 139 | 138 | |
| 140 | -SOURCES += [
|
|
| 141 | - "TorFileUtils.cpp",
|
|
| 142 | -]
|
|
| 143 | - |
|
| 144 | 139 | if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
|
| 145 | 140 | SOURCES += [
|
| 146 | 141 | "CocoaFileUtils.mm",
|
| ... | ... | @@ -27,8 +27,6 @@ |
| 27 | 27 | # include <sys/param.h>
|
| 28 | 28 | #endif
|
| 29 | 29 | |
| 30 | -#include "TorFileUtils.h"
|
|
| 31 | - |
|
| 32 | 30 | // WARNING: These hard coded names need to go away. They need to
|
| 33 | 31 | // come from localizable resources
|
| 34 | 32 | |
| ... | ... | @@ -231,66 +229,137 @@ nsresult nsAppFileLocationProvider::CloneMozBinDirectory(nsIFile** aLocalFile) { |
| 231 | 229 | return NS_OK;
|
| 232 | 230 | }
|
| 233 | 231 | |
| 234 | -//----------------------------------------------------------------------------------------
|
|
| 235 | -// GetProductDirectory - Gets the directory which contains the application data
|
|
| 236 | -// folder
|
|
| 237 | -//
|
|
| 238 | -// UNIX : ~/.mozilla/
|
|
| 239 | -// WIN : <Application Data folder on user's machine>\Mozilla
|
|
| 240 | -// Mac : :Documents:Mozilla:
|
|
| 241 | -//----------------------------------------------------------------------------------------
|
|
| 242 | -nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
|
|
| 243 | - bool aLocal) {
|
|
| 244 | - if (NS_WARN_IF(!aLocalFile)) {
|
|
| 245 | - return NS_ERROR_INVALID_ARG;
|
|
| 246 | - }
|
|
| 232 | +#ifdef RELATIVE_DATA_DIR
|
|
| 233 | +static nsresult SetupPortableMode(nsIFile** aDirectory, bool aLocal,
|
|
| 234 | + bool& aIsPortable) {
|
|
| 235 | + // This is almost the same as nsXREDirProvider::GetPortableDataDir.
|
|
| 236 | + // However, it seems that this is never called, at least during simple usage
|
|
| 237 | + // of the browser.
|
|
| 247 | 238 | |
| 248 | 239 | nsresult rv = NS_ERROR_UNEXPECTED;
|
| 249 | - bool exists;
|
|
| 250 | - nsCOMPtr<nsIFile> localDir;
|
|
| 251 | - |
|
| 252 | -#if defined(RELATIVE_DATA_DIR) || defined(TOR_BROWSER_DATA_OUTSIDE_APP_DIR)
|
|
| 253 | 240 | nsCOMPtr<nsIProperties> directoryService(
|
| 254 | 241 | do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
|
| 255 | 242 | NS_ENSURE_SUCCESS(rv, rv);
|
| 256 | - |
|
| 257 | - bool persistent = false;
|
|
| 258 | - nsCOMPtr<nsIFile> file, appRootDir;
|
|
| 243 | + nsCOMPtr<nsIFile> exeFile, exeDir;
|
|
| 259 | 244 | rv = directoryService->Get(XRE_EXECUTABLE_FILE, NS_GET_IID(nsIFile),
|
| 260 | - getter_AddRefs(file));
|
|
| 245 | + getter_AddRefs(exeFile));
|
|
| 246 | + rv = exeFile->Normalize();
|
|
| 261 | 247 | NS_ENSURE_SUCCESS(rv, rv);
|
| 262 | - rv = file->Normalize();
|
|
| 248 | + rv = exeFile->GetParent(getter_AddRefs(exeDir));
|
|
| 263 | 249 | NS_ENSURE_SUCCESS(rv, rv);
|
| 264 | - int levelsToRemove = 1;
|
|
| 250 | + |
|
| 265 | 251 | # if defined(XP_MACOSX)
|
| 266 | - levelsToRemove += 2;
|
|
| 252 | + nsAutoString exeDirPath;
|
|
| 253 | + rv = exeDir->GetPath(exeDirPath);
|
|
| 254 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 255 | + // When the browser is installed in /Applications, we never run in portable
|
|
| 256 | + // mode.
|
|
| 257 | + if (exeDirPath.Find("/Applications/", true /* ignore case */) == 0) {
|
|
| 258 | + aIsPortable = false;
|
|
| 259 | + return NS_OK;
|
|
| 260 | + }
|
|
| 267 | 261 | # endif
|
| 268 | - while (levelsToRemove-- > 0) {
|
|
| 269 | - rv = file->GetParent(getter_AddRefs(appRootDir));
|
|
| 270 | - NS_ENSURE_SUCCESS(rv, rv);
|
|
| 271 | - file = appRootDir;
|
|
| 262 | + |
|
| 263 | + nsCOMPtr<nsIFile> systemInstallFile;
|
|
| 264 | + rv = exeDir->Clone(getter_AddRefs(systemInstallFile));
|
|
| 265 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 266 | + rv = systemInstallFile->AppendNative("system-install"_ns);
|
|
| 267 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 268 | + |
|
| 269 | + bool exists = false;
|
|
| 270 | + rv = systemInstallFile->Exists(&exists);
|
|
| 271 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 272 | + if (exists) {
|
|
| 273 | + aIsPortable = false;
|
|
| 274 | + return NS_OK;
|
|
| 272 | 275 | }
|
| 273 | 276 | |
| 274 | -# ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
|
|
| 275 | - rv = TorBrowser_GetUserDataDir(appRootDir, getter_AddRefs(localDir));
|
|
| 277 | + nsCOMPtr<nsIFile> localDir = exeDir;
|
|
| 278 | +# if defined(XP_MACOSX)
|
|
| 279 | + rv = exeDir->GetParent(getter_AddRefs(localDir));
|
|
| 276 | 280 | NS_ENSURE_SUCCESS(rv, rv);
|
| 277 | - rv = localDir->AppendNative("Browser"_ns);
|
|
| 278 | -# else
|
|
| 279 | - localDir = appRootDir;
|
|
| 280 | - nsAutoCString profileDir(RELATIVE_DATA_DIR);
|
|
| 281 | - rv = localDir->SetRelativePath(localDir.get(), profileDir);
|
|
| 282 | -# endif
|
|
| 281 | + exeDir = localDir;
|
|
| 282 | + rv = exeDir->GetParent(getter_AddRefs(localDir));
|
|
| 283 | 283 | NS_ENSURE_SUCCESS(rv, rv);
|
| 284 | +# endif
|
|
| 284 | 285 | |
| 286 | + rv = localDir->SetRelativePath(localDir.get(),
|
|
| 287 | + nsLiteralCString(RELATIVE_DATA_DIR));
|
|
| 288 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 285 | 289 | if (aLocal) {
|
| 286 | 290 | rv = localDir->AppendNative("Caches"_ns);
|
| 287 | 291 | NS_ENSURE_SUCCESS(rv, rv);
|
| 288 | 292 | }
|
| 289 | 293 | |
| 290 | -#elif defined(MOZ_WIDGET_COCOA)
|
|
| 294 | + rv = localDir->Exists(&exists);
|
|
| 295 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 296 | + if (!exists) {
|
|
| 297 | + rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
|
| 298 | +# if defined(XP_MACOSX)
|
|
| 299 | + if (NS_FAILED(rv)) {
|
|
| 300 | + // On macOS, we forgive this failure to allow running from the DMG.
|
|
| 301 | + aIsPortable = false;
|
|
| 302 | + return NS_OK;
|
|
| 303 | + }
|
|
| 304 | +# else
|
|
| 305 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 306 | +# endif
|
|
| 307 | + }
|
|
| 308 | + |
|
| 309 | + localDir.forget(aDirectory);
|
|
| 310 | + aIsPortable = true;
|
|
| 311 | + return rv;
|
|
| 312 | +}
|
|
| 313 | +#endif
|
|
| 314 | + |
|
| 315 | +//----------------------------------------------------------------------------------------
|
|
| 316 | +// GetProductDirectory - Gets the directory which contains the application data
|
|
| 317 | +// folder
|
|
| 318 | +//
|
|
| 319 | +// If portable mode is enabled:
|
|
| 320 | +// - aLocal == false: $APP_ROOT/$RELATIVE_DATA_DIR
|
|
| 321 | +// - aLocal == true: $APP_ROOT/$RELATIVE_DATA_DIR/Caches
|
|
| 322 | +// where $APP_ROOT is:
|
|
| 323 | +// - the parent directory of the executable on Windows and Linux
|
|
| 324 | +// - the root of the app bundle on macOS
|
|
| 325 | +//
|
|
| 326 | +// Otherwise:
|
|
| 327 | +// - Windows:
|
|
| 328 | +// - aLocal == false: %APPDATA%/$MOZ_USER_DIR
|
|
| 329 | +// - aLocal == true: %LOCALAPPDATA%/$MOZ_USER_DIR
|
|
| 330 | +// - macOS:
|
|
| 331 | +// - aLocal == false: kDomainLibraryFolderType/$MOZ_USER_DIR
|
|
| 332 | +// - aLocal == true: kCachedDataFolderType/$MOZ_USER_DIR
|
|
| 333 | +// - Unix: ~/$MOZ_USER_DIR
|
|
| 334 | +//----------------------------------------------------------------------------------------
|
|
| 335 | +nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
|
|
| 336 | + bool aLocal) {
|
|
| 337 | + if (NS_WARN_IF(!aLocalFile)) {
|
|
| 338 | + return NS_ERROR_INVALID_ARG;
|
|
| 339 | + }
|
|
| 340 | + |
|
| 341 | + nsresult rv = NS_ERROR_UNEXPECTED;
|
|
| 342 | + bool exists;
|
|
| 343 | + nsCOMPtr<nsIFile> localDir;
|
|
| 344 | + |
|
| 345 | +#if defined(RELATIVE_DATA_DIR)
|
|
| 346 | + bool isPortable = false;
|
|
| 347 | + rv = SetupPortableMode(aLocalFile, aLocal, isPortable);
|
|
| 348 | + // If portable mode is enabled, we absolutely want it (e.g., to be sure there
|
|
| 349 | + // will not be disk leaks), so a failure is to be propagated.
|
|
| 350 | + if (NS_FAILED(rv) || isPortable) {
|
|
| 351 | + return rv;
|
|
| 352 | + }
|
|
| 353 | +#endif
|
|
| 354 | + |
|
| 355 | +#if defined(MOZ_WIDGET_COCOA)
|
|
| 291 | 356 | FSRef fsRef;
|
| 357 | +# if defined(TOR_BROWSER_VERSION)
|
|
| 358 | + OSType folderType = kApplicationSupportFolderType;
|
|
| 359 | +# else
|
|
| 292 | 360 | OSType folderType =
|
| 293 | 361 | aLocal ? (OSType)kCachedDataFolderType : (OSType)kDomainLibraryFolderType;
|
| 362 | +# endif
|
|
| 294 | 363 | OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
|
| 295 | 364 | if (err) {
|
| 296 | 365 | return NS_ERROR_FAILURE;
|
| ... | ... | @@ -304,6 +373,17 @@ nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile, |
| 304 | 373 | if (NS_FAILED(rv)) {
|
| 305 | 374 | return rv;
|
| 306 | 375 | }
|
| 376 | + |
|
| 377 | +# if defined(TOR_BROWSER_VERSION)
|
|
| 378 | + rv = localDir->AppendNative("TorBrowser-Data"_ns);
|
|
| 379 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 380 | + rv = localDir->AppendNative("Browser"_ns);
|
|
| 381 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 382 | + if (aLocal) {
|
|
| 383 | + rv = localDir->AppendNative("Caches"_ns);
|
|
| 384 | + NS_ENSURE_SUCCESS(rv, rv);
|
|
| 385 | + }
|
|
| 386 | +# endif
|
|
| 307 | 387 | #elif defined(XP_WIN)
|
| 308 | 388 | nsCOMPtr<nsIProperties> directoryService =
|
| 309 | 389 | do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
| ... | ... | @@ -326,7 +406,7 @@ nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile, |
| 326 | 406 | # error dont_know_how_to_get_product_dir_on_your_platform
|
| 327 | 407 | #endif
|
| 328 | 408 | |
| 329 | -#if !defined(RELATIVE_DATA_DIR) && !defined(TOR_BROWSER_VERSION)
|
|
| 409 | +#if !defined(TOR_BROWSER_VERSION)
|
|
| 330 | 410 | rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR);
|
| 331 | 411 | if (NS_FAILED(rv)) {
|
| 332 | 412 | return rv;
|
| ... | ... | @@ -350,6 +430,11 @@ nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile, |
| 350 | 430 | //----------------------------------------------------------------------------------------
|
| 351 | 431 | // GetDefaultUserProfileRoot - Gets the directory which contains each user
|
| 352 | 432 | // profile dir
|
| 433 | +//
|
|
| 434 | +// - Windows and macOS: $PRODUCT_DIRECTORY/Profiles
|
|
| 435 | +// - Unix: $PRODUCT_DIRECTORY
|
|
| 436 | +// See also GetProductDirectory for instructions on how $PRODUCT_DIRECTORY is
|
|
| 437 | +// generated.
|
|
| 353 | 438 | //----------------------------------------------------------------------------------------
|
| 354 | 439 | nsresult nsAppFileLocationProvider::GetDefaultUserProfileRoot(
|
| 355 | 440 | nsIFile** aLocalFile, bool aLocal) {
|