diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index 35b6732ac54f..23d05bf46f08 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -2020,7 +2020,7 @@ nsScriptSecurityManager::SavePrincipal(nsIPrincipal* aToSave) mSecurityPrefs->SecurityClearUserPref(idPrefName); mIsWritingPrefs = PR_FALSE; - return mPrefs->SavePrefFile(); + return mPrefs->SavePrefFile(nsnull); } static nsDOMProp diff --git a/editor/ui/composer/content/editor.js b/editor/ui/composer/content/editor.js index 25f6aeae13c1..3231ddd8283d 100644 --- a/editor/ui/composer/content/editor.js +++ b/editor/ui/composer/content/editor.js @@ -1420,7 +1420,7 @@ function BuildRecentMenu(savePrefs) } // Force saving to file so next file opened finds these values if (savePrefs) - gPrefs.SavePrefFile(); + gPrefs.savePrefFile(null); // Disable menu item if no entries DisableItem("menu_RecentFiles", disableMenu); diff --git a/editor/ui/dialogs/content/EdHLineProps.js b/editor/ui/dialogs/content/EdHLineProps.js index c0569df35c4e..4254cdc83189 100644 --- a/editor/ui/dialogs/content/EdHLineProps.js +++ b/editor/ui/dialogs/content/EdHLineProps.js @@ -153,7 +153,7 @@ function onSaveDefault() prefs.SetBoolPref("editor.hrule.shading", shading); // Write the prefs out NOW! - prefs.SavePrefFile(); + prefs.savePrefFile(null); } } } diff --git a/embedding/browser/gtk/src/EmbedPrivate.cpp b/embedding/browser/gtk/src/EmbedPrivate.cpp index 8d6600246920..0ae6e94c70ab 100644 --- a/embedding/browser/gtk/src/EmbedPrivate.cpp +++ b/embedding/browser/gtk/src/EmbedPrivate.cpp @@ -635,7 +635,7 @@ EmbedPrivate::StartupProfile(void) sPrefs = pref.get(); NS_ADDREF(sPrefs); sPrefs->ResetPrefs(); - sPrefs->ReadUserPrefs(); + sPrefs->ReadUserPrefs(nsnull); } return NS_OK; } @@ -645,7 +645,6 @@ void EmbedPrivate::ShutdownProfile(void) { if (sPrefs) { - sPrefs->ShutDown(); NS_RELEASE(sPrefs); sPrefs = 0; } diff --git a/embedding/browser/powerplant/source/CBrowserApp.cp b/embedding/browser/powerplant/source/CBrowserApp.cp index a12d096743eb..eb9cd0789565 100644 --- a/embedding/browser/powerplant/source/CBrowserApp.cp +++ b/embedding/browser/powerplant/source/CBrowserApp.cp @@ -213,7 +213,7 @@ CBrowserApp::~CBrowserApp() nsresult rv; NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv); if (NS_SUCCEEDED(rv) && prefs) - prefs->SavePrefFile(); + prefs->SavePrefFile(nsnull); NS_TermEmbedding(); } @@ -515,7 +515,7 @@ nsresult CBrowserApp::InitializePrefs() prefs->SetIntPref("font.size.fixed.x-western", 12); rv = prefs->SetBoolPref("ppbrowser.prefs_inited", PR_TRUE); if (NS_SUCCEEDED(rv)) - rv = prefs->SavePrefFile(); + rv = prefs->SavePrefFile(nsnull); } } diff --git a/embedding/tests/mfcembed/MfcEmbed.cpp b/embedding/tests/mfcembed/MfcEmbed.cpp index 49c04005e974..b0e96a44c86b 100644 --- a/embedding/tests/mfcembed/MfcEmbed.cpp +++ b/embedding/tests/mfcembed/MfcEmbed.cpp @@ -421,7 +421,7 @@ void CMfcEmbedApp::OnEditPreferences() prefs->SetIntPref("browser.startup.page", m_iStartupPage); rv = prefs->SetCharPref("browser.startup.homepage", m_strHomePage); if (NS_SUCCEEDED(rv)) - rv = prefs->SavePrefFile(); + rv = prefs->SavePrefFile(nsnull); } else NS_ASSERTION(PR_FALSE, "Could not get preferences service"); @@ -486,7 +486,7 @@ nsresult CMfcEmbedApp::InitializePrefs() prefs->SetIntPref("font.size.fixed.x-western", 13); rv = prefs->SetBoolPref("mfcbrowser.prefs_inited", PR_TRUE); if (NS_SUCCEEDED(rv)) - rv = prefs->SavePrefFile(); + rv = prefs->SavePrefFile(nsnull); } else { diff --git a/extensions/psm-glue/src/nsFSDR.cpp b/extensions/psm-glue/src/nsFSDR.cpp index c22e0ce8f7b4..abe816c4eb95 100644 --- a/extensions/psm-glue/src/nsFSDR.cpp +++ b/extensions/psm-glue/src/nsFSDR.cpp @@ -280,7 +280,7 @@ SI_SetCharPref(const char * prefname, const char * prefvalue) { if (!NS_FAILED(ret)) { ret = pPrefService->SetCharPref(prefname, prefvalue); if (!NS_FAILED(ret)) { - ret = pPrefService->SavePrefFile(); + ret = pPrefService->SavePrefFile(nsnull); } } } @@ -303,7 +303,7 @@ SI_SetBoolPref(const char * prefname, PRBool prefvalue) { if (!NS_FAILED(ret)) { ret = pPrefService->SetBoolPref(prefname, prefvalue); if (!NS_FAILED(ret)) { - ret = pPrefService->SavePrefFile(); + ret = pPrefService->SavePrefFile(nsnull); } } } diff --git a/extensions/wallet/src/singsign.cpp b/extensions/wallet/src/singsign.cpp index 197aeb4f4e3a..dca9b9a29ab8 100644 --- a/extensions/wallet/src/singsign.cpp +++ b/extensions/wallet/src/singsign.cpp @@ -161,7 +161,7 @@ SI_SetBoolPref(const char * prefname, PRBool prefvalue) { if (!NS_FAILED(ret)) { ret = pPrefService->SetBoolPref(prefname, prefvalue); if (!NS_FAILED(ret)) { - ret = pPrefService->SavePrefFile(); + ret = pPrefService->SavePrefFile(nsnull); } } } @@ -187,7 +187,7 @@ SI_SetCharPref(const char * prefname, const char * prefvalue) { if (!NS_FAILED(ret)) { ret = pPrefService->SetCharPref(prefname, prefvalue); if (!NS_FAILED(ret)) { - ret = pPrefService->SavePrefFile(); + ret = pPrefService->SavePrefFile(nsnull); } } } diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 3da4750e8bdf..780352d719c6 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -288,16 +288,16 @@ nsPresContext::GetUserPreferences() // * document colors PRBool usePrefColors = PR_TRUE; - PRUint32 colorPref; + PRInt32 colorPref; PRBool boolPref; if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_system_colors", &boolPref))) { usePrefColors = !boolPref; } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.display.foreground_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.foreground_color", &colorPref))) { mDefaultColor = (nscolor)colorPref; } - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.display.background_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.background_color", &colorPref))) { mDefaultBackgroundColor = (nscolor)colorPref; } } @@ -320,10 +320,10 @@ nsPresContext::GetUserPreferences() if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.underline_anchors", &boolPref))) { mUnderlineLinks = boolPref; } - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.anchor_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.anchor_color", &colorPref))) { mLinkColor = (nscolor)colorPref; } - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.visited_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.visited_color", &colorPref))) { mVisitedLinkColor = (nscolor)colorPref; } @@ -332,10 +332,10 @@ nsPresContext::GetUserPreferences() mUseFocusColors = boolPref; mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mDefaultBackgroundColor; - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.display.focus_text_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_text_color", &colorPref))) { mFocusTextColor = (nscolor)colorPref; } - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.display.focus_background_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_background_color", &colorPref))) { mFocusBackgroundColor = (nscolor)colorPref; } } diff --git a/layout/base/src/nsPresContext.cpp b/layout/base/src/nsPresContext.cpp index 3da4750e8bdf..780352d719c6 100644 --- a/layout/base/src/nsPresContext.cpp +++ b/layout/base/src/nsPresContext.cpp @@ -288,16 +288,16 @@ nsPresContext::GetUserPreferences() // * document colors PRBool usePrefColors = PR_TRUE; - PRUint32 colorPref; + PRInt32 colorPref; PRBool boolPref; if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_system_colors", &boolPref))) { usePrefColors = !boolPref; } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.display.foreground_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.foreground_color", &colorPref))) { mDefaultColor = (nscolor)colorPref; } - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.display.background_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.background_color", &colorPref))) { mDefaultBackgroundColor = (nscolor)colorPref; } } @@ -320,10 +320,10 @@ nsPresContext::GetUserPreferences() if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.underline_anchors", &boolPref))) { mUnderlineLinks = boolPref; } - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.anchor_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.anchor_color", &colorPref))) { mLinkColor = (nscolor)colorPref; } - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.visited_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.visited_color", &colorPref))) { mVisitedLinkColor = (nscolor)colorPref; } @@ -332,10 +332,10 @@ nsPresContext::GetUserPreferences() mUseFocusColors = boolPref; mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mDefaultBackgroundColor; - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.display.focus_text_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_text_color", &colorPref))) { mFocusTextColor = (nscolor)colorPref; } - if (NS_SUCCEEDED(mPrefs->GetColorPrefDWord("browser.display.focus_background_color", &colorPref))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_background_color", &colorPref))) { mFocusBackgroundColor = (nscolor)colorPref; } } diff --git a/mailnews/addrbook/src/nsDirPrefs.cpp b/mailnews/addrbook/src/nsDirPrefs.cpp index c4df7962f20f..19571a85036b 100644 --- a/mailnews/addrbook/src/nsDirPrefs.cpp +++ b/mailnews/addrbook/src/nsDirPrefs.cpp @@ -412,7 +412,7 @@ nsresult DIR_ShutDown() /* FEs should call this when the app is shutting down. NS_WITH_SERVICE(nsIPref, pPref, kPrefCID, &rv); if (NS_FAILED(rv) || !pPref) return NS_ERROR_FAILURE; - pPref->SavePrefFile(); + pPref->SavePrefFile(nsnull); if (dir_ServerList) { @@ -487,7 +487,7 @@ nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, P NS_WITH_SERVICE(nsIPref, pPref, kPrefCID, &rv); if (NS_FAILED(rv) || !pPref) return NS_ERROR_FAILURE; - pPref->SavePrefFile(); + pPref->SavePrefFile(nsnull); return NS_OK; } @@ -2009,7 +2009,7 @@ nsresult DIR_DeleteServerFromList(DIR_Server *server) NS_WITH_SERVICE(nsIPref, pPref, kPrefCID, &rv); if (NS_FAILED(rv) || !pPref) return NS_ERROR_FAILURE; - pPref->SavePrefFile(); + pPref->SavePrefFile(nsnull); return NS_OK; } diff --git a/mailnews/base/prefs/resources/content/AccountManager.js b/mailnews/base/prefs/resources/content/AccountManager.js index 86f4201cc997..2c17120d40b6 100644 --- a/mailnews/base/prefs/resources/content/AccountManager.js +++ b/mailnews/base/prefs/resources/content/AccountManager.js @@ -148,7 +148,7 @@ function onOk() { // hack hack - save the prefs file NOW in case we crash try { var prefs = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref); - prefs.SavePrefFile(); + prefs.savePrefFile(null); } catch (ex) { dump("Error saving prefs!\n"); } diff --git a/mailnews/base/prefs/resources/content/AccountWizard.js b/mailnews/base/prefs/resources/content/AccountWizard.js index 3907529277c5..d1854e4ccd39 100644 --- a/mailnews/base/prefs/resources/content/AccountWizard.js +++ b/mailnews/base/prefs/resources/content/AccountWizard.js @@ -224,7 +224,7 @@ function FinishAccount() { // hack hack - save the prefs file NOW in case we crash try { var prefs = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref); - prefs.SavePrefFile(); + prefs.savePrefFile(null); } catch (ex) { dump("Error saving prefs!\n"); dump("ex = " + ex + "\n"); diff --git a/mailnews/base/src/nsMessengerMigrator.cpp b/mailnews/base/src/nsMessengerMigrator.cpp index 5d88e81374cf..ca820f129354 100644 --- a/mailnews/base/src/nsMessengerMigrator.cpp +++ b/mailnews/base/src/nsMessengerMigrator.cpp @@ -676,7 +676,7 @@ nsMessengerMigrator::UpgradePrefs() if (NS_FAILED(rv)) return rv; // we're done migrating, let's save the prefs - rv = m_prefs->SavePrefFile(); + rv = m_prefs->SavePrefFile(nsnull); if (NS_FAILED(rv)) return rv; // remove the temporary identity we used for migration purposes diff --git a/modules/libpref/macbuild/libpref.mcp b/modules/libpref/macbuild/libpref.mcp index b8ef95d5a924..bdc185e3fa0d 100644 Binary files a/modules/libpref/macbuild/libpref.mcp and b/modules/libpref/macbuild/libpref.mcp differ diff --git a/modules/libpref/macbuild/libprefIDL.mcp b/modules/libpref/macbuild/libprefIDL.mcp index 4f1788c05ac0..f2bad1de7512 100644 Binary files a/modules/libpref/macbuild/libprefIDL.mcp and b/modules/libpref/macbuild/libprefIDL.mcp differ diff --git a/modules/libpref/public/MANIFEST_IDL b/modules/libpref/public/MANIFEST_IDL index cc560983a31d..5f3c1daa7406 100644 --- a/modules/libpref/public/MANIFEST_IDL +++ b/modules/libpref/public/MANIFEST_IDL @@ -3,4 +3,4 @@ # nsIPref.idl -nsISecurityPref.idl +nsIPrefBranch.idl diff --git a/modules/libpref/public/Makefile.in b/modules/libpref/public/Makefile.in index 153aa3926135..7f66c9e41433 100644 --- a/modules/libpref/public/Makefile.in +++ b/modules/libpref/public/Makefile.in @@ -28,7 +28,14 @@ include $(DEPTH)/config/autoconf.mk MODULE = pref -XPIDLSRCS = nsIPref.idl nsISecurityPref.idl +XPIDLSRCS = \ + nsIPref.idl \ + nsIPrefBranch.idl \ + nsIPrefBranchInternal.idl \ + nsIPrefLocalizedString.idl \ + nsIPrefService.idl \ + nsISecurityPref.idl \ + $(NULL) EXPORTS = prefldap.h EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/modules/libpref/public/makefile.win b/modules/libpref/public/makefile.win index c810e1919c77..c1dbcb475309 100644 --- a/modules/libpref/public/makefile.win +++ b/modules/libpref/public/makefile.win @@ -24,7 +24,14 @@ MODULE=pref DEPTH=..\..\.. EXPORTS=prefldap.h -XPIDLSRCS = .\nsIPref.idl .\nsISecurityPref.idl +XPIDLSRCS = \ + .\nsIPref.idl \ + .\nsIPrefBranch.idl \ + .\nsIPrefBranchInternal.idl \ + .\nsIPrefLocalizedString.idl \ + .\nsIPrefService.idl \ + .\nsISecurityPref.idl \ + $(NULL) include <$(DEPTH)\config\config.mak> include <$(DEPTH)\config\rules.mak> diff --git a/modules/libpref/public/nsIPref.idl b/modules/libpref/public/nsIPref.idl index d0f219214bce..a27ba51d2fe7 100644 --- a/modules/libpref/public/nsIPref.idl +++ b/modules/libpref/public/nsIPref.idl @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -20,20 +20,28 @@ * Contributor(s): */ -#include "nsISupports.idl" +#include "nsIPrefService.idl" +#include "nsIFile.idl" +#include "nsIFileSpec.idl" #include "nsILocalFile.idl" #include "nsIObserver.idl" +#include "nsIPrefBranch.idl" +#include "nsIPrefBranchInternal.idl" -/** - * @status UNDER_REVIEW +/* + * This entire interface is depricated and should not be used. + * See nsIPrefService and nsIPrefBranch for the new implementations. */ %{C++ +#ifndef have_PrefChangedFunc_typedef typedef int (*PR_CALLBACK PrefChangedFunc)(const char *, void *); +#define have_PrefChangedFunc_typedef +#endif typedef void (*PrefEnumerationFunc)(const char *, void *); - + #define NS_PREF_CID \ { /* {dc26e0e0-ca94-11d1-a9a4-00805f8a7ac4} */ \ 0xdc26e0e0, \ @@ -52,111 +60,191 @@ typedef void (*PrefEnumerationFunc)(const char *, void *); native PrefChangedFunc(PrefChangedFunc); native PrefEnumerationFunc(PrefEnumerationFunc); -interface nsIFileSpec; [scriptable, uuid(a22ad7b0-ca86-11d1-a9a4-00805f8a7ac4)] interface nsIPref : nsISupports { - const long ePrefInvalid = 0; - const long ePrefLocked = 1; - const long ePrefUserset = 2; - const long ePrefConfig = 4; - const long ePrefRemote = 8; - const long ePrefLilocal = 16; - const long ePrefString = 32; - const long ePrefInt = 64; - const long ePrefBool = 128; - const long ePrefValuetypeMask = (ePrefString | ePrefInt | ePrefBool); - - // Initialize/shutdown - void StartUp(); - void ReadUserPrefs(); - void ReadUserPrefsFrom(in nsIFileSpec spec); - void ResetUserPrefs(); + + /* + * These are the the Prefs Service methods we will support for now + */ + + /* + * readConfigFile + * + * identify and read the configuration (.cfg) file + */ + void readConfigFile(); + + /* + * readUserPrefs + * + * read a user preference file, pass in null for default file + */ + void readUserPrefs(in nsIFile aFile); + + /* + * resetPrefs + * + * completely flush and reload the preferences system + */ void ResetPrefs(); - void ShutDown(); - // Config file input - void SavePrefFileAs(in nsIFileSpec filename); + /* + * resetUserPrefs + * + * flush all current user prefrences (reset all preferences to the default values) + */ + void ResetUserPrefs(); - /* Getters */ - long GetPrefType(in string pref); - long GetIntPref(in string pref); - boolean GetBoolPref(in string pref); - [noscript] void GetBinaryPref(in string pref, in voidPtr buf, - inout long buf_length); + /* + * savePrefFile + * + * write current preferences state to a file, pass in null for default file + */ + void savePrefFile(in nsIFile aFile); - unsigned long GetColorPrefDWord(in string pref); - /* set preferences */ - void SetCharPref(in string pref, in string value); - void SetUnicharPref(in string pref, in wstring value); - void SetIntPref(in string pref, in long value); - void SetBoolPref(in string pref, in boolean value); - [noscript] void SetBinaryPref(in string pref, in voidPtr value, - in unsigned long size); + /* + * branch operations + */ - - void ClearUserPref(in string pref_name); - - /* get defaults */ - long GetDefaultIntPref(in string pref); - boolean GetDefaultBoolPref(in string pref); - [noscript] void GetDefaultBinaryPref(in string pref, in voidPtr value, - out long length); + nsIPrefBranch getBranch(in string aPrefRoot); + nsIPrefBranch getDefaultBranch(in string aPrefRoot); - /* set defaults */ - void SetDefaultCharPref(in string pref, in string value); - void SetDefaultUnicharPref(in string pref, in wstring value); - void SetDefaultIntPref(in string pref, in long value); - void SetDefaultBoolPref(in string pref, in boolean value); - [noscript] void SetDefaultBinaryPref(in string pref, in voidPtr value, - in unsigned long size); - - // these are eventually changing from Copy->get - string CopyCharPref(in string pref); - wstring CopyUnicharPref(in string pref); - [noscript] voidPtr CopyBinaryPref(in string pref, out long size); - - // "localized" prefs - stored in the properties files - wstring getLocalizedUnicharPref(in string pref); - wstring getDefaultLocalizedUnicharPref(in string pref); - - string CopyDefaultCharPref(in string pref); - wstring CopyDefaultUnicharPref(in string pref); - [noscript] voidPtr CopyDefaultBinaryPref(in string pref, out long size); - nsIFileSpec GetFilePref(in string pref); - void SetFilePref(in string pref, in nsIFileSpec value, in boolean setDefault); - nsILocalFile getFileXPref(in string pref); - void setFileXPref(in string pref, in nsILocalFile value); + /* + * These are the the Prefs Branch methods we will support for now + */ - /* pref attributes */ - boolean PrefIsLocked(in string pref); + const long ePrefInvalid = 0; + const long ePrefLocked = 1; + const long ePrefUserset = 2; + const long ePrefConfig = 4; + const long ePrefRemote = 8; + const long ePrefLilocal = 16; + const long ePrefString = 32; + const long ePrefInt = 64; + const long ePrefBool = 128; + const long ePrefValuetypeMask = (ePrefString | ePrefInt | ePrefBool); - /* save pref values */ - void SavePrefFile(); + /* + * the root of this branch, such as "browser." + */ + readonly attribute string root; + + /* + * standard methods for accessing preferences + */ + long GetPrefType(in string aPrefName); + + boolean GetBoolPref(in string aPrefName); + void SetBoolPref(in string aPrefName, in long aValue); + + string GetCharPref(in string aPrefName); + void SetCharPref(in string aPrefName, in string aValue); + + long GetIntPref(in string aPrefName); + void SetIntPref(in string aPrefName, in long aValue); + + /* + * methods for accessing complex preferences (i.e. items beyond the simple bool, char, and int) + */ + void getComplexValue(in string aPrefName, in nsIIDRef aType, [iid_is(aType), retval] out nsQIResult aValue); + void setComplexValue(in string aPrefName, in nsIIDRef aType, in nsISupports aValue); + + /* + * methods for preference state manipulation + */ + void ClearUserPref(in string aPrefName); + boolean PrefIsLocked(in string aPrefName); + void lockPref(in string aPrefName); + void unlockPref(in string aPrefName); + + + /* + * branch-level operations + */ + + /* + * resetBranch + * + * clears all user preferences starting at the given preference prefix + * pass in null or "" to clear this branch + */ + void resetBranch(in string aStartingAt); + + /* + * deleteBranch + * + * removes all preferences starting at the given preference prefix + * pass in null or "" to remove this branch + */ + void DeleteBranch(in string aStartingAt); + + /* + * getChildList + * + * Returns an array of strings representing the child preferences of the branch root + * + * @param startingAt pass in null or "" to enumerate the entire branch + * @param count Receives the number of elements in the array. + * @param childArray Receives the array of child preferences. + */ + void getChildList(in string aStartingAt, + out unsigned long aCount, + [array, size_is(aCount), retval] out string aChildArray); + + + /* + * Listeners + */ - /* callbacks */ - [noscript] void RegisterCallback(in string domain, - in PrefChangedFunc callback, - in voidPtr closure); - [noscript] void UnregisterCallback(in string domain, - in PrefChangedFunc callback, - in voidPtr closure); /* * The observers have their |Observe| methods called with * ([the observer], "nsPref:changed", [pref name]). */ - void addObserver(in string domain, in nsIObserver observer); - void removeObserver(in string domain, in nsIObserver observer); + void addObserver(in string aDomain, in nsIObserver aObserver); + void removeObserver(in string aDomain, in nsIObserver aObserver); + /* + * Finally some depricated methods + */ + - /* void CopyPrefsTree(in string srcRoot, in string destRoot); */ - void DeleteBranch(in string branchName); - + // these are changing from Copy->get + string CopyCharPref(in string pref); + string CopyDefaultCharPref(in string pref); + + /* get & set defaults */ + boolean GetDefaultBoolPref(in string pref); + long GetDefaultIntPref(in string pref); + + void SetDefaultBoolPref(in string pref, in boolean value); + void SetDefaultCharPref(in string pref, in string value); + void SetDefaultIntPref(in string pref, in long value); + + /* unichar & localized unichar prefs */ + wstring CopyUnicharPref(in string pref); + wstring CopyDefaultUnicharPref(in string pref); + void SetUnicharPref(in string pref, in wstring value); + void SetDefaultUnicharPref(in string pref, in wstring value); + wstring getLocalizedUnicharPref(in string pref); + wstring getDefaultLocalizedUnicharPref(in string pref); + + /* file & filespec prefs */ + nsIFileSpec GetFilePref(in string pref); + void SetFilePref(in string pref, in nsIFileSpec value, in boolean setDefault); + nsILocalFile getFileXPref(in string pref); + void setFileXPref(in string pref, in nsILocalFile value); + + /* callbacks */ + [noscript] void RegisterCallback(in string domain, in PrefChangedFunc callback, in voidPtr closure); + [noscript] void UnregisterCallback(in string domain, in PrefChangedFunc callback, in voidPtr closure); + void CreateChildList(in string parent_node,out string childList); [noscript] string NextChild(in string child_list, inout short index); + /** * EnumerateChildren * @@ -167,7 +255,5 @@ interface nsIPref : nsISupports { * @param callback A function to call back for each matching preference * @param data A piece of data to pass on to the callback */ - [noscript] void EnumerateChildren(in string parent, - in PrefEnumerationFunc callback, - in voidPtr data); + [noscript] void EnumerateChildren(in string parent, in PrefEnumerationFunc callback, in voidPtr data); }; diff --git a/modules/libpref/src/Makefile.in b/modules/libpref/src/Makefile.in index 6f14a1e09975..0f8c73cbdeee 100644 --- a/modules/libpref/src/Makefile.in +++ b/modules/libpref/src/Makefile.in @@ -35,7 +35,11 @@ include $(topsrcdir)/config/config.mk CSRCS = prefapi.c -CPPSRCS = nsPref.cpp +CPPSRCS = nsPref.cpp \ + nsPrefBranch.cpp \ + nsPrefService.cpp \ + nsPrefsFactory.cpp \ + $(NULL) PREF_JS_EXPORTS = \ $(srcdir)/initpref.js \ diff --git a/modules/libpref/src/makefile.win b/modules/libpref/src/makefile.win index 64d63463e041..53ba4a1cd81f 100644 --- a/modules/libpref/src/makefile.win +++ b/modules/libpref/src/makefile.win @@ -72,6 +72,9 @@ LLIBS = \ OBJS = \ .\$(OBJDIR)\prefapi.obj \ .\$(OBJDIR)\nsPref.obj \ + .\$(OBJDIR)\nsPrefBranch.obj \ + .\$(OBJDIR)\nsPrefService.obj \ + .\$(OBJDIR)\nsPrefsFactory.obj \ $(NULL) #//------------------------------------------------------------------------ diff --git a/modules/libpref/src/nsPref.cpp b/modules/libpref/src/nsPref.cpp index cfb707c3e871..7e28fb3ccc7b 100644 --- a/modules/libpref/src/nsPref.cpp +++ b/modules/libpref/src/nsPref.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -34,1194 +34,476 @@ */ #include "nsIPref.h" -#include "nsISecurityPref.h" +#include "nsIFactory.h" +#include "nsIComponentManager.h" +#include "nsComponentManagerUtils.h" +#include "nsCOMPtr.h" +#include "nsMemory.h" +#include "prefapi.h" #include "nsIFileSpec.h" +#include "nsILocalFile.h" +#include "nsIPrefBranch.h" +#include "nsIPrefLocalizedString.h" +#include "nsISecurityPref.h" +#include "nsIPrefService.h" +#include "nsISupportsPrimitives.h" + +#include "nsIJSRuntimeService.h" #include "nsIModule.h" #include "nsIGenericFactory.h" -#include "nsVoidArray.h" - -#include "pratom.h" -#include "prefapi.h" -#include "nsIFactory.h" -#include "nsIComponentManager.h" -#ifdef XP_MAC -#include "nsIPrompt.h" -#include "nsIStreamListener.h" -#endif /* XP_MAC */ -#include "nsIServiceManager.h" -#include "nsCOMPtr.h" -#include "nsFileStream.h" -#include "nsIDirectoryService.h" -#include "nsDirectoryServiceDefs.h" -#include "nsAppDirectoryServiceDefs.h" -#include "nsQuickSort.h" -#include "nsIObserverService.h" -#include "nsWeakReference.h" -#include "nsISupportsArray.h" - -#include "nsTextFormatter.h" - -#include "plhash.h" -#include "prmem.h" #include "plstr.h" +#include "prmem.h" #include "prprf.h" -#include "nsIJSRuntimeService.h" -#include "jsapi.h" -#include "nsQuickSort.h" -#include "nsXPIDLString.h" -#include "nsScriptSecurityManager.h" -#include "nsISignatureVerifier.h" -#include "nsIStringBundle.h" - -#ifdef _WIN32 -#include "windows.h" -#endif /* _WIN32 */ - -#define PREFS_HEADER_LINE_1 "# Mozilla User Preferences" -#define PREFS_HEADER_LINE_2 "// This is a generated file!" - -#define INITIAL_MAX_DEFAULT_PREF_FILES 10 -#include "prefapi_private_data.h" - -#if defined(DEBUG_mcafee) -#define DEBUG_prefs -#endif - -static NS_DEFINE_CID(kSecurityManagerCID, NS_SCRIPTSECURITYMANAGER_CID); -static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); - -//======================================================================================== -class nsPref: public nsIPref, - public nsISecurityPref, - public nsIObserver, - public nsSupportsWeakReference -//======================================================================================== +class nsPref : public nsIPref, + public nsIPrefService, + public nsIObserver, + public nsIPrefBranch, + public nsIPrefBranchInternal, + public nsISecurityPref { - NS_DECL_ISUPPORTS - public: - static nsPref *GetInstance(); + static nsPref *GetInstance(); - /* Use xpidl-generated macro to declare everything required by nsIPref */ - NS_DECL_NSIPREF - NS_DECL_NSISECURITYPREF - NS_DECL_NSIOBSERVER + /* Use xpidl-generated macro to declare everything required by nsIPref */ + NS_DECL_ISUPPORTS + NS_DECL_NSIPREFBRANCH + NS_DECL_NSIPREFBRANCHINTERNAL + NS_DECL_NSISECURITYPREF + NS_DECL_NSIOBSERVER + NS_FORWARD_NSIPREFSERVICE(mPrefService->) + + NS_IMETHOD CopyCharPref(const char *pref, char ** return_buf); + + NS_IMETHODIMP GetDefaultBoolPref(const char *pref, PRBool *_retval) + { return mDefaultBranch->GetBoolPref(pref, _retval); } + NS_IMETHODIMP CopyDefaultCharPref(const char *pref, char **_retval) + { return mDefaultBranch->GetCharPref(pref, _retval); } + NS_IMETHODIMP GetDefaultIntPref(const char *pref, PRInt32 *_retval) + { return mDefaultBranch->GetIntPref(pref, _retval); } + NS_IMETHODIMP SetDefaultBoolPref(const char *pref, PRBool value) + { return mDefaultBranch->SetBoolPref(pref, value); } + NS_IMETHODIMP SetDefaultCharPref(const char *pref, const char *value) + { return mDefaultBranch->SetCharPref(pref, value); } + NS_IMETHODIMP SetDefaultIntPref(const char *pref, PRInt32 value) + { return mDefaultBranch->SetIntPref(pref, value); } + + NS_IMETHOD CopyUnicharPref(const char *pref, PRUnichar **_retval); + NS_IMETHOD CopyDefaultUnicharPref(const char *pref, PRUnichar **_retval); + NS_IMETHOD SetUnicharPref(const char *pref, const PRUnichar *value); + NS_IMETHOD SetDefaultUnicharPref(const char *pref, const PRUnichar *value); + NS_IMETHOD GetLocalizedUnicharPref(const char *pref, PRUnichar **_retval); + NS_IMETHOD GetDefaultLocalizedUnicharPref(const char *pref, PRUnichar **_retval); + + NS_IMETHOD GetFilePref(const char *pref, nsIFileSpec **_retval); + NS_IMETHOD SetFilePref(const char *pref, nsIFileSpec *value, PRBool setDefault); + NS_IMETHOD GetFileXPref(const char *pref, nsILocalFile **_retval); + NS_IMETHOD SetFileXPref(const char *pref, nsILocalFile *value); + + NS_IMETHOD RegisterCallback(const char *domain, PrefChangedFunc callback, void * closure); + NS_IMETHOD UnregisterCallback(const char *domain, PrefChangedFunc callback, void * closure); + NS_IMETHOD CreateChildList(const char *parent_node, char **childList); + NS_IMETHOD NextChild(const char *child_list, PRInt16 *index, char **_retval); + NS_IMETHOD EnumerateChildren(const char *parent, PrefEnumerationFunc callback, void * data); protected: + nsPref(); + virtual ~nsPref(); - nsPref(); - virtual ~nsPref(); + static nsPref *gInstance; - nsresult GetConfigContext(JSContext **js_context); - nsresult GetGlobalConfigObject(JSObject **js_object); - nsresult GetPrefConfigObject(JSObject **js_object); - - nsresult EvaluateConfigScript(const char * js_buffer, - PRUint32 length, - PRBool bGlobalContext, - PRBool bCallbacks); - - nsresult EvaluateConfigScriptFile(const char * js_buffer, - PRUint32 length, - nsIFileSpec* fileSpec, - PRBool bGlobalContext, - PRBool bCallbacks); - - nsresult useDefaultPrefFile(); - nsresult useUserPrefFile(); - nsresult useLockPrefFile(); - nsresult getLockPrefFileInfo(); - - nsresult unregisterObservers(); - - inline static nsresult SecurePrefCheck(const char* aPrefName); - - static nsPref *gInstance; - - nsIFileSpec* mFileSpec; - nsIFileSpec* mLIFileSpec; - - static nsresult convertUTF8ToUnicode(const char *utf8String, - PRUnichar **aResult); - - // these two objects must be updated together such that the - // observer the observer in mObservers[i] matches the domain in - // mObserverDomains[i] - nsCOMPtr mObservers; - nsCStringArray mObserverDomains; - -}; // class nsPref +private: + nsCOMPtr mPrefService; + nsCOMPtr mDefaultBranch; +}; nsPref* nsPref::gInstance = NULL; - static PRInt32 g_InstanceCount = 0; -static PrefResult pref_OpenFileSpec( - nsIFileSpec* fileSpec, - PRBool is_error_fatal, - PRBool verifyHash, - PRBool bGlobalContext, - PRBool skipFirstLine); - -static PRBool pref_VerifyLockFileSpec(char* buf, long buflen); -extern "C" void pref_Alert(char* msg); - -//---------------------------------------------------------------------------------------- -static nsresult _convertRes(int res) -//---------------------------------------------------------------------------------------- -{ - switch (res) - { - case PREF_OUT_OF_MEMORY: - return NS_ERROR_OUT_OF_MEMORY; - case PREF_NOT_INITIALIZED: - return NS_ERROR_NOT_INITIALIZED; - case PREF_TYPE_CHANGE_ERR: - case PREF_ERROR: - case PREF_BAD_LOCKFILE: - case PREF_DEFAULT_VALUE_NOT_INITIALIZED: - return NS_ERROR_UNEXPECTED; - case PREF_VALUECHANGED: - return NS_PREF_VALUE_CHANGED; - } - - NS_ASSERTION((res >= PREF_DEFAULT_VALUE_NOT_INITIALIZED) && (res <= PREF_PROFILE_UPGRADE), "you added a new error code to prefapi.h and didn't update _convertRes"); - - return NS_OK; -} - -//---------------------------------------------------------------------------------------- -// So discouraged is the use of nsIFileSpec, nobody wanted to have this routine be -// public - It might lead to continued use of nsIFileSpec. Right now, this code has -// such a need for it, here it is. Let's stop having to use it though. -static nsresult _nsIFileToFileSpec(nsIFile* inFile, nsIFileSpec **aFileSpec) -//---------------------------------------------------------------------------------------- -{ - nsresult rv; - nsCOMPtr newFileSpec; - nsXPIDLCString pathBuf; - - rv = inFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; - rv = NS_NewFileSpec(getter_AddRefs(newFileSpec)); - if (NS_FAILED(rv)) return rv; - rv = newFileSpec->SetNativePath((const char *)pathBuf); - if (NS_FAILED(rv)) return rv; - - *aFileSpec = newFileSpec; - NS_ADDREF(*aFileSpec); - - return NS_OK; -} +NS_IMPL_THREADSAFE_ISUPPORTS6(nsPref, nsIPref, nsIPrefService, nsIObserver, nsIPrefBranch, nsIPrefBranchInternal, nsISecurityPref); //---------------------------------------------------------------------------------------- nsPref::nsPref() //---------------------------------------------------------------------------------------- - : mFileSpec(nsnull) - , mLIFileSpec(nsnull) { - PR_AtomicIncrement(&g_InstanceCount); - NS_INIT_REFCNT(); + nsIPrefBranch *pBranch; + nsresult rv; + + PR_AtomicIncrement(&g_InstanceCount); + NS_INIT_REFCNT(); + + NS_WITH_SERVICE(nsIPrefService, pService, NS_PREFSERVICE_CONTRACTID, &rv); + mPrefService = pService; + + mPrefService->GetDefaultBranch("", &pBranch); + mDefaultBranch = (nsIPrefBranch *)pBranch; - nsresult rv; - NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv); - if (observerService) { - // Our refcnt must be > 0 when we call this, or we'll get deleted! - ++mRefCnt; - rv = observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get()); - rv = observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get()); - --mRefCnt; - } } //---------------------------------------------------------------------------------------- nsPref::~nsPref() //---------------------------------------------------------------------------------------- { - NS_IF_RELEASE(mFileSpec); - NS_IF_RELEASE(mLIFileSpec); - ShutDown(); - PR_AtomicDecrement(&g_InstanceCount); - gInstance = NULL; + PR_AtomicDecrement(&g_InstanceCount); + gInstance = NULL; } -//---------------------------------------------------------------------------------------- -nsresult nsPref::useDefaultPrefFile() -//---------------------------------------------------------------------------------------- -{ - nsresult rv; - nsCOMPtr aFile; - - // Anything which calls NS_InitXPCOM will have this - rv = NS_GetSpecialDirectory(NS_APP_PREFS_50_FILE, getter_AddRefs(aFile)); +/* + * Implementations to pass branch calls through the PrefService. + */ - if (!aFile) - { - // We know we have XPCOM directory services, but we might not have a provider which - // knows about NS_APP_PREFS_50_FILE. Put the file in NS_XPCOM_CURRENT_PROCESS_DIR. - rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(aFile)); - if (NS_FAILED(rv)) return rv; - rv = aFile->Append("default_prefs.js"); - if (NS_FAILED(rv)) return rv; - } - - nsCOMPtr prefsFileSpec; - - // TODO: modify the rest of this code to take - // nsIFile and not do this conversion into nsIFileSpec - rv = _nsIFileToFileSpec(aFile, getter_AddRefs(prefsFileSpec)); - if (NS_FAILED(rv)) return rv; - - rv = ReadUserPrefsFrom(prefsFileSpec); +NS_IMETHODIMP nsPref::GetRoot(char * *aRoot) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetRoot(aRoot); + return rv; +} + +NS_IMETHODIMP nsPref::GetPrefType(const char *aPrefName, PRInt32 *_retval) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetPrefType(aPrefName, _retval); + return rv; +} + +NS_IMETHODIMP nsPref::CopyCharPref(const char *pref, char ** return_buf) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetCharPref(pref, return_buf); + return rv; +} + +NS_IMETHODIMP nsPref::GetBoolPref(const char *aPrefName, PRBool *_retval) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetBoolPref(aPrefName, _retval); + return rv; +} + +NS_IMETHODIMP nsPref::SetBoolPref(const char *aPrefName, PRInt32 aValue) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->SetBoolPref(aPrefName, aValue); + return rv; +} + +NS_IMETHODIMP nsPref::GetCharPref(const char *aPrefName, char **_retval) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetCharPref(aPrefName, _retval); + return rv; +} + +NS_IMETHODIMP nsPref::SetCharPref(const char *aPrefName, const char *aValue) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->SetCharPref(aPrefName, aValue); + return rv; +} + +NS_IMETHODIMP nsPref::GetIntPref(const char *aPrefName, PRInt32 *_retval) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetIntPref(aPrefName, _retval); + return rv; +} + +NS_IMETHODIMP nsPref::SetIntPref(const char *aPrefName, PRInt32 aValue) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->SetIntPref(aPrefName, aValue); + return rv; +} + +NS_IMETHODIMP nsPref::GetComplexValue(const char *aPrefName, const nsIID & aType, void * *aValue) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetComplexValue(aPrefName, aType, aValue); + return rv; +} + +NS_IMETHODIMP nsPref::SetComplexValue(const char *aPrefName, const nsIID & aType, nsISupports *aValue) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->SetComplexValue(aPrefName, aType, aValue); + return rv; +} + +NS_IMETHODIMP nsPref::ClearUserPref(const char *aPrefName) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->ClearUserPref(aPrefName); + return rv; +} + +NS_IMETHODIMP nsPref::LockPref(const char *aPrefName) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->LockPref(aPrefName); + return rv; +} + +NS_IMETHODIMP nsPref::PrefIsLocked(const char *aPrefName, PRBool *_retval) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->PrefIsLocked(aPrefName, _retval); + return rv; +} + +NS_IMETHODIMP nsPref::UnlockPref(const char *aPrefName) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->UnlockPref(aPrefName); + return rv; +} + +NS_IMETHODIMP nsPref::ResetBranch(const char *aStartingAt) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->ResetBranch(aStartingAt); + return rv; +} + +NS_IMETHODIMP nsPref::DeleteBranch(const char *aStartingAt) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->DeleteBranch(aStartingAt); + return rv; +} + +NS_IMETHODIMP nsPref::GetChildList(const char *aStartingAt, PRUint32 *aCount, char ***aChildArray) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetChildList(aStartingAt, aCount, aChildArray); + return rv; +} + +NS_IMETHODIMP nsPref::AddObserver(const char *aDomain, nsIObserver *aObserver) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->AddObserver(aDomain, aObserver); + return rv; +} + +NS_IMETHODIMP nsPref::RemoveObserver(const char *aDomain, nsIObserver *aObserver) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->RemoveObserver(aDomain, aObserver); + return rv; +} + +NS_IMETHODIMP nsPref::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData) +{ + nsresult rv; + + nsCOMPtr observer = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = observer->Observe(aSubject, aTopic, someData); + return rv; +} + + +/* + * Some temporary support for depricated functions. + */ + +/* + * Items replaced by Get/SetComplexValue + */ + +NS_IMETHODIMP nsPref::CopyUnicharPref(const char *pref, PRUnichar **_retval) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr theString; + rv = prefBranch->GetComplexValue(pref, NS_GET_IID(nsISupportsWString), + getter_AddRefs(theString)); if (NS_SUCCEEDED(rv)) { - return rv; + rv = theString->GetData(_retval); } - - // need to save the prefs now - mFileSpec = prefsFileSpec; - NS_ADDREF(mFileSpec); - rv = SavePrefFile(); - - return rv; -} // nsPref::useDefaultPrefFile - -//---------------------------------------------------------------------------------------- -nsresult nsPref::useUserPrefFile() -//---------------------------------------------------------------------------------------- -{ - nsresult rv = NS_OK; - nsCOMPtr aFile; - - static const char* userFiles[] = {"user.js"}; - - rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(aFile)); - if (NS_SUCCEEDED(rv) && aFile) - { - rv = aFile->Append(userFiles[0]); - if (NS_SUCCEEDED(rv)) - { - nsCOMPtr userPrefFile; - - // TODO: modify the rest of this code to take - // nsIFile and not do this conversion into nsIFileSpec - rv = _nsIFileToFileSpec(aFile, getter_AddRefs(userPrefFile)); - - if (NS_SUCCEEDED(rv)) - { - if (NS_FAILED(StartUp())) - return NS_ERROR_FAILURE; - - if (pref_OpenFileSpec(userPrefFile, PR_FALSE, PR_FALSE, PR_FALSE, PR_TRUE) - != PREF_NOERROR) - rv = NS_ERROR_FAILURE; - } - } - } - return rv; -} // nsPref::useUserPrefFile - -//---------------------------------------------------------------------------------------- -nsresult nsPref::getLockPrefFileInfo() -//---------------------------------------------------------------------------------------- -{ - nsresult rv = NS_OK; - - gLockFileName = nsnull; - gLockVendor = nsnull; - - if (gLockInfoRead) - return rv; - - gLockInfoRead = PR_TRUE; - - if (NS_SUCCEEDED(rv = CopyCharPref("general.config.filename", - &gLockFileName)) && (gLockFileName)) - { -#ifdef NS_DEBUG - printf("\ngLockFileName %s \n", gLockFileName); -#endif - if (NS_SUCCEEDED(rv = CopyCharPref("general.config.vendor", - &gLockVendor)) && (gLockVendor)) - { -#ifdef NS_DEBUG - printf("\ngLockVendor %s \n", gLockVendor); -#endif - } - else - { - /* No vendor name specified, hence cannot verify it */ - rv = NS_ERROR_FAILURE; - return rv; - } - } - else - { - /* config file is not specified, hence no need to read it.*/ - rv = NS_OK; - return rv; - } - return rv; -} // nsPref::getLockPrefFileInfo - - -//---------------------------------------------------------------------------------------- -nsresult nsPref::useLockPrefFile() -//---------------------------------------------------------------------------------------- -{ - nsresult rv = NS_OK; - PrefResult result = PREF_NOERROR; - nsCOMPtr lockPrefFile; - nsXPIDLCString lockFileName; - nsXPIDLCString lockVendor; - char *return_error = nsnull; - PRUint32 fileNameLen = 0; - PRUint32 vendorLen = 0; - nsXPIDLCString configFile; - -#ifdef DEBUG_tao - nsXPIDLString prefVal; - if (NS_SUCCEEDED(rv = GetLocalizedUnicharPref("browser.startup.homepage", - getter_Copies(prefVal)) && (prefVal))) - { - printf("\nStartup homepage %s \n", NS_ConvertUCS2toUTF8(prefVal).get()); - } -#endif - - if (NS_SUCCEEDED(rv = CopyCharPref("general.config.filename", - getter_Copies(lockFileName)) && (lockFileName))) - { -#ifdef NS_DEBUG - printf("\nlockFile %s \n", (const char *)lockFileName); -#endif - } - - if (NS_SUCCEEDED(rv = CopyCharPref("general.config.vendor", - getter_Copies(lockVendor)) && (lockVendor))) - { -#ifdef NS_DEBUG - printf("\nlockVendor %s \n", (const char *)lockVendor); -#endif - } - - if ((gLockFileName == nsnull) && (gLockVendor == nsnull)) - { - if ((lockFileName == nsnull) && (lockVendor == nsnull)) - { - return NS_OK; - } - if ((lockFileName == nsnull) || (lockVendor == nsnull)) - { - return_error = PL_strdup("The required configuration filename or vendor name is incorrect.Please check your preferences."); - if (return_error) - { - pref_Alert(return_error); - return NS_ERROR_FAILURE; - } - } - - fileNameLen = PL_strlen(lockFileName); - vendorLen = PL_strlen(lockVendor); - if (PL_strncmp(lockFileName, lockVendor, fileNameLen -4) != 0) - { - return_error = PL_strdup("The required configuration filename and vendor name do not match.Please check your preferences."); - if (return_error) - { - pref_Alert(return_error); - PR_FREEIF(return_error); - return NS_ERROR_FAILURE; - } - } - else - { - configFile = nsXPIDLCString::Copy(lockFileName); - if(configFile == nsnull) - return NS_ERROR_FAILURE; - } - } - else if ((gLockFileName == nsnull) || (gLockVendor == nsnull)) - { - return_error = PL_strdup("The required configuration filename or vendor name is incorrect.Please contact your administrator."); - if (return_error) - { - pref_Alert(return_error); - PR_FREEIF(return_error); - return NS_ERROR_FAILURE; - } - } - else - { - fileNameLen = PL_strlen(gLockFileName); - vendorLen = PL_strlen(gLockVendor); - if (PL_strncmp(gLockFileName, gLockVendor, fileNameLen -4) != 0) - { - return_error = PL_strdup("The required configuration filename and vendor name do not match.Please contact your administrator."); - if (return_error) - { - pref_Alert(return_error); - PR_FREEIF(return_error); - return NS_ERROR_FAILURE; - } - } - else - { - configFile = nsXPIDLCString::Copy(lockFileName); - if(configFile == nsnull) - return NS_ERROR_FAILURE; - } - } - - - { - nsCOMPtr aFile; - rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(aFile)); - -#ifdef XP_MAC - aFile->Append("Essential Files"); -#endif - // TODO: Make the rest of this code use nsIFile and - // avoid this conversion - rv = _nsIFileToFileSpec(aFile, getter_AddRefs(lockPrefFile)); - - if (NS_SUCCEEDED(rv) && lockPrefFile) - { - if (NS_SUCCEEDED(lockPrefFile->AppendRelativeUnixPath(configFile))) - { - if (NS_FAILED(StartUp())) - return NS_ERROR_FAILURE; - - JS_BeginRequest(gMochaContext); - result = pref_OpenFileSpec(lockPrefFile, PR_TRUE, PR_TRUE, PR_FALSE, PR_FALSE); - if (result != PREF_NOERROR) - { - rv = NS_ERROR_FAILURE; - if (result != PREF_BAD_LOCKFILE) - { - return_error = PL_strdup("The required configuration file netscape.cfg could not be found. Please reinstall the software or contact your administrator."); - if (return_error) - { - pref_Alert(return_error); - PR_FREEIF(return_error); - } - } - } - JS_EndRequest(gMochaContext); - } - } -#ifdef DEBUG_tao - GetLocalizedUnicharPref("browser.startup.homepage",getter_Copies(prefVal)); - printf("\nStartup homepage %s \n", NS_ConvertUCS2toUTF8(prefVal).get()); -#endif - } - return rv; -} // nsPref::useLockPrefFile - -//---------------------------------------------------------------------------------------- -nsPref* nsPref::GetInstance() -//---------------------------------------------------------------------------------------- -{ - if (!gInstance) - { - gInstance = new nsPref(); - gInstance->StartUp(); - } - return gInstance; -} // nsPref::GetInstance - -//---------------------------------------------------------------------------------------- -nsresult nsPref::SecurePrefCheck(const char* aPrefName) -//---------------------------------------------------------------------------------------- -{ - static const char capabilityPrefix[] = "capability."; - if ((aPrefName[0] == 'c' || aPrefName[0] == 'C') && - PL_strncasecmp(aPrefName, capabilityPrefix, sizeof(capabilityPrefix)-1) == 0) - { - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, secMan, kSecurityManagerCID, &rv); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - PRBool enabled; - rv = secMan->IsCapabilityEnabled("CapabilityPreferencesAccess", &enabled); - if (NS_FAILED(rv) || !enabled) - return NS_ERROR_FAILURE; - } - return NS_OK; + } + return rv; } -NS_IMPL_THREADSAFE_ISUPPORTS4(nsPref, nsIPref, nsISecurityPref, nsIObserver, nsISupportsWeakReference); - -//======================================================================================== -// nsIPref Implementation -//======================================================================================== - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::StartUp() -// It must be safe to call this multiple times. -//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::CopyDefaultUnicharPref(const char *pref, PRUnichar **_retval) { - return PREF_Init(nsnull) ? NS_OK : NS_ERROR_FAILURE; -} // nsPref::StartUp + nsresult rv; + nsCOMPtr theString; -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::ReadUserPrefs() -//---------------------------------------------------------------------------------------- -{ - nsresult rv = StartUp(); // just to be sure - if (NS_SUCCEEDED(rv)) { - rv = getLockPrefFileInfo(); - rv = useDefaultPrefFile(); // really should return a value... - } - if (NS_SUCCEEDED(rv)) - useUserPrefFile(); -/* -#ifndef NS_DEBUG -#ifndef XP_MAC - rv = useLockPrefFile(); -#endif -#endif -*/ - - JS_MaybeGC(gMochaContext); - return rv; -} - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::ReadUserPrefsFrom(nsIFileSpec* inFile) -//---------------------------------------------------------------------------------------- -{ - if (mFileSpec == inFile) - return NS_OK; - - NS_IF_RELEASE(mFileSpec); - mFileSpec = inFile; - NS_ADDREF(mFileSpec); - - gErrorOpeningUserPrefs = PR_FALSE; - - if (NS_FAILED(StartUp())) - return NS_ERROR_FAILURE; - - nsresult rv = NS_OK; - if (pref_OpenFileSpec(mFileSpec, PR_TRUE, PR_FALSE, PR_FALSE, PR_TRUE) - != PREF_NOERROR) - rv = NS_ERROR_FAILURE; - // pref_OpenFileSpec will set this for us, we don't need to. - // gErrorOpeningUserPrefs = NS_FAILED(rv); - return rv; -} // nsPref::ReadUserPrefsFrom - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::ResetUserPrefs() -//---------------------------------------------------------------------------------------- -{ - PREF_ClearAllUserPrefs(); - return NS_OK; -} - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::ResetPrefs() -//---------------------------------------------------------------------------------------- -{ - nsresult rv; - PREF_CleanupPrefs(); - rv = StartUp(); - return rv; -} // nsPref::ResetPrefs - -static int PR_CALLBACK -NotifyObserver(const char *newpref, void *data) -{ - nsCOMPtr observer = NS_STATIC_CAST(nsIObserver *, data); - observer->Observe(NS_STATIC_CAST(nsIPref *, nsPref::GetInstance()), - NS_LITERAL_STRING("nsPref:changed").get(), - NS_ConvertASCIItoUCS2(newpref).get()); - return 0; -} - -// unregisters the observers -nsresult -nsPref::unregisterObservers() -{ - nsresult rv; - - if (!mObservers) return NS_OK; - - PRUint32 count = 0; - rv = mObservers->Count(&count); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr obs; - nsCAutoString domain; - - PRUint32 i; - for (i=0; i< count; i++) { - rv = mObservers->QueryElementAt(i, NS_GET_IID(nsIObserver), - getter_AddRefs(obs)); - if (NS_SUCCEEDED(rv)) { - mObserverDomains.CStringAt(i, domain); - - PREF_UnregisterCallback(domain, NotifyObserver, obs); - } - } - - // clear the last reference - obs = nsnull; - - // now empty the observer arrays in bulk - mObservers->Clear(); - mObserverDomains.Clear(); - - return NS_OK; -} - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::ShutDown() -//---------------------------------------------------------------------------------------- -{ - unregisterObservers(); -#ifdef DEBUG_alecf - printf("PREF_Cleanup()\n"); -#endif - PREF_Cleanup(); - return NS_OK; -} // nsPref::ShutDown - - -//---------------------------------------------------------------------------------------- -nsresult nsPref::EvaluateConfigScript(const char * js_buffer, - PRUint32 length, - PRBool bGlobalContext, - PRBool bCallbacks) -//---------------------------------------------------------------------------------------- -{ - return _convertRes(PREF_EvaluateConfigScript(js_buffer, - length, - nsnull, // bad, but not used for parsing. - bGlobalContext, - bCallbacks, - PR_TRUE)); -} - -//---------------------------------------------------------------------------------------- -nsresult nsPref::EvaluateConfigScriptFile(const char * js_buffer, - PRUint32 length, - nsIFileSpec* fileSpec, - PRBool bGlobalContext, - PRBool bCallbacks) -//---------------------------------------------------------------------------------------- -{ - nsXPIDLCString path; - fileSpec->GetNativePath(getter_Copies(path)); - return _convertRes(PREF_EvaluateConfigScript(js_buffer, - length, - (const char *)path, // bad, but not used for parsing. - bGlobalContext, - bCallbacks, - PR_TRUE)); -} - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::SavePrefFileAs(nsIFileSpec* fileSpec) -//---------------------------------------------------------------------------------------- -{ - return _convertRes(PREF_SavePrefFileSpecWith(fileSpec, (PLHashEnumerator)pref_savePref)); -} - - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::SavePrefFile() -//---------------------------------------------------------------------------------------- -{ - if (!gHashTable || !mFileSpec) - return _convertRes(PREF_NOT_INITIALIZED); - return _convertRes(PREF_SavePrefFileSpecWith(mFileSpec, (PLHashEnumerator)pref_savePref)); -} - -/* - * JS stuff - */ - -nsresult nsPref::GetConfigContext(JSContext **js_context) -{ - return _convertRes(PREF_GetConfigContext(js_context)); -} - -nsresult nsPref::GetGlobalConfigObject(JSObject **js_object) -{ - return _convertRes(PREF_GetGlobalConfigObject(js_object)); -} - -nsresult nsPref::GetPrefConfigObject(JSObject **js_object) -{ - return _convertRes(PREF_GetPrefConfigObject(js_object)); -} - -/* - * Getters - */ -NS_IMETHODIMP nsPref::GetPrefType(const char *pref, PRInt32 * return_type) -{ - // XXX The current implementation returns the raw type - the - // enums defining the types have been duplicated. If the old - // types don't all make sense in the context of the new API, - // we might need to do some translation. - - *return_type = PREF_GetPrefType(pref); - return NS_OK; -} - -NS_IMETHODIMP nsPref::GetIntPref(const char *pref, PRInt32 * return_int) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_GetIntPref(pref, return_int, PR_FALSE)); -} - -NS_IMETHODIMP nsPref::GetBoolPref(const char *pref, PRBool * return_val) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_GetBoolPref(pref, return_val, PR_FALSE)); -} - -NS_IMETHODIMP nsPref::GetBinaryPref(const char *pref, - void * return_val, int * buf_length) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_GetBinaryPref(pref, return_val, buf_length, PR_FALSE)); -} - - -NS_IMETHODIMP nsPref::GetColorPrefDWord(const char *pref, - PRUint32 *colorref) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_GetColorPrefDWord(pref, colorref, PR_FALSE)); -} - - -/* - * Setters - */ - -NS_IMETHODIMP nsPref::SetCharPref(const char *pref,const char* value) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_SetCharPref(pref, value)); + rv = mDefaultBranch->GetComplexValue(pref, NS_GET_IID(nsISupportsWString), + getter_AddRefs(theString)); + if (NS_SUCCEEDED(rv)) { + rv = theString->GetData(_retval); + } + return rv; } NS_IMETHODIMP nsPref::SetUnicharPref(const char *pref, const PRUnichar *value) { - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return SetCharPref(pref, NS_ConvertUCS2toUTF8(value).get()); -} + nsresult rv; -NS_IMETHODIMP nsPref::SetIntPref(const char *pref,PRInt32 value) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_SetIntPref(pref, value)); -} - -NS_IMETHODIMP nsPref::SetBoolPref(const char *pref,PRBool value) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_SetBoolPref(pref, value)); -} - -NS_IMETHODIMP nsPref::SetBinaryPref(const char *pref,void * value, PRUint32 size) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_SetBinaryPref(pref, value, size)); -} - - -/* - * Get Defaults - */ - -NS_IMETHODIMP nsPref::GetDefaultIntPref(const char *pref, - PRInt32 * return_int) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_GetIntPref(pref, return_int, PR_TRUE)); -} - -NS_IMETHODIMP nsPref::GetDefaultBoolPref(const char *pref, - PRBool * return_val) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_GetBoolPref(pref, return_val, PR_TRUE)); -} - -NS_IMETHODIMP nsPref::GetDefaultBinaryPref(const char *pref, - void * return_val, - int * buf_length) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_GetBinaryPref(pref, return_val, buf_length, PR_TRUE)); -} - - -/* - * Set defaults - */ - -NS_IMETHODIMP nsPref::SetDefaultCharPref(const char *pref,const char* value) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_SetDefaultCharPref(pref, value)); -} - -NS_IMETHODIMP nsPref::SetDefaultUnicharPref(const char *pref, - const PRUnichar *value) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return SetDefaultCharPref(pref, NS_ConvertUCS2toUTF8(value).get()); -} - -NS_IMETHODIMP nsPref::SetDefaultIntPref(const char *pref,PRInt32 value) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_SetDefaultIntPref(pref, value)); -} - -NS_IMETHODIMP nsPref::SetDefaultBoolPref(const char *pref, PRBool value) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_SetDefaultBoolPref(pref, value)); -} - -NS_IMETHODIMP nsPref::SetDefaultBinaryPref(const char *pref, - void * value, PRUint32 size) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_SetDefaultBinaryPref(pref, value, size)); -} - - -NS_IMETHODIMP nsPref::ClearUserPref(const char *pref_name) -{ - if (NS_FAILED(SecurePrefCheck(pref_name))) return NS_ERROR_FAILURE; - return _convertRes(PREF_ClearUserPref(pref_name)); -} - -/* - * Copy prefs - */ -#if defined(DEBUG_tao_) -//3456789012345678901234567890123456789012 34567890123456789012345678901234567890 -static const char strArr[][64] = { - "browser.startup.homepage", - "browser.throbber.url", - "startup.homepage_override_url", - NULL}; - -static void checkPref(const char* fname, const char* pref) { - int i=0; - nsCString cstr(strArr[i]); - while (cstr.Length()) { - if (pref == cstr) { - printf("\n --> %s:: SHALL use GetLocalizedUnicharPrefto get --%s--\n", fname, pref); - NS_ASSERTION(0, "\n\n"); - return; - } - cstr = strArr[++i]; + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr theString = do_CreateInstance(NS_SUPPORTS_WSTRING_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + theString->SetData(value); + rv = prefBranch->SetComplexValue(pref, NS_GET_IID(nsISupportsWString), theString); } -} -#endif - -NS_IMETHODIMP nsPref::CopyCharPref(const char *pref, char ** return_buf) -{ -#if defined(DEBUG_tao_) - checkPref("CopyCharPref", pref); -#endif - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_CopyCharPref(pref, return_buf, PR_FALSE)); + } + return rv; } -// unicode "%s" format string -static const PRUnichar unicodeFormatter[] = { - (PRUnichar)'%', - (PRUnichar)'s', - (PRUnichar)0, -}; - -NS_IMETHODIMP nsPref::CopyUnicharPref(const char *pref, PRUnichar ** return_buf) +NS_IMETHODIMP nsPref::SetDefaultUnicharPref(const char *pref, const PRUnichar *value) { -#if defined(DEBUG_tao_) - checkPref("CopyUnicharPref", pref); -#endif - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - nsresult rv; - - // get the UTF8 string for conversion - nsXPIDLCString utf8String; - rv = CopyCharPref(pref, getter_Copies(utf8String)); - if (NS_FAILED(rv)) return rv; + nsresult rv; - return convertUTF8ToUnicode(utf8String, return_buf); + nsCOMPtr theString = do_CreateInstance(NS_SUPPORTS_WSTRING_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + theString->SetData(value); + rv = mDefaultBranch->SetComplexValue(pref, NS_GET_IID(nsISupportsWString), theString); + } + return rv; } -NS_IMETHODIMP -nsPref::GetLocalizedUnicharPref(const char *pref, PRUnichar **return_buf) +NS_IMETHODIMP nsPref::GetLocalizedUnicharPref(const char *pref, PRUnichar **_retval) { -#if defined(DEBUG_tao_) - printf("\n --> nsPref::GetLocalizedUnicharPref(%s) --", pref); -#endif - // if the user has set this pref, then just return the user value - if (PREF_HasUserPref(pref)) - return CopyUnicharPref(pref, return_buf); + nsresult rv; - // user has not set the pref, so the default value - // contains a URL to a .properties file - return GetDefaultLocalizedUnicharPref(pref, return_buf); -} - -NS_IMETHODIMP -nsPref::GetDefaultLocalizedUnicharPref(const char *pref, PRUnichar **return_buf) -{ - nsresult rv; - - // the default value contains a URL to a .properties file - - nsXPIDLCString propertyFileURL; - rv = CopyDefaultCharPref(pref, getter_Copies(propertyFileURL)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr bundleService = - do_GetService(kStringBundleServiceCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr bundle; - rv = bundleService->CreateBundle(propertyFileURL, nsnull, - getter_AddRefs(bundle)); - if (NS_FAILED(rv)) return rv; - - // string names are in unicdoe - nsAutoString stringId; - stringId.AssignWithConversion(pref); - - return bundle->GetStringFromName(stringId.GetUnicode(), return_buf); -} - -nsresult -nsPref::convertUTF8ToUnicode(const char *utf8String, PRUnichar ** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - // convert to PRUnichar using nsTextFormatter - // this is so ugly, it allocates memory at least 4 times :( - PRUnichar *unicodeString = - nsTextFormatter::smprintf(unicodeFormatter, utf8String); - if (!unicodeString) return NS_ERROR_OUT_OF_MEMORY; - - // use the right allocator - *aResult = nsCRT::strdup(unicodeString); - nsTextFormatter::smprintf_free(unicodeString); - if (!*aResult) return NS_ERROR_OUT_OF_MEMORY; - - return NS_OK; -} - -NS_IMETHODIMP nsPref::CopyBinaryPref(const char *pref, - int *size, void ** return_value) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_CopyBinaryPref(pref, return_value, size, PR_FALSE)); -} - -NS_IMETHODIMP nsPref::CopyDefaultCharPref( const char *pref, - char ** return_buffer ) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_CopyCharPref(pref, return_buffer, PR_TRUE)); -} - -NS_IMETHODIMP nsPref::CopyDefaultUnicharPref( const char *pref, - PRUnichar ** return_buf) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - nsresult rv; - - nsXPIDLCString utf8String; - rv = CopyDefaultCharPref(pref, getter_Copies(utf8String)); - if (NS_FAILED(rv)) return rv; - - return convertUTF8ToUnicode(utf8String, return_buf); -} - -NS_IMETHODIMP nsPref::CopyDefaultBinaryPref(const char *pref, - int * size, void ** return_val) -{ - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - return _convertRes(PREF_CopyBinaryPref(pref, return_val, size, PR_TRUE)); -} - - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::GetFilePref(const char *pref_name, nsIFileSpec** value) -//---------------------------------------------------------------------------------------- -{ - if (!value) - return NS_ERROR_NULL_POINTER; - if (NS_FAILED(SecurePrefCheck(pref_name))) return NS_ERROR_FAILURE; - - nsresult rv = nsComponentManager::CreateInstance( - (const char*)NS_FILESPEC_CONTRACTID, - (nsISupports*)nsnull, - (const nsID&)NS_GET_IID(nsIFileSpec), - (void**)value); - NS_ASSERTION(NS_SUCCEEDED(rv), "ERROR: Could not make a file spec."); - if (!*value) - return NS_ERROR_FAILURE; - - char *encodedString = nsnull; - rv = CopyCharPref(pref_name, &encodedString); - if (NS_FAILED(rv)) return rv; - - PRBool valid; - (*value)->SetPersistentDescriptorString(encodedString); - (*value)->IsValid(&valid); - if (! valid) - /* if the ecodedString wasn't a valid persitent descriptor, it might be a valid native path*/ - (*value)->SetNativePath(encodedString); - - PR_Free(encodedString); // Allocated by CopyCharPref - return NS_OK; -} - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::SetFilePref(const char *pref_name, - nsIFileSpec* value, PRBool set_default) -//---------------------------------------------------------------------------------------- -{ - if (!value) - return NS_ERROR_NULL_POINTER; - if (NS_FAILED(SecurePrefCheck(pref_name))) return NS_ERROR_FAILURE; - nsresult rv = NS_OK; - if (!Exists(value)) - { - // nsPersistentFileDescriptor requires an existing - // object. Make it first. COM makes this difficult, of course... - nsIFileSpec* tmp = nsnull; - rv = nsComponentManager::CreateInstance( - (const char*)NS_FILESPEC_CONTRACTID, - (nsISupports*)nsnull, - (const nsID&)NS_GET_IID(nsIFileSpec), - (void**)&tmp); - NS_ASSERTION(NS_SUCCEEDED(rv), "ERROR: Could not make a file spec."); - if (!tmp) - return NS_ERROR_FAILURE; - tmp->FromFileSpec(value); - tmp->CreateDir(); - NS_RELEASE(tmp); + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr theString; + rv = prefBranch->GetComplexValue(pref, NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(theString)); + if (NS_SUCCEEDED(rv)) { + rv = theString->GetData(_retval); } - char* encodedString = nsnull; - value->GetPersistentDescriptorString(&encodedString); - if (encodedString && *encodedString) - { - if (set_default) - rv = PREF_SetDefaultCharPref(pref_name, encodedString); - else - rv = PREF_SetCharPref(pref_name, encodedString); - } - PR_FREEIF(encodedString); // Allocated by nsOutputStringStream - return _convertRes(rv); + } + return rv; } -NS_IMETHODIMP -nsPref::GetFileXPref(const char *aPref, nsILocalFile ** aResult) +NS_IMETHODIMP nsPref::GetDefaultLocalizedUnicharPref(const char *pref, PRUnichar **_retval) { - nsresult rv; - nsCOMPtr file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsresult rv; + nsCOMPtr theString; - nsXPIDLCString descriptorString; - rv = CopyCharPref(aPref, getter_Copies(descriptorString)); - if (NS_FAILED(rv)) return rv; - - rv = file->SetPersistentDescriptor(descriptorString); - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = file; - NS_ADDREF(*aResult); - return NS_OK; + rv = mDefaultBranch->GetComplexValue(pref, NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(theString)); + if (NS_SUCCEEDED(rv)) { + rv = theString->GetData(_retval); + } + return rv; } -NS_IMETHODIMP -nsPref::SetFileXPref(const char *aPref, nsILocalFile *aValue) +NS_IMETHODIMP nsPref::GetFilePref(const char *pref, nsIFileSpec **_retval) { - nsresult rv; - nsXPIDLCString descriptorString; + nsresult rv; - rv = aValue->GetPersistentDescriptor(getter_Copies(descriptorString)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = SetCharPref(aPref, descriptorString); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetComplexValue(pref, NS_GET_IID(nsIFileSpec), (void **)_retval); + return rv; } -/* - * Pref access without security check - these are here - * to support nsScriptSecurityManager. - * These functions are part of nsISecurityPref, not nsIPref. - * **PLEASE** do not call these functions from elsewhere - */ -NS_IMETHODIMP nsPref::SecurityGetBoolPref(const char *pref, PRBool * return_val) +NS_IMETHODIMP nsPref::SetFilePref(const char *pref, nsIFileSpec *value, PRBool setDefault) { - return _convertRes(PREF_GetBoolPref(pref, return_val, PR_FALSE)); + nsresult rv; + + if (setDefault) { + rv = mDefaultBranch->SetComplexValue(pref, NS_GET_IID(nsIFileSpec), value); + } else { + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->SetComplexValue(pref, NS_GET_IID(nsIFileSpec), value); + } + return rv; } -NS_IMETHODIMP nsPref::SecuritySetBoolPref(const char *pref, PRBool value) +NS_IMETHODIMP nsPref::GetFileXPref(const char *pref, nsILocalFile **_retval) { - return _convertRes(PREF_SetBoolPref(pref, value)); + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetComplexValue(pref, NS_GET_IID(nsILocalFile), (void **)_retval); + return rv; } -NS_IMETHODIMP nsPref::SecurityGetCharPref(const char *pref, char ** return_buf) +NS_IMETHODIMP nsPref::SetFileXPref(const char *pref, nsILocalFile *value) { -#if defined(DEBUG_tao_) - checkPref("CopyCharPref", pref); -#endif - return _convertRes(PREF_CopyCharPref(pref, return_buf, PR_FALSE)); + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_SUCCEEDED(rv)) + rv = prefBranch->SetComplexValue(pref, NS_GET_IID(nsILocalFile), value); + return rv; } -NS_IMETHODIMP nsPref::SecuritySetCharPref(const char *pref, const char* value) -{ - return _convertRes(PREF_SetCharPref(pref, value)); -} - -NS_IMETHODIMP nsPref::SecurityGetIntPref(const char *pref, PRInt32 * return_val) -{ - return _convertRes(PREF_GetIntPref(pref, return_val, PR_FALSE)); -} - -NS_IMETHODIMP nsPref::SecuritySetIntPref(const char *pref, PRInt32 value) -{ - return _convertRes(PREF_SetIntPref(pref, value)); -} - -NS_IMETHODIMP nsPref::SecurityClearUserPref(const char *pref_name) -{ - return _convertRes(PREF_ClearUserPref(pref_name)); -} - -/* - * Pref info - */ - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::PrefIsLocked(const char *pref, PRBool *res) -//---------------------------------------------------------------------------------------- -{ - if (res == NULL) - return NS_ERROR_INVALID_POINTER; - if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE; - - *res = PREF_PrefIsLocked(pref); - return NS_OK; -} /* * Callbacks @@ -1243,730 +525,279 @@ NS_IMETHODIMP nsPref::UnregisterCallback( const char* domain, void* instance_data ) //---------------------------------------------------------------------------------------- { - return _convertRes(PREF_UnregisterCallback(domain, callback, instance_data)); -} - -NS_IMETHODIMP nsPref::AddObserver(const char *domain, - nsIObserver *observer) -{ - NS_ENSURE_ARG_POINTER(domain); - NS_ENSURE_ARG_POINTER(observer); - - nsresult rv = NS_OK; - if (!mObservers) { - rv = NS_NewISupportsArray(getter_AddRefs(mObservers)); - NS_ENSURE_SUCCESS(rv, rv); - } - - mObservers->AppendElement(observer); - mObserverDomains.AppendCString(nsCAutoString(domain)); - - return RegisterCallback(domain, NotifyObserver, observer); -} - -NS_IMETHODIMP nsPref::RemoveObserver(const char *aDomain, - nsIObserver *aObserver) -{ - NS_ENSURE_ARG_POINTER(aDomain); - NS_ENSURE_ARG_POINTER(aObserver); - - nsresult rv; - - if (!mObservers) return NS_OK; - - // need to find the index of observer, so we can remove it from - // the domain list too - PRUint32 count; - rv = mObservers->Count(&count); - if (NS_FAILED(rv)) return NS_OK; - - PRUint32 i; - nsCOMPtr obs; - nsCAutoString domain; - for (i=0; i< count; i++) { - rv = mObservers->QueryElementAt(i, NS_GET_IID(nsIObserver), - getter_AddRefs(obs)); - if (NS_SUCCEEDED(rv) && obs.get() == aObserver) { - mObserverDomains.CStringAt(i, domain); - if (domain.Equals(aDomain)) - break; - } - } - - if (i == count) // not found, just return - return NS_OK; - - // clear the last reference - obs = nsnull; - - mObservers->RemoveElementAt(i); - mObserverDomains.RemoveCStringAt(i); - - return UnregisterCallback(aDomain, NotifyObserver, aObserver); + if (PREF_UnregisterCallback(domain, callback, instance_data) == PREF_NOERROR) { + return NS_OK; + } else { + return NS_ERROR_FAILURE; + } } /* - * Tree editing + * Preference enumeration */ -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPref::DeleteBranch(const char *branchName) -//---------------------------------------------------------------------------------------- -{ - return _convertRes(PREF_DeleteBranch(branchName)); -} - -#include "prprf.h" -/* - * Creates an iterator over the children of a node. - */ -typedef struct -{ - char* childList; - char* parent; - unsigned int bufsize; -} PrefChildIter; - -/* if entry begins with the given string, i.e. if string is - "a" - and entry is - "a.b.c" or "a.b" - then add "a.b" to the list. */ -static PRIntn PR_CALLBACK -pref_addChild(PLHashEntry *he, int i, void *arg) -{ - PrefChildIter* pcs = (PrefChildIter*) arg; - const char *pref = (const char*)he->key; - if ( PL_strncmp(pref, pcs->parent, PL_strlen(pcs->parent)) == 0 ) - { - char buf[512]; - char* nextdelim; - PRUint32 parentlen = PL_strlen(pcs->parent); - char* substring; - - PL_strncpy(buf, (char*)he->key, PR_MIN(512, PL_strlen((char*)he->key) + 1)); - nextdelim = buf + parentlen; - if (parentlen < PL_strlen(buf)) - { - /* Find the next delimiter if any and truncate the string there */ - nextdelim = PL_strstr(nextdelim, "."); - if (nextdelim) - { - *nextdelim = ';'; - *(nextdelim + 1) = '\0'; - } - } - - substring = PL_strstr(pcs->childList, buf); - if (!substring) - { - unsigned int newsize = PL_strlen(pcs->childList) + PL_strlen(buf) + 2; - if (newsize > pcs->bufsize) - { - pcs->bufsize *= 3; - pcs->childList = (char*) realloc(pcs->childList, sizeof(char) * pcs->bufsize); - if (!pcs->childList) - return HT_ENUMERATE_STOP; - } - PL_strcat(pcs->childList, buf); - } - } - return 0; -} - -#ifdef XP_OS2_VACPP -/* See comment in xpcom/ds/nsHashtable.cpp. */ -#define pref_addChild (PRIntn(*_Optlink)(PLHashEntry*,PRIntn,void *))(pref_addChild) -#endif - NS_IMETHODIMP nsPref::CreateChildList(const char* parent_node, char **child_list) { - PrefChildIter pcs; + PRUint32 bufferSize; + PRUint32 theCount; + PRUint32 i; + nsresult rv; + char **childArray; + char *childList; + char *prefName; - pcs.bufsize = 2048; - pcs.childList = (char*) malloc(sizeof(char) * pcs.bufsize); - if (*parent_node > 0) - pcs.parent = PR_smprintf("%s.", parent_node); - else - pcs.parent = PL_strdup(""); - if (!pcs.parent || !pcs.childList) - return _convertRes(PREF_OUT_OF_MEMORY); - pcs.childList[0] = '\0'; + NS_ENSURE_ARG_POINTER(parent_node); + NS_ENSURE_ARG_POINTER(child_list); - PL_HashTableEnumerateEntries(gHashTable, pref_addChild, &pcs); + if (*parent_node > 0) + prefName = PR_smprintf("%s.", parent_node); + else + prefName = PL_strdup(""); - *child_list = pcs.childList; - PR_Free(pcs.parent); - - return (pcs.childList == NULL) ? PREF_OUT_OF_MEMORY : PREF_OK; + if (prefName == nsnull) { + return NS_ERROR_OUT_OF_MEMORY; + } + + rv = GetChildList(prefName, &theCount, &childArray); + if (NS_SUCCEEDED(rv)) { + // now that we've built up the list, build a buffer from the results + bufferSize = 2048; + childList = (char *)nsMemory::Alloc(sizeof(char) * bufferSize); + if (childList != nsnull) { + char buf[512]; + char* nextdelim; + PRUint32 parentlen = PL_strlen(prefName); + char* substring; + + for (i = 0; i < theCount; ++i) { + PL_strncpy(buf, (char *)&childArray[i], PR_MIN(512, PL_strlen((char *)&childArray[i]) + 1)); + nextdelim = buf + parentlen; + if (parentlen < PL_strlen(buf)) { + // Find the next delimiter if any and truncate the string there + nextdelim = PL_strstr(nextdelim, "."); + if (nextdelim) { + *nextdelim = ';'; + *(nextdelim + 1) = '\0'; + } + } + + // if this substring isn't already in the buffer, add it + substring = PL_strstr(childList, buf); + if (!substring) { + unsigned int newsize = PL_strlen(childList) + PL_strlen(buf) + 2; + if (newsize > bufferSize) { + bufferSize *= 2; + childList = (char *)nsMemory::Realloc(childList, sizeof(char) * bufferSize); + if (childList == nsnull) { + // problem... break out of for loop + break; + } + } + PL_strcat(childList, buf); + } + } + *child_list = childList; + } + + // if we had an Alloc or Realloc problem + if (childList == nsnull) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + + // release the memory allocated by GetChildList + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(theCount, childArray); + } + PR_Free(prefName); + + return rv; } NS_IMETHODIMP nsPref::NextChild(const char *child_list, PRInt16 *indx, char **listchild) { - char* temp = (char*)&child_list[*indx]; - char* child = strtok(temp, ";"); - if (child) - { - *indx += PL_strlen(child) + 1; - *listchild = child; - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -} - -struct EnumerateData { - const char *parent; - nsVoidArray *pref_list; -}; - -PR_STATIC_CALLBACK(PRIntn) -pref_enumChild(PLHashEntry *he, int i, void *arg) -{ - EnumerateData *d = (EnumerateData *) arg; - if (PL_strncmp((char*)he->key, d->parent, PL_strlen(d->parent)) == 0) { - d->pref_list->AppendElement((void *)he->key); - } - return HT_ENUMERATE_NEXT; -} - -NS_IMETHODIMP -nsPref::EnumerateChildren(const char *parent, PrefEnumerationFunc callback, void *arg) -{ - // this will contain a list of all the pref name strings - // allocate on the stack for speed - nsAutoVoidArray prefArray; - - EnumerateData ed; - ed.parent = parent; - ed.pref_list = &prefArray; - PL_HashTableEnumerateEntries(gHashTable, pref_enumChild, &ed); - - // now that we've built up the list, run the callback on - // all the matching elements - PRInt32 numPrefs = prefArray.Count(); - PRInt32 i; - for (i=0; i < numPrefs; i++) { - char *prefName = (char *)prefArray.ElementAt(i); - (*callback)((char*)prefName, arg); - } - + char* temp = (char*)&child_list[*indx]; + char* child = strtok(temp, ";"); + if (child) { + *indx += PL_strlen(child) + 1; + *listchild = child; return NS_OK; + } else + return NS_ERROR_NULL_POINTER; } -NS_IMETHODIMP nsPref::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData) +NS_IMETHODIMP nsPref::EnumerateChildren(const char *parent, PrefEnumerationFunc callback, void *arg) { - nsresult rv = NS_OK; + PRUint32 theCount; + PRUint32 i; + nsresult rv; + char **childArray; + char *prefName; - if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get())) { - if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) { - if (mFileSpec) { - mFileSpec->Delete(PR_FALSE); - NS_RELEASE(mFileSpec); - } - } - else - rv = SavePrefFile(); - } - else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-do-change").get())) { - PREF_ClearAllUserPrefs(); - rv = ReadUserPrefs(); + rv = GetChildList(parent, &theCount, &childArray); + if (NS_SUCCEEDED(rv)) { + // now that we've built up the list, run the callback on all the matching elements + for (i = 0; i < theCount; i++) { + prefName = (char *)childArray[i]; + (*callback)((char*)prefName, arg); } + + // now release all the memory + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(theCount, childArray); + } + + return NS_OK; +} + +/* + * Pref access without security check - these are here + * to support nsScriptSecurityManager. + * These functions are part of nsISecurityPref, not nsIPref. + * **PLEASE** do not call these functions from elsewhere + */ +NS_IMETHODIMP nsPref::SecurityGetBoolPref(const char *pref, PRBool * return_val) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr securityPref = do_QueryInterface(prefBranch, &rv); + if (NS_SUCCEEDED(rv)) + rv = securityPref->SecurityGetBoolPref(pref, return_val); + return rv; +} + +NS_IMETHODIMP nsPref::SecuritySetBoolPref(const char *pref, PRBool value) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr securityPref = do_QueryInterface(prefBranch, &rv); + if (NS_SUCCEEDED(rv)) + rv = securityPref->SecuritySetBoolPref(pref, value); + return rv; +} + +NS_IMETHODIMP nsPref::SecurityGetCharPref(const char *pref, char ** return_buf) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr securityPref = do_QueryInterface(prefBranch, &rv); + if (NS_SUCCEEDED(rv)) + rv = securityPref->SecurityGetCharPref(pref, return_buf); + return rv; +} + +NS_IMETHODIMP nsPref::SecuritySetCharPref(const char *pref, const char* value) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr securityPref = do_QueryInterface(prefBranch, &rv); + if (NS_SUCCEEDED(rv)) + rv = securityPref->SecuritySetCharPref(pref, value); + return rv; +} + +NS_IMETHODIMP nsPref::SecurityGetIntPref(const char *pref, PRInt32 * return_val) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr securityPref = do_QueryInterface(prefBranch, &rv); + if (NS_SUCCEEDED(rv)) + rv = securityPref->SecurityGetIntPref(pref, return_val); + return rv; +} + +NS_IMETHODIMP nsPref::SecuritySetIntPref(const char *pref, PRInt32 value) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr securityPref = do_QueryInterface(prefBranch, &rv); + if (NS_SUCCEEDED(rv)) + rv = securityPref->SecuritySetIntPref(pref, value); + return rv; +} + +NS_IMETHODIMP nsPref::SecurityClearUserPref(const char *pref_name) +{ + nsresult rv; + + nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr securityPref = do_QueryInterface(prefBranch, &rv); + if (NS_SUCCEEDED(rv)) + rv = securityPref->SecurityClearUserPref(pref_name); + return rv; } -//======================================================================================== -// C++ implementations of old C routines -//======================================================================================== - //---------------------------------------------------------------------------------------- -PrefResult pref_OpenFileSpec( - nsIFileSpec* fileSpec, - PRBool is_error_fatal, - PRBool verifyHash, - PRBool bGlobalContext, - PRBool skipFirstLine) +nsPref* nsPref::GetInstance() //---------------------------------------------------------------------------------------- { - PrefResult result = PREF_NOERROR; - char *return_error; - - if (NS_FAILED(fileSpec->ResolveSymlink())) - return PREF_ERROR; - - if (!Exists(fileSpec)) - return PREF_ERROR; - - char* readBuf; - if (NS_FAILED(fileSpec->GetFileContents(&readBuf))) - return PREF_ERROR; - long fileLength = PL_strlen(readBuf); - if (verifyHash && !pref_VerifyLockFileSpec(readBuf, fileLength)) - { - result = PREF_BAD_LOCKFILE; - if (is_error_fatal) - { - return_error = PL_strdup("An error occurred reading the startup configuration file. Please contact your administrator."); - if (return_error) - { - pref_Alert(return_error); - PR_Free(return_error); - } - PR_Free(readBuf); - return result; - } - } - if (result == PREF_NOERROR) - { - if (!PREF_EvaluateConfigScript(readBuf, fileLength, - nsnull, bGlobalContext, PR_TRUE, skipFirstLine)) - { - result = PREF_ERROR; - if (verifyHash) - { - PR_Free(readBuf); - return result; - } - } - } - PR_Free(readBuf); - - // If the user prefs file exists but generates an error, - // don't clobber the file when we try to save it - if ((!readBuf || result != PREF_NOERROR) && is_error_fatal) - gErrorOpeningUserPrefs = PR_TRUE; -#if defined(XP_WIN) - if (gErrorOpeningUserPrefs && is_error_fatal) - MessageBox(nsnull,"Error in preference file (prefs.js). Default preferences will be used.","Netscape - Warning", MB_OK); -#endif - - return result; -} // pref_OpenFile - -//---------------------------------------------------------------------------------------- -// Computes the MD5 hash of the given buffer (not including the first line) -// and verifies the first line of the buffer expresses the correct hash in the form: -// // xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx -// where each 'xx' is a hex value. */ -//---------------------------------------------------------------------------------------- -PRBool pref_VerifyLockFileSpec(char* buf, long buflen) -//---------------------------------------------------------------------------------------- -{ - - PRBool success = PR_FALSE; - const int obscure_value = 7; - const long hash_length = 51; /* len = 48 chars of MD5 + // + EOL */ - unsigned char *digest; - char szHash[64]; - - /* Unobscure file by subtracting some value from every char. */ - long i; - for (i = 0; i < buflen; i++) - buf[i] -= obscure_value; - - if (buflen >= hash_length) - { - const unsigned char magic_key[] = "VonGloda5652TX75235ISBN"; - unsigned char *pStart = (unsigned char*) buf + hash_length; - unsigned int len; - - nsresult rv; - - NS_WITH_SERVICE(nsISignatureVerifier, verifier, SIGNATURE_VERIFIER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return success; // No signature verifier available - - //-- Calculate the digest - PRUint32 id; - rv = verifier->HashBegin(nsISignatureVerifier::MD5, &id); - if (NS_FAILED(rv)) return success; - - rv = verifier->HashUpdate(id, (const char*)magic_key, sizeof(magic_key)); - if (NS_FAILED(rv)) return success; - - rv = verifier->HashUpdate(id, (const char*)pStart, (unsigned int)(buflen - hash_length)); - if (NS_FAILED(rv)) return success; - - digest = (unsigned char*)PR_MALLOC(nsISignatureVerifier::MD5_LENGTH); - if (digest == nsnull) return success; - - rv = verifier->HashEnd(id,&digest, &len, nsISignatureVerifier::MD5_LENGTH); - if (NS_FAILED(rv)) { PR_FREEIF(digest); return success; } - - - - PR_snprintf(szHash, 64, "%x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - (int)digest[0],(int)digest[1],(int)digest[2],(int)digest[3], - (int)digest[4],(int)digest[5],(int)digest[6],(int)digest[7], - (int)digest[8],(int)digest[9],(int)digest[10],(int)digest[11], - (int)digest[12],(int)digest[13],(int)digest[14],(int)digest[15]); - -#ifdef DEBUG_neeti - printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - (int)digest[0],(int)digest[1],(int)digest[2],(int)digest[3], - (int)digest[4],(int)digest[5],(int)digest[6],(int)digest[7], - (int)digest[8],(int)digest[9],(int)digest[10],(int)digest[11], - (int)digest[12],(int)digest[13],(int)digest[14],(int)digest[15]); -#endif - - - success = ( PL_strncmp((const char*) buf + 3, szHash, (PRUint32)(hash_length - 4)) == 0 ); - - PR_FREEIF(digest); - - } - return success; - -} - -//---------------------------------------------------------------------------------------- -PrefResult PREF_SavePrefFileSpecWith( - nsIFileSpec* fileSpec, - PLHashEnumerator heSaveProc) -//---------------------------------------------------------------------------------------- -{ - if (!gHashTable) - return PREF_NOT_INITIALIZED; - - /* ?! Don't save (blank) user prefs if there was an error reading them */ - if (gErrorOpeningUserPrefs) - return PREF_NOERROR; - - char** valueArray = (char**) PR_Calloc(sizeof(char*), gHashTable->nentries); - if (!valueArray) - return PREF_OUT_OF_MEMORY; - - nsOutputFileStream stream(fileSpec); - if (!stream.is_open()) - return PREF_ERROR; - - stream << PREFS_HEADER_LINE_1 << nsEndl << PREFS_HEADER_LINE_2 << nsEndl << nsEndl; - - /* LI_STUFF here we pass in the heSaveProc proc used so that li can do its own thing */ - PR_HashTableEnumerateEntries(gHashTable, heSaveProc, valueArray); - - /* Sort the preferences to make a readable file on disk */ - NS_QuickSort(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings, NULL); - char** walker = valueArray; - for (PRUint32 valueIdx = 0; valueIdx < gHashTable->nentries; valueIdx++,walker++) - { - if (*walker) - { - stream << *walker << nsEndl; - PR_Free(*walker); - } - } - PR_Free(valueArray); - fileSpec->CloseStream(); - return PREF_NOERROR; -} - -/// Note: inplaceSortCallback is a small C callback stub for NS_QuickSort -static int PR_CALLBACK -inplaceSortCallback(const void *data1, const void *data2, void *privateData) -{ - char *name1 = nsnull; - char *name2 = nsnull; - nsIFileSpec *file1= *(nsIFileSpec **)data1; - nsIFileSpec *file2= *(nsIFileSpec **)data2; - nsresult rv; - int sortResult = 0; - - rv = file1->GetLeafName(&name1); - NS_ASSERTION(NS_SUCCEEDED(rv),"failed to get the leaf name"); - if (NS_SUCCEEDED(rv)) { - rv = file2->GetLeafName(&name2); - NS_ASSERTION(NS_SUCCEEDED(rv),"failed to get the leaf name"); - if (NS_SUCCEEDED(rv)) { - if (name1 && name2) { - // we want it so foo.js will come before foo-.js - // "foo." is before "foo-", so we have to reverse the order to accomplish - sortResult = PL_strcmp(name2,name1); - } - if (name1) nsCRT::free((char*)name1); - if (name2) nsCRT::free((char*)name2); - } - } - return sortResult; -} - -//---------------------------------------------------------------------------------------- -extern "C" JSBool pref_InitInitialObjects() -// Initialize default preference JavaScript buffers from -// appropriate TEXT resources -//---------------------------------------------------------------------------------------- -{ - JSBool funcResult; - nsresult rv; - PRBool exists; - nsCOMPtr aFile; - nsCOMPtr defaultPrefDir; - - rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(aFile)); - if (NS_FAILED(rv)) - return JS_FALSE; - rv = _nsIFileToFileSpec(aFile, getter_AddRefs(defaultPrefDir)); - if (NS_FAILED(rv)) - return JS_FALSE; - - static const char* specialFiles[] = { - "initpref.js" -#ifdef XP_MAC - , "macprefs.js" -#elif defined(XP_WIN) - , "winpref.js" -#elif defined(XP_UNIX) - , "unix.js" -#if defined(VMS) - , "openvms.js" -#endif -#elif defined(XP_OS2) - , "os2pref.js" -#endif - }; - - int k=0; - JSBool worked = JS_FALSE; - nsIFileSpec ** defaultPrefFiles = new nsIFileSpec*[INITIAL_MAX_DEFAULT_PREF_FILES]; - int maxDefaultPrefFiles = INITIAL_MAX_DEFAULT_PREF_FILES; - int numFiles = 0; - - // Parse all the random files that happen to be in the components directory. - nsCOMPtr dirIterator; - rv = nsComponentManager::CreateInstance( - (const char*)NS_DIRECTORYITERATOR_CONTRACTID, - (nsISupports*)nsnull, - (const nsID&)NS_GET_IID(nsIDirectoryIterator), - getter_AddRefs(dirIterator)); - NS_ASSERTION(NS_SUCCEEDED(rv), "ERROR: Could not make a directory iterator."); - if (!dirIterator || NS_FAILED(dirIterator->Init(defaultPrefDir, PR_TRUE))) - return JS_FALSE; - - // Get any old child of the components directory. Warning: aliases get resolved, so - // SetLeafName will not work here. - nsCOMPtr aFile2; - nsCOMPtr specialChild; - - rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(aFile2)); - if (NS_FAILED(rv)) - return JS_TRUE; - - // TODO: Convert the rest of this code to nsIFile - // and avoid this conversion to nsIFileSpec - rv = _nsIFileToFileSpec(aFile2, getter_AddRefs(specialChild)); - if (NS_FAILED(rv)) - return JS_TRUE; - - if NS_FAILED(specialChild->AppendRelativeUnixPath((char*)specialFiles[0])) - { - funcResult = JS_FALSE; - goto done; - } - - if (NS_FAILED(specialChild->Exists(&exists))) - { - funcResult = JS_FALSE; - goto done; - } - - if (exists) - { - worked = (JSBool)(pref_OpenFileSpec( - specialChild, - PR_FALSE, - PR_FALSE, - PR_FALSE, - PR_FALSE) == PREF_NOERROR); - NS_ASSERTION(worked, "initpref.js not parsed successfully"); - } - // Keep this child - -#ifdef DEBUG_prefs - printf("Parsing default JS files.\n"); -#endif /* DEBUG_prefs */ - for (; Exists(dirIterator); dirIterator->Next()) - { - nsCOMPtr child; - PRBool shouldParse = PR_TRUE; - if NS_FAILED(dirIterator->GetCurrentSpec(getter_AddRefs(child))) - continue; - char* leafName; - rv = child->GetLeafName(&leafName); - if (NS_SUCCEEDED(rv)) - { - // Skip non-js files - if (PL_strstr(leafName, ".js") + PL_strlen(".js") != leafName + PL_strlen(leafName)) - shouldParse = PR_FALSE; - // Skip files in the special list. - if (shouldParse) - { - for (int j = 0; j < (int) (sizeof(specialFiles) / sizeof(char*)); j++) - if (PL_strcmp(leafName, specialFiles[j]) == 0) - shouldParse = PR_FALSE; - } - if (shouldParse) - { - #ifdef DEBUG_prefs - printf("Adding %s to the list to be sorted\n", leafName); - #endif /* DEBUG_prefs */ - rv = NS_NewFileSpec(&(defaultPrefFiles[numFiles])); - NS_ASSERTION(NS_SUCCEEDED(rv),"failed to create a file spec"); - if (NS_SUCCEEDED(rv) && defaultPrefFiles[numFiles]) { - rv = defaultPrefFiles[numFiles]->FromFileSpec(child); - NS_ASSERTION(NS_SUCCEEDED(rv),"failed to set the spec"); - if (NS_SUCCEEDED(rv)) { - numFiles++; - } - if (numFiles == maxDefaultPrefFiles) { - // double the size of the array - nsIFileSpec **newArray; - newArray = new nsIFileSpec*[maxDefaultPrefFiles * 2]; - nsCRT::memcpy(newArray,defaultPrefFiles,maxDefaultPrefFiles*sizeof(nsIFileSpec *)); - maxDefaultPrefFiles *= 2; - delete [] defaultPrefFiles; - defaultPrefFiles = newArray; - } - } - } - if (leafName) nsCRT::free((char*)leafName); - } - } -#ifdef DEBUG_prefs - printf("Sort defaultPrefFiles. we need them sorted so all-ns.js will override all.js (where override == parsed later)\n"); -#endif /* DEBUG_prefs */ - NS_QuickSort((void *)defaultPrefFiles, numFiles,sizeof(nsIFileSpec *), inplaceSortCallback, nsnull); - - for (k=0;kGetLeafName(¤tLeafName); -#ifdef DEBUG_prefs - printf("Parsing %s\n", currentLeafName); -#endif /* DEBUG_prefs */ - if (currentLeafName) nsCRT::free((char*)currentLeafName); - - if (NS_SUCCEEDED(rv)) { - worked = (JSBool)(pref_OpenFileSpec( - defaultPrefFiles[k], - PR_FALSE, - PR_FALSE, - PR_FALSE, - PR_FALSE) == PREF_NOERROR); - NS_ASSERTION(worked, "Config file not parsed successfully"); - } - } - } - for (k=0;k aFile3; - nsCOMPtr anotherSpecialChild2; - - rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(aFile3)); - if (NS_FAILED(rv)) continue; - rv = aFile3->Append((char*)specialFiles[k]); - if (NS_FAILED(rv)) continue; - - // TODO: Convert the rest of this code to nsIFile - // and avoid this conversion to nsIFileSpec - rv = _nsIFileToFileSpec(aFile3, getter_AddRefs(anotherSpecialChild2)); - if (NS_FAILED(rv)) continue; - -#ifdef DEBUG_prefs - printf("Parsing %s\n", specialFiles[k]); -#endif /* DEBUG_prefs */ - - if (NS_FAILED(anotherSpecialChild2->Exists(&exists)) || !exists) - continue; - - worked = (JSBool)(pref_OpenFileSpec( - anotherSpecialChild2, - PR_FALSE, - PR_FALSE, - PR_FALSE, - PR_FALSE) == PREF_NOERROR); - NS_ASSERTION(worked, ".js was not parsed successfully"); - } -done: - JS_MaybeGC(gMochaContext); - return JS_TRUE; -} - -//---------------------------------------------------------------------------------------- -// Module implementation for the pref library -class nsPrefModule : public nsIModule -{ -public: - nsPrefModule(); - virtual ~nsPrefModule(); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIMODULE - -protected: - nsresult Initialize(); - - void Shutdown(); - - PRBool mInitialized; - nsCOMPtr mFactory; -}; + if (!gInstance) + { + NS_NEWXPCOM(gInstance, nsPref); + } + return gInstance; +} // nsPref::GetInstance //---------------------------------------------------------------------------------------- // Functions used to create new instances of a given object by the // generic factory. -static NS_IMETHODIMP -CreateNewPref(nsISupports *aDelegate, REFNSIID aIID, void **aResult) -{ - if (aDelegate != NULL) - return NS_ERROR_NO_AGGREGATION; - - nsPref *t = nsPref::GetInstance(); - - if (t == NULL) - return NS_ERROR_OUT_OF_MEMORY; - - nsresult res = t->QueryInterface(aIID, aResult); - - if (NS_FAILED(res)) - *aResult = NULL; - - return res; -} - -// The list of components we register -static nsModuleComponentInfo components[] = { - { NS_PREF_CLASSNAME, NS_PREF_CID, NS_PREF_CONTRACTID, CreateNewPref, }, -}; - -extern "C" JSRuntime* PREF_GetJSRuntime() -{ - nsresult rv; - - NS_WITH_SERVICE(nsIJSRuntimeService, rtsvc, "@mozilla.org/js/xpc/RuntimeService;1", &rv); - if (NS_FAILED(rv)) return nsnull; - - JSRuntime* rt; - rv = rtsvc->GetRuntime(&rt); - if (NS_FAILED(rv)) return nsnull; - - return rt; -} //////////////////////////////////////////////////////////////////////// -// Implement the NSGetModule() exported function for your module -// and the entire implementation of the module object. +// Hand implement the GenericFactory constructor macro so I can make it +// non static. This is simply to keep us from having to make an nsPref.h +// file because we are trying to remove this object, not add to it. // -NS_IMPL_NSGETMODULE("nsPrefModule", components) + +NS_IMETHODIMP nsPrefConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsresult rv; + + if (NULL == aResult) { + rv = NS_ERROR_NULL_POINTER; + return rv; + } + *aResult = NULL; + if (NULL != aOuter) { + rv = NS_ERROR_NO_AGGREGATION; + return rv; + } + + nsPref *inst = nsPref::GetInstance(); + + if (NULL == inst) { + rv = NS_ERROR_OUT_OF_MEMORY; + return rv; + } + NS_ADDREF(inst); + rv = inst->QueryInterface(aIID, aResult); + NS_RELEASE(inst); + + return rv; +} diff --git a/modules/libpref/src/nsPrefService.cpp b/modules/libpref/src/nsPrefService.cpp index 9e851c0b1859..71d035cf5f7e 100644 --- a/modules/libpref/src/nsPrefService.cpp +++ b/modules/libpref/src/nsPrefService.cpp @@ -24,7 +24,6 @@ #include "nsPrefService.h" #include "jsapi.h" #include "nsIObserverService.h" -#include "nsIProfileChangeStatus.h" #include "nsISignatureVerifier.h" #include "nsPrefBranch.h" #include "nsXPIDLString.h" diff --git a/modules/libpref/src/prefapi.h b/modules/libpref/src/prefapi.h index ef7647e1f5e7..6b3eb61eb5d5 100644 --- a/modules/libpref/src/prefapi.h +++ b/modules/libpref/src/prefapi.h @@ -386,9 +386,10 @@ PrefResult PREF_CopyPrefsTree(const char *srcRoot, const char *destRoot); ** file. The two types need to be in sync for now. Certain ** compilers were having problems with multiple definitions. */ -#ifndef __gen_nsIPref_h__ +#ifndef have_PrefChangedFunc_typedef typedef int (*PrefChangedFunc) (const char *, void *); -#endif /* __gen_nsIPref_h__ */ +#define have_PrefChangedFunc_typedef +#endif /* // diff --git a/netwerk/cache/src/nsCacheService.cpp b/netwerk/cache/src/nsCacheService.cpp index b5cb4ef68c22..4ff3c7e0a9ce 100644 --- a/netwerk/cache/src/nsCacheService.cpp +++ b/netwerk/cache/src/nsCacheService.cpp @@ -37,7 +37,9 @@ #include "nsIEventQueue.h" #include "nsProxiedService.h" #include "nsIObserverService.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsIPrefBranchInternal.h" static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); @@ -82,19 +84,25 @@ nsresult nsCachePrefObserver::Install() { nsresult rv, rv2; - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; - rv = prefs->AddObserver(ENABLE_MEMORY_CACHE_PREF, this); + nsCOMPtr prefInternal = do_QueryInterface(prefs, &rv); + if (NS_FAILED(rv)) return rv; + + rv = prefInternal->AddObserver(ENABLE_MEMORY_CACHE_PREF, this); if (NS_FAILED(rv)) rv2 = rv; - rv = prefs->AddObserver(ENABLE_DISK_CACHE_PREF, this); + rv = prefInternal->AddObserver(ENABLE_DISK_CACHE_PREF, this); if (NS_FAILED(rv)) rv2 = rv; - rv = prefs->GetBoolPref(ENABLE_DISK_CACHE_PREF, &mDiskCacheEnabled); + nsCOMPtr prefBranch = do_QueryInterface(prefs, &rv); + if (NS_FAILED(rv)) return rv; + + rv = prefBranch->GetBoolPref(ENABLE_DISK_CACHE_PREF, &mDiskCacheEnabled); if (NS_FAILED(rv)) rv2 = rv; - rv = prefs->GetBoolPref(ENABLE_MEMORY_CACHE_PREF, &mMemoryCacheEnabled); + rv = prefBranch->GetBoolPref(ENABLE_MEMORY_CACHE_PREF, &mMemoryCacheEnabled); // if (NS_FAILED(rv)) rv2 = rv; if (NS_SUCCEEDED(rv)) rv = rv2; @@ -107,11 +115,14 @@ nsCachePrefObserver::Remove() { nsresult rv, rv2; - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; - rv = prefs->RemoveObserver(ENABLE_DISK_CACHE_PREF, this); - rv2 = prefs->RemoveObserver(ENABLE_MEMORY_CACHE_PREF, this); + nsCOMPtr prefInternal = do_QueryInterface(prefs, &rv); + if (NS_FAILED(rv)) return rv; + + rv = prefInternal->RemoveObserver(ENABLE_DISK_CACHE_PREF, this); + rv2 = prefInternal->RemoveObserver(ENABLE_MEMORY_CACHE_PREF, this); if (NS_SUCCEEDED(rv)) rv = rv2; return rv; @@ -126,7 +137,7 @@ nsCachePrefObserver::Observe(nsISupports * subject, nsresult rv; if (NS_LITERAL_STRING("nsPref:changed").Equals(topic)) { - nsCOMPtr prefs = do_QueryInterface(subject, &rv); + nsCOMPtr prefs = do_QueryInterface(subject, &rv); if (NS_FAILED(rv)) return rv; // which preference changed? @@ -211,11 +222,14 @@ nsCacheService::Init() rv = mActiveEntries.Init(); if (NS_FAILED(rv)) goto error; - { // scope nsCOMPtr - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID, &rv); + { // scope nsCOMPtr and nsCOMPtr + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr prefBranch = do_QueryInterface(prefs, &rv); if (NS_SUCCEEDED(rv)) { - rv = prefs->GetBoolPref(ENABLE_DISK_CACHE_PREF, &mEnableDiskDevice); - rv = prefs->GetBoolPref(ENABLE_MEMORY_CACHE_PREF, &mEnableMemoryDevice); + rv = prefBranch->GetBoolPref(ENABLE_DISK_CACHE_PREF, &mEnableDiskDevice); + rv = prefBranch->GetBoolPref(ENABLE_MEMORY_CACHE_PREF, &mEnableMemoryDevice); // ignore errors } } diff --git a/profile/pref-migrator/src/nsPrefMigration.cpp b/profile/pref-migrator/src/nsPrefMigration.cpp index 8d7df2d98c7b..d7809dfc99cf 100644 --- a/profile/pref-migrator/src/nsPrefMigration.cpp +++ b/profile/pref-migrator/src/nsPrefMigration.cpp @@ -585,7 +585,7 @@ nsPrefMigration::ProcessPrefsCallback(const char* oldProfilePathStr, const char nsCOMPtr newIMAPLocalMailPath; nsCOMPtr oldNewsPath; nsCOMPtr newNewsPath; - nsCOMPtr newPrefsFile; + nsCOMPtr newPrefsFile; #ifdef HAVE_MOVEMAIL nsCOMPtr oldMOVEMAILMailPath; nsCOMPtr newMOVEMAILMailPath; @@ -694,14 +694,16 @@ nsPrefMigration::ProcessPrefsCallback(const char* oldProfilePathStr, const char tempPrefsFile += PREF_FILE_NAME_IN_4x; //Create the m_prefsFile fileSpec for use in ReadUserPrefsFrom - rv = NS_NewFileSpecWithSpec(tempPrefsFile, getter_AddRefs(m_prefsFile)); - if (NS_FAILED(rv)) return rv; +// rv = NS_NewFileSpecWithSpec(tempPrefsFile, getter_AddRefs(m_prefsFile)); +// if (NS_FAILED(rv)) return rv; + + NS_NewLocalFile((const char *)tempPrefsFile, PR_TRUE, getter_AddRefs(m_prefsFile)); //Clear the prefs in case a previous set was read in. m_prefs->ResetPrefs(); //Now read the prefs from the prefs file in the system directory - m_prefs->ReadUserPrefsFrom(m_prefsFile); + m_prefs->ReadUserPrefs(m_prefsFile); // // Start computing the sizes required for migration @@ -1171,13 +1173,15 @@ nsPrefMigration::ProcessPrefsCallback(const char* oldProfilePathStr, const char if (NS_FAILED(rv)) return rv; PR_FREEIF(popServerName); - NS_NewFileSpec(getter_AddRefs(newPrefsFile)); - newPrefsFile->FromFileSpec(newProfilePath); + nsXPIDLCString path; - rv = newPrefsFile->AppendRelativeUnixPath(PREF_FILE_NAME_IN_5x); + newProfilePath->GetNativePath(getter_Copies(path)); + NS_NewLocalFile(path, PR_TRUE, getter_AddRefs(newPrefsFile)); + + rv = newPrefsFile->Append(PREF_FILE_NAME_IN_5x); if (NS_FAILED(rv)) return rv; - rv=m_prefs->SavePrefFileAs(newPrefsFile); + rv=m_prefs->SavePrefFile(newPrefsFile); if (NS_FAILED(rv)) return rv; rv=m_prefs->ResetPrefs(); if (NS_FAILED(rv)) return rv; diff --git a/profile/pref-migrator/src/nsPrefMigration.h b/profile/pref-migrator/src/nsPrefMigration.h index 2bbafb8dde1c..dc89ffa13bef 100644 --- a/profile/pref-migrator/src/nsPrefMigration.h +++ b/profile/pref-migrator/src/nsPrefMigration.h @@ -151,7 +151,7 @@ class nsPrefMigration: public nsIPrefMigration nsresult getPrefService(); nsCOMPtr m_prefs; - nsCOMPtr m_prefsFile; + nsCOMPtr m_prefsFile; nsCOMPtr m_parentWindow; nsCOMPtr mPMProgressWindow; }; diff --git a/profile/src/nsProfile.cpp b/profile/src/nsProfile.cpp index da6676185867..cf452be4b22e 100644 --- a/profile/src/nsProfile.cpp +++ b/profile/src/nsProfile.cpp @@ -1616,7 +1616,7 @@ nsresult nsProfile::LoadNewProfilePrefs() if (NS_FAILED(rv)) return rv; prefs->ResetUserPrefs(); - prefs->ReadUserPrefs(); + prefs->ReadUserPrefs(nsnull); return NS_OK; } diff --git a/webshell/tests/viewer/nsBrowserWindow.cpp b/webshell/tests/viewer/nsBrowserWindow.cpp index f1ea119e2364..02c183b17053 100644 --- a/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/webshell/tests/viewer/nsBrowserWindow.cpp @@ -3317,7 +3317,7 @@ nsBrowserWindow::ToggleBoolPrefAndRefresh(const char * aPrefName) PRBool value; prefs->GetBoolPref(aPrefName,&value); prefs->SetBoolPref(aPrefName,!value); - prefs->SavePrefFile(); + prefs->SavePrefFile(nsnull); ForceRefresh(); } @@ -3334,7 +3334,7 @@ nsBrowserWindow::SetBoolPref(const char * aPrefName, PRBool aValue) if (prefs && nsnull != aPrefName) { prefs->SetBoolPref(aPrefName, aValue); - prefs->SavePrefFile(); + prefs->SavePrefFile(nsnull); } } @@ -3348,7 +3348,7 @@ nsBrowserWindow::SetStringPref(const char * aPrefName, const nsString& aValue) { char * prefStr = aValue.ToNewCString(); prefs->SetCharPref(aPrefName, prefStr); - prefs->SavePrefFile(); + prefs->SavePrefFile(nsnull); delete [] prefStr; } @@ -3693,7 +3693,7 @@ nsBrowserWindow::SetCompatibilityMode(PRUint32 aMode) prefInt = eCompatibility_NavQuirks; } pref->SetIntPref("nglayout.compatibility.mode", prefInt); - pref->SavePrefFile(); + pref->SavePrefFile(nsnull); } } diff --git a/webshell/tests/viewer/nsViewerApp.cpp b/webshell/tests/viewer/nsViewerApp.cpp index 79c641bdd685..903e9b8bdff7 100644 --- a/webshell/tests/viewer/nsViewerApp.cpp +++ b/webshell/tests/viewer/nsViewerApp.cpp @@ -184,7 +184,6 @@ nsViewerApp::Destroy() } if (nsnull != mPrefs) { - mPrefs->ShutDown(); NS_RELEASE(mPrefs); } } @@ -320,8 +319,7 @@ nsViewerApp::Initialize(int argc, char** argv) if (NS_OK != rv) { return rv; } - mPrefs->StartUp(); - mPrefs->ReadUserPrefs(); + mPrefs->ReadUserPrefs(nsnull); // Load Fullcircle Talkback crash-reporting mechanism. // http://www.fullcirclesoftware.com for more details. diff --git a/xpfe/bootstrap/nsAppRunner.cpp b/xpfe/bootstrap/nsAppRunner.cpp index 5b92caa9bf98..f91ccc26c093 100644 --- a/xpfe/bootstrap/nsAppRunner.cpp +++ b/xpfe/bootstrap/nsAppRunner.cpp @@ -593,7 +593,7 @@ static nsresult DoOnShutdown() nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get prefs, so unable to save them"); if (NS_SUCCEEDED(rv)) - prefs->SavePrefFile(); + prefs->SavePrefFile(nsnull); } // at this point, all that is on the clipboard is a proxy object, but that object @@ -766,7 +766,7 @@ static nsresult InitializeProfileService(nsICmdLineService *cmdLineArgs) rv = prefs->ResetPrefs(); if (NS_FAILED(rv)) return rv; - rv = prefs->ReadUserPrefs(); + rv = prefs->ReadUserPrefs(nsnull); if (NS_FAILED(rv)) return rv; } else diff --git a/xpfe/components/prefwindow/resources/content/nsPrefWindow.js b/xpfe/components/prefwindow/resources/content/nsPrefWindow.js index b2137b631685..0c9a967dfc1f 100644 --- a/xpfe/components/prefwindow/resources/content/nsPrefWindow.js +++ b/xpfe/components/prefwindow/resources/content/nsPrefWindow.js @@ -244,7 +244,7 @@ nsPrefWindow.prototype = } } } - this.pref.SavePrefFile(); + this.pref.savePrefFile(null); }, switchPage: