summaryrefslogtreecommitdiff
blob: 6732652432a3bbf37189f7b197ecfe1c5c601ec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
From 0084df27957d0788bdccaeec0830647a61a3e877 Mon Sep 17 00:00:00 2001
From: Kathy Brade <brade@pearlcrescent.com>
Date: Fri, 18 Oct 2013 15:20:06 -0400
Subject: Bug #9173: Change the default Firefox profile directory to be
 TBB-relative.

This should eliminate our need to rely on a wrapper script that sets $HOME and
launches Firefox with -profile.

diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp
index 88a4348..4835541 100644
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -30,6 +30,7 @@
 #include "nsArrayEnumerator.h"
 #include "nsEnumeratorUtils.h"
 #include "nsReadableUtils.h"
+#include "nsXPCOMPrivate.h"  // for XPCOM_FILE_PATH_SEPARATOR
 #include "mozilla/Services.h"
 #include "mozilla/Omnijar.h"
 #include "mozilla/Preferences.h"
@@ -188,9 +189,6 @@ nsXREDirProvider::GetUserProfilesRootDir(nsIFile** aResult,
                                      aProfileName, aAppName, aVendorName);
 
   if (NS_SUCCEEDED(rv)) {
-#if !defined(XP_UNIX) || defined(XP_MACOSX)
-    rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles"));
-#endif
     // We must create the profile directory here if it does not exist.
     nsresult tmp = EnsureDirectoryExists(file);
     if (NS_FAILED(tmp)) {
@@ -213,9 +211,6 @@ nsXREDirProvider::GetUserProfilesLocalDir(nsIFile** aResult,
                                      aProfileName, aAppName, aVendorName);
 
   if (NS_SUCCEEDED(rv)) {
-#if !defined(XP_UNIX) || defined(XP_MACOSX)
-    rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles"));
-#endif
     // We must create the profile directory here if it does not exist.
     nsresult tmp = EnsureDirectoryExists(file);
     if (NS_FAILED(tmp)) {
@@ -1143,82 +1138,45 @@ nsresult
 nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal)
 {
   // Copied from nsAppFileLocationProvider (more or less)
-  nsresult rv;
+  NS_ENSURE_ARG_POINTER(aFile);
   nsCOMPtr<nsIFile> localDir;
 
-#if defined(XP_MACOSX)
-  FSRef fsRef;
-  OSType folderType;
-  if (aLocal) {
-    folderType = kCachedDataFolderType;
-  } else {
-#ifdef MOZ_THUNDERBIRD
-    folderType = kDomainLibraryFolderType;
-#else
-    folderType = kApplicationSupportFolderType;
-#endif
-  }
-  OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
-  NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
-
-  rv = NS_NewNativeLocalFile(EmptyCString(), true, getter_AddRefs(localDir));
+  nsresult rv = GetAppDir()->Clone(getter_AddRefs(localDir));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir);
-  NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED);
+  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(".");
 
-  rv = dirFileMac->InitWithFSRef(&fsRef);
-  NS_ENSURE_SUCCESS(rv, rv);
+    // Remove a directory component.
+    nsCOMPtr<nsIFile> parentDir;
+    rv = localDir->GetParent(getter_AddRefs(parentDir));
+    NS_ENSURE_SUCCESS(rv, rv);
+    localDir = parentDir;
 
-  localDir = do_QueryInterface(dirFileMac, &rv);
-#elif defined(XP_WIN)
-  nsString path;
-  if (aLocal) {
-    rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path);
-    if (NS_FAILED(rv))
-      rv = GetRegWindowsAppDataFolder(aLocal, path);
+    if (didRemove)
+      --levelsToRemove;
   }
-  if (!aLocal || NS_FAILED(rv)) {
-    rv = GetShellFolderPath(CSIDL_APPDATA, path);
-    if (NS_FAILED(rv)) {
-      if (!aLocal)
-        rv = GetRegWindowsAppDataFolder(aLocal, path);
-    }
-  }
-  NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir));
-#elif defined(MOZ_WIDGET_GONK)
-  rv = NS_NewNativeLocalFile(NS_LITERAL_CSTRING("/data/b2g"), true,
-                             getter_AddRefs(localDir));
-#elif defined(XP_UNIX)
-  const char* homeDir = getenv("HOME");
-  if (!homeDir || !*homeDir)
+  if (!localDir)
     return NS_ERROR_FAILURE;
 
-#ifdef ANDROID /* We want (ProfD == ProfLD) on Android. */
-  aLocal = false;
-#endif
+  rv = localDir->AppendRelativeNativePath(NS_LITERAL_CSTRING("TorBrowser"
+                                     XPCOM_FILE_PATH_SEPARATOR "Data"
+                                     XPCOM_FILE_PATH_SEPARATOR "Browser"));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (aLocal) {
-    // If $XDG_CACHE_HOME is defined use it, otherwise use $HOME/.cache.
-    const char* cacheHome = getenv("XDG_CACHE_HOME");
-    if (cacheHome && *cacheHome) {
-      rv = NS_NewNativeLocalFile(nsDependentCString(cacheHome), true,
-                                 getter_AddRefs(localDir));
-    } else {
-      rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
-                                 getter_AddRefs(localDir));
-      if (NS_SUCCEEDED(rv))
-        rv = localDir->AppendNative(NS_LITERAL_CSTRING(".cache"));
-    }
-  } else {
-    rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
-                               getter_AddRefs(localDir));
+    rv = localDir->AppendNative(NS_LITERAL_CSTRING("Caches"));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
-#else
-#error "Don't know how to get product dir on your platform"
-#endif
 
   NS_IF_ADDREF(*aFile = localDir);
   return rv;
