Commit cc5f2fcd authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃 Committed by Richard Pospesel
Browse files

fixup! Bug 9173: Change the default Firefox profile directory to be relative.

Bug 20497: Make it possible to disable portable mode

9173 is the patch that enables portable mode for Tor Browser.
We modified it to make it optional, but it still used to remove a few
important parts that made it compulsory to define a profile directory
in the application.ini (through the mozconfig).

This commit restores these parts, and makes it hopefully possible to
disable portable mode without filling the home directory with TBB
files.
A few parts are then disabled in a following commit, since they are
TBB-legacy behavior, but we might not want them for base-browser and
for privacy-browser.

Also, this commit changes the configure flag from
--with-relative-profile-directory to --with-relative-data-dir, because
the data directories can contain the profile and the local data such as
caches, not only the profile.
Still, we are assuming we are using the same data directory for the
profile and for the caches, which is not the case on Windows (where the
profile is roaming, and the caches are local) and on Linux (where the
profile is in the home, and the cache is in ~/.cache).
parent 0bd2aa9f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -42,4 +42,4 @@ if test -z "$WASI_SYSROOT"; then
    ac_add_options --without-wasm-sandboxed-libraries
fi

ac_add_options --with-relative-profile=BaseBrowser/Data/Browser
ac_add_options --with-relative-data-dir=BaseBrowser/Data/Browser
+6 −6
Original line number Diff line number Diff line
@@ -1026,22 +1026,22 @@ set_define("BASE_BROWSER", True, when="--enable-base-browser")


option(
    "--with-relative-profile",
    "--with-relative-data-dir",
    nargs=1,
    help="Sets the directory of the profile, relative to the application directory"
    help="Sets the data directories to be relative to the application directory"
)


@depends("--with-relative-profile", target)
@depends("--with-relative-data-dir", target)
@imports("json")
def relative_profile(value, target):
def relative_data_dir(value, target):
    if value and target.os == "Android":
        die("--with-relative-profile is not supported on Android")
        die("--with-relative-data-dir is not supported on Android")
    if value:
        return json.dumps(value[0])


set_define("RELATIVE_PROFILE_DIRECTORY", relative_profile)
set_define("RELATIVE_DATA_DIR", relative_data_dir)


# Please do not add configure checks from here on.
+3 −0
Original line number Diff line number Diff line
@@ -4,3 +4,6 @@ ac_add_options --enable-strip

# See bug #41131
ac_add_options --disable-update-agent

