From cfd35e7c04dbb09a748a0c944972ab452be5d530 Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Mon, 23 Oct 2006 15:29:09 +0000 Subject: [PATCH] Bug 357616 Remove remaining traces of nsIPref from widget/ r+sr=roc --- widget/src/beos/nsDeviceContextSpecB.cpp | 12 +++-- widget/src/beos/nsSound.cpp | 1 - widget/src/gtk/nsWidget.cpp | 2 - widget/src/gtk2/nsDeviceContextSpecG.cpp | 23 ++++---- widget/src/mac/nsDeviceContextMac.cpp | 5 +- widget/src/os2/nsDeviceContextSpecOS2.cpp | 5 +- widget/src/os2/nsSound.cpp | 1 - widget/src/photon/nsAppShell.cpp | 1 - widget/src/photon/nsWidget.cpp | 1 - widget/src/windows/nsWindow.cpp | 2 +- widget/src/xpwidgets/nsBaseWidget.cpp | 65 +++++++++++------------ widget/src/xpwidgets/nsXPLookAndFeel.h | 2 - 12 files changed, 57 insertions(+), 63 deletions(-) diff --git a/widget/src/beos/nsDeviceContextSpecB.cpp b/widget/src/beos/nsDeviceContextSpecB.cpp index b65599a069d..1b485dca798 100644 --- a/widget/src/beos/nsDeviceContextSpecB.cpp +++ b/widget/src/beos/nsDeviceContextSpecB.cpp @@ -39,7 +39,8 @@ #include "nsIWidget.h" #include "nsDeviceContextSpecB.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "prenv.h" /* for PR_GetEnv */ #include "nsIServiceManager.h" #include "nsReadableUtils.h" @@ -158,7 +159,7 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS::Init(nsIPrintSettings* aPS) if (aPS != nsnull) { PRBool isOn; aPS->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn); } @@ -508,9 +509,10 @@ nsresult GlobalPrinters::InitializeGlobalPrinters () if (!printerList) { nsresult rv; - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, + &rv); if (NS_SUCCEEDED(rv)) { - (void) pPrefs->CopyCharPref("print.printer_list", &printerList); + (void) pPrefs->GetCharPref("print.printer_list", &printerList); } } @@ -533,7 +535,7 @@ nsresult GlobalPrinters::InitializeGlobalPrinters () mGlobalNumPrinters++; } - free(printerList); + NS_Free(printerList); } #endif /* USE_POSTSCRIPT */ diff --git a/widget/src/beos/nsSound.cpp b/widget/src/beos/nsSound.cpp index 5b6800f9d65..c853e1b9adf 100644 --- a/widget/src/beos/nsSound.cpp +++ b/widget/src/beos/nsSound.cpp @@ -45,7 +45,6 @@ #include "nsIFileURL.h" #include "nsSound.h" #include "nsNetUtil.h" -#include "nsIPref.h" #include "nsDirectoryServiceDefs.h" diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index 537e6722ab8..5e56a9eebc0 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -57,8 +57,6 @@ #include "nsGtkUtils.h" // for nsGtkUtils::gdk_keyboard_get_modifiers() -#include "nsIPref.h" - static void ConvertKeyEventToContextMenuEvent(const nsKeyEvent* inKeyEvent, nsMouseEvent* outCMEvent); diff --git a/widget/src/gtk2/nsDeviceContextSpecG.cpp b/widget/src/gtk2/nsDeviceContextSpecG.cpp index a71f4490c78..641a3333119 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.cpp +++ b/widget/src/gtk2/nsDeviceContextSpecG.cpp @@ -52,7 +52,8 @@ #include "nsDeviceContextSpecG.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "prenv.h" /* for PR_GetEnv */ #include "nsPrintfCString.h" @@ -185,8 +186,8 @@ private: void SetIntValue( const char *tagname, PRInt32 value ); void SetCharValue( const char *tagname, const char *value ); - nsXPIDLCString mPrinterName; - nsCOMPtr mPrefs; + nsXPIDLCString mPrinterName; + nsCOMPtr mPrefs; }; void nsPrinterFeatures::SetBoolValue( const char *tagname, PRBool value ) @@ -208,7 +209,7 @@ nsPrinterFeatures::nsPrinterFeatures( const char *printername ) { DO_PR_DEBUG_LOG(("nsPrinterFeatures::nsPrinterFeatures('%s')\n", printername)); mPrinterName.Assign(printername); - mPrefs = do_GetService(NS_PREF_CONTRACTID); + mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID); SetBoolValue("has_special_printerfeatures", PR_TRUE); } @@ -720,7 +721,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::ClosePrintManager() * - Get prefs */ static -nsresult CopyPrinterCharPref(nsIPref *pref, const char *modulename, const char *printername, const char *prefname, char **return_buf) +nsresult CopyPrinterCharPref(nsIPrefBranch *pref, const char *modulename, const char *printername, const char *prefname, char **return_buf) { DO_PR_DEBUG_LOG(("CopyPrinterCharPref('%s', '%s', '%s')\n", modulename, printername, prefname)); @@ -733,7 +734,7 @@ nsresult CopyPrinterCharPref(nsIPref *pref, const char *modulename, const char * /* Get prefs per printer name and module name */ name = nsPrintfCString(512, "print.%s.printer_%s.%s", modulename, printername, prefname); DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->CopyCharPref(name, return_buf); + rv = pref->GetCharPref(name, return_buf); } if (NS_FAILED(rv)) { @@ -741,7 +742,7 @@ nsresult CopyPrinterCharPref(nsIPref *pref, const char *modulename, const char * /* Get prefs per printer name */ name = nsPrintfCString(512, "print.printer_%s.%s", printername, prefname); DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->CopyCharPref(name, return_buf); + rv = pref->GetCharPref(name, return_buf); } if (NS_FAILED(rv)) { @@ -749,14 +750,14 @@ nsresult CopyPrinterCharPref(nsIPref *pref, const char *modulename, const char * /* Get prefs per module name */ name = nsPrintfCString(512, "print.%s.%s", modulename, prefname); DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->CopyCharPref(name, return_buf); + rv = pref->GetCharPref(name, return_buf); } if (NS_FAILED(rv)) { /* Get prefs */ name = nsPrintfCString(512, "print.%s", prefname); DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->CopyCharPref(name, return_buf); + rv = pref->GetCharPref(name, return_buf); } } } @@ -857,7 +858,7 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich NS_ENSURE_TRUE(*aPrinterName, NS_ERROR_FAILURE); NS_ENSURE_TRUE(aPrintSettings, NS_ERROR_FAILURE); - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; @@ -1339,7 +1340,7 @@ nsresult GlobalPrinters::InitializeGlobalPrinters () return NS_ERROR_OUT_OF_MEMORY; nsresult rv; - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; diff --git a/widget/src/mac/nsDeviceContextMac.cpp b/widget/src/mac/nsDeviceContextMac.cpp index 8aa93a54c02..130c0354c72 100644 --- a/widget/src/mac/nsDeviceContextMac.cpp +++ b/widget/src/mac/nsDeviceContextMac.cpp @@ -52,7 +52,8 @@ #include #include #include -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsIServiceManager.h" #include "nsQuickSort.h" #include "nsUnicodeMappingUtil.h" @@ -871,7 +872,7 @@ PRUint32 nsDeviceContextMac::GetScreenResolution() initialized = PR_TRUE; nsresult rv; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv) && prefs) { PRInt32 intVal; if (NS_SUCCEEDED(prefs->GetIntPref("layout.css.dpi", &intVal)) && intVal > 0) { diff --git a/widget/src/os2/nsDeviceContextSpecOS2.cpp b/widget/src/os2/nsDeviceContextSpecOS2.cpp index 47ab32807ce..9e9d8012a43 100644 --- a/widget/src/os2/nsDeviceContextSpecOS2.cpp +++ b/widget/src/os2/nsDeviceContextSpecOS2.cpp @@ -42,7 +42,8 @@ #include "nsReadableUtils.h" #include "nsISupportsArray.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "prenv.h" /* for PR_GetEnv */ #include "nsPrintfCString.h" @@ -524,7 +525,7 @@ nsresult GlobalPrinters::InitializeGlobalPrinters () return NS_ERROR_OUT_OF_MEMORY; nsresult rv; - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); BOOL prefFailed = NS_FAILED(rv); // don't return on failure, optional feature for (ULONG i = 0; i < mGlobalNumPrinters; i++) { diff --git a/widget/src/os2/nsSound.cpp b/widget/src/os2/nsSound.cpp index b3304df591a..3d3fcec7361 100644 --- a/widget/src/os2/nsSound.cpp +++ b/widget/src/os2/nsSound.cpp @@ -51,7 +51,6 @@ #include "nsSound.h" #include "nsIURL.h" #include "nsNetUtil.h" -#include "nsIPref.h" #include "nsDirectoryServiceDefs.h" diff --git a/widget/src/photon/nsAppShell.cpp b/widget/src/photon/nsAppShell.cpp index 000f6d89eb4..d5c0e0bedfe 100644 --- a/widget/src/photon/nsAppShell.cpp +++ b/widget/src/photon/nsAppShell.cpp @@ -46,7 +46,6 @@ #include #include "nsIWidget.h" -#include "nsIPref.h" #include "nsCRT.h" #include diff --git a/widget/src/photon/nsWidget.cpp b/widget/src/photon/nsWidget.cpp index 5b91ba88c4e..bd7e9e494f3 100644 --- a/widget/src/photon/nsWidget.cpp +++ b/widget/src/photon/nsWidget.cpp @@ -59,7 +59,6 @@ #endif #include "nsReadableUtils.h" -#include "nsIPref.h" #include "nsClipboard.h" #include diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 2ace7b4a2ea..9529b7c159a 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -4251,7 +4251,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT if (didChange) { // update device context font cache // Dirty but easiest way: - // Changing nsIPref entry which triggers callbacks + // Changing nsIPrefBranch entry which triggers callbacks // and flows into calling mDeviceContext->FlushFontCache() // to update the font cache in all the instance of Browsers nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); diff --git a/widget/src/xpwidgets/nsBaseWidget.cpp b/widget/src/xpwidgets/nsBaseWidget.cpp index 681a4b75ebd..f75c7f6715b 100644 --- a/widget/src/xpwidgets/nsBaseWidget.cpp +++ b/widget/src/xpwidgets/nsBaseWidget.cpp @@ -50,7 +50,9 @@ #ifdef DEBUG #include "nsIServiceManager.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch2.h" +#include "nsIObserver.h" static void debug_RegisterPrefCallbacks(); @@ -1025,7 +1027,7 @@ static PRUint32 debug_NumPrefValues = ////////////////////////////////////////////////////////////// -static PRBool debug_GetBoolPref(nsIPref * aPrefs,const char * aPrefName) +static PRBool debug_GetBoolPref(nsIPrefBranch * aPrefs,const char * aPrefName) { NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null."); NS_ASSERTION(nsnull != aPrefs,"cmon, prefs are null."); @@ -1074,30 +1076,29 @@ static void debug_SetCachedBoolPref(const char * aPrefName,PRBool aValue) } ////////////////////////////////////////////////////////////// -/* static */ int PR_CALLBACK -debug_PrefChangedCallback(const char * name,void * closure) +class Debug_PrefObserver : public nsIObserver { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER +}; + +NS_IMPL_ISUPPORTS1(Debug_PrefObserver, nsIObserver) + +NS_IMETHODIMP +Debug_PrefObserver::Observe(nsISupports* subject, const char* topic, + const PRUnichar* data) { + nsCOMPtr branch(do_QueryInterface(subject)); + NS_ASSERTION(branch, "must implement nsIPrefBranch"); - nsIPref * prefs = nsnull; - - nsresult rv = CallGetService(NS_PREF_CONTRACTID, &prefs); - - NS_ASSERTION(NS_SUCCEEDED(rv),"Could not get prefs service."); - NS_ASSERTION(nsnull != prefs,"Prefs services is null."); + NS_ConvertUTF16toUTF8 prefName(data); - if (NS_SUCCEEDED(rv)) - { - PRBool value = PR_FALSE; - - prefs->GetBoolPref(name,&value); - - debug_SetCachedBoolPref(name,value); - - NS_RELEASE(prefs); - } - - return 0; + PRBool value = PR_FALSE; + branch->GetBoolPref(prefName.get(), &value); + debug_SetCachedBoolPref(prefName.get(), value); + return NS_OK; } + ////////////////////////////////////////////////////////////// /* static */ void debug_RegisterPrefCallbacks() @@ -1108,28 +1109,24 @@ debug_RegisterPrefCallbacks() { once = PR_FALSE; - nsIPref * prefs = nsnull; - - nsresult rv = CallGetService(NS_PREF_CONTRACTID, &prefs); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); - NS_ASSERTION(NS_SUCCEEDED(rv),"Could not get prefs service."); - NS_ASSERTION(nsnull != prefs,"Prefs services is null."); + NS_ASSERTION(prefs, "Prefs services is null."); - if (NS_SUCCEEDED(rv)) + if (prefs) { + nsCOMPtr obs(new Debug_PrefObserver()); for (PRUint32 i = 0; i < debug_NumPrefValues; i++) { // Initialize the pref values debug_PrefValues[i].value = debug_GetBoolPref(prefs,debug_PrefValues[i].name); - // Register callbacks for when these change - prefs->RegisterCallback(debug_PrefValues[i].name, - debug_PrefChangedCallback, - NULL); + if (obs) { + // Register callbacks for when these change + prefs->AddObserver(debug_PrefValues[i].name, obs, PR_FALSE); + } } - - NS_RELEASE(prefs); } } } diff --git a/widget/src/xpwidgets/nsXPLookAndFeel.h b/widget/src/xpwidgets/nsXPLookAndFeel.h index 0285a6c44d2..d8c93f1c89b 100644 --- a/widget/src/xpwidgets/nsXPLookAndFeel.h +++ b/widget/src/xpwidgets/nsXPLookAndFeel.h @@ -43,8 +43,6 @@ #include "nsIObserver.h" #include "nsIPrefBranch.h" -class nsIPref; - #ifdef NS_DEBUG struct nsSize; #endif