@@ -1431,48 +1389,25 @@ nsXREDirProvider::AppendProfilePath(nsIFile* aFile,
   }
 
   nsAutoCString profile;
-  nsAutoCString appName;
-  nsAutoCString vendor;
   if (aProfileName && !aProfileName->IsEmpty()) {
     profile = *aProfileName;
-  } else if (aAppName) {
-    appName = *aAppName;
-    if (aVendorName) {
-      vendor = *aVendorName;
-    }
   } else if (gAppData->profile) {
     profile = gAppData->profile;
-  } else {
-    appName = gAppData->name;
-    vendor = gAppData->vendor;
   }
 
-  nsresult rv;
+  nsresult rv = NS_ERROR_FAILURE;
 
 #if defined (XP_MACOSX)
   if (!profile.IsEmpty()) {
     rv = AppendProfileString(aFile, profile.get());
+    NS_ENSURE_SUCCESS(rv, rv);
   }
-  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);
-  }
-  NS_ENSURE_SUCCESS(rv, rv);
 
 #elif defined(XP_WIN)
   if (!profile.IsEmpty()) {
     rv = AppendProfileString(aFile, profile.get());
+    NS_ENSURE_SUCCESS(rv, rv);
   }
-  else {
-    if (!vendor.IsEmpty()) {
-      rv = aFile->AppendNative(vendor);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-    rv = aFile->AppendNative(appName);
-  }
-  NS_ENSURE_SUCCESS(rv, rv);
 
 #elif defined(ANDROID)
   // The directory used for storing profiles
@@ -1484,12 +1419,6 @@ nsXREDirProvider::AppendProfilePath(nsIFile* aFile,
   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).
-  if (!aLocal)
-    folder.Assign('.');
-
   if (!profile.IsEmpty()) {
     // Skip any leading path characters
     const char* profileStart = profile.get();
@@ -1498,31 +1427,17 @@ nsXREDirProvider::AppendProfilePath(nsIFile* aFile,
 
     // On the off chance that someone wanted their folder to be hidden don't
     // let it become ".."
-    if (*profileStart == '.' && !aLocal)
+    if (*profileStart == '.')
       profileStart++;
 
+    // Make it hidden (by starting with ".").
+    nsAutoCString folder(".");
     folder.Append(profileStart);
     ToLowerCase(folder);
 
     rv = AppendProfileString(aFile, folder.BeginReading());
+    NS_ENSURE_SUCCESS(rv, rv);
   }
-  else {
-    if (!vendor.IsEmpty()) {
-      folder.Append(vendor);
-      ToLowerCase(folder);
-
-      rv = aFile->AppendNative(folder);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      folder.Truncate();
-    }
-
-    folder.Append(appName);
-    ToLowerCase(folder);
-
-    rv = aFile->AppendNative(folder);
-  }
-  NS_ENSURE_SUCCESS(rv, rv);
 
 #else
 #error "Don't know how to get profile path on your platform"
diff --git a/toolkit/xre/nsXREDirProvider.h b/toolkit/xre/nsXREDirProvider.h
index 4a9f9a0..054075c 100644
--- a/toolkit/xre/nsXREDirProvider.h
+++ b/toolkit/xre/nsXREDirProvider.h
@@ -56,16 +56,16 @@ public:
 
   nsresult GetProfileDefaultsDir(nsIFile* *aResult);
 
-  static nsresult GetUserAppDataDirectory(nsIFile* *aFile) {
+  nsresult GetUserAppDataDirectory(nsIFile* *aFile) {
     return GetUserDataDirectory(aFile, false, nullptr, nullptr, nullptr);
   }
-  static nsresult GetUserLocalDataDirectory(nsIFile* *aFile) {
+  nsresult GetUserLocalDataDirectory(nsIFile* *aFile) {
     return GetUserDataDirectory(aFile, true, nullptr, nullptr, nullptr);
   }
 
   // By default GetUserDataDirectory gets profile path from gAppData,
   // but that can be overridden by using aProfileName/aAppName/aVendorName.
-  static nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal,
+  nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal,
                                        const nsACString* aProfileName,
                                        const nsACString* aAppName,
                                        const nsACString* aVendorName);
@@ -101,8 +101,8 @@ public:
 
 protected:
   nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult);
-  static nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal);
-  static nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile);
+  nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal);
+  nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile);
 #if defined(XP_UNIX) || defined(XP_MACOSX)
   static nsresult GetSystemExtensionsDirectory(nsIFile** aFile);
 #endif
