From 42bfc2d2bfb60d06312b5fcec6bc022d62488aef Mon Sep 17 00:00:00 2001 From: "ccarlen%netscape.com" Date: Tue, 6 Feb 2001 15:41:37 +0000 Subject: [PATCH] Bug 65907 - remove dependency on chrome from XPCOM. r=racham@netscape.com,tao@netscape.com, cls@seawood.org, sr=hyatt@netscape.com --- profile/src/nsProfile.cpp | 68 +++++++++++++++----------- profile/src/nsProfile.h | 1 + xpcom/io/Makefile.in | 2 +- xpcom/io/nsAppFileLocationProvider.cpp | 49 +------------------ 4 files changed, 44 insertions(+), 76 deletions(-) diff --git a/profile/src/nsProfile.cpp b/profile/src/nsProfile.cpp index 217d40d01ba..6ba746302e9 100644 --- a/profile/src/nsProfile.cpp +++ b/profile/src/nsProfile.cpp @@ -610,15 +610,9 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs, *profileDirSet = PR_FALSE; } else { - nsCOMPtr aFile; - rv = GetProfileDir(currProfileName.GetUnicode(), getter_AddRefs(aFile)); - if (NS_SUCCEEDED(rv)){ + rv = SetCurrentProfile(currProfileName.GetUnicode()); + if (NS_SUCCEEDED(rv)) *profileDirSet = PR_TRUE; - mCurrentProfileAvailable = PR_TRUE; - - // Need to load new profile prefs. - rv = LoadNewProfilePrefs(); - } } } } @@ -994,6 +988,13 @@ nsProfile::SetCurrentProfile(const PRUnichar * aCurrentProfile) // Phase 3: Notify observers of a profile change observerService->Notify(subject, PROFILE_BEFORE_CHANGE_TOPIC, nsnull); } + + // Flush the stringbundle cache + NS_WITH_SERVICE(nsIStringBundleService, bundleService, NS_STRINGBUNDLE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = bundleService->FlushBundles(); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to flush bundle cache"); + } // Do the profile switch gProfileDataAccess->SetCurrentProfile(aCurrentProfile); @@ -1029,6 +1030,10 @@ nsProfile::SetCurrentProfile(const PRUnichar * aCurrentProfile) else rv = LoadNewProfilePrefs(); + // Now that a profile is established, set the profile defaults dir for the locale of this profile + rv = DefineLocaleDefaultsDir(); + NS_ASSERTION(NS_SUCCEEDED(rv), "nsProfile::DefineLocaleDefaultsDir failed"); + return NS_OK; } @@ -1570,27 +1575,9 @@ NS_IMETHODIMP nsProfile::StartApprunner(const PRUnichar* profileName) } #endif - // flush the stringbundle cache first -#if defined(DEBUG_tao) - printf("\n--> nsProfile::StartApprunner: FlushBundles() \n"); -#endif - nsCOMPtr bundleService = - do_GetService(kStringBundleServiceCID, &rv); + rv = SetCurrentProfile(profileName); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to set profile"); - if (NS_SUCCEEDED(rv)) { - rv = bundleService->FlushBundles(); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to flush bundle cache"); - } - - gProfileDataAccess->SetCurrentProfile(profileName); - mCurrentProfileAvailable = PR_TRUE; - - // Update registry entries - gProfileDataAccess->mProfileDataChanged = PR_TRUE; - gProfileDataAccess->UpdateRegistry(nsnull); - - // Need to load new profile prefs. - rv = LoadNewProfilePrefs(); return rv; } @@ -1704,6 +1691,31 @@ nsProfile::EnsureProfileFileExists(nsIFile *aFile) return rv; } +nsresult +nsProfile::DefineLocaleDefaultsDir() +{ + nsresult rv; + + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_CONTRACTID, &rv); + NS_ENSURE_TRUE(directoryService, NS_ERROR_FAILURE); + + nsCOMPtr localeDefaults; + rv = directoryService->Get(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(localeDefaults)); + if (NS_SUCCEEDED(rv)) + { + NS_WITH_SERVICE(nsIChromeRegistry, chromeRegistry, kChromeRegistryCID, &rv); + if (NS_SUCCEEDED(rv)) + { + nsXPIDLString localeName; + rv = chromeRegistry->GetSelectedLocale(NS_LITERAL_STRING("navigator"), getter_Copies(localeName)); + if (NS_SUCCEEDED(rv)) + rv = localeDefaults->AppendUnicode(localeName); + } + (void) directoryService->Undefine(NS_APP_PROFILE_DEFAULTS_50_DIR); + rv = directoryService->Define(NS_APP_PROFILE_DEFAULTS_50_DIR, localeDefaults); + } + return rv; +} // Migrate a selected profile // Set the profile to the current profile....debatable. diff --git a/profile/src/nsProfile.h b/profile/src/nsProfile.h index f690650af0c..8e2bf14bb4e 100644 --- a/profile/src/nsProfile.h +++ b/profile/src/nsProfile.h @@ -64,6 +64,7 @@ private: nsresult CloneProfileDirectorySpec(nsILocalFile **aLocalFile); nsresult AddLevelOfIndirection(nsIFile *aDir); + nsresult DefineLocaleDefaultsDir(); PRBool mAutomigrate; PRBool mOutofDiskSpace; diff --git a/xpcom/io/Makefile.in b/xpcom/io/Makefile.in index 690d819c054..56ccd8f315e 100644 --- a/xpcom/io/Makefile.in +++ b/xpcom/io/Makefile.in @@ -29,7 +29,7 @@ include $(DEPTH)/config/autoconf.mk MODULE = xpcom XPIDL_MODULE = xpcom_io LIBRARY_NAME = xpcomio_s -REQUIRES = uconv chrome necko +REQUIRES = uconv CPPSRCS = \ nsDirectoryService.cpp \ diff --git a/xpcom/io/nsAppFileLocationProvider.cpp b/xpcom/io/nsAppFileLocationProvider.cpp index 35965c7777d..a4121e13f70 100755 --- a/xpcom/io/nsAppFileLocationProvider.cpp +++ b/xpcom/io/nsAppFileLocationProvider.cpp @@ -55,12 +55,6 @@ #include #endif -#ifndef XPCOM_STANDALONE -#include "nsIChromeRegistry.h" - -static nsresult GetChromeLocale(PRUnichar** localeName); -static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID); -#endif // WARNING: These hard coded names need to go away. They need to // come from localizable resources @@ -158,25 +152,8 @@ nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile rv = localFile->AppendRelativePath(DEFAULTS_PREF_DIR_NAME); } } - else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_50_DIR) == 0) - { - rv = CloneMozBinDirectory(getter_AddRefs(localFile)); - if (NS_SUCCEEDED(rv)) { - rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); - if (NS_SUCCEEDED(rv)) { - rv = localFile->AppendRelativePath(DEFAULTS_PROFILE_DIR_NAME); -#ifndef XPCOM_STANDALONE - if (NS_SUCCEEDED(rv)) { - nsXPIDLString localeName; - rv = GetChromeLocale(getter_Copies(localeName)); - if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativeUnicodePath(localeName); - } -#endif - } - } - } - else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR) == 0) + else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_50_DIR) == 0 || + nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { @@ -363,25 +340,3 @@ NS_METHOD nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsILocalFile **aL return rv; } -//**************************************************************************************** -// Static Routines -//**************************************************************************************** - -#ifndef XPCOM_STANDALONE - -static nsresult GetChromeLocale(PRUnichar** localeName) -{ - NS_ENSURE_ARG_POINTER(localeName); - - nsresult rv; - *localeName = nsnull; - nsCOMPtr chromeRegistry = do_GetService(kChromeRegistryCID, &rv); - - if (NS_SUCCEEDED(rv)) { - nsString tmpstr; tmpstr.AssignWithConversion("navigator"); - rv = chromeRegistry->GetSelectedLocale(tmpstr.GetUnicode(), localeName); - } - return rv; -} - -#endif