Line data Source code
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 "mozilla/ArrayUtils.h"
8 :
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"
17 :
18 : #include "nsICategoryManager.h"
19 : #include "nsISimpleEnumerator.h"
20 : #include "nsIStringEnumerator.h"
21 :
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
37 :
38 : #include "SpecialSystemDirectory.h"
39 : #include "nsAppFileLocationProvider.h"
40 :
41 : using namespace mozilla;
42 :
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
52 :
53 : //----------------------------------------------------------------------------------------
54 : nsresult
55 4 : nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile)
56 : //----------------------------------------------------------------------------------------
57 : {
58 4 : if (NS_WARN_IF(!aFile)) {
59 0 : return NS_ERROR_INVALID_ARG;
60 : }
61 4 : *aFile = nullptr;
62 :
63 : // Set the component registry location:
64 4 : if (!gService) {
65 0 : return NS_ERROR_FAILURE;
66 : }
67 :
68 : nsresult rv;
69 :
70 8 : nsCOMPtr<nsIProperties> dirService;
71 4 : rv = nsDirectoryService::Create(nullptr,
72 : NS_GET_IID(nsIProperties),
73 8 : getter_AddRefs(dirService)); // needs to be around for life of product
74 4 : if (NS_FAILED(rv)) {
75 0 : return rv;
76 : }
77 :
78 4 : if (dirService) {
79 4 : nsCOMPtr<nsIFile> localFile;
80 8 : dirService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
81 8 : getter_AddRefs(localFile));
82 4 : if (localFile) {
83 4 : localFile.forget(aFile);
84 4 : return NS_OK;
85 : }
86 : }
87 :
88 0 : RefPtr<nsLocalFile> localFile = new nsLocalFile;
89 :
90 : #ifdef XP_WIN
91 : wchar_t buf[MAX_PATH + 1];
92 : SetLastError(ERROR_SUCCESS);
93 : if (GetModuleFileNameW(0, buf, mozilla::ArrayLength(buf)) &&
94 : GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
95 : // chop off the executable name by finding the rightmost backslash
96 : wchar_t* lastSlash = wcsrchr(buf, L'\\');
97 : if (lastSlash) {
98 : *(lastSlash + 1) = L'\0';
99 : }
100 :
101 : localFile->InitWithPath(nsDependentString(buf));
102 : localFile.forget(aFile);
103 : return NS_OK;
104 : }
105 :
106 : #elif defined(MOZ_WIDGET_COCOA)
107 : // Works even if we're not bundled.
108 : CFBundleRef appBundle = CFBundleGetMainBundle();
109 : if (appBundle) {
110 : CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle);
111 : if (bundleURL) {
112 : CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(
113 : kCFAllocatorDefault, bundleURL);
114 : if (parentURL) {
115 : // Pass true for the "resolveAgainstBase" arg to CFURLGetFileSystemRepresentation.
116 : // This will resolve the relative portion of the CFURL against it base, giving a full
117 : // path, which CFURLCopyFileSystemPath doesn't do.
118 : char buffer[PATH_MAX];
119 : if (CFURLGetFileSystemRepresentation(parentURL, true,
120 : (UInt8*)buffer, sizeof(buffer))) {
121 : #ifdef DEBUG_conrad
122 : printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer);
123 : #endif
124 : rv = localFile->InitWithNativePath(nsDependentCString(buffer));
125 : if (NS_SUCCEEDED(rv)) {
126 : localFile.forget(aFile);
127 : }
128 : }
129 : CFRelease(parentURL);
130 : }
131 : CFRelease(bundleURL);
132 : }
133 : }
134 :
135 : NS_ASSERTION(*aFile, "nsDirectoryService - Could not determine CurrentProcessDir.\n");
136 : if (*aFile) {
137 : return NS_OK;
138 : }
139 :
140 : #elif defined(XP_UNIX)
141 :
142 : // In the absence of a good way to get the executable directory let
143 : // us try this for unix:
144 : // - if MOZILLA_FIVE_HOME is defined, that is it
145 : // - else give the current directory
146 : char buf[MAXPATHLEN];
147 :
148 : // The MOZ_DEFAULT_MOZILLA_FIVE_HOME variable can be set at configure time with
149 : // a --with-default-mozilla-five-home=foo autoconf flag.
150 : //
151 : // The idea here is to allow for builds that have a default MOZILLA_FIVE_HOME
152 : // regardless of the environment. This makes it easier to write apps that
153 : // embed mozilla without having to worry about setting up the environment
154 : //
155 : // We do this by putenv()ing the default value into the environment. Note that
156 : // we only do this if it is not already set.
157 : #ifdef MOZ_DEFAULT_MOZILLA_FIVE_HOME
158 : const char* home = PR_GetEnv("MOZILLA_FIVE_HOME");
159 : if (!home || !*home) {
160 : putenv("MOZILLA_FIVE_HOME=" MOZ_DEFAULT_MOZILLA_FIVE_HOME);
161 : }
162 : #endif
163 :
164 0 : char* moz5 = PR_GetEnv("MOZILLA_FIVE_HOME");
165 0 : if (moz5 && *moz5) {
166 0 : if (realpath(moz5, buf)) {
167 0 : localFile->InitWithNativePath(nsDependentCString(buf));
168 0 : localFile.forget(aFile);
169 0 : return NS_OK;
170 : }
171 : }
172 : #if defined(DEBUG)
173 : static bool firstWarning = true;
174 :
175 0 : if ((!moz5 || !*moz5) && firstWarning) {
176 : // Warn that MOZILLA_FIVE_HOME not set, once.
177 0 : printf("Warning: MOZILLA_FIVE_HOME not set.\n");
178 0 : firstWarning = false;
179 : }
180 : #endif /* DEBUG */
181 :
182 : // Fall back to current directory.
183 0 : if (getcwd(buf, sizeof(buf))) {
184 0 : localFile->InitWithNativePath(nsDependentCString(buf));
185 0 : localFile.forget(aFile);
186 0 : return NS_OK;
187 : }
188 :
189 : #endif
190 :
191 0 : NS_ERROR("unable to get current process directory");
192 0 : return NS_ERROR_FAILURE;
193 : } // GetCurrentProcessDirectory()
194 :
195 3 : StaticRefPtr<nsDirectoryService> nsDirectoryService::gService;
196 :
197 3 : nsDirectoryService::nsDirectoryService()
198 3 : : mHashtable(128)
199 : {
200 3 : }
201 :
202 : nsresult
203 13 : nsDirectoryService::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
204 : {
205 13 : if (NS_WARN_IF(!aResult)) {
206 0 : return NS_ERROR_INVALID_ARG;
207 : }
208 13 : if (NS_WARN_IF(aOuter)) {
209 0 : return NS_ERROR_NO_AGGREGATION;
210 : }
211 :
212 13 : if (!gService) {
213 0 : return NS_ERROR_NOT_INITIALIZED;
214 : }
215 :
216 13 : return gService->QueryInterface(aIID, aResult);
217 : }
218 :
219 : #define DIR_ATOM(name_, value_) nsIAtom* nsDirectoryService::name_ = nullptr;
220 : #include "nsDirectoryServiceAtomList.h"
221 : #undef DIR_ATOM
222 :
223 : #define DIR_ATOM(name_, value_) NS_STATIC_ATOM_BUFFER(name_##_buffer, value_)
224 : #include "nsDirectoryServiceAtomList.h"
225 : #undef DIR_ATOM
226 :
227 : static const nsStaticAtom directory_atoms[] = {
228 : #define DIR_ATOM(name_, value_) NS_STATIC_ATOM(name_##_buffer, &nsDirectoryService::name_),
229 : #include "nsDirectoryServiceAtomList.h"
230 : #undef DIR_ATOM
231 : };
232 :
233 : NS_IMETHODIMP
234 0 : nsDirectoryService::Init()
235 : {
236 0 : NS_NOTREACHED("nsDirectoryService::Init() for internal use only!");
237 0 : return NS_OK;
238 : }
239 :
240 : void
241 3 : nsDirectoryService::RealInit()
242 : {
243 3 : NS_ASSERTION(!gService,
244 : "nsDirectoryService::RealInit Mustn't initialize twice!");
245 :
246 3 : gService = new nsDirectoryService();
247 :
248 3 : NS_RegisterStaticAtoms(directory_atoms);
249 :
250 : // Let the list hold the only reference to the provider.
251 3 : nsAppFileLocationProvider* defaultProvider = new nsAppFileLocationProvider;
252 3 : gService->mProviders.AppendElement(defaultProvider);
253 3 : }
254 :
255 0 : nsDirectoryService::~nsDirectoryService()
256 : {
257 0 : }
258 :
259 554 : NS_IMPL_ISUPPORTS(nsDirectoryService,
260 : nsIProperties,
261 : nsIDirectoryService,
262 : nsIDirectoryServiceProvider,
263 : nsIDirectoryServiceProvider2)
264 :
265 :
266 : NS_IMETHODIMP
267 0 : nsDirectoryService::Undefine(const char* aProp)
268 : {
269 0 : if (NS_WARN_IF(!aProp)) {
270 0 : return NS_ERROR_INVALID_ARG;
271 : }
272 :
273 0 : nsDependentCString key(aProp);
274 0 : return mHashtable.Remove(key) ? NS_OK : NS_ERROR_FAILURE;
275 : }
276 :
277 : NS_IMETHODIMP
278 0 : nsDirectoryService::GetKeys(uint32_t* aCount, char*** aKeys)
279 : {
280 0 : return NS_ERROR_NOT_IMPLEMENTED;
281 : }
282 :
283 61 : struct MOZ_STACK_CLASS FileData
284 : {
285 61 : FileData(const char* aProperty, const nsIID& aUUID)
286 61 : : property(aProperty)
287 : , data(nullptr)
288 : , persistent(true)
289 61 : , uuid(aUUID)
290 : {
291 61 : }
292 :
293 : const char* property;
294 : nsCOMPtr<nsISupports> data;
295 : bool persistent;
296 : const nsIID& uuid;
297 : };
298 :
299 : static bool
300 196 : FindProviderFile(nsIDirectoryServiceProvider* aElement, FileData* aData)
301 : {
302 : nsresult rv;
303 196 : if (aData->uuid.Equals(NS_GET_IID(nsISimpleEnumerator))) {
304 : // Not all providers implement this iface
305 115 : nsCOMPtr<nsIDirectoryServiceProvider2> prov2 = do_QueryInterface(aElement);
306 68 : if (prov2) {
307 115 : nsCOMPtr<nsISimpleEnumerator> newFiles;
308 68 : rv = prov2->GetFiles(aData->property, getter_AddRefs(newFiles));
309 68 : if (NS_SUCCEEDED(rv) && newFiles) {
310 21 : if (aData->data) {
311 2 : nsCOMPtr<nsISimpleEnumerator> unionFiles;
312 :
313 3 : NS_NewUnionEnumerator(getter_AddRefs(unionFiles),
314 2 : (nsISimpleEnumerator*)aData->data.get(), newFiles);
315 :
316 1 : if (unionFiles) {
317 1 : unionFiles.swap(*(nsISimpleEnumerator**)&aData->data);
318 : }
319 : } else {
320 20 : aData->data = newFiles;
321 : }
322 :
323 21 : aData->persistent = false; // Enumerators can never be persistent
324 21 : return rv == NS_SUCCESS_AGGREGATE_RESULT;
325 : }
326 : }
327 : } else {
328 128 : rv = aElement->GetFile(aData->property, &aData->persistent,
329 256 : (nsIFile**)&aData->data);
330 128 : if (NS_SUCCEEDED(rv) && aData->data) {
331 31 : return false;
332 : }
333 : }
334 :
335 144 : return true;
336 : }
337 :
338 : NS_IMETHODIMP
339 933 : nsDirectoryService::Get(const char* aProp, const nsIID& aUuid, void** aResult)
340 : {
341 933 : if (NS_WARN_IF(!aProp)) {
342 0 : return NS_ERROR_INVALID_ARG;
343 : }
344 :
345 1866 : nsDependentCString key(aProp);
346 :
347 1866 : nsCOMPtr<nsIFile> cachedFile = mHashtable.Get(key);
348 :
349 933 : if (cachedFile) {
350 1744 : nsCOMPtr<nsIFile> cloneFile;
351 872 : cachedFile->Clone(getter_AddRefs(cloneFile));
352 872 : return cloneFile->QueryInterface(aUuid, aResult);
353 : }
354 :
355 : // it is not one of our defaults, lets check any providers
356 122 : FileData fileData(aProp, aUuid);
357 :
358 215 : for (int32_t i = mProviders.Length() - 1; i >= 0; i--) {
359 179 : if (!FindProviderFile(mProviders[i], &fileData)) {
360 25 : break;
361 : }
362 : }
363 61 : if (fileData.data) {
364 44 : if (fileData.persistent) {
365 24 : Set(aProp, static_cast<nsIFile*>(fileData.data.get()));
366 : }
367 44 : nsresult rv = (fileData.data)->QueryInterface(aUuid, aResult);
368 44 : fileData.data = nullptr; // AddRef occurs in FindProviderFile()
369 44 : return rv;
370 : }
371 :
372 17 : FindProviderFile(static_cast<nsIDirectoryServiceProvider*>(this), &fileData);
373 17 : if (fileData.data) {
374 7 : if (fileData.persistent) {
375 6 : Set(aProp, static_cast<nsIFile*>(fileData.data.get()));
376 : }
377 7 : nsresult rv = (fileData.data)->QueryInterface(aUuid, aResult);
378 7 : fileData.data = nullptr; // AddRef occurs in FindProviderFile()
379 7 : return rv;
380 : }
381 :
382 10 : return NS_ERROR_FAILURE;
383 : }
384 :
385 : NS_IMETHODIMP
386 36 : nsDirectoryService::Set(const char* aProp, nsISupports* aValue)
387 : {
388 36 : if (NS_WARN_IF(!aProp)) {
389 0 : return NS_ERROR_INVALID_ARG;
390 : }
391 36 : if (!aValue) {
392 0 : return NS_ERROR_FAILURE;
393 : }
394 :
395 72 : nsDependentCString key(aProp);
396 36 : if (auto entry = mHashtable.LookupForAdd(key)) {
397 0 : return NS_ERROR_FAILURE;
398 : } else {
399 36 : nsCOMPtr<nsIFile> ourFile = do_QueryInterface(aValue);
400 36 : if (ourFile) {
401 72 : nsCOMPtr<nsIFile> cloneFile;
402 36 : ourFile->Clone(getter_AddRefs(cloneFile));
403 72 : entry.OrInsert([&cloneFile] () { return cloneFile.forget(); });
404 36 : return NS_OK;
405 : }
406 0 : mHashtable.Remove(key); // another hashtable lookup, but should be rare
407 : }
408 0 : return NS_ERROR_FAILURE;
409 : }
410 :
411 : NS_IMETHODIMP
412 0 : nsDirectoryService::Has(const char* aProp, bool* aResult)
413 : {
414 0 : if (NS_WARN_IF(!aProp)) {
415 0 : return NS_ERROR_INVALID_ARG;
416 : }
417 :
418 0 : *aResult = false;
419 0 : nsCOMPtr<nsIFile> value;
420 0 : nsresult rv = Get(aProp, NS_GET_IID(nsIFile), getter_AddRefs(value));
421 0 : if (NS_FAILED(rv)) {
422 0 : return NS_OK;
423 : }
424 :
425 0 : if (value) {
426 0 : *aResult = true;
427 : }
428 :
429 0 : return rv;
430 : }
431 :
432 : NS_IMETHODIMP
433 9 : nsDirectoryService::RegisterProvider(nsIDirectoryServiceProvider* aProv)
434 : {
435 9 : if (!aProv) {
436 0 : return NS_ERROR_FAILURE;
437 : }
438 :
439 9 : mProviders.AppendElement(aProv);
440 9 : return NS_OK;
441 : }
442 :
443 : void
444 3 : nsDirectoryService::RegisterCategoryProviders()
445 : {
446 : nsCOMPtr<nsICategoryManager> catman
447 6 : (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
448 3 : if (!catman) {
449 0 : return;
450 : }
451 :
452 6 : nsCOMPtr<nsISimpleEnumerator> entries;
453 6 : catman->EnumerateCategory(XPCOM_DIRECTORY_PROVIDER_CATEGORY,
454 6 : getter_AddRefs(entries));
455 :
456 6 : nsCOMPtr<nsIUTF8StringEnumerator> strings(do_QueryInterface(entries));
457 3 : if (!strings) {
458 0 : return;
459 : }
460 :
461 : bool more;
462 15 : while (NS_SUCCEEDED(strings->HasMore(&more)) && more) {
463 12 : nsAutoCString entry;
464 6 : strings->GetNext(entry);
465 :
466 12 : nsXPIDLCString contractID;
467 12 : catman->GetCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY, entry.get(),
468 12 : getter_Copies(contractID));
469 :
470 6 : if (contractID) {
471 12 : nsCOMPtr<nsIDirectoryServiceProvider> provider = do_GetService(contractID.get());
472 6 : if (provider) {
473 6 : RegisterProvider(provider);
474 : }
475 : }
476 : }
477 : }
478 :
479 : NS_IMETHODIMP
480 0 : nsDirectoryService::UnregisterProvider(nsIDirectoryServiceProvider* aProv)
481 : {
482 0 : if (!aProv) {
483 0 : return NS_ERROR_FAILURE;
484 : }
485 :
486 0 : mProviders.RemoveElement(aProv);
487 0 : return NS_OK;
488 : }
489 :
490 : #if defined(MOZ_CONTENT_SANDBOX) && defined(XP_WIN)
491 : static nsresult
492 : GetLowIntegrityTempBase(nsIFile** aLowIntegrityTempBase)
493 : {
494 : nsCOMPtr<nsIFile> localFile;
495 : nsresult rv = GetSpecialSystemDirectory(Win_LocalAppdataLow,
496 : getter_AddRefs(localFile));
497 : if (NS_WARN_IF(NS_FAILED(rv))) {
498 : return rv;
499 : }
500 :
501 : rv = localFile->Append(NS_LITERAL_STRING(MOZ_USER_DIR));
502 : if (NS_WARN_IF(NS_FAILED(rv))) {
503 : return rv;
504 : }
505 :
506 : localFile.forget(aLowIntegrityTempBase);
507 : return rv;
508 : }
509 : #endif
510 :
511 : // DO NOT ADD ANY LOCATIONS TO THIS FUNCTION UNTIL YOU TALK TO: dougt@netscape.com.
512 : // This is meant to be a place of xpcom or system specific file locations, not
513 : // application specific locations. If you need the later, register a callback for
514 : // your application.
515 :
516 : NS_IMETHODIMP
517 18 : nsDirectoryService::GetFile(const char* aProp, bool* aPersistent,
518 : nsIFile** aResult)
519 : {
520 36 : nsCOMPtr<nsIFile> localFile;
521 18 : nsresult rv = NS_ERROR_FAILURE;
522 :
523 18 : *aResult = nullptr;
524 18 : *aPersistent = true;
525 :
526 36 : nsCOMPtr<nsIAtom> inAtom = NS_Atomize(aProp);
527 :
528 : // check to see if it is one of our defaults
529 :
530 32 : if (inAtom == nsDirectoryService::sCurrentProcess ||
531 14 : inAtom == nsDirectoryService::sOS_CurrentProcessDirectory) {
532 4 : rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
533 : }
534 :
535 : // Unless otherwise set, the core pieces of the GRE exist
536 : // in the current process directory.
537 28 : else if (inAtom == nsDirectoryService::sGRE_Directory ||
538 14 : inAtom == nsDirectoryService::sGRE_BinDirectory) {
539 0 : rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
540 14 : } else if (inAtom == nsDirectoryService::sOS_DriveDirectory) {
541 0 : rv = GetSpecialSystemDirectory(OS_DriveDirectory, getter_AddRefs(localFile));
542 14 : } else if (inAtom == nsDirectoryService::sOS_TemporaryDirectory) {
543 1 : rv = GetSpecialSystemDirectory(OS_TemporaryDirectory, getter_AddRefs(localFile));
544 13 : } else if (inAtom == nsDirectoryService::sOS_CurrentProcessDirectory) {
545 0 : rv = GetSpecialSystemDirectory(OS_CurrentProcessDirectory, getter_AddRefs(localFile));
546 13 : } else if (inAtom == nsDirectoryService::sOS_CurrentWorkingDirectory) {
547 1 : rv = GetSpecialSystemDirectory(OS_CurrentWorkingDirectory, getter_AddRefs(localFile));
548 : }
549 :
550 : #if defined(MOZ_WIDGET_COCOA)
551 : else if (inAtom == nsDirectoryService::sDirectory) {
552 : rv = GetOSXFolderType(kClassicDomain, kSystemFolderType, getter_AddRefs(localFile));
553 : } else if (inAtom == nsDirectoryService::sTrashDirectory) {
554 : rv = GetOSXFolderType(kClassicDomain, kTrashFolderType, getter_AddRefs(localFile));
555 : } else if (inAtom == nsDirectoryService::sStartupDirectory) {
556 : rv = GetOSXFolderType(kClassicDomain, kStartupFolderType, getter_AddRefs(localFile));
557 : } else if (inAtom == nsDirectoryService::sShutdownDirectory) {
558 : rv = GetOSXFolderType(kClassicDomain, kShutdownFolderType, getter_AddRefs(localFile));
559 : } else if (inAtom == nsDirectoryService::sAppleMenuDirectory) {
560 : rv = GetOSXFolderType(kClassicDomain, kAppleMenuFolderType, getter_AddRefs(localFile));
561 : } else if (inAtom == nsDirectoryService::sControlPanelDirectory) {
562 : rv = GetOSXFolderType(kClassicDomain, kControlPanelFolderType, getter_AddRefs(localFile));
563 : } else if (inAtom == nsDirectoryService::sExtensionDirectory) {
564 : rv = GetOSXFolderType(kClassicDomain, kExtensionFolderType, getter_AddRefs(localFile));
565 : } else if (inAtom == nsDirectoryService::sFontsDirectory) {
566 : rv = GetOSXFolderType(kClassicDomain, kFontsFolderType, getter_AddRefs(localFile));
567 : } else if (inAtom == nsDirectoryService::sPreferencesDirectory) {
568 : rv = GetOSXFolderType(kClassicDomain, kPreferencesFolderType, getter_AddRefs(localFile));
569 : } else if (inAtom == nsDirectoryService::sDocumentsDirectory) {
570 : rv = GetOSXFolderType(kClassicDomain, kDocumentsFolderType, getter_AddRefs(localFile));
571 : } else if (inAtom == nsDirectoryService::sInternetSearchDirectory) {
572 : rv = GetOSXFolderType(kClassicDomain, kInternetSearchSitesFolderType, getter_AddRefs(localFile));
573 : } else if (inAtom == nsDirectoryService::sUserLibDirectory) {
574 : rv = GetOSXFolderType(kUserDomain, kDomainLibraryFolderType, getter_AddRefs(localFile));
575 : } else if (inAtom == nsDirectoryService::sOS_HomeDirectory) {
576 : rv = GetOSXFolderType(kUserDomain, kDomainTopLevelFolderType, getter_AddRefs(localFile));
577 : } else if (inAtom == nsDirectoryService::sDefaultDownloadDirectory) {
578 : // 10.5 and later, we can use kDownloadsFolderType which is defined in
579 : // Folders.h as "down". However, in order to support 10.4 still, we
580 : // cannot use the named constant. We'll use it's value, and if it
581 : // fails, fall back to the desktop.
582 : #ifndef kDownloadsFolderType
583 : #define kDownloadsFolderType 'down'
584 : #endif
585 :
586 : rv = GetOSXFolderType(kUserDomain, kDownloadsFolderType,
587 : getter_AddRefs(localFile));
588 : if (NS_FAILED(rv)) {
589 : rv = GetOSXFolderType(kUserDomain, kDesktopFolderType,
590 : getter_AddRefs(localFile));
591 : }
592 : } else if (inAtom == nsDirectoryService::sUserDesktopDirectory ||
593 : inAtom == nsDirectoryService::sOS_DesktopDirectory) {
594 : rv = GetOSXFolderType(kUserDomain, kDesktopFolderType, getter_AddRefs(localFile));
595 : } else if (inAtom == nsDirectoryService::sLocalDesktopDirectory) {
596 : rv = GetOSXFolderType(kLocalDomain, kDesktopFolderType, getter_AddRefs(localFile));
597 : } else if (inAtom == nsDirectoryService::sUserApplicationsDirectory) {
598 : rv = GetOSXFolderType(kUserDomain, kApplicationsFolderType, getter_AddRefs(localFile));
599 : } else if (inAtom == nsDirectoryService::sLocalApplicationsDirectory) {
600 : rv = GetOSXFolderType(kLocalDomain, kApplicationsFolderType, getter_AddRefs(localFile));
601 : } else if (inAtom == nsDirectoryService::sUserDocumentsDirectory) {
602 : rv = GetOSXFolderType(kUserDomain, kDocumentsFolderType, getter_AddRefs(localFile));
603 : } else if (inAtom == nsDirectoryService::sLocalDocumentsDirectory) {
604 : rv = GetOSXFolderType(kLocalDomain, kDocumentsFolderType, getter_AddRefs(localFile));
605 : } else if (inAtom == nsDirectoryService::sUserInternetPlugInDirectory) {
606 : rv = GetOSXFolderType(kUserDomain, kInternetPlugInFolderType, getter_AddRefs(localFile));
607 : } else if (inAtom == nsDirectoryService::sLocalInternetPlugInDirectory) {
608 : rv = GetOSXFolderType(kLocalDomain, kInternetPlugInFolderType, getter_AddRefs(localFile));
609 : } else if (inAtom == nsDirectoryService::sUserFrameworksDirectory) {
610 : rv = GetOSXFolderType(kUserDomain, kFrameworksFolderType, getter_AddRefs(localFile));
611 : } else if (inAtom == nsDirectoryService::sLocalFrameworksDirectory) {
612 : rv = GetOSXFolderType(kLocalDomain, kFrameworksFolderType, getter_AddRefs(localFile));
613 : } else if (inAtom == nsDirectoryService::sUserPreferencesDirectory) {
614 : rv = GetOSXFolderType(kUserDomain, kPreferencesFolderType, getter_AddRefs(localFile));
615 : } else if (inAtom == nsDirectoryService::sLocalPreferencesDirectory) {
616 : rv = GetOSXFolderType(kLocalDomain, kPreferencesFolderType, getter_AddRefs(localFile));
617 : } else if (inAtom == nsDirectoryService::sPictureDocumentsDirectory) {
618 : rv = GetOSXFolderType(kUserDomain, kPictureDocumentsFolderType, getter_AddRefs(localFile));
619 : } else if (inAtom == nsDirectoryService::sMovieDocumentsDirectory) {
620 : rv = GetOSXFolderType(kUserDomain, kMovieDocumentsFolderType, getter_AddRefs(localFile));
621 : } else if (inAtom == nsDirectoryService::sMusicDocumentsDirectory) {
622 : rv = GetOSXFolderType(kUserDomain, kMusicDocumentsFolderType, getter_AddRefs(localFile));
623 : } else if (inAtom == nsDirectoryService::sInternetSitesDirectory) {
624 : rv = GetOSXFolderType(kUserDomain, kInternetSitesFolderType, getter_AddRefs(localFile));
625 : }
626 : #elif defined (XP_WIN)
627 : else if (inAtom == nsDirectoryService::sSystemDirectory) {
628 : rv = GetSpecialSystemDirectory(Win_SystemDirectory, getter_AddRefs(localFile));
629 : } else if (inAtom == nsDirectoryService::sWindowsDirectory) {
630 : rv = GetSpecialSystemDirectory(Win_WindowsDirectory, getter_AddRefs(localFile));
631 : } else if (inAtom == nsDirectoryService::sWindowsProgramFiles) {
632 : rv = GetSpecialSystemDirectory(Win_ProgramFiles, getter_AddRefs(localFile));
633 : } else if (inAtom == nsDirectoryService::sOS_HomeDirectory) {
634 : rv = GetSpecialSystemDirectory(Win_HomeDirectory, getter_AddRefs(localFile));
635 : } else if (inAtom == nsDirectoryService::sDesktop) {
636 : rv = GetSpecialSystemDirectory(Win_Desktop, getter_AddRefs(localFile));
637 : } else if (inAtom == nsDirectoryService::sPrograms) {
638 : rv = GetSpecialSystemDirectory(Win_Programs, getter_AddRefs(localFile));
639 : } else if (inAtom == nsDirectoryService::sControls) {
640 : rv = GetSpecialSystemDirectory(Win_Controls, getter_AddRefs(localFile));
641 : } else if (inAtom == nsDirectoryService::sPrinters) {
642 : rv = GetSpecialSystemDirectory(Win_Printers, getter_AddRefs(localFile));
643 : } else if (inAtom == nsDirectoryService::sPersonal) {
644 : rv = GetSpecialSystemDirectory(Win_Personal, getter_AddRefs(localFile));
645 : } else if (inAtom == nsDirectoryService::sFavorites) {
646 : rv = GetSpecialSystemDirectory(Win_Favorites, getter_AddRefs(localFile));
647 : } else if (inAtom == nsDirectoryService::sStartup) {
648 : rv = GetSpecialSystemDirectory(Win_Startup, getter_AddRefs(localFile));
649 : } else if (inAtom == nsDirectoryService::sRecent) {
650 : rv = GetSpecialSystemDirectory(Win_Recent, getter_AddRefs(localFile));
651 : } else if (inAtom == nsDirectoryService::sSendto) {
652 : rv = GetSpecialSystemDirectory(Win_Sendto, getter_AddRefs(localFile));
653 : } else if (inAtom == nsDirectoryService::sBitbucket) {
654 : rv = GetSpecialSystemDirectory(Win_Bitbucket, getter_AddRefs(localFile));
655 : } else if (inAtom == nsDirectoryService::sStartmenu) {
656 : rv = GetSpecialSystemDirectory(Win_Startmenu, getter_AddRefs(localFile));
657 : } else if (inAtom == nsDirectoryService::sDesktopdirectory ||
658 : inAtom == nsDirectoryService::sOS_DesktopDirectory) {
659 : rv = GetSpecialSystemDirectory(Win_Desktopdirectory, getter_AddRefs(localFile));
660 : } else if (inAtom == nsDirectoryService::sDrives) {
661 : rv = GetSpecialSystemDirectory(Win_Drives, getter_AddRefs(localFile));
662 : } else if (inAtom == nsDirectoryService::sNetwork) {
663 : rv = GetSpecialSystemDirectory(Win_Network, getter_AddRefs(localFile));
664 : } else if (inAtom == nsDirectoryService::sNethood) {
665 : rv = GetSpecialSystemDirectory(Win_Nethood, getter_AddRefs(localFile));
666 : } else if (inAtom == nsDirectoryService::sFonts) {
667 : rv = GetSpecialSystemDirectory(Win_Fonts, getter_AddRefs(localFile));
668 : } else if (inAtom == nsDirectoryService::sTemplates) {
669 : rv = GetSpecialSystemDirectory(Win_Templates, getter_AddRefs(localFile));
670 : } else if (inAtom == nsDirectoryService::sCommon_Startmenu) {
671 : rv = GetSpecialSystemDirectory(Win_Common_Startmenu, getter_AddRefs(localFile));
672 : } else if (inAtom == nsDirectoryService::sCommon_Programs) {
673 : rv = GetSpecialSystemDirectory(Win_Common_Programs, getter_AddRefs(localFile));
674 : } else if (inAtom == nsDirectoryService::sCommon_Startup) {
675 : rv = GetSpecialSystemDirectory(Win_Common_Startup, getter_AddRefs(localFile));
676 : } else if (inAtom == nsDirectoryService::sCommon_Desktopdirectory) {
677 : rv = GetSpecialSystemDirectory(Win_Common_Desktopdirectory, getter_AddRefs(localFile));
678 : } else if (inAtom == nsDirectoryService::sCommon_AppData) {
679 : rv = GetSpecialSystemDirectory(Win_Common_AppData, getter_AddRefs(localFile));
680 : } else if (inAtom == nsDirectoryService::sAppdata) {
681 : rv = GetSpecialSystemDirectory(Win_Appdata, getter_AddRefs(localFile));
682 : } else if (inAtom == nsDirectoryService::sLocalAppdata) {
683 : rv = GetSpecialSystemDirectory(Win_LocalAppdata, getter_AddRefs(localFile));
684 : #if defined(MOZ_CONTENT_SANDBOX)
685 : } else if (inAtom == nsDirectoryService::sLocalAppdataLow) {
686 : rv = GetSpecialSystemDirectory(Win_LocalAppdataLow, getter_AddRefs(localFile));
687 : } else if (inAtom == nsDirectoryService::sLowIntegrityTempBase) {
688 : rv = GetLowIntegrityTempBase(getter_AddRefs(localFile));
689 : #endif
690 : } else if (inAtom == nsDirectoryService::sPrinthood) {
691 : rv = GetSpecialSystemDirectory(Win_Printhood, getter_AddRefs(localFile));
692 : } else if (inAtom == nsDirectoryService::sWinCookiesDirectory) {
693 : rv = GetSpecialSystemDirectory(Win_Cookies, getter_AddRefs(localFile));
694 : } else if (inAtom == nsDirectoryService::sDefaultDownloadDirectory) {
695 : rv = GetSpecialSystemDirectory(Win_Downloads, getter_AddRefs(localFile));
696 : } else if (inAtom == nsDirectoryService::sDocs) {
697 : rv = GetSpecialSystemDirectory(Win_Documents, getter_AddRefs(localFile));
698 : } else if (inAtom == nsDirectoryService::sPictures) {
699 : rv = GetSpecialSystemDirectory(Win_Pictures, getter_AddRefs(localFile));
700 : } else if (inAtom == nsDirectoryService::sMusic) {
701 : rv = GetSpecialSystemDirectory(Win_Music, getter_AddRefs(localFile));
702 : } else if (inAtom == nsDirectoryService::sVideos) {
703 : rv = GetSpecialSystemDirectory(Win_Videos, getter_AddRefs(localFile));
704 : }
705 : #elif defined (XP_UNIX)
706 :
707 12 : else if (inAtom == nsDirectoryService::sLocalDirectory) {
708 0 : rv = GetSpecialSystemDirectory(Unix_LocalDirectory, getter_AddRefs(localFile));
709 12 : } else if (inAtom == nsDirectoryService::sLibDirectory) {
710 0 : rv = GetSpecialSystemDirectory(Unix_LibDirectory, getter_AddRefs(localFile));
711 12 : } else if (inAtom == nsDirectoryService::sOS_HomeDirectory) {
712 1 : rv = GetSpecialSystemDirectory(Unix_HomeDirectory, getter_AddRefs(localFile));
713 22 : } else if (inAtom == nsDirectoryService::sXDGDesktop ||
714 11 : inAtom == nsDirectoryService::sOS_DesktopDirectory) {
715 1 : rv = GetSpecialSystemDirectory(Unix_XDG_Desktop, getter_AddRefs(localFile));
716 1 : *aPersistent = false;
717 10 : } else if (inAtom == nsDirectoryService::sXDGDocuments) {
718 0 : rv = GetSpecialSystemDirectory(Unix_XDG_Documents, getter_AddRefs(localFile));
719 0 : *aPersistent = false;
720 20 : } else if (inAtom == nsDirectoryService::sXDGDownload ||
721 10 : inAtom == nsDirectoryService::sDefaultDownloadDirectory) {
722 0 : rv = GetSpecialSystemDirectory(Unix_XDG_Download, getter_AddRefs(localFile));
723 0 : *aPersistent = false;
724 10 : } else if (inAtom == nsDirectoryService::sXDGMusic) {
725 0 : rv = GetSpecialSystemDirectory(Unix_XDG_Music, getter_AddRefs(localFile));
726 0 : *aPersistent = false;
727 10 : } else if (inAtom == nsDirectoryService::sXDGPictures) {
728 0 : rv = GetSpecialSystemDirectory(Unix_XDG_Pictures, getter_AddRefs(localFile));
729 0 : *aPersistent = false;
730 10 : } else if (inAtom == nsDirectoryService::sXDGPublicShare) {
731 0 : rv = GetSpecialSystemDirectory(Unix_XDG_PublicShare, getter_AddRefs(localFile));
732 0 : *aPersistent = false;
733 10 : } else if (inAtom == nsDirectoryService::sXDGTemplates) {
734 0 : rv = GetSpecialSystemDirectory(Unix_XDG_Templates, getter_AddRefs(localFile));
735 0 : *aPersistent = false;
736 10 : } else if (inAtom == nsDirectoryService::sXDGVideos) {
737 0 : rv = GetSpecialSystemDirectory(Unix_XDG_Videos, getter_AddRefs(localFile));
738 0 : *aPersistent = false;
739 : }
740 : #endif
741 :
742 18 : if (NS_FAILED(rv)) {
743 10 : return rv;
744 : }
745 :
746 8 : if (!localFile) {
747 0 : return NS_ERROR_FAILURE;
748 : }
749 :
750 8 : localFile.forget(aResult);
751 8 : return NS_OK;
752 : }
753 :
754 : NS_IMETHODIMP
755 0 : nsDirectoryService::GetFiles(const char* aProp, nsISimpleEnumerator** aResult)
756 : {
757 0 : if (NS_WARN_IF(!aResult)) {
758 0 : return NS_ERROR_INVALID_ARG;
759 : }
760 0 : *aResult = nullptr;
761 :
762 0 : return NS_ERROR_FAILURE;
763 : }
|