toolkit/xre/nsXREDirProvider.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/xre/nsXREDirProvider.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,145 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef _nsXREDirProvider_h__
    1.10 +#define _nsXREDirProvider_h__
    1.11 +
    1.12 +#include "nsIDirectoryService.h"
    1.13 +#include "nsIProfileMigrator.h"
    1.14 +#include "nsIFile.h"
    1.15 +
    1.16 +#include "nsCOMPtr.h"
    1.17 +#include "nsCOMArray.h"
    1.18 +#include "mozilla/Attributes.h"
    1.19 +
    1.20 +class nsXREDirProvider MOZ_FINAL : public nsIDirectoryServiceProvider2,
    1.21 +                                   public nsIProfileStartup
    1.22 +{
    1.23 +public:
    1.24 +  // we use a custom isupports implementation (no refcount)
    1.25 +  NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
    1.26 +  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
    1.27 +  NS_IMETHOD_(MozExternalRefCountType) Release(void);
    1.28 +
    1.29 +  NS_DECL_NSIDIRECTORYSERVICEPROVIDER
    1.30 +  NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
    1.31 +  NS_DECL_NSIPROFILESTARTUP
    1.32 +
    1.33 +  nsXREDirProvider();
    1.34 +
    1.35 +  // if aXULAppDir is null, use gArgv[0]
    1.36 +  nsresult Initialize(nsIFile *aXULAppDir,
    1.37 +                      nsIFile *aGREDir,
    1.38 +                      nsIDirectoryServiceProvider* aAppProvider = nullptr);
    1.39 +  ~nsXREDirProvider();
    1.40 +
    1.41 +  static nsXREDirProvider* GetSingleton();
    1.42 +
    1.43 +  nsresult GetUserProfilesRootDir(nsIFile** aResult,
    1.44 +                                  const nsACString* aProfileName,
    1.45 +                                  const nsACString* aAppName,
    1.46 +                                  const nsACString* aVendorName);
    1.47 +  nsresult GetUserProfilesLocalDir(nsIFile** aResult,
    1.48 +                                   const nsACString* aProfileName,
    1.49 +                                   const nsACString* aAppName,
    1.50 +                                   const nsACString* aVendorName);
    1.51 +
    1.52 +  // We only set the profile dir, we don't ensure that it exists;
    1.53 +  // that is the responsibility of the toolkit profile service.
    1.54 +  // We also don't fire profile-changed notifications... that is
    1.55 +  // the responsibility of the apprunner.
    1.56 +  nsresult SetProfile(nsIFile* aProfileDir, nsIFile* aProfileLocalDir);
    1.57 +
    1.58 +  void DoShutdown();
    1.59 +
    1.60 +  nsresult GetProfileDefaultsDir(nsIFile* *aResult);
    1.61 +
    1.62 +  nsresult GetUserAppDataDirectory(nsIFile* *aFile) {
    1.63 +    return GetUserDataDirectory(aFile, false, nullptr, nullptr, nullptr);
    1.64 +  }
    1.65 +  nsresult GetUserLocalDataDirectory(nsIFile* *aFile) {
    1.66 +    return GetUserDataDirectory(aFile, true, nullptr, nullptr, nullptr);
    1.67 +  }
    1.68 +
    1.69 +  // By default GetUserDataDirectory gets profile path from gAppData,
    1.70 +  // but that can be overridden by using aProfileName/aAppName/aVendorName.
    1.71 +  nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal,
    1.72 +                                       const nsACString* aProfileName,
    1.73 +                                       const nsACString* aAppName,
    1.74 +                                       const nsACString* aVendorName);
    1.75 +
    1.76 +  /* make sure you clone it, if you need to do stuff to it */
    1.77 +  nsIFile* GetGREDir() { return mGREDir; }
    1.78 +  nsIFile* GetAppDir() {
    1.79 +    if (mXULAppDir)
    1.80 +      return mXULAppDir;
    1.81 +    return mGREDir;
    1.82 +  }
    1.83 +
    1.84 +  /**
    1.85 +   * Get the directory under which update directory is created.
    1.86 +   * This method may be called before XPCOM is started. aResult
    1.87 +   * is a clone, it may be modified.
    1.88 +   */
    1.89 +  nsresult GetUpdateRootDir(nsIFile* *aResult);
    1.90 +
    1.91 +  /**
    1.92 +   * Get the profile startup directory as determined by this class or by
    1.93 +   * mAppProvider. This method may be called before XPCOM is started. aResult
    1.94 +   * is a clone, it may be modified.
    1.95 +   */
    1.96 +  nsresult GetProfileStartupDir(nsIFile* *aResult);
    1.97 +
    1.98 +  /**
    1.99 +   * Get the profile directory as determined by this class or by an
   1.100 +   * embedder-provided XPCOM directory provider. Only call this method
   1.101 +   * when XPCOM is initialized! aResult is a clone, it may be modified.
   1.102 +   */
   1.103 +  nsresult GetProfileDir(nsIFile* *aResult);
   1.104 +
   1.105 +protected:
   1.106 +  nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult);
   1.107 +  nsresult GetUserDataDirectoryHome(nsIFile* *aFile, bool aLocal);
   1.108 +  nsresult GetSysUserExtensionsDirectory(nsIFile* *aFile);
   1.109 +#if defined(XP_UNIX) || defined(XP_MACOSX)
   1.110 +  static nsresult GetSystemExtensionsDirectory(nsIFile** aFile);
   1.111 +#endif
   1.112 +  static nsresult EnsureDirectoryExists(nsIFile* aDirectory);
   1.113 +  void EnsureProfileFileExists(nsIFile* aFile);
   1.114 +
   1.115 +  // Determine the profile path within the UAppData directory. This is different
   1.116 +  // on every major platform.
   1.117 +  static nsresult AppendProfilePath(nsIFile* aFile,
   1.118 +                                    const nsACString* aProfileName,
   1.119 +                                    const nsACString* aAppName,
   1.120 +                                    const nsACString* aVendorName,
   1.121 +                                    bool aLocal);
   1.122 +
   1.123 +  static nsresult AppendSysUserExtensionPath(nsIFile* aFile);
   1.124 +
   1.125 +  // Internal helper that splits a path into components using the '/' and '\\'
   1.126 +  // delimiters.
   1.127 +  static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath);
   1.128 +
   1.129 +  // Calculate and register extension and theme bundle directories.
   1.130 +  void LoadExtensionBundleDirectories();
   1.131 +
   1.132 +  // Calculate and register app-bundled extension directories.
   1.133 +  void LoadAppBundleDirs();
   1.134 +
   1.135 +  void Append(nsIFile* aDirectory);
   1.136 +
   1.137 +  nsCOMPtr<nsIDirectoryServiceProvider> mAppProvider;
   1.138 +  nsCOMPtr<nsIFile>      mGREDir;
   1.139 +  nsCOMPtr<nsIFile>      mXULAppDir;
   1.140 +  nsCOMPtr<nsIFile>      mProfileDir;
   1.141 +  nsCOMPtr<nsIFile>      mProfileLocalDir;
   1.142 +  bool                   mProfileNotified;
   1.143 +  nsCOMArray<nsIFile>    mAppBundleDirectories;
   1.144 +  nsCOMArray<nsIFile>    mExtensionDirectories;
   1.145 +  nsCOMArray<nsIFile>    mThemeDirectories;
   1.146 +};
   1.147 +
   1.148 +#endif

mercurial