2002-08-21 10:25:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2002
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2003-09-29 06:04:02 +00:00
|
|
|
* Brian Ryner <bryner@brianryner.com>
|
2004-06-17 21:23:51 +00:00
|
|
|
* Benjamin Smedberg <bsmedberg@covad.net>
|
|
|
|
* Ben Goodger <ben@mozilla.org>
|
2005-06-10 13:13:53 +00:00
|
|
|
* Jens Bannmann <jens.b@web.de>
|
2002-08-21 10:25:54 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsAppRunner.h"
|
|
|
|
#include "nsXREDirProvider.h"
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
|
|
|
#include "nsIJSContextStack.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
#include "nsILocalFile.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIProfileChangeStatus.h"
|
2006-08-08 18:18:50 +00:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2005-02-22 21:49:45 +00:00
|
|
|
#include "nsIToolkitChromeRegistry.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2002-08-21 10:25:54 +00:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2006-01-12 15:29:10 +00:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
|
|
|
#include "nsINIParser.h"
|
|
|
|
#include "nsDependentString.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsArrayEnumerator.h"
|
2006-01-12 15:29:10 +00:00
|
|
|
#include "nsEnumeratorUtils.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <shlobj.h>
|
2005-04-26 01:26:16 +00:00
|
|
|
// This is not defined by VC6.
|
|
|
|
#ifndef CSIDL_LOCAL_APPDATA
|
|
|
|
#define CSIDL_LOCAL_APPDATA 0x001C
|
|
|
|
#endif
|
2002-08-21 10:25:54 +00:00
|
|
|
#endif
|
2002-11-15 02:05:19 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "nsILocalFileMac.h"
|
|
|
|
#endif
|
2002-11-16 09:15:36 +00:00
|
|
|
#ifdef XP_BEOS
|
2004-06-17 21:23:51 +00:00
|
|
|
#include <be/kernel/image.h>
|
2002-11-16 09:15:36 +00:00
|
|
|
#include <FindDirectory.h>
|
|
|
|
#endif
|
2004-06-17 21:23:51 +00:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
#include <ctype.h>
|
|
|
|
#endif
|
|
|
|
#ifdef XP_OS2
|
|
|
|
#define INCL_DOS
|
|
|
|
#include <os2.h>
|
|
|
|
#endif
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-07-22 15:14:02 +00:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
#define APP_REGISTRY_NAME "Application Registry"
|
|
|
|
#elif defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
#define APP_REGISTRY_NAME "registry.dat"
|
|
|
|
#else
|
|
|
|
#define APP_REGISTRY_NAME "appreg"
|
|
|
|
#endif
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsXREDirProvider* gDirServiceProvider = nsnull;
|
2002-08-26 10:18:41 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsXREDirProvider::nsXREDirProvider() :
|
2004-09-15 23:02:10 +00:00
|
|
|
mProfileNotified(PR_FALSE)
|
2004-06-17 21:23:51 +00:00
|
|
|
{
|
|
|
|
gDirServiceProvider = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXREDirProvider::~nsXREDirProvider()
|
|
|
|
{
|
|
|
|
gDirServiceProvider = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-01-12 15:29:10 +00:00
|
|
|
nsXREDirProvider::Initialize(nsIFile *aXULAppDir,
|
|
|
|
nsILocalFile *aGREDir,
|
|
|
|
nsIDirectoryServiceProvider* aAppProvider)
|
2006-08-17 14:22:04 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aGREDir);
|
|
|
|
|
2006-01-12 15:29:10 +00:00
|
|
|
mAppProvider = aAppProvider;
|
2004-09-07 18:59:07 +00:00
|
|
|
mXULAppDir = aXULAppDir;
|
2006-08-17 14:22:04 +00:00
|
|
|
mGREDir = aGREDir;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-06-13 16:45:22 +00:00
|
|
|
return NS_OK;
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2002-08-26 10:18:41 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsresult
|
2005-04-26 00:37:23 +00:00
|
|
|
nsXREDirProvider::SetProfile(nsIFile* aDir, nsIFile* aLocalDir)
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2005-04-26 00:37:23 +00:00
|
|
|
NS_ASSERTION(aDir && aLocalDir, "We don't support no-profile apps yet!");
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_bsmedberg
|
2005-04-26 00:37:23 +00:00
|
|
|
nsCAutoString path, path2;
|
2004-06-17 21:23:51 +00:00
|
|
|
aDir->GetNativePath(path);
|
2005-04-26 00:37:23 +00:00
|
|
|
aLocalDir->GetNativePath(path2);
|
|
|
|
printf("nsXREDirProvider::SetProfile('%s', '%s')\n", path.get(), path2.get());
|
2002-08-21 10:25:54 +00:00
|
|
|
#endif
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = EnsureDirectoryExists(aDir);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = EnsureDirectoryExists(aLocalDir);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
mProfileDir = aDir;
|
2005-04-26 00:37:23 +00:00
|
|
|
mProfileLocalDir = aLocalDir;
|
2004-06-17 21:23:51 +00:00
|
|
|
return NS_OK;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_IMPL_QUERY_INTERFACE3(nsXREDirProvider,
|
|
|
|
nsIDirectoryServiceProvider,
|
|
|
|
nsIDirectoryServiceProvider2,
|
|
|
|
nsIProfileStartup)
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsXREDirProvider::AddRef()
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2004-06-17 21:23:51 +00:00
|
|
|
return 1;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsXREDirProvider::Release()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXREDirProvider::GetFile(const char* aProperty, PRBool* aPersistent,
|
|
|
|
nsIFile** aFile)
|
|
|
|
{
|
2006-01-12 15:29:10 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
PRBool gettingProfile = PR_FALSE;
|
|
|
|
|
|
|
|
if (!strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR)) {
|
|
|
|
// If XRE_NotifyProfile hasn't been called, don't fall through to
|
|
|
|
// mAppProvider on the profile keys.
|
|
|
|
if (!mProfileNotified)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mProfileLocalDir)
|
|
|
|
return mProfileLocalDir->Clone(aFile);
|
|
|
|
|
|
|
|
if (mAppProvider)
|
|
|
|
return mAppProvider->GetFile(aProperty, aPersistent, aFile);
|
|
|
|
|
|
|
|
// This falls through to the case below
|
|
|
|
gettingProfile = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (!strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR) || gettingProfile) {
|
|
|
|
if (!mProfileNotified)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mProfileDir)
|
|
|
|
return mProfileDir->Clone(aFile);
|
|
|
|
|
|
|
|
if (mAppProvider)
|
|
|
|
return mAppProvider->GetFile(aProperty, aPersistent, aFile);
|
|
|
|
|
|
|
|
// If we don't succeed here, bail early so that we aren't reentrant
|
|
|
|
// through the "GetProfileDir" call below.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAppProvider) {
|
|
|
|
rv = mAppProvider->GetFile(aProperty, aPersistent, aFile);
|
|
|
|
if (NS_SUCCEEDED(rv) && *aFile)
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-08-21 10:25:54 +00:00
|
|
|
*aPersistent = PR_TRUE;
|
|
|
|
|
2005-12-23 14:51:39 +00:00
|
|
|
if (!strcmp(aProperty, NS_GRE_DIR)) {
|
|
|
|
return mGREDir->Clone(aFile);
|
|
|
|
}
|
2006-01-12 15:29:10 +00:00
|
|
|
else if (!strcmp(aProperty, NS_OS_CURRENT_PROCESS_DIR) ||
|
2004-06-17 21:23:51 +00:00
|
|
|
!strcmp(aProperty, NS_APP_INSTALL_CLEANUP_DIR)) {
|
2005-12-23 14:51:39 +00:00
|
|
|
return GetAppDir()->Clone(aFile);
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2005-09-01 13:21:55 +00:00
|
|
|
|
2006-01-12 15:29:10 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2005-09-01 13:21:55 +00:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
|
|
|
|
if (!strcmp(aProperty, NS_APP_PROFILE_DEFAULTS_50_DIR) ||
|
2004-06-17 21:23:51 +00:00
|
|
|
!strcmp(aProperty, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR)) {
|
|
|
|
return GetProfileDefaultsDir(aFile);
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_PREF_DEFAULTS_50_DIR))
|
|
|
|
{
|
2005-12-23 14:51:39 +00:00
|
|
|
// return the GRE default prefs directory here, and the app default prefs
|
|
|
|
// directory (if applicable) in NS_APP_PREFS_DEFAULTS_DIR_LIST.
|
|
|
|
rv = mGREDir->Clone(getter_AddRefs(file));
|
2004-06-17 21:23:51 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-09-07 18:59:07 +00:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("defaults"));
|
2004-06-17 21:23:51 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2004-09-07 18:59:07 +00:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("pref"));
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2002-08-26 10:18:41 +00:00
|
|
|
}
|
2005-07-23 14:00:07 +00:00
|
|
|
else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_DIR) ||
|
|
|
|
!strcmp(aProperty, XRE_USER_APP_DATA_DIR)) {
|
2004-07-22 15:14:02 +00:00
|
|
|
rv = GetUserAppDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE)) {
|
|
|
|
rv = GetUserAppDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));
|
2006-01-12 15:29:10 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING(APP_REGISTRY_NAME));
|
2004-07-22 15:14:02 +00:00
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
else if (!strcmp(aProperty, NS_APP_USER_PROFILES_ROOT_DIR)) {
|
2004-06-17 21:23:51 +00:00
|
|
|
rv = GetUserAppDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2006-01-12 15:29:10 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2005-04-26 00:37:23 +00:00
|
|
|
#if !defined(XP_UNIX) || defined(XP_MACOSX)
|
2006-01-12 15:29:10 +00:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles"));
|
2005-04-26 00:37:23 +00:00
|
|
|
#endif
|
|
|
|
|
2006-01-12 15:29:10 +00:00
|
|
|
// We must create the profile directory here if it does not exist.
|
|
|
|
rv |= EnsureDirectoryExists(file);
|
|
|
|
}
|
2005-04-26 00:37:23 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_USER_PROFILES_LOCAL_ROOT_DIR)) {
|
|
|
|
rv = GetUserLocalDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));
|
|
|
|
|
2006-01-12 15:29:10 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2002-11-16 11:16:58 +00:00
|
|
|
#if !defined(XP_UNIX) || defined(XP_MACOSX)
|
2006-01-12 15:29:10 +00:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles"));
|
2002-08-21 10:25:54 +00:00
|
|
|
#endif
|
|
|
|
|
2006-01-12 15:29:10 +00:00
|
|
|
// We must create the profile directory here if it does not exist.
|
|
|
|
rv |= EnsureDirectoryExists(file);
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2006-01-12 15:29:10 +00:00
|
|
|
else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE) && gArgv[0]) {
|
2005-10-04 18:06:26 +00:00
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
|
|
|
rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
file = lf;
|
|
|
|
}
|
2005-12-23 14:51:39 +00:00
|
|
|
else if (!strcmp(aProperty, "resource:app")) {
|
|
|
|
rv = GetAppDir()->Clone(getter_AddRefs(file));
|
2004-09-07 18:59:07 +00:00
|
|
|
}
|
2006-01-12 15:29:10 +00:00
|
|
|
|
|
|
|
else if (!strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP) && mProfileDir) {
|
|
|
|
return mProfileDir->Clone(aFile);
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP)) {
|
|
|
|
if (mProfileLocalDir)
|
|
|
|
return mProfileLocalDir->Clone(aFile);
|
|
|
|
|
|
|
|
if (mProfileDir)
|
|
|
|
return mProfileDir->Clone(aFile);
|
|
|
|
|
|
|
|
if (mAppProvider)
|
|
|
|
return mAppProvider->GetFile(NS_APP_PROFILE_DIR_STARTUP, aPersistent,
|
|
|
|
aFile);
|
|
|
|
}
|
|
|
|
else if (NS_SUCCEEDED(GetProfileStartupDir(getter_AddRefs(file)))) {
|
2004-09-08 20:25:45 +00:00
|
|
|
// We need to allow component, xpt, and chrome registration to
|
|
|
|
// occur prior to the profile-after-change notification.
|
2004-06-17 21:23:51 +00:00
|
|
|
if (!strcmp(aProperty, NS_XPCOM_COMPONENT_REGISTRY_FILE)) {
|
2006-01-12 15:29:10 +00:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("compreg.dat"));
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_XPCOM_XPTI_REGISTRY_FILE)) {
|
2006-01-12 15:29:10 +00:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("xpti.dat"));
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2004-09-08 20:25:45 +00:00
|
|
|
else if (!strcmp(aProperty, NS_APP_USER_CHROME_DIR)) {
|
2006-01-12 15:29:10 +00:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("chrome"));
|
2004-09-08 20:25:45 +00:00
|
|
|
}
|
2006-01-12 15:29:10 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 17:16:15 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && file) {
|
|
|
|
NS_ADDREF(*aFile = file);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-01-12 15:29:10 +00:00
|
|
|
if (NS_SUCCEEDED(GetProfileDir(getter_AddRefs(file)))) {
|
|
|
|
if (!strcmp(aProperty, NS_APP_PREFS_50_DIR)) {
|
|
|
|
rv = NS_OK;
|
2005-02-22 21:49:45 +00:00
|
|
|
}
|
2006-01-12 15:29:10 +00:00
|
|
|
else if (!strcmp(aProperty, NS_APP_PREFS_50_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("prefs.js"));
|
2005-10-20 16:39:24 +00:00
|
|
|
}
|
2006-01-12 15:29:10 +00:00
|
|
|
else if (!strcmp(aProperty, NS_LOCALSTORE_UNSAFE_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_LOCALSTORE_50_FILE)) {
|
|
|
|
if (gSafeMode) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("localstore-safe.rdf"));
|
|
|
|
file->Remove(PR_FALSE);
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2006-01-12 15:29:10 +00:00
|
|
|
else {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
|
2004-06-17 21:23:51 +00:00
|
|
|
EnsureProfileFileExists(file);
|
|
|
|
}
|
2006-01-12 15:29:10 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_HISTORY_50_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("history.dat"));
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_USER_MIMETYPES_50_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("mimeTypes.rdf"));
|
|
|
|
EnsureProfileFileExists(file);
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_STORAGE_50_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("storage.sdb"));
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_DOWNLOADS_50_FILE)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("downloads.rdf"));
|
|
|
|
}
|
|
|
|
// XXXbsmedberg move these defines into application-specific providers.
|
|
|
|
else if (!strcmp(aProperty, NS_APP_MAIL_50_DIR)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("Mail"));
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_IMAP_MAIL_50_DIR)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("ImapMail"));
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_NEWS_50_DIR)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("News"));
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_MESSENGER_FOLDER_CACHE_50_DIR)) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("panacea.dat"));
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-12 15:29:10 +00:00
|
|
|
if (NS_FAILED(rv) || !file)
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
NS_ADDREF(*aFile = file);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-02-22 21:49:45 +00:00
|
|
|
LoadDirsIntoArray(nsIFile* aComponentsList, const char* aSection,
|
|
|
|
const char *const* aAppendList,
|
|
|
|
nsCOMArray<nsIFile>& aDirectories)
|
2004-06-17 21:23:51 +00:00
|
|
|
{
|
|
|
|
nsINIParser parser;
|
|
|
|
nsCOMPtr<nsILocalFile> lf(do_QueryInterface(aComponentsList));
|
2005-08-15 18:29:55 +00:00
|
|
|
nsresult rv = parser.Init(lf);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-06-10 13:13:53 +00:00
|
|
|
NS_NAMED_LITERAL_CSTRING(platform, "platform");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(osTarget, OS_TARGET);
|
|
|
|
#ifdef TARGET_OS_ABI
|
|
|
|
NS_NAMED_LITERAL_CSTRING(targetOSABI, TARGET_OS_ABI);
|
|
|
|
#endif
|
|
|
|
|
2005-04-23 01:39:51 +00:00
|
|
|
PRInt32 i = 0;
|
|
|
|
do {
|
2005-08-15 18:29:55 +00:00
|
|
|
nsCAutoString buf("Extension");
|
|
|
|
buf.AppendInt(i++);
|
2005-04-23 01:39:51 +00:00
|
|
|
|
2005-08-15 18:29:55 +00:00
|
|
|
nsCAutoString path;
|
|
|
|
rv = parser.GetString(aSection, buf.get(), path);
|
2005-04-23 01:39:51 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
2005-06-30 20:46:59 +00:00
|
|
|
nsCOMPtr<nsILocalFile> dir = do_CreateInstance("@mozilla.org/file/local;1", &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
|
2005-06-07 22:10:56 +00:00
|
|
|
nsCOMPtr<nsIFile> platformDir;
|
|
|
|
#ifdef TARGET_OS_ABI
|
|
|
|
nsCOMPtr<nsIFile> platformABIDir;
|
|
|
|
#endif
|
2005-08-15 18:29:55 +00:00
|
|
|
rv = dir->SetPersistentDescriptor(path);
|
2005-07-23 14:00:07 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
2005-06-07 22:10:56 +00:00
|
|
|
|
2005-06-30 20:46:59 +00:00
|
|
|
rv = dir->Clone(getter_AddRefs(platformDir));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
|
2005-06-10 13:13:53 +00:00
|
|
|
platformDir->AppendNative(platform);
|
|
|
|
platformDir->AppendNative(osTarget);
|
2005-06-07 22:10:56 +00:00
|
|
|
|
|
|
|
#ifdef TARGET_OS_ABI
|
2005-06-30 20:46:59 +00:00
|
|
|
rv = dir->Clone(getter_AddRefs(platformABIDir));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
|
2005-06-10 13:13:53 +00:00
|
|
|
platformABIDir->AppendNative(platform);
|
|
|
|
platformABIDir->AppendNative(targetOSABI);
|
2005-06-07 22:10:56 +00:00
|
|
|
#endif
|
|
|
|
|
2005-04-23 01:39:51 +00:00
|
|
|
const char* const* a = aAppendList;
|
|
|
|
while (*a) {
|
2005-06-10 13:13:53 +00:00
|
|
|
nsDependentCString directory(*a);
|
|
|
|
dir->AppendNative(directory);
|
|
|
|
platformDir->AppendNative(directory);
|
2005-06-07 22:10:56 +00:00
|
|
|
#ifdef TARGET_OS_ABI
|
2005-06-10 13:13:53 +00:00
|
|
|
platformABIDir->AppendNative(directory);
|
2005-06-07 22:10:56 +00:00
|
|
|
#endif
|
2005-04-23 01:39:51 +00:00
|
|
|
++a;
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2005-04-23 01:39:51 +00:00
|
|
|
|
|
|
|
PRBool exists;
|
|
|
|
rv = dir->Exists(&exists);
|
|
|
|
if (NS_SUCCEEDED(rv) && exists)
|
|
|
|
aDirectories.AppendObject(dir);
|
2005-06-07 22:10:56 +00:00
|
|
|
|
|
|
|
rv = platformDir->Exists(&exists);
|
|
|
|
if (NS_SUCCEEDED(rv) && exists)
|
|
|
|
aDirectories.AppendObject(platformDir);
|
|
|
|
|
|
|
|
#ifdef TARGET_OS_ABI
|
|
|
|
rv = platformABIDir->Exists(&exists);
|
|
|
|
if (NS_SUCCEEDED(rv) && exists)
|
|
|
|
aDirectories.AppendObject(platformABIDir);
|
|
|
|
#endif
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2005-04-23 01:39:51 +00:00
|
|
|
while (PR_TRUE);
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
static const char *const kAppendChromeManifests[] =
|
|
|
|
{ "chrome.manifest", nsnull };
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXREDirProvider::GetFiles(const char* aProperty, nsISimpleEnumerator** aResult)
|
2006-01-12 15:29:10 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> appEnum;
|
|
|
|
nsCOMPtr<nsIDirectoryServiceProvider2>
|
|
|
|
appP2(do_QueryInterface(mAppProvider));
|
|
|
|
if (appP2) {
|
|
|
|
rv = appP2->GetFiles(aProperty, getter_AddRefs(appEnum));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
appEnum = nsnull;
|
|
|
|
}
|
|
|
|
else if (rv != NS_SUCCESS_AGGREGATE_RESULT) {
|
|
|
|
NS_ADDREF(*aResult = appEnum);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> xreEnum;
|
|
|
|
rv = GetFilesInternal(aProperty, getter_AddRefs(xreEnum));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (appEnum) {
|
|
|
|
NS_ADDREF(*aResult = appEnum);
|
|
|
|
return NS_SUCCESS_AGGREGATE_RESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewUnionEnumerator(aResult, appEnum, xreEnum);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return NS_SUCCESS_AGGREGATE_RESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetFilesInternal(const char* aProperty,
|
|
|
|
nsISimpleEnumerator** aResult)
|
2004-06-17 21:23:51 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
2005-06-02 13:33:07 +00:00
|
|
|
nsCOMPtr<nsIFile> profileFile;
|
|
|
|
if (mProfileDir) {
|
|
|
|
mProfileDir->Clone(getter_AddRefs(profileFile));
|
|
|
|
profileFile->AppendNative(NS_LITERAL_CSTRING("extensions.ini"));
|
|
|
|
}
|
|
|
|
|
2005-06-07 19:45:11 +00:00
|
|
|
if (!strcmp(aProperty, XRE_EXTENSIONS_DIR_LIST)) {
|
|
|
|
nsCOMArray<nsIFile> directories;
|
|
|
|
|
|
|
|
if (mProfileDir && !gSafeMode) {
|
|
|
|
static const char *const kAppendNothing[] = { nsnull };
|
|
|
|
|
|
|
|
LoadDirsIntoArray(profileFile, "ExtensionDirs",
|
|
|
|
kAppendNothing, directories);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_XPCOM_COMPONENT_DIR_LIST)) {
|
2004-09-15 23:02:10 +00:00
|
|
|
nsCOMArray<nsIFile> directories;
|
2005-06-02 13:33:07 +00:00
|
|
|
|
2004-09-15 23:02:10 +00:00
|
|
|
if (mXULAppDir) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
mXULAppDir->Clone(getter_AddRefs(file));
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("components"));
|
|
|
|
PRBool exists;
|
|
|
|
if (NS_SUCCEEDED(file->Exists(&exists)) && exists)
|
|
|
|
directories.AppendObject(file);
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
if (mProfileDir && !gSafeMode) {
|
|
|
|
static const char *const kAppendCompDir[] = { "components", nsnull };
|
2005-02-22 21:49:45 +00:00
|
|
|
|
|
|
|
LoadDirsIntoArray(profileFile, "ExtensionDirs",
|
|
|
|
kAppendCompDir, directories);
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2004-09-15 23:02:10 +00:00
|
|
|
|
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_APP_PREFS_DEFAULTS_DIR_LIST)) {
|
|
|
|
nsCOMArray<nsIFile> directories;
|
2005-05-12 13:23:30 +00:00
|
|
|
|
2004-09-07 18:59:07 +00:00
|
|
|
if (mXULAppDir) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
mXULAppDir->Clone(getter_AddRefs(file));
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("defaults"));
|
2005-02-24 19:40:21 +00:00
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("preferences"));
|
2004-09-07 18:59:07 +00:00
|
|
|
PRBool exists;
|
|
|
|
if (NS_SUCCEEDED(file->Exists(&exists)) && exists)
|
|
|
|
directories.AppendObject(file);
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-06-02 13:33:07 +00:00
|
|
|
if (mProfileDir && !gSafeMode) {
|
2005-05-12 13:23:30 +00:00
|
|
|
static const char *const kAppendPrefDir[] = { "defaults", "preferences", nsnull };
|
2005-06-02 13:33:07 +00:00
|
|
|
|
|
|
|
LoadDirsIntoArray(profileFile, "ExtensionDirs",
|
|
|
|
kAppendPrefDir, directories);
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
|
|
|
}
|
2005-02-22 21:49:45 +00:00
|
|
|
else if (!strcmp(aProperty, NS_CHROME_MANIFESTS_FILE_LIST)) {
|
|
|
|
nsCOMArray<nsIFile> manifests;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> manifest;
|
2005-12-23 14:51:39 +00:00
|
|
|
mGREDir->Clone(getter_AddRefs(manifest));
|
2005-02-22 21:49:45 +00:00
|
|
|
manifest->AppendNative(NS_LITERAL_CSTRING("chrome"));
|
|
|
|
manifests.AppendObject(manifest);
|
|
|
|
|
|
|
|
if (mXULAppDir) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
mXULAppDir->Clone(getter_AddRefs(file));
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("chrome"));
|
|
|
|
PRBool exists;
|
|
|
|
if (NS_SUCCEEDED(file->Exists(&exists)) && exists)
|
|
|
|
manifests.AppendObject(file);
|
2005-06-02 13:33:07 +00:00
|
|
|
|
|
|
|
mXULAppDir->Clone(getter_AddRefs(file));
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("chrome.manifest"));
|
|
|
|
if (NS_SUCCEEDED(file->Exists(&exists)) && exists)
|
|
|
|
manifests.AppendObject(file);
|
2005-02-22 21:49:45 +00:00
|
|
|
}
|
2005-05-12 13:23:30 +00:00
|
|
|
|
|
|
|
if (mProfileDir && !gSafeMode) {
|
2005-02-22 21:49:45 +00:00
|
|
|
LoadDirsIntoArray(profileFile, "ExtensionDirs",
|
|
|
|
kAppendChromeManifests, manifests);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewArrayEnumerator(aResult, manifests);
|
|
|
|
}
|
|
|
|
else if (!strcmp(aProperty, NS_SKIN_MANIFESTS_FILE_LIST)) {
|
|
|
|
nsCOMArray<nsIFile> manifests;
|
2005-05-12 13:23:30 +00:00
|
|
|
if (mProfileDir && !gSafeMode) {
|
2005-02-22 21:49:45 +00:00
|
|
|
LoadDirsIntoArray(profileFile, "ThemeDirs",
|
|
|
|
kAppendChromeManifests, manifests);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewArrayEnumerator(aResult, manifests);
|
|
|
|
}
|
2004-09-07 18:59:07 +00:00
|
|
|
else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) {
|
2005-04-11 12:43:42 +00:00
|
|
|
// NS_APP_CHROME_DIR_LIST is only used to get default (native) icons
|
|
|
|
// for OS window decoration.
|
|
|
|
|
2004-09-07 18:59:07 +00:00
|
|
|
nsCOMArray<nsIFile> directories;
|
|
|
|
|
|
|
|
if (mXULAppDir) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
mXULAppDir->Clone(getter_AddRefs(file));
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("chrome"));
|
|
|
|
PRBool exists;
|
|
|
|
if (NS_SUCCEEDED(file->Exists(&exists)) && exists)
|
|
|
|
directories.AppendObject(file);
|
|
|
|
}
|
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
if (mProfileDir && !gSafeMode) {
|
2005-04-11 12:43:42 +00:00
|
|
|
static const char *const kAppendChromeDir[] = { "chrome", nsnull };
|
|
|
|
|
|
|
|
LoadDirsIntoArray(profileFile, "ExtensionDirs",
|
|
|
|
kAppendChromeDir, directories);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:59:07 +00:00
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
|
|
|
}
|
2005-06-02 13:33:07 +00:00
|
|
|
else if (!strcmp(aProperty, NS_APP_PLUGINS_DIR_LIST)) {
|
|
|
|
nsCOMArray<nsIFile> directories;
|
|
|
|
|
|
|
|
// The root dirserviceprovider does quite a bit for us: we're mainly
|
|
|
|
// interested in xulapp and extension-provided plugins.
|
|
|
|
if (mXULAppDir) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
mXULAppDir->Clone(getter_AddRefs(file));
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("plugins"));
|
|
|
|
PRBool exists;
|
|
|
|
if (NS_SUCCEEDED(file->Exists(&exists)) && exists)
|
|
|
|
directories.AppendObject(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mProfileDir && !gSafeMode) {
|
|
|
|
static const char *const kAppendPlugins[] = { "plugins", nsnull };
|
|
|
|
|
|
|
|
LoadDirsIntoArray(profileFile, "ExtensionDirs",
|
|
|
|
kAppendPlugins, directories);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewArrayEnumerator(aResult, directories);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = NS_SUCCESS_AGGREGATE_RESULT;
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
else
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXREDirProvider::GetDirectory(nsIFile* *aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mProfileDir, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
return mProfileDir->Clone(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXREDirProvider::DoStartup()
|
|
|
|
{
|
|
|
|
if (!mProfileNotified) {
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc
|
|
|
|
(do_GetService("@mozilla.org/observer-service;1"));
|
|
|
|
if (!obsSvc) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mProfileNotified = PR_TRUE;
|
|
|
|
|
|
|
|
static const PRUnichar kStartup[] = {'s','t','a','r','t','u','p','\0'};
|
|
|
|
obsSvc->NotifyObservers(nsnull, "profile-do-change", kStartup);
|
|
|
|
obsSvc->NotifyObservers(nsnull, "profile-after-change", kStartup);
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProfileChangeStatusImpl : public nsIProfileChangeStatus
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPROFILECHANGESTATUS
|
|
|
|
ProfileChangeStatusImpl() { }
|
|
|
|
private:
|
|
|
|
~ProfileChangeStatusImpl() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(ProfileChangeStatusImpl, nsIProfileChangeStatus)
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ProfileChangeStatusImpl::VetoChange()
|
|
|
|
{
|
|
|
|
NS_ERROR("Can't veto change!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ProfileChangeStatusImpl::ChangeFailed()
|
|
|
|
{
|
|
|
|
NS_ERROR("Profile change cancellation.");
|
2002-08-21 10:25:54 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
void
|
|
|
|
nsXREDirProvider::DoShutdown()
|
|
|
|
{
|
|
|
|
if (mProfileNotified) {
|
|
|
|
nsCOMPtr<nsIObserverService> obssvc
|
|
|
|
(do_GetService("@mozilla.org/observer-service;1"));
|
|
|
|
NS_ASSERTION(obssvc, "No observer service?");
|
|
|
|
if (obssvc) {
|
|
|
|
nsCOMPtr<nsIProfileChangeStatus> cs = new ProfileChangeStatusImpl();
|
|
|
|
static const PRUnichar kShutdownPersist[] =
|
|
|
|
{'s','h','u','t','d','o','w','n','-','p','e','r','s','i','s','t','\0'};
|
|
|
|
obssvc->NotifyObservers(cs, "profile-change-net-teardown", kShutdownPersist);
|
|
|
|
obssvc->NotifyObservers(cs, "profile-change-teardown", kShutdownPersist);
|
|
|
|
|
|
|
|
// Phase 2c: Now that things are torn down, force JS GC so that things which depend on
|
|
|
|
// resources which are about to go away in "profile-before-change" are destroyed first.
|
|
|
|
nsCOMPtr<nsIThreadJSContextStack> stack
|
|
|
|
(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
|
|
|
|
if (stack)
|
|
|
|
{
|
|
|
|
JSContext *cx = nsnull;
|
|
|
|
stack->GetSafeJSContext(&cx);
|
|
|
|
if (cx)
|
|
|
|
::JS_GC(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Phase 3: Notify observers of a profile change
|
|
|
|
obssvc->NotifyObservers(cs, "profile-before-change", kShutdownPersist);
|
|
|
|
}
|
|
|
|
mProfileNotified = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetProfileFolderName(char* aProfileFolderName, const char* aSource)
|
|
|
|
{
|
|
|
|
const char* reading = aSource;
|
|
|
|
|
|
|
|
while (*reading) {
|
|
|
|
*aProfileFolderName = tolower(*reading);
|
|
|
|
++aProfileFolderName; ++reading;
|
|
|
|
}
|
|
|
|
*aProfileFolderName = '\0';
|
|
|
|
}
|
|
|
|
|
2005-05-15 17:33:14 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
static nsresult
|
|
|
|
GetShellFolderPath(int folder, char result[MAXPATHLEN])
|
|
|
|
{
|
|
|
|
LPITEMIDLIST pItemIDList = NULL;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, folder, &pItemIDList)) &&
|
|
|
|
SUCCEEDED(SHGetPathFromIDList(pItemIDList, result))) {
|
|
|
|
rv = NS_OK;
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2005-10-07 00:49:05 +00:00
|
|
|
CoTaskMemFree(pItemIDList);
|
|
|
|
|
2005-05-15 17:33:14 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-12 15:29:10 +00:00
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetProfileStartupDir(nsIFile* *aResult)
|
|
|
|
{
|
|
|
|
if (mProfileDir)
|
|
|
|
return mProfileDir->Clone(aResult);
|
|
|
|
|
|
|
|
if (mAppProvider) {
|
|
|
|
nsCOMPtr<nsIFile> needsclone;
|
|
|
|
PRBool dummy;
|
|
|
|
nsresult rv = mAppProvider->GetFile(NS_APP_PROFILE_DIR_STARTUP,
|
|
|
|
&dummy,
|
|
|
|
getter_AddRefs(needsclone));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return needsclone->Clone(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetProfileDir(nsIFile* *aResult)
|
|
|
|
{
|
|
|
|
if (mProfileDir) {
|
|
|
|
if (!mProfileNotified)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return mProfileDir->Clone(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAppProvider) {
|
|
|
|
nsCOMPtr<nsIFile> needsclone;
|
|
|
|
PRBool dummy;
|
|
|
|
nsresult rv = mAppProvider->GetFile(NS_APP_USER_PROFILE_50_DIR,
|
|
|
|
&dummy,
|
|
|
|
getter_AddRefs(needsclone));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return needsclone->Clone(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, aResult);
|
|
|
|
}
|
|
|
|
|
2002-08-21 10:25:54 +00:00
|
|
|
nsresult
|
2005-04-26 00:37:23 +00:00
|
|
|
nsXREDirProvider::GetUserDataDirectory(nsILocalFile** aFile, PRBool aLocal)
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2006-01-12 15:29:10 +00:00
|
|
|
if (!gAppData)
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2002-08-21 10:25:54 +00:00
|
|
|
// Copied from nsAppFileLocationProvider (more or less)
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsILocalFile> localDir;
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
#if defined(XP_MACOSX)
|
2005-04-26 00:37:23 +00:00
|
|
|
FSRef fsRef;
|
|
|
|
OSType folderType;
|
|
|
|
if (aLocal) {
|
|
|
|
folderType = kCachedDataFolderType;
|
|
|
|
} else {
|
2004-06-18 07:38:59 +00:00
|
|
|
#ifdef MOZ_THUNDERBIRD
|
2005-04-26 00:37:23 +00:00
|
|
|
folderType = kDomainLibraryFolderType;
|
2004-06-18 07:38:59 +00:00
|
|
|
#else
|
2005-04-26 00:37:23 +00:00
|
|
|
folderType = kApplicationSupportFolderType;
|
2004-06-18 07:38:59 +00:00
|
|
|
#endif
|
2005-04-26 00:37:23 +00:00
|
|
|
}
|
|
|
|
OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
|
2005-04-26 01:38:00 +00:00
|
|
|
NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(localDir));
|
2002-08-21 10:25:54 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir);
|
|
|
|
NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
rv = dirFileMac->InitWithFSRef(&fsRef);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Note that MacOS ignores the vendor when creating the profile hierarchy - all
|
|
|
|
// application preferences directories live alongside one another in
|
|
|
|
// ~/Library/Application Support/
|
2005-05-12 13:23:30 +00:00
|
|
|
rv = dirFileMac->AppendNative(nsDependentCString(gAppData->name));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-08-21 10:25:54 +00:00
|
|
|
#elif defined(XP_WIN)
|
2005-05-15 17:33:14 +00:00
|
|
|
char path[MAXPATHLEN];
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-05-15 17:33:14 +00:00
|
|
|
// CSIDL_LOCAL_APPDATA is only defined on newer versions of Windows. If the
|
|
|
|
// OS does not understand it, then we'll fallback to the regular APPDATA
|
|
|
|
// location. If neither is defined, then we fallback to the Windows folder.
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-05-15 17:33:14 +00:00
|
|
|
if (aLocal)
|
|
|
|
rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path);
|
|
|
|
if (!aLocal || NS_FAILED(rv))
|
|
|
|
rv = GetShellFolderPath(CSIDL_APPDATA, path);
|
2005-04-26 00:37:23 +00:00
|
|
|
|
2005-05-15 17:33:14 +00:00
|
|
|
if (NS_FAILED(rv) && !GetWindowsDirectory(path, sizeof(path))) {
|
|
|
|
NS_WARNING("Aaah, no windows directory!");
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-05-15 17:33:14 +00:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(path),
|
2004-06-17 21:23:51 +00:00
|
|
|
PR_TRUE, getter_AddRefs(localDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
if (gAppData->vendor) {
|
|
|
|
rv = localDir->AppendNative(nsDependentCString(gAppData->vendor));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2005-05-12 13:23:30 +00:00
|
|
|
rv = localDir->AppendNative(nsDependentCString(gAppData->name));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#elif defined(XP_OS2)
|
|
|
|
#if 0 /* For OS/2 we want to always use MOZILLA_HOME */
|
|
|
|
// we want an environment variable of the form
|
|
|
|
// FIREFOX_HOME, etc
|
2005-05-12 13:23:30 +00:00
|
|
|
nsDependentCString envVar(nsDependentCString(gAppData->name));
|
2004-06-17 21:23:51 +00:00
|
|
|
envVar.Append("_HOME");
|
|
|
|
char *pHome = getenv(envVar.get());
|
|
|
|
#endif
|
|
|
|
char *pHome = getenv("MOZILLA_HOME");
|
|
|
|
if (pHome && *pHome) {
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(pHome), PR_TRUE,
|
|
|
|
getter_AddRefs(localDir));
|
|
|
|
} else {
|
|
|
|
PPIB ppib;
|
|
|
|
PTIB ptib;
|
|
|
|
char appDir[CCHMAXPATH];
|
|
|
|
|
|
|
|
DosGetInfoBlocks(&ptib, &ppib);
|
|
|
|
DosQueryModuleName(ppib->pib_hmte, CCHMAXPATH, appDir);
|
|
|
|
*strrchr(appDir, '\\') = '\0';
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(appDir), PR_TRUE, getter_AddRefs(localDir));
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
if (gAppData->vendor) {
|
|
|
|
rv = localDir->AppendNative(nsDependentCString(gAppData->vendor));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2005-05-12 13:23:30 +00:00
|
|
|
rv = localDir->AppendNative(nsDependentCString(gAppData->name));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-08-21 10:25:54 +00:00
|
|
|
#elif defined(XP_BEOS)
|
2004-06-17 21:23:51 +00:00
|
|
|
char appDir[MAXPATHLEN];
|
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, NULL, true, appDir, MAXPATHLEN))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
int len = strlen(appDir);
|
|
|
|
appDir[len] = '/';
|
|
|
|
appDir[len+1] = '\0';
|
|
|
|
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(appDir), PR_TRUE,
|
|
|
|
getter_AddRefs(localDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
if (gAppData->vendor) {
|
|
|
|
rv = localDir->AppendNative(nsDependentCString(gAppData->vendor));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2005-05-12 13:23:30 +00:00
|
|
|
rv = localDir->AppendNative(nsDependentCString(gAppData->name));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
const char* homeDir = getenv("HOME");
|
|
|
|
if (!homeDir || !*homeDir)
|
2002-08-21 10:25:54 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), PR_TRUE,
|
|
|
|
getter_AddRefs(localDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
char* appNameFolder = nsnull;
|
|
|
|
char profileFolderName[MAXPATHLEN] = ".";
|
|
|
|
|
|
|
|
// Offset 1 for the outermost folder to make it hidden (i.e. using the ".")
|
|
|
|
char* writing = profileFolderName + 1;
|
2005-05-12 13:23:30 +00:00
|
|
|
if (gAppData->vendor) {
|
|
|
|
GetProfileFolderName(writing, gAppData->vendor);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
rv = localDir->AppendNative(nsDependentCString(profileFolderName));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
char temp[MAXPATHLEN];
|
2005-05-12 13:23:30 +00:00
|
|
|
GetProfileFolderName(temp, gAppData->name);
|
2004-06-17 21:23:51 +00:00
|
|
|
appNameFolder = temp;
|
|
|
|
}
|
|
|
|
else {
|
2005-05-12 13:23:30 +00:00
|
|
|
GetProfileFolderName(writing, gAppData->name);
|
2004-06-17 21:23:51 +00:00
|
|
|
appNameFolder = profileFolderName;
|
|
|
|
}
|
|
|
|
rv = localDir->AppendNative(nsDependentCString(appNameFolder));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-08-21 10:25:54 +00:00
|
|
|
#else
|
|
|
|
#error dont_know_how_to_get_product_dir_on_your_platform
|
|
|
|
#endif
|
|
|
|
|
2006-03-22 04:26:30 +00:00
|
|
|
#ifdef DEBUG_jungshik
|
|
|
|
nsCAutoString cwd;
|
|
|
|
localDir->GetNativePath(cwd);
|
|
|
|
printf("nsXREDirProvider::GetUserDataDirectory: %s\n", cwd.get());
|
|
|
|
#endif
|
2002-08-26 10:18:41 +00:00
|
|
|
rv = EnsureDirectoryExists(localDir);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aFile = localDir;
|
|
|
|
NS_ADDREF(*aFile);
|
2002-08-21 10:25:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-08-26 10:18:41 +00:00
|
|
|
|
|
|
|
nsresult
|
2004-06-17 21:23:51 +00:00
|
|
|
nsXREDirProvider::EnsureDirectoryExists(nsIFile* aDirectory)
|
2002-08-26 10:18:41 +00:00
|
|
|
{
|
|
|
|
PRBool exists;
|
|
|
|
nsresult rv = aDirectory->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-03-22 04:26:30 +00:00
|
|
|
#ifdef DEBUG_jungshik
|
|
|
|
if (!exists) {
|
|
|
|
nsCAutoString cwd;
|
|
|
|
aDirectory->GetNativePath(cwd);
|
|
|
|
printf("nsXREDirProvider::EnsureDirectoryExists: %s does not\n", cwd.get());
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-26 10:18:41 +00:00
|
|
|
if (!exists)
|
2005-04-26 00:37:23 +00:00
|
|
|
rv = aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
2006-03-22 04:26:30 +00:00
|
|
|
#ifdef DEBUG_jungshik
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
NS_WARNING("nsXREDirProvider::EnsureDirectoryExists: create failed");
|
|
|
|
#endif
|
2002-08-26 10:18:41 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsXREDirProvider::EnsureProfileFileExists(nsIFile *aFile)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
PRBool exists;
|
|
|
|
|
|
|
|
rv = aFile->Exists(&exists);
|
|
|
|
if (NS_FAILED(rv) || exists) return;
|
|
|
|
|
|
|
|
nsCAutoString leafName;
|
|
|
|
rv = aFile->GetNativeLeafName(leafName);
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> defaultsFile;
|
|
|
|
rv = GetProfileDefaultsDir(getter_AddRefs(defaultsFile));
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
rv = defaultsFile->AppendNative(leafName);
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
defaultsFile->CopyToNative(mProfileDir, EmptyCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXREDirProvider::GetProfileDefaultsDir(nsIFile* *aResult)
|
|
|
|
{
|
2005-12-23 14:51:39 +00:00
|
|
|
NS_ASSERTION(mGREDir, "nsXREDirProvider not initialized.");
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_PRECONDITION(aResult, "Null out-param");
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFile> defaultsDir;
|
|
|
|
|
2005-12-23 14:51:39 +00:00
|
|
|
rv = GetAppDir()->Clone(getter_AddRefs(defaultsDir));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-09-07 18:59:07 +00:00
|
|
|
rv = defaultsDir->AppendNative(NS_LITERAL_CSTRING("defaults"));
|
|
|
|
rv |= defaultsDir->AppendNative(NS_LITERAL_CSTRING("profile"));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult = defaultsDir);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|