Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: sw=4 ts=4 sts=4 et
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/. */
7 #include "mozilla/ArrayUtils.h"
9 #include "nsCOMPtr.h"
10 #include "nsAutoPtr.h"
11 #include "nsDirectoryService.h"
12 #include "nsDirectoryServiceDefs.h"
13 #include "nsLocalFile.h"
14 #include "nsDebug.h"
15 #include "nsStaticAtom.h"
16 #include "nsEnumeratorUtils.h"
18 #include "nsICategoryManager.h"
19 #include "nsISimpleEnumerator.h"
20 #include "nsIStringEnumerator.h"
22 #if defined(XP_WIN)
23 #include <windows.h>
24 #include <shlobj.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #elif defined(XP_UNIX)
28 #include <unistd.h>
29 #include <stdlib.h>
30 #include <sys/param.h>
31 #include "prenv.h"
32 #ifdef MOZ_WIDGET_COCOA
33 #include <CoreServices/CoreServices.h>
34 #include <Carbon/Carbon.h>
35 #endif
36 #endif
38 #include "SpecialSystemDirectory.h"
39 #include "nsAppFileLocationProvider.h"
41 using namespace mozilla;
43 // define home directory
44 // For Windows platform, We are choosing Appdata folder as HOME
45 #if defined (XP_WIN)
46 #define HOME_DIR NS_WIN_APPDATA_DIR
47 #elif defined (MOZ_WIDGET_COCOA)
48 #define HOME_DIR NS_OSX_HOME_DIR
49 #elif defined (XP_UNIX)
50 #define HOME_DIR NS_UNIX_HOME_DIR
51 #endif
53 //----------------------------------------------------------------------------------------
54 nsresult
55 nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile)
56 //----------------------------------------------------------------------------------------
57 {
58 if (NS_WARN_IF(!aFile))
59 return NS_ERROR_INVALID_ARG;
60 *aFile = nullptr;
62 // Set the component registry location:
63 if (!gService)
64 return NS_ERROR_FAILURE;
66 nsresult rv;
68 nsCOMPtr<nsIProperties> dirService;
69 rv = nsDirectoryService::Create(nullptr,
70 NS_GET_IID(nsIProperties),
71 getter_AddRefs(dirService)); // needs to be around for life of product
72 if (NS_FAILED(rv))
73 return rv;
75 if (dirService)
76 {
77 nsCOMPtr <nsIFile> aLocalFile;
78 dirService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(aLocalFile));
79 if (aLocalFile)
80 {
81 *aFile = aLocalFile;
82 NS_ADDREF(*aFile);
83 return NS_OK;
84 }
85 }
87 nsLocalFile* localFile = new nsLocalFile;
89 if (localFile == nullptr)
90 return NS_ERROR_OUT_OF_MEMORY;
91 NS_ADDREF(localFile);
95 #ifdef XP_WIN
96 wchar_t buf[MAX_PATH + 1];
97 SetLastError(ERROR_SUCCESS);
98 if (GetModuleFileNameW(0, buf, mozilla::ArrayLength(buf)) &&
99 GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
100 // chop off the executable name by finding the rightmost backslash
101 wchar_t* lastSlash = wcsrchr(buf, L'\\');
102 if (lastSlash)
103 *(lastSlash + 1) = L'\0';
105 localFile->InitWithPath(nsDependentString(buf));
106 *aFile = localFile;
107 return NS_OK;
108 }
110 #elif defined(MOZ_WIDGET_COCOA)
111 // Works even if we're not bundled.
112 CFBundleRef appBundle = CFBundleGetMainBundle();
113 if (appBundle != nullptr)
114 {
115 CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle);
116 if (bundleURL != nullptr)
117 {
118 CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, bundleURL);
119 if (parentURL)
120 {
121 // Pass true for the "resolveAgainstBase" arg to CFURLGetFileSystemRepresentation.
122 // This will resolve the relative portion of the CFURL against it base, giving a full
123 // path, which CFURLCopyFileSystemPath doesn't do.
124 char buffer[PATH_MAX];
125 if (CFURLGetFileSystemRepresentation(parentURL, true, (UInt8 *)buffer, sizeof(buffer)))
126 {
127 #ifdef DEBUG_conrad
128 printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer);
129 #endif
130 rv = localFile->InitWithNativePath(nsDependentCString(buffer));
131 if (NS_SUCCEEDED(rv))
132 *aFile = localFile;
133 }
134 CFRelease(parentURL);
135 }
136 CFRelease(bundleURL);
137 }
138 }
140 NS_ASSERTION(*aFile, "nsDirectoryService - Could not determine CurrentProcessDir.\n");
141 if (*aFile)
142 return NS_OK;
144 #elif defined(XP_UNIX)
146 // In the absence of a good way to get the executable directory let
147 // us try this for unix:
148 // - if MOZILLA_FIVE_HOME is defined, that is it
149 // - else give the current directory
150 char buf[MAXPATHLEN];
152 // The MOZ_DEFAULT_MOZILLA_FIVE_HOME variable can be set at configure time with
153 // a --with-default-mozilla-five-home=foo autoconf flag.
154 //
155 // The idea here is to allow for builds that have a default MOZILLA_FIVE_HOME
156 // regardless of the environment. This makes it easier to write apps that
157 // embed mozilla without having to worry about setting up the environment
158 //
159 // We do this by putenv()ing the default value into the environment. Note that
160 // we only do this if it is not already set.
161 #ifdef MOZ_DEFAULT_MOZILLA_FIVE_HOME
162 const char *home = PR_GetEnv("MOZILLA_FIVE_HOME");
163 if (!home || !*home)
164 {
165 putenv("MOZILLA_FIVE_HOME=" MOZ_DEFAULT_MOZILLA_FIVE_HOME);
166 }
167 #endif
169 char *moz5 = PR_GetEnv("MOZILLA_FIVE_HOME");
170 if (moz5 && *moz5)
171 {
172 if (realpath(moz5, buf)) {
173 localFile->InitWithNativePath(nsDependentCString(buf));
174 *aFile = localFile;
175 return NS_OK;
176 }
177 }
178 #if defined(DEBUG)
179 static bool firstWarning = true;
181 if((!moz5 || !*moz5) && firstWarning) {
182 // Warn that MOZILLA_FIVE_HOME not set, once.
183 printf("Warning: MOZILLA_FIVE_HOME not set.\n");
184 firstWarning = false;
185 }
186 #endif /* DEBUG */
188 // Fall back to current directory.
189 if (getcwd(buf, sizeof(buf)))
190 {
191 localFile->InitWithNativePath(nsDependentCString(buf));
192 *aFile = localFile;
193 return NS_OK;
194 }
196 #endif
198 NS_RELEASE(localFile);
200 NS_ERROR("unable to get current process directory");
201 return NS_ERROR_FAILURE;
202 } // GetCurrentProcessDirectory()
204 nsDirectoryService* nsDirectoryService::gService = nullptr;
206 nsDirectoryService::nsDirectoryService()
207 : mHashtable(256)
208 {
209 }
211 nsresult
212 nsDirectoryService::Create(nsISupports *outer, REFNSIID aIID, void **aResult)
213 {
214 if (NS_WARN_IF(!aResult))
215 return NS_ERROR_INVALID_ARG;
216 if (NS_WARN_IF(outer))
217 return NS_ERROR_NO_AGGREGATION;
219 if (!gService)
220 {
221 return NS_ERROR_NOT_INITIALIZED;
222 }
224 return gService->QueryInterface(aIID, aResult);
225 }
227 #define DIR_ATOM(name_, value_) nsIAtom* nsDirectoryService::name_ = nullptr;
228 #include "nsDirectoryServiceAtomList.h"
229 #undef DIR_ATOM
231 #define DIR_ATOM(name_, value_) NS_STATIC_ATOM_BUFFER(name_##_buffer, value_)
232 #include "nsDirectoryServiceAtomList.h"
233 #undef DIR_ATOM
235 static const nsStaticAtom directory_atoms[] = {
236 #define DIR_ATOM(name_, value_) NS_STATIC_ATOM(name_##_buffer, &nsDirectoryService::name_),
237 #include "nsDirectoryServiceAtomList.h"
238 #undef DIR_ATOM
239 };
241 NS_IMETHODIMP
242 nsDirectoryService::Init()
243 {
244 NS_NOTREACHED("nsDirectoryService::Init() for internal use only!");
245 return NS_OK;
246 }
248 void
249 nsDirectoryService::RealInit()
250 {
251 NS_ASSERTION(!gService,
252 "nsDirectoryService::RealInit Mustn't initialize twice!");
254 nsRefPtr<nsDirectoryService> self = new nsDirectoryService();
256 NS_RegisterStaticAtoms(directory_atoms);
258 // Let the list hold the only reference to the provider.
259 nsAppFileLocationProvider *defaultProvider = new nsAppFileLocationProvider;
260 self->mProviders.AppendElement(defaultProvider);
262 self.swap(gService);
263 }
265 nsDirectoryService::~nsDirectoryService()
266 {
267 }
269 NS_IMPL_ISUPPORTS(nsDirectoryService, nsIProperties, nsIDirectoryService, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2)
272 NS_IMETHODIMP
273 nsDirectoryService::Undefine(const char* prop)
274 {
275 if (NS_WARN_IF(!prop))
276 return NS_ERROR_INVALID_ARG;
278 nsDependentCString key(prop);
279 if (!mHashtable.Get(key, nullptr))
280 return NS_ERROR_FAILURE;
282 mHashtable.Remove(key);
283 return NS_OK;
284 }
286 NS_IMETHODIMP
287 nsDirectoryService::GetKeys(uint32_t *count, char ***keys)
288 {
289 return NS_ERROR_NOT_IMPLEMENTED;
290 }
292 struct FileData
293 {
294 FileData(const char* aProperty,
295 const nsIID& aUUID) :
296 property(aProperty),
297 data(nullptr),
298 persistent(true),
299 uuid(aUUID) {}
301 const char* property;
302 nsISupports* data;
303 bool persistent;
304 const nsIID& uuid;
305 };
307 static bool FindProviderFile(nsIDirectoryServiceProvider* aElement,
308 FileData* aData)
309 {
310 nsresult rv;
311 if (aData->uuid.Equals(NS_GET_IID(nsISimpleEnumerator))) {
312 // Not all providers implement this iface
313 nsCOMPtr<nsIDirectoryServiceProvider2> prov2 = do_QueryInterface(aElement);
314 if (prov2)
315 {
316 nsCOMPtr<nsISimpleEnumerator> newFiles;
317 rv = prov2->GetFiles(aData->property, getter_AddRefs(newFiles));
318 if (NS_SUCCEEDED(rv) && newFiles) {
319 if (aData->data) {
320 nsCOMPtr<nsISimpleEnumerator> unionFiles;
322 NS_NewUnionEnumerator(getter_AddRefs(unionFiles),
323 (nsISimpleEnumerator*) aData->data, newFiles);
325 if (unionFiles)
326 unionFiles.swap(* (nsISimpleEnumerator**) &aData->data);
327 }
328 else
329 {
330 NS_ADDREF(aData->data = newFiles);
331 }
333 aData->persistent = false; // Enumerators can never be persistent
334 return rv == NS_SUCCESS_AGGREGATE_RESULT;
335 }
336 }
337 }
338 else
339 {
340 rv = aElement->GetFile(aData->property, &aData->persistent,
341 (nsIFile **)&aData->data);
342 if (NS_SUCCEEDED(rv) && aData->data)
343 return false;
344 }
346 return true;
347 }
349 NS_IMETHODIMP
350 nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result)
351 {
352 if (NS_WARN_IF(!prop))
353 return NS_ERROR_INVALID_ARG;
355 nsDependentCString key(prop);
357 nsCOMPtr<nsIFile> cachedFile = mHashtable.Get(key);
359 if (cachedFile) {
360 nsCOMPtr<nsIFile> cloneFile;
361 cachedFile->Clone(getter_AddRefs(cloneFile));
362 return cloneFile->QueryInterface(uuid, result);
363 }
365 // it is not one of our defaults, lets check any providers
366 FileData fileData(prop, uuid);
368 for (int32_t i = mProviders.Length() - 1; i >= 0; i--) {
369 if (!FindProviderFile(mProviders[i], &fileData)) {
370 break;
371 }
372 }
373 if (fileData.data)
374 {
375 if (fileData.persistent)
376 {
377 Set(prop, static_cast<nsIFile*>(fileData.data));
378 }
379 nsresult rv = (fileData.data)->QueryInterface(uuid, result);
380 NS_RELEASE(fileData.data); // addref occurs in FindProviderFile()
381 return rv;
382 }
384 FindProviderFile(static_cast<nsIDirectoryServiceProvider*>(this), &fileData);
385 if (fileData.data)
386 {
387 if (fileData.persistent)
388 {
389 Set(prop, static_cast<nsIFile*>(fileData.data));
390 }
391 nsresult rv = (fileData.data)->QueryInterface(uuid, result);
392 NS_RELEASE(fileData.data); // addref occurs in FindProviderFile()
393 return rv;
394 }
396 return NS_ERROR_FAILURE;
397 }
399 NS_IMETHODIMP
400 nsDirectoryService::Set(const char* prop, nsISupports* value)
401 {
402 if (NS_WARN_IF(!prop))
403 return NS_ERROR_INVALID_ARG;
405 nsDependentCString key(prop);
406 if (mHashtable.Get(key, nullptr) || !value) {
407 return NS_ERROR_FAILURE;
408 }
410 nsCOMPtr<nsIFile> ourFile = do_QueryInterface(value);
411 if (ourFile) {
412 nsCOMPtr<nsIFile> cloneFile;
413 ourFile->Clone (getter_AddRefs (cloneFile));
414 mHashtable.Put(key, cloneFile);
416 return NS_OK;
417 }
419 return NS_ERROR_FAILURE;
420 }
422 NS_IMETHODIMP
423 nsDirectoryService::Has(const char *prop, bool *_retval)
424 {
425 if (NS_WARN_IF(!prop))
426 return NS_ERROR_INVALID_ARG;
428 *_retval = false;
429 nsCOMPtr<nsIFile> value;
430 nsresult rv = Get(prop, NS_GET_IID(nsIFile), getter_AddRefs(value));
431 if (NS_FAILED(rv))
432 return NS_OK;
434 if (value)
435 {
436 *_retval = true;
437 }
439 return rv;
440 }
442 NS_IMETHODIMP
443 nsDirectoryService::RegisterProvider(nsIDirectoryServiceProvider *prov)
444 {
445 if (!prov)
446 return NS_ERROR_FAILURE;
448 mProviders.AppendElement(prov);
449 return NS_OK;
450 }
452 void
453 nsDirectoryService::RegisterCategoryProviders()
454 {
455 nsCOMPtr<nsICategoryManager> catman
456 (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
457 if (!catman)
458 return;
460 nsCOMPtr<nsISimpleEnumerator> entries;
461 catman->EnumerateCategory(XPCOM_DIRECTORY_PROVIDER_CATEGORY,
462 getter_AddRefs(entries));
464 nsCOMPtr<nsIUTF8StringEnumerator> strings(do_QueryInterface(entries));
465 if (!strings)
466 return;
468 bool more;
469 while (NS_SUCCEEDED(strings->HasMore(&more)) && more) {
470 nsAutoCString entry;
471 strings->GetNext(entry);
473 nsXPIDLCString contractID;
474 catman->GetCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY, entry.get(), getter_Copies(contractID));
476 if (contractID) {
477 nsCOMPtr<nsIDirectoryServiceProvider> provider = do_GetService(contractID.get());
478 if (provider)
479 RegisterProvider(provider);
480 }
481 }
482 }
484 NS_IMETHODIMP
485 nsDirectoryService::UnregisterProvider(nsIDirectoryServiceProvider *prov)
486 {
487 if (!prov)
488 return NS_ERROR_FAILURE;
490 mProviders.RemoveElement(prov);
491 return NS_OK;
492 }
494 // DO NOT ADD ANY LOCATIONS TO THIS FUNCTION UNTIL YOU TALK TO: dougt@netscape.com.
495 // This is meant to be a place of xpcom or system specific file locations, not
496 // application specific locations. If you need the later, register a callback for
497 // your application.
499 NS_IMETHODIMP
500 nsDirectoryService::GetFile(const char *prop, bool *persistent, nsIFile **_retval)
501 {
502 nsCOMPtr<nsIFile> localFile;
503 nsresult rv = NS_ERROR_FAILURE;
505 *_retval = nullptr;
506 *persistent = true;
508 nsCOMPtr<nsIAtom> inAtom = do_GetAtom(prop);
510 // check to see if it is one of our defaults
512 if (inAtom == nsDirectoryService::sCurrentProcess ||
513 inAtom == nsDirectoryService::sOS_CurrentProcessDirectory )
514 {
515 rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
516 }
518 // Unless otherwise set, the core pieces of the GRE exist
519 // in the current process directory.
520 else if (inAtom == nsDirectoryService::sGRE_Directory)
521 {
522 rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
523 }
524 else if (inAtom == nsDirectoryService::sOS_DriveDirectory)
525 {
526 rv = GetSpecialSystemDirectory(OS_DriveDirectory, getter_AddRefs(localFile));
527 }
528 else if (inAtom == nsDirectoryService::sOS_TemporaryDirectory)
529 {
530 rv = GetSpecialSystemDirectory(OS_TemporaryDirectory, getter_AddRefs(localFile));
531 }
532 else if (inAtom == nsDirectoryService::sOS_CurrentProcessDirectory)
533 {
534 rv = GetSpecialSystemDirectory(OS_CurrentProcessDirectory, getter_AddRefs(localFile));
535 }
536 else if (inAtom == nsDirectoryService::sOS_CurrentWorkingDirectory)
537 {
538 rv = GetSpecialSystemDirectory(OS_CurrentWorkingDirectory, getter_AddRefs(localFile));
539 }
541 #if defined(MOZ_WIDGET_COCOA)
542 else if (inAtom == nsDirectoryService::sDirectory)
543 {
544 rv = GetOSXFolderType(kClassicDomain, kSystemFolderType, getter_AddRefs(localFile));
545 }
546 else if (inAtom == nsDirectoryService::sTrashDirectory)
547 {
548 rv = GetOSXFolderType(kClassicDomain, kTrashFolderType, getter_AddRefs(localFile));
549 }
550 else if (inAtom == nsDirectoryService::sStartupDirectory)
551 {
552 rv = GetOSXFolderType(kClassicDomain, kStartupFolderType, getter_AddRefs(localFile));
553 }
554 else if (inAtom == nsDirectoryService::sShutdownDirectory)
555 {
556 rv = GetOSXFolderType(kClassicDomain, kShutdownFolderType, getter_AddRefs(localFile));
557 }
558 else if (inAtom == nsDirectoryService::sAppleMenuDirectory)
559 {
560 rv = GetOSXFolderType(kClassicDomain, kAppleMenuFolderType, getter_AddRefs(localFile));
561 }
562 else if (inAtom == nsDirectoryService::sControlPanelDirectory)
563 {
564 rv = GetOSXFolderType(kClassicDomain, kControlPanelFolderType, getter_AddRefs(localFile));
565 }
566 else if (inAtom == nsDirectoryService::sExtensionDirectory)
567 {
568 rv = GetOSXFolderType(kClassicDomain, kExtensionFolderType, getter_AddRefs(localFile));
569 }
570 else if (inAtom == nsDirectoryService::sFontsDirectory)
571 {
572 rv = GetOSXFolderType(kClassicDomain, kFontsFolderType, getter_AddRefs(localFile));
573 }
574 else if (inAtom == nsDirectoryService::sPreferencesDirectory)
575 {
576 rv = GetOSXFolderType(kClassicDomain, kPreferencesFolderType, getter_AddRefs(localFile));
577 }
578 else if (inAtom == nsDirectoryService::sDocumentsDirectory)
579 {
580 rv = GetOSXFolderType(kClassicDomain, kDocumentsFolderType, getter_AddRefs(localFile));
581 }
582 else if (inAtom == nsDirectoryService::sInternetSearchDirectory)
583 {
584 rv = GetOSXFolderType(kClassicDomain, kInternetSearchSitesFolderType, getter_AddRefs(localFile));
585 }
586 else if (inAtom == nsDirectoryService::sUserLibDirectory)
587 {
588 rv = GetOSXFolderType(kUserDomain, kDomainLibraryFolderType, getter_AddRefs(localFile));
589 }
590 else if (inAtom == nsDirectoryService::sOS_HomeDirectory)
591 {
592 rv = GetOSXFolderType(kUserDomain, kDomainTopLevelFolderType, getter_AddRefs(localFile));
593 }
594 else if (inAtom == nsDirectoryService::sDefaultDownloadDirectory)
595 {
596 // 10.5 and later, we can use kDownloadsFolderType which is defined in
597 // Folders.h as "down". However, in order to support 10.4 still, we
598 // cannot use the named constant. We'll use it's value, and if it
599 // fails, fall back to the desktop.
600 #ifndef kDownloadsFolderType
601 #define kDownloadsFolderType 'down'
602 #endif
604 rv = GetOSXFolderType(kUserDomain, kDownloadsFolderType,
605 getter_AddRefs(localFile));
606 if (NS_FAILED(rv)) {
607 rv = GetOSXFolderType(kUserDomain, kDesktopFolderType,
608 getter_AddRefs(localFile));
609 }
610 }
611 else if (inAtom == nsDirectoryService::sUserDesktopDirectory ||
612 inAtom == nsDirectoryService::sOS_DesktopDirectory)
613 {
614 rv = GetOSXFolderType(kUserDomain, kDesktopFolderType, getter_AddRefs(localFile));
615 }
616 else if (inAtom == nsDirectoryService::sLocalDesktopDirectory)
617 {
618 rv = GetOSXFolderType(kLocalDomain, kDesktopFolderType, getter_AddRefs(localFile));
619 }
620 else if (inAtom == nsDirectoryService::sUserApplicationsDirectory)
621 {
622 rv = GetOSXFolderType(kUserDomain, kApplicationsFolderType, getter_AddRefs(localFile));
623 }
624 else if (inAtom == nsDirectoryService::sLocalApplicationsDirectory)
625 {
626 rv = GetOSXFolderType(kLocalDomain, kApplicationsFolderType, getter_AddRefs(localFile));
627 }
628 else if (inAtom == nsDirectoryService::sUserDocumentsDirectory)
629 {
630 rv = GetOSXFolderType(kUserDomain, kDocumentsFolderType, getter_AddRefs(localFile));
631 }
632 else if (inAtom == nsDirectoryService::sLocalDocumentsDirectory)
633 {
634 rv = GetOSXFolderType(kLocalDomain, kDocumentsFolderType, getter_AddRefs(localFile));
635 }
636 else if (inAtom == nsDirectoryService::sUserInternetPlugInDirectory)
637 {
638 rv = GetOSXFolderType(kUserDomain, kInternetPlugInFolderType, getter_AddRefs(localFile));
639 }
640 else if (inAtom == nsDirectoryService::sLocalInternetPlugInDirectory)
641 {
642 rv = GetOSXFolderType(kLocalDomain, kInternetPlugInFolderType, getter_AddRefs(localFile));
643 }
644 else if (inAtom == nsDirectoryService::sUserFrameworksDirectory)
645 {
646 rv = GetOSXFolderType(kUserDomain, kFrameworksFolderType, getter_AddRefs(localFile));
647 }
648 else if (inAtom == nsDirectoryService::sLocalFrameworksDirectory)
649 {
650 rv = GetOSXFolderType(kLocalDomain, kFrameworksFolderType, getter_AddRefs(localFile));
651 }
652 else if (inAtom == nsDirectoryService::sUserPreferencesDirectory)
653 {
654 rv = GetOSXFolderType(kUserDomain, kPreferencesFolderType, getter_AddRefs(localFile));
655 }
656 else if (inAtom == nsDirectoryService::sLocalPreferencesDirectory)
657 {
658 rv = GetOSXFolderType(kLocalDomain, kPreferencesFolderType, getter_AddRefs(localFile));
659 }
660 else if (inAtom == nsDirectoryService::sPictureDocumentsDirectory)
661 {
662 rv = GetOSXFolderType(kUserDomain, kPictureDocumentsFolderType, getter_AddRefs(localFile));
663 }
664 else if (inAtom == nsDirectoryService::sMovieDocumentsDirectory)
665 {
666 rv = GetOSXFolderType(kUserDomain, kMovieDocumentsFolderType, getter_AddRefs(localFile));
667 }
668 else if (inAtom == nsDirectoryService::sMusicDocumentsDirectory)
669 {
670 rv = GetOSXFolderType(kUserDomain, kMusicDocumentsFolderType, getter_AddRefs(localFile));
671 }
672 else if (inAtom == nsDirectoryService::sInternetSitesDirectory)
673 {
674 rv = GetOSXFolderType(kUserDomain, kInternetSitesFolderType, getter_AddRefs(localFile));
675 }
676 #elif defined (XP_WIN)
677 else if (inAtom == nsDirectoryService::sSystemDirectory)
678 {
679 rv = GetSpecialSystemDirectory(Win_SystemDirectory, getter_AddRefs(localFile));
680 }
681 else if (inAtom == nsDirectoryService::sWindowsDirectory)
682 {
683 rv = GetSpecialSystemDirectory(Win_WindowsDirectory, getter_AddRefs(localFile));
684 }
685 else if (inAtom == nsDirectoryService::sWindowsProgramFiles)
686 {
687 rv = GetSpecialSystemDirectory(Win_ProgramFiles, getter_AddRefs(localFile));
688 }
689 else if (inAtom == nsDirectoryService::sOS_HomeDirectory)
690 {
691 rv = GetSpecialSystemDirectory(Win_HomeDirectory, getter_AddRefs(localFile));
692 }
693 else if (inAtom == nsDirectoryService::sDesktop)
694 {
695 rv = GetSpecialSystemDirectory(Win_Desktop, getter_AddRefs(localFile));
696 }
697 else if (inAtom == nsDirectoryService::sPrograms)
698 {
699 rv = GetSpecialSystemDirectory(Win_Programs, getter_AddRefs(localFile));
700 }
701 else if (inAtom == nsDirectoryService::sControls)
702 {
703 rv = GetSpecialSystemDirectory(Win_Controls, getter_AddRefs(localFile));
704 }
705 else if (inAtom == nsDirectoryService::sPrinters)
706 {
707 rv = GetSpecialSystemDirectory(Win_Printers, getter_AddRefs(localFile));
708 }
709 else if (inAtom == nsDirectoryService::sPersonal)
710 {
711 rv = GetSpecialSystemDirectory(Win_Personal, getter_AddRefs(localFile));
712 }
713 else if (inAtom == nsDirectoryService::sFavorites)
714 {
715 rv = GetSpecialSystemDirectory(Win_Favorites, getter_AddRefs(localFile));
716 }
717 else if (inAtom == nsDirectoryService::sStartup)
718 {
719 rv = GetSpecialSystemDirectory(Win_Startup, getter_AddRefs(localFile));
720 }
721 else if (inAtom == nsDirectoryService::sRecent)
722 {
723 rv = GetSpecialSystemDirectory(Win_Recent, getter_AddRefs(localFile));
724 }
725 else if (inAtom == nsDirectoryService::sSendto)
726 {
727 rv = GetSpecialSystemDirectory(Win_Sendto, getter_AddRefs(localFile));
728 }
729 else if (inAtom == nsDirectoryService::sBitbucket)
730 {
731 rv = GetSpecialSystemDirectory(Win_Bitbucket, getter_AddRefs(localFile));
732 }
733 else if (inAtom == nsDirectoryService::sStartmenu)
734 {
735 rv = GetSpecialSystemDirectory(Win_Startmenu, getter_AddRefs(localFile));
736 }
737 else if (inAtom == nsDirectoryService::sDesktopdirectory ||
738 inAtom == nsDirectoryService::sOS_DesktopDirectory)
739 {
740 rv = GetSpecialSystemDirectory(Win_Desktopdirectory, getter_AddRefs(localFile));
741 }
742 else if (inAtom == nsDirectoryService::sDrives)
743 {
744 rv = GetSpecialSystemDirectory(Win_Drives, getter_AddRefs(localFile));
745 }
746 else if (inAtom == nsDirectoryService::sNetwork)
747 {
748 rv = GetSpecialSystemDirectory(Win_Network, getter_AddRefs(localFile));
749 }
750 else if (inAtom == nsDirectoryService::sNethood)
751 {
752 rv = GetSpecialSystemDirectory(Win_Nethood, getter_AddRefs(localFile));
753 }
754 else if (inAtom == nsDirectoryService::sFonts)
755 {
756 rv = GetSpecialSystemDirectory(Win_Fonts, getter_AddRefs(localFile));
757 }
758 else if (inAtom == nsDirectoryService::sTemplates)
759 {
760 rv = GetSpecialSystemDirectory(Win_Templates, getter_AddRefs(localFile));
761 }
762 else if (inAtom == nsDirectoryService::sCommon_Startmenu)
763 {
764 rv = GetSpecialSystemDirectory(Win_Common_Startmenu, getter_AddRefs(localFile));
765 }
766 else if (inAtom == nsDirectoryService::sCommon_Programs)
767 {
768 rv = GetSpecialSystemDirectory(Win_Common_Programs, getter_AddRefs(localFile));
769 }
770 else if (inAtom == nsDirectoryService::sCommon_Startup)
771 {
772 rv = GetSpecialSystemDirectory(Win_Common_Startup, getter_AddRefs(localFile));
773 }
774 else if (inAtom == nsDirectoryService::sCommon_Desktopdirectory)
775 {
776 rv = GetSpecialSystemDirectory(Win_Common_Desktopdirectory, getter_AddRefs(localFile));
777 }
778 else if (inAtom == nsDirectoryService::sCommon_AppData)
779 {
780 rv = GetSpecialSystemDirectory(Win_Common_AppData, getter_AddRefs(localFile));
781 }
782 else if (inAtom == nsDirectoryService::sAppdata)
783 {
784 rv = GetSpecialSystemDirectory(Win_Appdata, getter_AddRefs(localFile));
785 }
786 else if (inAtom == nsDirectoryService::sLocalAppdata)
787 {
788 rv = GetSpecialSystemDirectory(Win_LocalAppdata, getter_AddRefs(localFile));
789 }
790 else if (inAtom == nsDirectoryService::sPrinthood)
791 {
792 rv = GetSpecialSystemDirectory(Win_Printhood, getter_AddRefs(localFile));
793 }
794 else if (inAtom == nsDirectoryService::sWinCookiesDirectory)
795 {
796 rv = GetSpecialSystemDirectory(Win_Cookies, getter_AddRefs(localFile));
797 }
798 else if (inAtom == nsDirectoryService::sDefaultDownloadDirectory)
799 {
800 rv = GetSpecialSystemDirectory(Win_Downloads, getter_AddRefs(localFile));
801 }
802 else if (inAtom == nsDirectoryService::sDocs)
803 {
804 rv = GetSpecialSystemDirectory(Win_Documents, getter_AddRefs(localFile));
805 }
806 else if (inAtom == nsDirectoryService::sPictures)
807 {
808 rv = GetSpecialSystemDirectory(Win_Pictures, getter_AddRefs(localFile));
809 }
810 else if (inAtom == nsDirectoryService::sMusic)
811 {
812 rv = GetSpecialSystemDirectory(Win_Music, getter_AddRefs(localFile));
813 }
814 else if (inAtom == nsDirectoryService::sVideos)
815 {
816 rv = GetSpecialSystemDirectory(Win_Videos, getter_AddRefs(localFile));
817 }
818 #elif defined (XP_UNIX)
820 else if (inAtom == nsDirectoryService::sLocalDirectory)
821 {
822 rv = GetSpecialSystemDirectory(Unix_LocalDirectory, getter_AddRefs(localFile));
823 }
824 else if (inAtom == nsDirectoryService::sLibDirectory)
825 {
826 rv = GetSpecialSystemDirectory(Unix_LibDirectory, getter_AddRefs(localFile));
827 }
828 else if (inAtom == nsDirectoryService::sOS_HomeDirectory)
829 {
830 rv = GetSpecialSystemDirectory(Unix_HomeDirectory, getter_AddRefs(localFile));
831 }
832 else if (inAtom == nsDirectoryService::sXDGDesktop ||
833 inAtom == nsDirectoryService::sOS_DesktopDirectory)
834 {
835 rv = GetSpecialSystemDirectory(Unix_XDG_Desktop, getter_AddRefs(localFile));
836 *persistent = false;
837 }
838 else if (inAtom == nsDirectoryService::sXDGDocuments)
839 {
840 rv = GetSpecialSystemDirectory(Unix_XDG_Documents, getter_AddRefs(localFile));
841 *persistent = false;
842 }
843 else if (inAtom == nsDirectoryService::sXDGDownload ||
844 inAtom == nsDirectoryService::sDefaultDownloadDirectory)
845 {
846 rv = GetSpecialSystemDirectory(Unix_XDG_Download, getter_AddRefs(localFile));
847 *persistent = false;
848 }
849 else if (inAtom == nsDirectoryService::sXDGMusic)
850 {
851 rv = GetSpecialSystemDirectory(Unix_XDG_Music, getter_AddRefs(localFile));
852 *persistent = false;
853 }
854 else if (inAtom == nsDirectoryService::sXDGPictures)
855 {
856 rv = GetSpecialSystemDirectory(Unix_XDG_Pictures, getter_AddRefs(localFile));
857 *persistent = false;
858 }
859 else if (inAtom == nsDirectoryService::sXDGPublicShare)
860 {
861 rv = GetSpecialSystemDirectory(Unix_XDG_PublicShare, getter_AddRefs(localFile));
862 *persistent = false;
863 }
864 else if (inAtom == nsDirectoryService::sXDGTemplates)
865 {
866 rv = GetSpecialSystemDirectory(Unix_XDG_Templates, getter_AddRefs(localFile));
867 *persistent = false;
868 }
869 else if (inAtom == nsDirectoryService::sXDGVideos)
870 {
871 rv = GetSpecialSystemDirectory(Unix_XDG_Videos, getter_AddRefs(localFile));
872 *persistent = false;
873 }
874 #endif
876 if (NS_FAILED(rv))
877 return rv;
879 if (!localFile)
880 return NS_ERROR_FAILURE;
882 localFile.forget(_retval);
883 return NS_OK;
884 }
886 NS_IMETHODIMP
887 nsDirectoryService::GetFiles(const char *prop, nsISimpleEnumerator **_retval)
888 {
889 if (NS_WARN_IF(!_retval))
890 return NS_ERROR_INVALID_ARG;
891 *_retval = nullptr;
893 return NS_ERROR_FAILURE;
894 }