diff --git a/xpcom/io/moz.build b/xpcom/io/moz.build
index cc467f9..609068b 100644
--- a/xpcom/io/moz.build
+++ b/xpcom/io/moz.build
@@ -126,4 +126,8 @@ FINAL_LIBRARY = 'xpcom_core'
 if CONFIG['OS_ARCH'] == 'Linux' and 'lib64' in CONFIG['libdir']:
     DEFINES['HAVE_USR_LIB64_DIR'] = True
 
+LOCAL_INCLUDES += [
+    '../build'
+]
+
 GENERATED_INCLUDES += ['..']
diff --git a/xpcom/io/nsAppFileLocationProvider.cpp b/xpcom/io/nsAppFileLocationProvider.cpp
index 1a38589..83f9836 100644
--- a/xpcom/io/nsAppFileLocationProvider.cpp
+++ b/xpcom/io/nsAppFileLocationProvider.cpp
@@ -13,6 +13,7 @@
 #include "nsISimpleEnumerator.h"
 #include "prenv.h"
 #include "nsCRT.h"
+#include "nsXPCOMPrivate.h"  // for XPCOM_FILE_PATH_SEPARATOR
 
 #if defined(MOZ_WIDGET_COCOA)
 #include <Carbon/Carbon.h>
@@ -284,9 +285,8 @@ NS_METHOD nsAppFileLocationProvider::CloneMozBinDirectory(nsIFile **aLocalFile)
 //----------------------------------------------------------------------------------------
 // GetProductDirectory - Gets the directory which contains the application data folder
 //
-// UNIX   : ~/.mozilla/
-// WIN    : <Application Data folder on user's machine>\Mozilla
-// Mac    : :Documents:Mozilla:
+// UNIX and WIN   : <App Folder>/TorBrowser/Data/Browser
+// Mac            : <App Folder>/../../TorBrowser/Data/Browser
 //----------------------------------------------------------------------------------------
 NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsIFile **aLocalFile, bool aLocal)
 {
@@ -297,32 +297,43 @@ NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsIFile **aLocalFile, b
     bool exists;
     nsCOMPtr<nsIFile> localDir;
 
-#if defined(MOZ_WIDGET_COCOA)
-    FSRef fsRef;
-    OSType folderType = aLocal ? (OSType) kCachedDataFolderType : (OSType) kDomainLibraryFolderType;
-    OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
-    if (err) return NS_ERROR_FAILURE;
-    NS_NewLocalFile(EmptyString(), true, getter_AddRefs(localDir));
-    if (!localDir) return NS_ERROR_FAILURE;
-    nsCOMPtr<nsILocalFileMac> localDirMac(do_QueryInterface(localDir));
-    rv = localDirMac->InitWithFSRef(&fsRef);
-    if (NS_FAILED(rv)) return rv;
-#elif defined(XP_WIN)
-    nsCOMPtr<nsIProperties> directoryService = 
-             do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
-    if (NS_FAILED(rv)) return rv;
-    const char* prop = aLocal ? NS_WIN_LOCAL_APPDATA_DIR : NS_WIN_APPDATA_DIR;
-    rv = directoryService->Get(prop, NS_GET_IID(nsIFile), getter_AddRefs(localDir));
-    if (NS_FAILED(rv)) return rv;
-#elif defined(XP_UNIX)
-    rv = NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), true, getter_AddRefs(localDir));
-    if (NS_FAILED(rv)) return rv;
-#else
-#error dont_know_how_to_get_product_dir_on_your_platform
+    rv = CloneMozBinDirectory(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(NS_LITERAL_CSTRING("TorBrowser"
+                                       XPCOM_FILE_PATH_SEPARATOR "Data"
+                                       XPCOM_FILE_PATH_SEPARATOR "Browser"));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (aLocal) {
+        rv = localDir->AppendNative(NS_LITERAL_CSTRING("Caches"));
+        NS_ENSURE_SUCCESS(rv, rv);
+    }
 
-    rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR);
-    if (NS_FAILED(rv)) return rv;
     rv = localDir->Exists(&exists);
 
     if (NS_SUCCEEDED(rv) && !exists)
@@ -339,10 +350,6 @@ NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsIFile **aLocalFile, b
 
 //----------------------------------------------------------------------------------------
 // GetDefaultUserProfileRoot - Gets the directory which contains each user profile dir
-//
-// UNIX   : ~/.mozilla/
-// WIN    : <Application Data folder on user's machine>\Mozilla\Profiles
-// Mac    : :Documents:Mozilla:Profiles:
 //----------------------------------------------------------------------------------------
 NS_METHOD nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsIFile **aLocalFile, bool aLocal)
 {
@@ -355,18 +362,6 @@ NS_METHOD nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsIFile **aLocalF
     rv = GetProductDirectory(getter_AddRefs(localDir), aLocal);
     if (NS_FAILED(rv)) 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(NS_LITERAL_CSTRING("Profiles"));
-    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
-
     *aLocalFile = localDir;
     NS_ADDREF(*aLocalFile);
 
-- 
cgit v0.10.2