# For base-browser we do not enable portable mode on macOS.
ac_add_options --without-relative-data-dir
+59 −6
Original line number Diff line number Diff line
@@ -234,6 +234,9 @@ nsresult nsXREDirProvider::GetUserProfilesRootDir(nsIFile** aResult) {
  nsresult rv = GetUserDataDirectory(getter_AddRefs(file), false);

  if (NS_SUCCEEDED(rv)) {
#if !defined(XP_UNIX) || defined(XP_MACOSX)
    rv = file->AppendNative("Profiles"_ns);
#endif
    // We must create the profile directory here if it does not exist.
    nsresult tmp = EnsureDirectoryExists(file);
    if (NS_FAILED(tmp)) {
@@ -249,6 +252,9 @@ nsresult nsXREDirProvider::GetUserProfilesLocalDir(nsIFile** aResult) {
  nsresult rv = GetUserDataDirectory(getter_AddRefs(file), true);

  if (NS_SUCCEEDED(rv)) {
#if !defined(XP_UNIX) || defined(XP_MACOSX)
    rv = file->AppendNative("Profiles"_ns);
#endif
    // We must create the profile directory here if it does not exist.
    nsresult tmp = EnsureDirectoryExists(file);
    if (NS_FAILED(tmp)) {
@@ -1332,14 +1338,14 @@ nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile,
    return gDataDirHome->Clone(aFile);
  }

#if defined(RELATIVE_PROFILE_DIRECTORY)
#if defined(RELATIVE_DATA_DIR)
  RefPtr<nsXREDirProvider> singleton = GetSingleton();
  if (!singleton) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  rv = singleton->GetAppRootDir(getter_AddRefs(localDir));
  NS_ENSURE_SUCCESS(rv, rv);
  nsAutoCString profileDir(RELATIVE_PROFILE_DIRECTORY);
  nsAutoCString profileDir(RELATIVE_DATA_DIR);
  rv = localDir->SetRelativePath(localDir.get(), profileDir);
  NS_ENSURE_SUCCESS(rv, rv);
  if (aLocal) {
@@ -1559,8 +1565,13 @@ nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal) {
  }

  nsAutoCString profile;
  nsAutoCString appName;
  nsAutoCString vendor;
  if (gAppData->profile) {
    profile = gAppData->profile;
  } else {
    appName = gAppData->name;
    vendor = gAppData->vendor;
  }

  nsresult rv = NS_OK;
@@ -1568,12 +1579,27 @@ nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal) {
#if defined(XP_MACOSX)
  if (!profile.IsEmpty()) {
    rv = AppendProfileString(aFile, profile.get());
#  ifndef RELATIVE_DATA_DIR
  } else {
    // Note that MacOS ignores the vendor when creating the profile hierarchy -
    // all application preferences directories live alongside one another in
    // ~/Library/Application Support/
    rv = aFile->AppendNative(appName);
#  endif
  }
  NS_ENSURE_SUCCESS(rv, rv);

#elif defined(XP_WIN)
  if (!profile.IsEmpty()) {
    rv = AppendProfileString(aFile, profile.get());
#  ifndef RELATIVE_DATA_DIR
  } else {
    if (!vendor.IsEmpty()) {
      rv = aFile->AppendNative(vendor);
      NS_ENSURE_SUCCESS(rv, rv);
    }
    rv = aFile->AppendNative(appName);
#  endif
  }
  NS_ENSURE_SUCCESS(rv, rv);

@@ -1585,21 +1611,48 @@ nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal) {
  rv = aFile->AppendNative(nsDependentCString("mozilla"));
  NS_ENSURE_SUCCESS(rv, rv);
#elif defined(XP_UNIX)
  nsAutoCString folder;
  // Make it hidden (by starting with "."), except when local (the
  // profile is already under ~/.cache or XDG_CACHE_HOME).
#  ifndef RELATIVE_DATA_DIR
  if (!aLocal) folder.Assign('.');
#  endif

  if (!profile.IsEmpty()) {
    // Skip any leading path characters
    const char* profileStart = profile.get();
    while (*profileStart == '/' || *profileStart == '\\') profileStart++;

#  ifndef RELATIVE_DATA_DIR
    // On the off chance that someone wanted their folder to be hidden don't
    // let it become ".."
    if (*profileStart == '.') profileStart++;
    if (*profileStart == '.' && !aLocal) profileStart++;
#  endif

    // Make it hidden (by starting with ".").
    nsAutoCString folder(".");
    folder.Append(profileStart);
    ToLowerCase(folder);

    rv = AppendProfileString(aFile, folder.BeginReading());
#  ifndef RELATIVE_DATA_DIR
  } else {
    if (!vendor.IsEmpty()) {
      folder.Append(vendor);
      ToLowerCase(folder);

      rv = aFile->AppendNative(folder);
      NS_ENSURE_SUCCESS(rv, rv);

      folder.Truncate();
    }

    // This can be the case in tests.
    if (!appName.IsEmpty()) {
      folder.Append(appName);
      ToLowerCase(folder);

      rv = aFile->AppendNative(folder);
    }
#  endif
  }
  NS_ENSURE_SUCCESS(rv, rv);

+27 −4
Original line number Diff line number Diff line
@@ -247,7 +247,7 @@ nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
  bool exists;
  nsCOMPtr<nsIFile> localDir;

#if defined(RELATIVE_PROFILE_DIRECTORY)
#if defined(RELATIVE_DATA_DIR)
  nsCOMPtr<nsIProperties> directoryService(
      do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);
@@ -270,7 +270,7 @@ nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
  }

  localDir = appRootDir;
  nsAutoCString profileDir(RELATIVE_PROFILE_DIRECTORY);
  nsAutoCString profileDir(RELATIVE_DATA_DIR);
  rv = localDir->SetRelativePath(localDir.get(), profileDir);
  NS_ENSURE_SUCCESS(rv, rv);

@@ -318,6 +318,12 @@ nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
#  error dont_know_how_to_get_product_dir_on_your_platform
#endif

#if !defined(RELATIVE_DATA_DIR)
  rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR);
  if (NS_FAILED(rv)) {
    return rv;
  }
#endif
  rv = localDir->Exists(&exists);

  if (NS_SUCCEEDED(rv) && !exists) {
@@ -351,6 +357,23 @@ nsresult nsAppFileLocationProvider::GetDefaultUserProfileRoot(
    return rv;
  }

#if defined(MOZ_WIDGET_COCOA) || defined(XP_WIN)
  // These 3 platforms share this part of the path - do them as one
  rv = localDir->AppendRelativeNativePath("Profiles"_ns);
  if (NS_FAILED(rv)) {
    return rv;
  }

  bool exists;
  rv = localDir->Exists(&exists);
  if (NS_SUCCEEDED(rv) && !exists) {
    rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
  }
  if (NS_FAILED(rv)) {
    return rv;
  }
#endif

  localDir.forget(aLocalFile);

  return rv;