commit 6ce69df577e4cdf4ad38f9ec24d3e2a847b7303d
Author: Kathy Brade <brade(a)pearlcrescent.com>
Date: Tue Feb 26 10:07:17 2019 -0500
Bug 28044: Integrate Tor Launcher into tor-browser
Build and package Tor Launcher as part of the browser (similar to
how pdfjs is handled).
If a Tor Launcher extension is present in the user's profile, it is
removed.
---
browser/extensions/moz.build | 3 +++
browser/installer/package-manifest.in …
[View More] | 5 +++++
toolkit/mozapps/extensions/internal/XPIProvider.jsm | 10 ++++++++++
3 files changed, 18 insertions(+)
diff --git a/browser/extensions/moz.build b/browser/extensions/moz.build
index 1ab9167d870a..fa60184daea8 100644
--- a/browser/extensions/moz.build
+++ b/browser/extensions/moz.build
@@ -17,3 +17,6 @@ if CONFIG["NIGHTLY_BUILD"]:
DIRS += [
"translations",
]
+
+if not CONFIG["TOR_BROWSER_DISABLE_TOR_LAUNCHER"]:
+ DIRS += ["tor-launcher"]
diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in
index deed2c129139..e31386ba0c40 100644
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -239,6 +239,11 @@
@RESPATH@/browser/chrome/browser.manifest
@RESPATH@/chrome/pdfjs.manifest
@RESPATH@/chrome/pdfjs/*
+#ifndef TOR_BROWSER_DISABLE_TOR_LAUNCHER
+@RESPATH@/browser/chrome/torlauncher.manifest
+@RESPATH@/browser/chrome/torlauncher/*
+@RESPATH@/browser/@PREF_DIR@/torlauncher-prefs.js
+#endif
@RESPATH@/chrome/toolkit@JAREXT@
@RESPATH@/chrome/toolkit.manifest
@RESPATH@/chrome/recording.manifest
diff --git a/toolkit/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
index 5bd7cabb0f73..acabe8cad3bc 100644
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -1472,6 +1472,16 @@ var XPIStates = {
for (let [id, file] of loc.readAddons()) {
knownIds.delete(id);
+ // Since it is now part of the browser, uninstall the Tor Launcher
+ // extension. This will remove the Tor Launcher .xpi from user
+ // profiles on macOS.
+ if (id === "tor-launcher(a)torproject.org") {
+ logger.debug("Uninstalling the Tor Launcher extension.");
+ loc.installer.uninstallAddon(id);
+ changed = true;
+ continue;
+ }
+
let xpiState = loc.get(id);
if (!xpiState) {
// If the location is not supported for sideloading, skip new
[View Less]
commit af6ea320e99a7c7a3344be84b2a6d0431ebe267d
Author: Arthur Edelstein <arthuredelstein(a)gmail.com>
Date: Wed Aug 27 16:25:00 2014 -0700
Bug 12620: TorBrowser regression tests
Regression tests for Bug #2950: Make Permissions Manager memory-only
Regression tests for TB4: Tor Browser's Firefox preference overrides.
Note: many more functional tests could be made here
Regression tests for #2874: Block Components.interfaces from content
…
[View More]Bug 18923: Add a script to run all Tor Browser specific tests
Regression tests for Bug #16441: Suppress "Reset Tor Browser" prompt.
---
run-tbb-tests | 66 +++++++++++++++++++++++++++++++++++
tbb-tests-ignore.txt | 13 +++++++
tbb-tests/browser.ini | 5 +++
tbb-tests/browser_tor_TB4.js | 35 +++++++++++++++++++
tbb-tests/browser_tor_bug2950.js | 74 ++++++++++++++++++++++++++++++++++++++++
tbb-tests/mochitest.ini | 3 ++
tbb-tests/moz.build | 9 +++++
tbb-tests/test_tor_bug2874.html | 25 ++++++++++++++
toolkit/toolkit.mozbuild | 3 +-
9 files changed, 232 insertions(+), 1 deletion(-)
diff --git a/run-tbb-tests b/run-tbb-tests
new file mode 100755
index 000000000000..bc09839f9f05
--- /dev/null
+++ b/run-tbb-tests
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# This script runs all the Mochitest tests that have been added or
+# modified since the last ffxbld commit.
+#
+# It does not currently run XPCShell tests. We should change this if we
+# start using this type or other types of tests.
+#
+# The logs of the tests are stored in the tbb-tests.log file.
+# Ignored tests are listed in the tbb-tests-ignore.txt file.
+#
+# https://trac.torproject.org/projects/tor/ticket/18923
+
+IFS=$'\n'
+
+if [ -n "$USE_TESTS_LIST" ] && [ -f tbb-tests-list.txt ]
+then
+ echo "Using tests list from file tbb-tests-list.txt"
+ tests=($(cat tbb-tests-list.txt))
+else
+ ffxbld_commit=$(git log -500 --format='oneline' | grep "TB3: Tor Browser's official .mozconfigs." \
+ | head -1 | cut -d ' ' -f 1)
+
+ tests=($(git diff --name-status "$ffxbld_commit" HEAD | \
+ grep -e '^[AM].*/test_[^/]\+\.\(html\|xul\)$' \
+ -e '^[AM].*/browser_[^/]\+\.js$' \
+ | sed 's/^[AM]\s\+//'))
+fi
+
+echo 'The following tests will be run:'
+for i in "${!tests[@]}"
+do
+ if [ -z "$USE_TESTS_LIST" ] \
+ && grep -q "^${tests[$i]}$" tbb-tests-ignore.txt
+ then
+ unset "tests[$i]"
+ continue
+ fi
+ echo "- ${tests[$i]}"
+done
+
+if [ -n "$WRITE_TESTS_LIST" ]
+then
+ rm -f tbb-tests-list.txt
+ for i in "${!tests[@]}"
+ do
+ echo "${tests[$i]}" >> tbb-tests-list.txt
+ done
+ exit 0
+fi
+
+rm -f tbb-tests.log
+echo $'\n''Starting tests'
+# We need `security.nocertdb = false` because of #18087. That pref is
+# forced to have the same value as `browser.privatebrowsing.autostart` in
+# torbutton, so we just set `browser.privatebrowsing.autostart=false` here.
+./mach mochitest --log-tbpl tbb-tests.log \
+ --setpref network.file.path_blacklist='' \
+ --setpref extensions.torbutton.use_nontor_proxy=true \
+ --setpref browser.privatebrowsing.autostart=false \
+ "${tests[@]}"
+
+echo "*************************"
+echo "*************************"
+echo "Summary of failed tests:"
+grep --color=never TEST-UNEXPECTED-FAIL tbb-tests.log
diff --git a/tbb-tests-ignore.txt b/tbb-tests-ignore.txt
new file mode 100644
index 000000000000..ee3927a9e7c4
--- /dev/null
+++ b/tbb-tests-ignore.txt
@@ -0,0 +1,13 @@
+browser/extensions/onboarding/test/browser/browser_onboarding_accessibility.js
+browser/extensions/onboarding/test/browser/browser_onboarding_keyboard.js
+browser/extensions/onboarding/test/browser/browser_onboarding_notification.js
+browser/extensions/onboarding/test/browser/browser_onboarding_notification_2.js
+browser/extensions/onboarding/test/browser/browser_onboarding_notification_3.js
+browser/extensions/onboarding/test/browser/browser_onboarding_notification_4.js
+browser/extensions/onboarding/test/browser/browser_onboarding_notification_5.js
+browser/extensions/onboarding/test/browser/browser_onboarding_notification_click_auto_complete_tour.js
+browser/extensions/onboarding/test/browser/browser_onboarding_select_default_tour.js
+browser/extensions/onboarding/test/browser/browser_onboarding_skip_tour.js
+browser/extensions/onboarding/test/browser/browser_onboarding_tours.js
+browser/extensions/onboarding/test/browser/browser_onboarding_tourset.js
+browser/extensions/onboarding/test/browser/browser_onboarding_uitour.js
diff --git a/tbb-tests/browser.ini b/tbb-tests/browser.ini
new file mode 100644
index 000000000000..f481660f1417
--- /dev/null
+++ b/tbb-tests/browser.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+
+[browser_tor_bug2950.js]
+[browser_tor_omnibox.js]
+[browser_tor_TB4.js]
diff --git a/tbb-tests/browser_tor_TB4.js b/tbb-tests/browser_tor_TB4.js
new file mode 100644
index 000000000000..8bb12f360e5e
--- /dev/null
+++ b/tbb-tests/browser_tor_TB4.js
@@ -0,0 +1,35 @@
+// # Test for TB4: Tor Browser's Firefox preference overrides
+// This is a minimal test to check whether the 000-tor-browser.js
+// pref overrides are being used at all or not. More comprehensive
+// pref tests are maintained in the tor-browser-bundle-testsuite project.
+
+function test() {
+
+let expectedPrefs = [
+ // Homepage
+ ["browser.startup.homepage", "about:tor"],
+
+ // Disable the "Refresh" prompt that is displayed for stale profiles.
+ ["browser.disableResetPrompt", true],
+
+ // Version placeholder
+ ["torbrowser.version", "dev-build"],
+ ];
+
+let getPref = function (prefName) {
+ let type = Services.prefs.getPrefType(prefName);
+ if (type === Services.prefs.PREF_INT) return Services.prefs.getIntPref(prefName);
+ if (type === Services.prefs.PREF_BOOL) return Services.prefs.getBoolPref(prefName);
+ if (type === Services.prefs.PREF_STRING) return Services.prefs.getCharPref(prefName);
+ // Something went wrong.
+ throw new Error("Can't access pref " + prefName);
+};
+
+let testPref = function([key, expectedValue]) {
+ let foundValue = getPref(key);
+ is(foundValue, expectedValue, "Pref '" + key + "' should be '" + expectedValue +"'.");
+};
+
+expectedPrefs.map(testPref);
+
+} // end function test()
diff --git a/tbb-tests/browser_tor_bug2950.js b/tbb-tests/browser_tor_bug2950.js
new file mode 100644
index 000000000000..16e41344a3c4
--- /dev/null
+++ b/tbb-tests/browser_tor_bug2950.js
@@ -0,0 +1,74 @@
+// # Regression tests for tor Bug #2950, Make Permissions Manager memory-only
+// Ensures that permissions.sqlite file in profile directory is not written to,
+// even when we write a value to Firefox's permissions database.
+
+// The requisite test() function.
+function test() {
+
+// Needed because of asynchronous part later in the test.
+waitForExplicitFinish();
+
+// Shortcut
+let Ci = Components.interfaces;
+
+// ## utility functions
+
+// __principal(spec)__.
+// Creates a principal instance from a spec
+// (string address such as "https://www.torproject.org").
+let principal = spec => Services.scriptSecurityManager.createContentPrincipalFromOrigin(spec);
+
+// __setPermission(spec, key, value)__.
+// Sets the site permission of type key to value, for the site located at address spec.
+let setPermission = (spec, key, value) => SitePermissions.setForPrincipal(principal(spec), key, value);
+
+// __getPermission(spec, key)__.
+// Reads the site permission value for permission type key, for the site
+// located at address spec.
+let getPermission = (spec, key) => SitePermissions.getForPrincipal(principal(spec), key);
+
+// __profileDirPath__.
+// The Firefox Profile directory. Expected location of various persistent files.
+let profileDirPath = Services.dirsvc.get("ProfD", Components.interfaces.nsIFile).path;
+
+// __fileInProfile(fileName)__.
+// Returns an nsIFile instance corresponding to a file in the Profile directory.
+let fileInProfile = fileName => FileUtils.File(profileDirPath + "/" + fileName);
+
+// ## Now let's run the test.
+
+let SITE = "https://www.torproject.org",
+ KEY = "popup";
+
+let permissionsFile = fileInProfile("permissions.sqlite"),
+ lastModifiedTime = null,
+ newModifiedTime = null;
+if (permissionsFile.exists()) {
+ lastModifiedTime = permissionsFile.lastModifiedTime;
+}
+// Read the original value of the permission.
+let originalValue = getPermission(SITE, KEY);
+
+// We need to delay by at least 1000 ms, because that's the granularity
+// of file time stamps, it seems.
+window.setTimeout(
+ function () {
+ // Set the permission to a new value.
+ setPermission(SITE, KEY, SitePermissions.BLOCK);
+ // Now read back the permission value again.
+ let newReadValue = getPermission(SITE, KEY);
+ // Compare to confirm that the permission
+ // value was successfully changed.
+ Assert.notDeepEqual(originalValue, newReadValue, "Set a value in permissions db (perhaps in memory).");
+ // If file existed or now exists, get the current time stamp.
+ if (permissionsFile.exists()) {
+ newModifiedTime = permissionsFile.lastModifiedTime;
+ }
+ // If file was created or modified since we began this test,
+ // then permissions db is not memory only. Complain!
+ is(lastModifiedTime, newModifiedTime, "Don't write to permissions.sqlite file on disk.");
+ // We are done with the test.
+ finish();
+ }, 1100);
+
+} // test()
diff --git a/tbb-tests/mochitest.ini b/tbb-tests/mochitest.ini
new file mode 100644
index 000000000000..cc5172733bbe
--- /dev/null
+++ b/tbb-tests/mochitest.ini
@@ -0,0 +1,3 @@
+[DEFAULT]
+
+[test_tor_bug2874.html]
diff --git a/tbb-tests/moz.build b/tbb-tests/moz.build
new file mode 100644
index 000000000000..01db60b9c28a
--- /dev/null
+++ b/tbb-tests/moz.build
@@ -0,0 +1,9 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+MOCHITEST_MANIFESTS += ["mochitest.ini"]
+
+BROWSER_CHROME_MANIFESTS += ["browser.ini"]
diff --git a/tbb-tests/test_tor_bug2874.html b/tbb-tests/test_tor_bug2874.html
new file mode 100644
index 000000000000..c0a956e9f687
--- /dev/null
+++ b/tbb-tests/test_tor_bug2874.html
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Tor bug
+https://trac.torproject.org/projects/tor/ticket/2874
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Tor Bug 2874</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script type="application/javascript">
+ is(typeof Components, 'undefined', "The global window object should not expose a Components property to untrusted content.");
+ </script>
+</head>
+<body>
+<a target="_blank" href="https://trac.torproject.org/projects/tor/ticket/2874">Tor Bug 2874</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
diff --git a/toolkit/toolkit.mozbuild b/toolkit/toolkit.mozbuild
index 5576f6acc427..a2c3ddf2dc38 100644
--- a/toolkit/toolkit.mozbuild
+++ b/toolkit/toolkit.mozbuild
@@ -99,7 +99,8 @@ if CONFIG['MOZ_WEBRTC'] and CONFIG['COMPILE_ENVIRONMENT']:
]
if CONFIG['ENABLE_TESTS']:
- DIRS += ['/testing/specialpowers']
+ DIRS += ['/testing/specialpowers',
+ '/tbb-tests']
DIRS += [
'/testing/gtest',
[View Less]
commit 23751dd57060115f874bebfa08411056da9e0fb1
Author: Mike Perry <mikeperry-git(a)torproject.org>
Date: Wed Aug 27 15:19:10 2014 -0700
Bug 12974: Disable NTLM and Negotiate HTTP Auth
This is technically an embargoed Mozilla bug, so I probably shouldn't provide
too many details.
Suffice to say that NTLM and Negotiate auth are bad for Tor users, and I doubt
very many (or any of them) actually need it.
The Mozilla bug is https://bugzilla.mozilla.…
[View More]org/show_bug.cgi?id=1046421
---
extensions/auth/nsHttpNegotiateAuth.cpp | 4 ++++
netwerk/protocol/http/nsHttpNTLMAuth.cpp | 3 +++
2 files changed, 7 insertions(+)
diff --git a/extensions/auth/nsHttpNegotiateAuth.cpp b/extensions/auth/nsHttpNegotiateAuth.cpp
index fde44d6ce9ef..a3b3422e2c42 100644
--- a/extensions/auth/nsHttpNegotiateAuth.cpp
+++ b/extensions/auth/nsHttpNegotiateAuth.cpp
@@ -155,6 +155,10 @@ nsHttpNegotiateAuth::ChallengeReceived(nsIHttpAuthenticableChannel* authChannel,
nsIAuthModule* rawModule = (nsIAuthModule*)*continuationState;
*identityInvalid = false;
+
+ /* Always fail Negotiate auth for Tor Browser. We don't need it. */
+ return NS_ERROR_ABORT;
+
if (rawModule) {
return NS_OK;
}
diff --git a/netwerk/protocol/http/nsHttpNTLMAuth.cpp b/netwerk/protocol/http/nsHttpNTLMAuth.cpp
index a98093b484fa..e44fc4153e2e 100644
--- a/netwerk/protocol/http/nsHttpNTLMAuth.cpp
+++ b/netwerk/protocol/http/nsHttpNTLMAuth.cpp
@@ -169,6 +169,9 @@ nsHttpNTLMAuth::ChallengeReceived(nsIHttpAuthenticableChannel* channel,
*identityInvalid = false;
+ /* Always fail Negotiate auth for Tor Browser. We don't need it. */
+ return NS_ERROR_ABORT;
+
// Start a new auth sequence if the challenge is exactly "NTLM".
// If native NTLM auth apis are available and enabled through prefs,
// try to use them.
[View Less]
commit c68be6cb06b7bd746fdaa2855e2847ddb81aa1f5
Author: Mike Perry <mikeperry-git(a)torproject.org>
Date: Mon Sep 29 14:30:19 2014 -0700
Bug 13028: Prevent potential proxy bypass cases.
It looks like these cases should only be invoked in the NSS command line
tools, and not the browser, but I decided to patch them anyway because there
literally is a maze of network function pointers being passed around, and it's
very hard to tell if some random code might not …
[View More]pass in the proper proxied
versions of the networking code here by accident.
---
security/nss/lib/certhigh/ocsp.c | 8 ++++++++
.../lib/libpkix/pkix_pl_nss/module/pkix_pl_socket.c | 21 +++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/security/nss/lib/certhigh/ocsp.c b/security/nss/lib/certhigh/ocsp.c
index cea8456606bf..86fa971cfbef 100644
--- a/security/nss/lib/certhigh/ocsp.c
+++ b/security/nss/lib/certhigh/ocsp.c
@@ -2932,6 +2932,14 @@ ocsp_ConnectToHost(const char *host, PRUint16 port)
PRNetAddr addr;
char *netdbbuf = NULL;
+ // XXX: Do we need a unittest ifdef here? We don't want to break the tests, but
+ // we want to ensure nothing can ever hit this code in production.
+#if 1
+ printf("Tor Browser BUG: Attempted OSCP direct connect to %s, port %u\n", host,
+ port);
+ goto loser;
+#endif
+
sock = PR_NewTCPSocket();
if (sock == NULL)
goto loser;
diff --git a/security/nss/lib/libpkix/pkix_pl_nss/module/pkix_pl_socket.c b/security/nss/lib/libpkix/pkix_pl_nss/module/pkix_pl_socket.c
index e8698376b5be..85791d84a932 100644
--- a/security/nss/lib/libpkix/pkix_pl_nss/module/pkix_pl_socket.c
+++ b/security/nss/lib/libpkix/pkix_pl_nss/module/pkix_pl_socket.c
@@ -1334,6 +1334,13 @@ pkix_pl_Socket_Create(
plContext),
PKIX_COULDNOTCREATESOCKETOBJECT);
+ // XXX: Do we need a unittest ifdef here? We don't want to break the tests, but
+ // we want to ensure nothing can ever hit this code in production.
+#if 1
+ printf("Tor Browser BUG: Attempted pkix direct socket connect\n");
+ PKIX_ERROR(PKIX_PRNEWTCPSOCKETFAILED);
+#endif
+
socket->isServer = isServer;
socket->timeout = timeout;
socket->clientSock = NULL;
@@ -1433,6 +1440,13 @@ pkix_pl_Socket_CreateByName(
localCopyName = PL_strdup(serverName);
+ // XXX: Do we need a unittest ifdef here? We don't want to break the tests, but
+ // we want to ensure nothing can ever hit this code in production.
+#if 1
+ printf("Tor Browser BUG: Attempted pkix direct connect to %s\n", serverName);
+ PKIX_ERROR(PKIX_PRNEWTCPSOCKETFAILED);
+#endif
+
sepPtr = strchr(localCopyName, ':');
/* First strip off the portnum, if present, from the end of the name */
if (sepPtr) {
@@ -1582,6 +1596,13 @@ pkix_pl_Socket_CreateByHostAndPort(
PKIX_ENTER(SOCKET, "pkix_pl_Socket_CreateByHostAndPort");
PKIX_NULLCHECK_THREE(hostname, pStatus, pSocket);
+ // XXX: Do we need a unittest ifdef here? We don't want to break the tests, but
+ // we want to ensure nothing can ever hit this code in production.
+#if 1
+ printf("Tor Browser BUG: Attempted pkix direct connect to %s, port %u\n", hostname,
+ portnum);
+ PKIX_ERROR(PKIX_PRNEWTCPSOCKETFAILED);
+#endif
prstatus = PR_GetHostByName(hostname, buf, sizeof(buf), &hostent);
[View Less]
commit 3006912afcc5ee27378085a5c643f7f1dd1855a8
Author: Kathy Brade <brade(a)pearlcrescent.com>
Date: Fri Mar 18 14:20:02 2016 -0400
Bug 13252: Do not store data in the app bundle
When --enable-tor-browser-data-outside-app-dir is enabled,
all user data is stored in a directory named
TorBrowser-Data which is located next to the application directory.
Display an informative error message if the TorBrowser-Data
directory cannot be created due to an "…
[View More]access denied" or a
"read only volume" error.
On Mac OS, add support for the --invisible command line option which
is used by the meek-http-helper to avoid showing an icon for the
helper browser on the dock.
---
toolkit/xre/nsAppRunner.cpp | 73 +++++++++++++++---
toolkit/xre/nsXREDirProvider.cpp | 43 +++++------
toolkit/xre/nsXREDirProvider.h | 6 ++
xpcom/io/TorFileUtils.cpp | 133 +++++++++++++++++++++++++++++++++
xpcom/io/TorFileUtils.h | 32 ++++++++
xpcom/io/moz.build | 5 ++
xpcom/io/nsAppFileLocationProvider.cpp | 53 ++++++-------
7 files changed, 278 insertions(+), 67 deletions(-)
diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp
index 93d88f5e238b..046a02180d3d 100644
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2453,6 +2453,8 @@ static nsresult ProfileMissingDialog(nsINativeAppSupport* aNative) {
}
}
+// If aUnlocker is NULL, it is also OK for the following arguments to be NULL:
+// aProfileDir, aProfileLocalDir, aResult.
static ReturnAbortOnError ProfileErrorDialog(nsIFile* aProfileDir,
nsIFile* aProfileLocalDir,
ProfileStatus aStatus,
@@ -2461,17 +2463,19 @@ static ReturnAbortOnError ProfileErrorDialog(nsIFile* aProfileDir,
nsIProfileLock** aResult) {
nsresult rv;
- bool exists;
- aProfileDir->Exists(&exists);
- if (!exists) {
- return ProfileMissingDialog(aNative);
+ if (aProfileDir) {
+ bool exists;
+ aProfileDir->Exists(&exists);
+ if (!exists) {
+ return ProfileMissingDialog(aNative);
+ }
}
ScopedXPCOMStartup xpcom;
rv = xpcom.Initialize();
NS_ENSURE_SUCCESS(rv, rv);
- mozilla::Telemetry::WriteFailedProfileLock(aProfileDir);
+ if (aProfileDir) mozilla::Telemetry::WriteFailedProfileLock(aProfileDir);
rv = xpcom.SetWindowCreator(aNative);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
@@ -2682,6 +2686,23 @@ static ReturnAbortOnError ShowProfileManager(
return LaunchChild(false, true);
}
+#ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
+static ProfileStatus CheckTorBrowserDataWriteAccess(nsIFile* aAppDir) {
+ // Check whether we can write to the directory that will contain
+ // TorBrowser-Data.
+ nsCOMPtr<nsIFile> tbDataDir;
+ RefPtr<nsXREDirProvider> dirProvider = nsXREDirProvider::GetSingleton();
+ if (!dirProvider) return PROFILE_STATUS_OTHER_ERROR;
+ nsresult rv =
+ dirProvider->GetTorBrowserUserDataDir(getter_AddRefs(tbDataDir));
+ NS_ENSURE_SUCCESS(rv, PROFILE_STATUS_OTHER_ERROR);
+ nsCOMPtr<nsIFile> tbDataDirParent;
+ rv = tbDataDir->GetParent(getter_AddRefs(tbDataDirParent));
+ NS_ENSURE_SUCCESS(rv, PROFILE_STATUS_OTHER_ERROR);
+ return nsToolkitProfileService::CheckProfileWriteAccess(tbDataDirParent);
+}
+#endif
+
static bool gDoMigration = false;
static bool gDoProfileReset = false;
static nsCOMPtr<nsIToolkitProfile> gResetOldProfile;
@@ -3725,6 +3746,14 @@ int XREMain::XRE_mainInit(bool* aExitFlag) {
if (PR_GetEnv("XRE_MAIN_BREAK")) NS_BREAK();
#endif
+#if defined(XP_MACOSX) && defined(TOR_BROWSER_DATA_OUTSIDE_APP_DIR)
+ bool hideDockIcon = (CheckArg("invisible") == ARG_FOUND);
+ if (hideDockIcon) {
+ ProcessSerialNumber psn = {0, kCurrentProcess};
+ TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
+ }
+#endif
+
IncreaseDescriptorLimits();
#ifdef USE_GLX_TEST
@@ -4561,7 +4590,34 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
}
#endif
+#if (defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)) || \
+ defined(TOR_BROWSER_DATA_OUTSIDE_APP_DIR)
+ nsCOMPtr<nsIFile> exeFile, exeDir;
+ bool persistent;
+ rv = mDirProvider.GetFile(XRE_EXECUTABLE_FILE, &persistent,
+ getter_AddRefs(exeFile));
+ NS_ENSURE_SUCCESS(rv, 1);
+ rv = exeFile->GetParent(getter_AddRefs(exeDir));
+ NS_ENSURE_SUCCESS(rv, 1);
+#endif
+
rv = NS_NewToolkitProfileService(getter_AddRefs(mProfileSvc));
+#ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
+ if (NS_FAILED(rv)) {
+ // NS_NewToolkitProfileService() returns a generic NS_ERROR_FAILURE error
+ // if creation of the TorBrowser-Data directory fails due to access denied
+ // or because of a read-only disk volume. Do an extra check here to detect
+ // these errors so we can display an informative error message.
+ ProfileStatus status = CheckTorBrowserDataWriteAccess(exeDir);
+ if ((PROFILE_STATUS_ACCESS_DENIED == status) ||
+ (PROFILE_STATUS_READ_ONLY == status)) {
+ ProfileErrorDialog(nullptr, nullptr, status, nullptr, mNativeApp,
+ nullptr);
+ return 1;
+ }
+ }
+#endif
+
if (rv == NS_ERROR_FILE_ACCESS_DENIED) {
PR_fprintf(PR_STDERR,
"Error: Access was denied while trying to open files in "
@@ -4631,7 +4687,6 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
if (ShouldProcessUpdates(mDirProvider)) {
// Check for and process any available updates
nsCOMPtr<nsIFile> updRoot;
- bool persistent;
rv = mDirProvider.GetFile(XRE_UPDATE_ROOT_DIR, &persistent,
getter_AddRefs(updRoot));
// XRE_UPDATE_ROOT_DIR may fail. Fallback to appDir if failed
@@ -4667,12 +4722,6 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
if (CheckArg("test-process-updates")) {
SaveToEnv("MOZ_TEST_PROCESS_UPDATES=1");
}
- nsCOMPtr<nsIFile> exeFile, exeDir;
- rv = mDirProvider.GetFile(XRE_EXECUTABLE_FILE, &persistent,
- getter_AddRefs(exeFile));
- NS_ENSURE_SUCCESS(rv, 1);
- rv = exeFile->GetParent(getter_AddRefs(exeDir));
- NS_ENSURE_SUCCESS(rv, 1);
ProcessUpdates(mDirProvider.GetGREDir(), exeDir, updRoot, gRestartArgc,
gRestartArgv, mAppData->version);
if (EnvHasValue("MOZ_TEST_PROCESS_UPDATES")) {
diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp
index b958258424a2..2e965b3526ad 100644
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -57,6 +57,8 @@
# include "nsIPK11Token.h"
#endif
+#include "TorFileUtils.h"
+
#include <stdlib.h>
#ifdef XP_WIN
@@ -1375,34 +1377,18 @@ nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile,
return gDataDirHome->Clone(aFile);
}
- nsresult rv = GetAppDir()->Clone(getter_AddRefs(localDir));
+ nsresult rv = GetTorBrowserUserDataDir(getter_AddRefs(localDir));
NS_ENSURE_SUCCESS(rv, rv);
- int levelsToRemove = 1; // In FF21+, appDir points to browser subdirectory.
-#if defined(XP_MACOSX)
- levelsToRemove += 2;
-#endif
- while (localDir && (levelsToRemove > 0)) {
- // When crawling up the hierarchy, components named "." do not count.
- nsAutoCString removedName;
- rv = localDir->GetNativeLeafName(removedName);
- NS_ENSURE_SUCCESS(rv, rv);
- bool didRemove = !removedName.Equals(".");
-
- // Remove a directory component.
- nsCOMPtr<nsIFile> parentDir;
- rv = localDir->GetParent(getter_AddRefs(parentDir));
- NS_ENSURE_SUCCESS(rv, rv);
- localDir = parentDir;
- if (didRemove) --levelsToRemove;
- }
-
- if (!localDir) return NS_ERROR_FAILURE;
-
- rv = localDir->AppendRelativeNativePath("TorBrowser" XPCOM_FILE_PATH_SEPARATOR
- "Data" XPCOM_FILE_PATH_SEPARATOR
+#if !defined(ANDROID)
+# ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
+ rv = localDir->AppendNative("Browser"_ns);
+# else
+ rv = localDir->AppendRelativeNativePath("Data" XPCOM_FILE_PATH_SEPARATOR
"Browser"_ns);
+# endif
NS_ENSURE_SUCCESS(rv, rv);
+#endif
if (aLocal) {
rv = localDir->AppendNative("Caches"_ns);
@@ -1508,6 +1494,15 @@ nsresult nsXREDirProvider::GetUserDataDirectory(nsIFile** aFile, bool aLocal) {
return NS_OK;
}
+nsresult nsXREDirProvider::GetTorBrowserUserDataDir(nsIFile** aFile) {
+ NS_ENSURE_ARG_POINTER(aFile);
+ nsCOMPtr<nsIFile> exeFile;
+ bool per = false;
+ nsresult rv = GetFile(XRE_EXECUTABLE_FILE, &per, getter_AddRefs(exeFile));
+ NS_ENSURE_SUCCESS(rv, rv);
+ return TorBrowser_GetUserDataDir(exeFile, aFile);
+}
+
nsresult nsXREDirProvider::EnsureDirectoryExists(nsIFile* aDirectory) {
nsresult rv = aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0700);
diff --git a/toolkit/xre/nsXREDirProvider.h b/toolkit/xre/nsXREDirProvider.h
index acea2e689821..98ef4ad770ea 100644
--- a/toolkit/xre/nsXREDirProvider.h
+++ b/toolkit/xre/nsXREDirProvider.h
@@ -113,6 +113,12 @@ class nsXREDirProvider final : public nsIDirectoryServiceProvider2,
*/
nsresult GetProfileDir(nsIFile** aResult);
+ /**
+ * Get the TorBrowser user data directory by calling the
+ * TorBrowser_GetUserDataDir() utility function.
+ */
+ nsresult GetTorBrowserUserDataDir(nsIFile** aFile);
+
protected:
nsresult GetFilesInternal(const char* aProperty,
nsISimpleEnumerator** aResult);
diff --git a/xpcom/io/TorFileUtils.cpp b/xpcom/io/TorFileUtils.cpp
new file mode 100644
index 000000000000..6bd03f1f7fed
--- /dev/null
+++ b/xpcom/io/TorFileUtils.cpp
@@ -0,0 +1,133 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "TorFileUtils.h"
+#include "nsString.h"
+#ifdef MOZ_WIDGET_COCOA
+# include <Carbon/Carbon.h>
+# include "nsILocalFileMac.h"
+#endif
+
+static nsresult GetAppRootDir(nsIFile* aExeFile, nsIFile** aFile);
+
+//-----------------------------------------------------------------------------
+nsresult TorBrowser_GetUserDataDir(nsIFile* aExeFile, nsIFile** aFile) {
+ NS_ENSURE_ARG_POINTER(aFile);
+ nsCOMPtr<nsIFile> tbDataDir;
+
+#ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
+ nsAutoCString tbDataLeafName("TorBrowser-Data"_ns);
+ nsCOMPtr<nsIFile> appRootDir;
+ nsresult rv = GetAppRootDir(aExeFile, getter_AddRefs(appRootDir));
+ NS_ENSURE_SUCCESS(rv, rv);
+# ifndef XP_MACOSX
+ // On all platforms except Mac OS, we always operate in a "portable" mode
+ // where the TorBrowser-Data directory is located next to the application.
+ rv = appRootDir->GetParent(getter_AddRefs(tbDataDir));
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = tbDataDir->AppendNative(tbDataLeafName);
+ NS_ENSURE_SUCCESS(rv, rv);
+# else
+ // For Mac OS, determine whether we should store user data in the OS's
+ // standard location (i.e., under ~/Library/Application Support). We use
+ // the OS location if (1) the application is installed in a directory whose
+ // path contains "/Applications" or (2) the TorBrowser-Data directory does
+ // not exist and cannot be created (which probably means we lack write
+ // permission to the directory that contains the application).
+ nsAutoString appRootPath;
+ rv = appRootDir->GetPath(appRootPath);
+ NS_ENSURE_SUCCESS(rv, rv);
+ bool useOSLocation =
+ (appRootPath.Find("/Applications", true /* ignore case */) >= 0);
+ if (!useOSLocation) {
+ // We hope to use the portable (aka side-by-side) approach, but before we
+ // commit to that, let's ensure that we can create the TorBrowser-Data
+ // directory. If it already exists, we will try to use it; if not and we
+ // fail to create it, we will switch to ~/Library/Application Support.
+ rv = appRootDir->GetParent(getter_AddRefs(tbDataDir));
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = tbDataDir->AppendNative(tbDataLeafName);
+ NS_ENSURE_SUCCESS(rv, rv);
+ bool exists = false;
+ rv = tbDataDir->Exists(&exists);
+ if (NS_SUCCEEDED(rv) && !exists)
+ rv = tbDataDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
+ useOSLocation = NS_FAILED(rv);
+ }
+
+ if (useOSLocation) {
+ // We are using ~/Library/Application Support/TorBrowser-Data. We do not
+ // need to create that directory here because the code in nsXREDirProvider
+ // will do so (and the user should always have write permission for
+ // ~/Library/Application Support; if they do not we have no more options).
+ FSRef fsRef;
+ OSErr err = ::FSFindFolder(kUserDomain, kApplicationSupportFolderType,
+ kCreateFolder, &fsRef);
+ NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
+ // To convert the FSRef returned by FSFindFolder() into an nsIFile that
+ // points to ~/Library/Application Support, we first create an empty
+ // nsIFile object (no path) and then use InitWithFSRef() to set the
+ // path.
+ rv = NS_NewNativeLocalFile(""_ns, true, getter_AddRefs(tbDataDir));
+ NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(tbDataDir);
+ if (!dirFileMac) return NS_ERROR_UNEXPECTED;
+ rv = dirFileMac->InitWithFSRef(&fsRef);
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = tbDataDir->AppendNative(tbDataLeafName);
+ NS_ENSURE_SUCCESS(rv, rv);
+ }
+# endif
+
+#elif defined(ANDROID)
+ // Tor Browser Android stores data in the app home directory.
+ const char* homeDir = getenv("HOME");
+ if (!homeDir || !*homeDir) return NS_ERROR_FAILURE;
+ nsresult rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
+ getter_AddRefs(tbDataDir));
+#else
+ // User data is embedded within the application directory (i.e.,
+ // TOR_BROWSER_DATA_OUTSIDE_APP_DIR is not defined).
+ nsresult rv = GetAppRootDir(aExeFile, getter_AddRefs(tbDataDir));
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = tbDataDir->AppendNative("TorBrowser"_ns);
+ NS_ENSURE_SUCCESS(rv, rv);
+#endif
+
+ tbDataDir.forget(aFile);
+ return NS_OK;
+}
+
+static nsresult GetAppRootDir(nsIFile* aExeFile, nsIFile** aFile) {
+ NS_ENSURE_ARG_POINTER(aExeFile);
+ NS_ENSURE_ARG_POINTER(aFile);
+ nsCOMPtr<nsIFile> appRootDir = aExeFile;
+
+ int levelsToRemove = 1; // Remove firefox (the executable file).
+#if defined(XP_MACOSX)
+ levelsToRemove += 2; // On Mac OS, we must also remove Contents/MacOS.
+#endif
+ while (appRootDir && (levelsToRemove > 0)) {
+ // When crawling up the hierarchy, components named "." do not count.
+ nsAutoCString removedName;
+ nsresult rv = appRootDir->GetNativeLeafName(removedName);
+ NS_ENSURE_SUCCESS(rv, rv);
+ bool didRemove = !removedName.Equals(".");
+
+ // Remove a directory component.
+ nsCOMPtr<nsIFile> parentDir;
+ rv = appRootDir->GetParent(getter_AddRefs(parentDir));
+ NS_ENSURE_SUCCESS(rv, rv);
+ appRootDir = parentDir;
+
+ if (didRemove) --levelsToRemove;
+ }
+
+ if (!appRootDir) return NS_ERROR_FAILURE;
+
+ appRootDir.forget(aFile);
+ return NS_OK;
+}
diff --git a/xpcom/io/TorFileUtils.h b/xpcom/io/TorFileUtils.h
new file mode 100644
index 000000000000..31e70a7e0d3a
--- /dev/null
+++ b/xpcom/io/TorFileUtils.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef TorFileUtils_h__
+#define TorFileUtils_h__
+
+#include "nsIFile.h"
+
+/**
+ * TorBrowser_GetUserDataDir
+ *
+ * Retrieve the Tor Browser user data directory.
+ * When built with --enable-tor-browser-data-outside-app-dir, the directory
+ * is next to the application directory, except on Mac OS where it may be
+ * there or it may be at ~/Library/Application Support/TorBrowser-Data (the
+ * latter location is used if the .app bundle is in a directory whose path
+ * contains /Applications or if we lack write access to the directory that
+ * contains the .app).
+ * When built without --enable-tor-browser-data-outside-app-dir, this
+ * directory is TorBrowser.app/TorBrowser.
+ *
+ * @param aExeFile The firefox executable.
+ * @param aFile Out parameter that is set to the Tor Browser user data
+ * directory.
+ * @return NS_OK on success. Error otherwise.
+ */
+extern nsresult TorBrowser_GetUserDataDir(nsIFile* aExeFile, nsIFile** aFile);
+
+#endif // !TorFileUtils_h__
diff --git a/xpcom/io/moz.build b/xpcom/io/moz.build
index d28c426e7bd7..af7b5be04f6e 100644
--- a/xpcom/io/moz.build
+++ b/xpcom/io/moz.build
@@ -86,6 +86,7 @@ EXPORTS += [
"nsUnicharInputStream.h",
"nsWildCard.h",
"SpecialSystemDirectory.h",
+ "TorFileUtils.h",
]
EXPORTS.mozilla += [
@@ -137,6 +138,10 @@ UNIFIED_SOURCES += [
"SpecialSystemDirectory.cpp",
]
+SOURCES += [
+ "TorFileUtils.cpp",
+]
+
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
SOURCES += [
"CocoaFileUtils.mm",
diff --git a/xpcom/io/nsAppFileLocationProvider.cpp b/xpcom/io/nsAppFileLocationProvider.cpp
index 2bbcee92aedb..66f6940beff6 100644
--- a/xpcom/io/nsAppFileLocationProvider.cpp
+++ b/xpcom/io/nsAppFileLocationProvider.cpp
@@ -28,6 +28,8 @@
# include <sys/param.h>
#endif
+#include "TorFileUtils.h"
+
// WARNING: These hard coded names need to go away. They need to
// come from localizable resources
@@ -234,8 +236,14 @@ nsresult nsAppFileLocationProvider::CloneMozBinDirectory(nsIFile** aLocalFile) {
// GetProductDirectory - Gets the directory which contains the application data
// folder
//
+#ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
+// UNIX and WIN : <App Folder>/../TorBrowser-Data/Browser
+// Mac : <App Folder>/../../../TorBrowser-Data/Browser OR
+// ~/Library/Application Support/TorBrowser-Data/Browser
+#else
// UNIX and WIN : <App Folder>/TorBrowser/Data/Browser
// Mac : <App Folder>/../../TorBrowser/Data/Browser
+#endif
//----------------------------------------------------------------------------------------
nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
bool aLocal) {
@@ -243,42 +251,25 @@ nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
return NS_ERROR_INVALID_ARG;
}
- nsresult rv;
+ nsresult rv = NS_ERROR_UNEXPECTED;
bool exists;
- nsCOMPtr<nsIFile> localDir;
+ nsCOMPtr<nsIFile> localDir, exeFile;
- rv = CloneMozBinDirectory(getter_AddRefs(localDir));
+ nsCOMPtr<nsIProperties> directoryService(
+ do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = directoryService->Get(XRE_EXECUTABLE_FILE, NS_GET_IID(nsIFile),
+ getter_AddRefs(exeFile));
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = TorBrowser_GetUserDataDir(exeFile, getter_AddRefs(localDir));
NS_ENSURE_SUCCESS(rv, rv);
- int levelsToRemove = 1; // In FF21+, bin dir points to browser subdirectory.
-#if defined(XP_MACOSX)
- levelsToRemove += 2;
-#endif
- while (localDir && (levelsToRemove > 0)) {
- // When crawling up the hierarchy, components named "." do not count.
- nsAutoCString removedName;
- rv = localDir->GetNativeLeafName(removedName);
- NS_ENSURE_SUCCESS(rv, rv);
- bool didRemove = !removedName.Equals(".");
-
- // Remove a directory component.
- nsCOMPtr<nsIFile> parentDir;
- rv = localDir->GetParent(getter_AddRefs(parentDir));
- NS_ENSURE_SUCCESS(rv, rv);
- localDir = parentDir;
-
- if (didRemove) {
- --levelsToRemove;
- }
- }
-
- if (!localDir) {
- return NS_ERROR_FAILURE;
- }
-
- rv = localDir->AppendRelativeNativePath("TorBrowser" XPCOM_FILE_PATH_SEPARATOR
- "Data" XPCOM_FILE_PATH_SEPARATOR
+#ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
+ rv = localDir->AppendNative("Browser"_ns);
+#else
+ rv = localDir->AppendRelativeNativePath("Data" XPCOM_FILE_PATH_SEPARATOR
"Browser"_ns);
+#endif
NS_ENSURE_SUCCESS(rv, rv);
if (aLocal) {
[View Less]