38 #include "nsIDirectoryService.h"
41 #include "nsISimpleEnumerator.h"
42 #include "nsIPrefService.h"
43 #include "nsIPrefBranch.h"
45 #include "nsArrayEnumerator.h"
46 #include "nsEnumeratorUtils.h"
48 #include "nsAppDirectoryServiceDefs.h"
49 #include "nsDirectoryServiceDefs.h"
50 #include "nsCategoryManagerUtils.h"
51 #include "nsComponentManagerUtils.h"
52 #include "nsCOMArray.h"
53 #include "nsDirectoryServiceUtils.h"
54 #include "nsIGenericFactory.h"
55 #include "nsServiceManagerUtils.h"
56 #include "nsStringAPI.h"
57 #include "nsXULAppAPI.h"
60 public nsIDirectoryServiceProvider2
64 NS_DECL_NSIDIRECTORYSERVICEPROVIDER
65 NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
67 static NS_METHOD
Register(nsIComponentManager* aCompMgr,
68 nsIFile*
aPath,
const char *aLoaderStr,
70 const nsModuleComponentInfo *aInfo);
72 static NS_METHOD
Unregister(nsIComponentManager* aCompMgr,
73 nsIFile* aPath,
const char *aLoaderStr,
74 const nsModuleComponentInfo *aInfo);
77 nsresult RestoreBookmarksFromBackup(
const nsACString& aLeafName,
78 nsIFile* aParentDir, nsIFile* aTarget);
79 void EnsureProfileFile(
const nsACString& aLeafName,
80 nsIFile* aParentDir, nsIFile* aTarget);
86 NS_DECL_NSISIMPLEENUMERATOR
89 char const *
const *aAppendList);
92 nsCOMPtr<nsISimpleEnumerator> mBase;
93 char const *
const *
const mAppendList;
94 nsCOMPtr<nsIFile> mNext;
99 nsIDirectoryServiceProvider,
100 nsIDirectoryServiceProvider2)
113 nsCOMPtr<nsIFile>
file;
115 char const* leafName = nsnull;
118 leafName =
"bookmarks.html";
123 rv = prefs->GetCharPref(
"browser.bookmarks.file", getter_Copies(path));
124 if (NS_SUCCEEDED(rv)) {
125 NS_NewNativeLocalFile(path, PR_TRUE, (nsILocalFile**)(nsIFile**) getter_AddRefs(file));
130 rv = NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR,
131 getter_AddRefs(file));
132 NS_ENSURE_SUCCESS(rv, rv);
134 file->AppendNative(NS_LITERAL_CSTRING(
"existing-profile-defaults.js"));
139 rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
140 getter_AddRefs(file));
141 NS_ENSURE_SUCCESS(rv, rv);
143 file->AppendNative(NS_LITERAL_CSTRING(
"microsummary-generators"));
149 getter_AddRefs(file));
150 NS_ENSURE_SUCCESS(rv, rv);
152 file->AppendNative(NS_LITERAL_CSTRING(
"microsummary-generators"));
157 return NS_ERROR_FAILURE;
160 nsDependentCString leafstr(leafName);
162 nsCOMPtr<nsIFile> parentDir;
164 rv = file->GetParent(getter_AddRefs(parentDir));
173 rv = parentDir->Clone(getter_AddRefs(file));
177 file->AppendNative(leafstr);
181 NS_ADDREF(*aResult = file);
188 nsCOMArray<nsIFile> &
array)
190 nsCOMPtr<nsIFile>
file;
191 nsresult rv = aDirSvc->Get(key, NS_GET_IID(nsIFile), getter_AddRefs(file));
196 rv = file->Exists(&exists);
197 if (NS_FAILED(rv) || !exists)
200 array.AppendObject(file);
223 nsCOMPtr<nsIFile> searchPlugins;
224 nsresult rv = aDirSvc->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
226 getter_AddRefs(searchPlugins));
229 searchPlugins->AppendNative(NS_LITERAL_CSTRING(
"distribution"));
230 searchPlugins->AppendNative(NS_LITERAL_CSTRING(
"searchplugins"));
233 rv = searchPlugins->Exists(&exists);
234 if (NS_FAILED(rv) || !exists)
237 nsCOMPtr<nsIFile> commonPlugins;
238 rv = searchPlugins->Clone(getter_AddRefs(commonPlugins));
239 if (NS_SUCCEEDED(rv)) {
240 commonPlugins->AppendNative(NS_LITERAL_CSTRING(
"common"));
241 rv = commonPlugins->Exists(&exists);
242 if (NS_SUCCEEDED(rv) && exists)
243 array.AppendObject(commonPlugins);
249 nsCOMPtr<nsIFile> localePlugins;
250 rv = searchPlugins->Clone(getter_AddRefs(localePlugins));
254 localePlugins->AppendNative(NS_LITERAL_CSTRING(
"locale"));
257 rv = prefs->GetCharPref(
"general.useragent.locale", getter_Copies(locale));
258 if (NS_SUCCEEDED(rv)) {
260 nsCOMPtr<nsIFile> curLocalePlugins;
261 rv = localePlugins->Clone(getter_AddRefs(curLocalePlugins));
262 if (NS_SUCCEEDED(rv)) {
264 curLocalePlugins->AppendNative(locale);
265 rv = curLocalePlugins->Exists(&exists);
266 if (NS_SUCCEEDED(rv) && exists) {
267 array.AppendObject(curLocalePlugins);
275 rv = prefs->GetCharPref(
"distribution.searchplugins.defaultLocale",
276 getter_Copies(defLocale));
277 if (NS_SUCCEEDED(rv)) {
279 nsCOMPtr<nsIFile> defLocalePlugins;
280 rv = localePlugins->Clone(getter_AddRefs(defLocalePlugins));
281 if (NS_SUCCEEDED(rv)) {
283 defLocalePlugins->AppendNative(defLocale);
284 rv = defLocalePlugins->Exists(&exists);
285 if (NS_SUCCEEDED(rv) && exists)
286 array.AppendObject(defLocalePlugins);
293 nsBrowserDirectoryProvider::GetFiles(
const char *aKey,
298 if (!strcmp(aKey, NS_APP_SEARCH_DIR_LIST)) {
299 nsCOMPtr<nsIProperties>
dirSvc
300 (do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
302 return NS_ERROR_FAILURE;
304 nsCOMArray<nsIFile> baseFiles;
310 nsCOMPtr<nsISimpleEnumerator> baseEnum;
311 rv = NS_NewArrayEnumerator(getter_AddRefs(baseEnum), baseFiles);
315 nsCOMPtr<nsISimpleEnumerator> list;
316 rv =
dirSvc->Get(XRE_EXTENSIONS_DIR_LIST,
321 static char const *
const kAppendSPlugins[] = {
"searchplugins", nsnull};
323 nsCOMPtr<nsISimpleEnumerator> extEnum =
324 new AppendingEnumerator(list, kAppendSPlugins);
326 return NS_ERROR_OUT_OF_MEMORY;
328 return NS_NewUnionEnumerator(aResult, extEnum, baseEnum);
331 return NS_ERROR_FAILURE;
334 static char const kContractID[] =
"@mozilla.org/browser/directory-provider;1";
337 #define NS_BROWSERDIRECTORYPROVIDER_CID \
338 { 0x6deb193c, 0xf87d, 0x4078, { 0xbc, 0x78, 0x5e, 0x64, 0x65, 0x5b, 0x4d, 0x62 } }
342 nsIFile*
aPath,
const char *aLoaderStr,
344 const nsModuleComponentInfo *aInfo)
348 nsCOMPtr<nsICategoryManager> catMan
349 (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
351 return NS_ERROR_FAILURE;
353 rv = catMan->AddCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY,
354 "browser-directory-provider",
355 kContractID, PR_TRUE, PR_TRUE, nsnull);
362 nsIFile*
aPath,
const char *aLoaderStr,
363 const nsModuleComponentInfo *aInfo)
367 nsCOMPtr<nsICategoryManager> catMan
368 (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
370 return NS_ERROR_FAILURE;
372 rv = catMan->DeleteCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY,
373 "browser-directory-provider", PR_TRUE);
381 "nsBrowserDirectoryProvider",
384 nsBrowserDirectoryProviderConstructor,
397 *aResult = mNext ? PR_TRUE : PR_FALSE;
402 nsBrowserDirectoryProvider::AppendingEnumerator::GetNext(
nsISupports* *aResult)
405 NS_ADDREF(*aResult = mNext);
414 while (NS_SUCCEEDED(mBase->HasMoreElements(&more)) && more) {
415 nsCOMPtr<nsISupports> nextbasesupp;
416 mBase->GetNext(getter_AddRefs(nextbasesupp));
418 nsCOMPtr<nsIFile> nextbase(do_QueryInterface(nextbasesupp));
422 nextbase->Clone(getter_AddRefs(mNext));
426 char const *
const *
i = mAppendList;
428 mNext->AppendNative(nsDependentCString(*i));
433 rv = mNext->Exists(&exists);
434 if (NS_SUCCEEDED(rv) && exists)
443 nsBrowserDirectoryProvider::AppendingEnumerator::AppendingEnumerator
445 char const *
const *aAppendList) :
447 mAppendList(aAppendList)
#define NS_BROWSERDIRECTORYPROVIDER_CID
#define NS_APP_EXISTING_PREF_OVERRIDE
static const nsModuleComponentInfo components[]
static void AppendDistroSearchDirs(nsIProperties *aDirSvc, nsCOMArray< nsIFile > &array)
const NS_PREFSERVICE_CONTRACTID
static char const kContractID[]
const NS_APP_BOOKMARKS_50_FILE
static void AppendFileKey(const char *key, nsIProperties *aDirSvc, nsCOMArray< nsIFile > &array)
NS_IMPL_ISUPPORTS1(nsBrowserDirectoryProvider::AppendingEnumerator, nsISimpleEnumerator) NS_IMETHODIMP nsBrowserDirectoryProvider
static NS_METHOD Unregister(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const nsModuleComponentInfo *aInfo)
NS_IMPL_NSGETMODULE(SongbirdIdentityServiceComponent, sbIdentityServiceComponent)
NS_DECL_ISUPPORTS NS_DECL_NSIDIRECTORYSERVICEPROVIDER static NS_DECL_NSIDIRECTORYSERVICEPROVIDER2 NS_METHOD Register(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
#define NS_APP_MICROSUMMARY_DIR
#define NS_APP_USER_MICROSUMMARY_DIR
NS_IMPL_ISUPPORTS2(nsBrowserDirectoryProvider, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2) NS_IMETHODIMP nsBrowserDirectoryProvider
_getSelectedPageStyle s i