From 6a048b1a8f1258a5c43861f64972b9ac8cf97024 Mon Sep 17 00:00:00 2001 From: "bnesse%netscape.com" Date: Thu, 19 Apr 2001 22:21:39 +0000 Subject: [PATCH] Landing PrefAPI refactoring bug 46863. r=valeski, sr=alecf, a=blizzard. --- caps/src/nsScriptSecurityManager.cpp | 2 +- editor/ui/composer/content/editor.js | 2 +- editor/ui/dialogs/content/EdHLineProps.js | 2 +- embedding/browser/gtk/src/EmbedPrivate.cpp | 3 +- .../browser/powerplant/source/CBrowserApp.cp | 4 +- embedding/tests/mfcembed/MfcEmbed.cpp | 4 +- extensions/psm-glue/src/nsFSDR.cpp | 4 +- extensions/wallet/src/singsign.cpp | 4 +- layout/base/nsPresContext.cpp | 14 +- layout/base/src/nsPresContext.cpp | 14 +- mailnews/addrbook/src/nsDirPrefs.cpp | 6 +- .../prefs/resources/content/AccountManager.js | 2 +- .../prefs/resources/content/AccountWizard.js | 2 +- mailnews/base/src/nsMessengerMigrator.cpp | 2 +- modules/libpref/macbuild/libpref.mcp | Bin 118705 -> 117165 bytes modules/libpref/macbuild/libprefIDL.mcp | Bin 77400 -> 79294 bytes modules/libpref/public/MANIFEST_IDL | 2 +- modules/libpref/public/Makefile.in | 9 +- modules/libpref/public/makefile.win | 9 +- modules/libpref/public/nsIPref.idl | 261 +- modules/libpref/src/Makefile.in | 6 +- modules/libpref/src/makefile.win | 3 + modules/libpref/src/nsPref.cpp | 2440 +++++------------ modules/libpref/src/nsPrefService.cpp | 14 +- modules/libpref/src/nsPrefsFactory.cpp | 2 +- netwerk/cache/src/nsCacheService.cpp | 42 +- profile/pref-migrator/src/nsPrefMigration.cpp | 20 +- profile/pref-migrator/src/nsPrefMigration.h | 2 +- profile/src/nsProfile.cpp | 2 +- webshell/tests/viewer/nsBrowserWindow.cpp | 8 +- webshell/tests/viewer/nsViewerApp.cpp | 4 +- xpfe/bootstrap/nsAppRunner.cpp | 4 +- .../resources/content/nsPrefWindow.js | 2 +- 33 files changed, 923 insertions(+), 1972 deletions(-) diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index 1e11ed3099f..aa765bd3e50 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -2039,7 +2039,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 a8797d234e5..ed6bcd491bd 100644 --- a/editor/ui/composer/content/editor.js +++ b/editor/ui/composer/content/editor.js @@ -1437,7 +1437,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 c0569df35c4..4254cdc8318 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 8d660024692..0ae6e94c70a 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 95112e5dcd0..b193226edbb 100644 --- a/embedding/browser/powerplant/source/CBrowserApp.cp +++ b/embedding/browser/powerplant/source/CBrowserApp.cp @@ -209,7 +209,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(); } @@ -482,7 +482,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 336066e8331..6e4383f5aa8 100644 --- a/embedding/tests/mfcembed/MfcEmbed.cpp +++ b/embedding/tests/mfcembed/MfcEmbed.cpp @@ -363,7 +363,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"); @@ -428,7 +428,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 4828d06b4d1..ea2d9ad617b 100644 --- a/extensions/psm-glue/src/nsFSDR.cpp +++ b/extensions/psm-glue/src/nsFSDR.cpp @@ -315,7 +315,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); } } } @@ -338,7 +338,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 197aeb4f4e3..dca9b9a29ab 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 3da4750e8bd..780352d719c 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 3da4750e8bd..780352d719c 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 c4df7962f20..19571a85036 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 86f4201cc99..2c17120d40b 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 3907529277c..d1854e4ccd3 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 5d88e81374c..ca820f12935 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 b8ef95d5a924a1c055c51e5a0ce5889e1f295464..ea8250c9550a3feceb94d45b2255cd013253ea6d 100644 GIT binary patch delta 1898 zcmaJ>e@xV67=NGd{R9pW{c_-0ctAB&;zSG;o${OG)HtTK&fFTEsHn&Z$Sku-Os6cA z^Oe1jQ!4c)nJazCQ_vPum=|f&>W_45mgRJdgqBM!XV3e6PyF#m@9n$ic|Xt3_w&5> z9_=(8p(fQ^Q?rH;q9X*-2=o*Y=&e4g{s?g?h~yFy`z0Y`&;e3dW&=D!ZORndl5h4G z);}AA@DvOb!5t{Hy$KckI{8n^P%Ld!vm$U;TU@%J$V5-86U1(d-2JTfPr%(CZAZxF z*0ACik`OvLHr<7p8Gh}ef+BEK+QRbb00IEmClLGzZFC9!BL8fa8EB3*mrgH#fv#}I z0MHTZ9MIE7lfwi=K_?ycFP}pHa?kaC$ke)kwGJr2WfJ(Rp{fkRI>SSx5|`DB*c0MUGD`DrzCZJoQea(RAj#ai#m46n~e zB(SKmwxP;f`501HT;Z*+seOyZEd#sXohA}39MIRjA3ilM8uxM|z zqTBMg-L89B+HBBtL>)p-qj*_&x#9o1 z0N{rQ;<4?7Kk0G7fg(#Elv}Scst&7eE9AxLJVx(YmkV6*MQpJ zv6>OhdGO$HKQej;g3t}UU|?cQEVCO@4eeq|QWXQk|86(f`S8lwfGHO0f+u@Kz+Nq& zuLlG6X#twrsRf{FN8e^WtLuYhwpdbKSC0>c?#82m&by9%k>E%ljKB=&3K628UR}T9 zDX)$1A?@kazPhR>qc6|KI-7&z&%$L;j@)Or`=QvVMq&Dy!Mp(kjm;&5n0+ky9ONr% zBda_I0VRGLiw;4tZC4PpP4nUXC#CaV!Av)0Uu`#8bqF%DKN!K@mP&i?614v=?N;QH zgyVKQ5Fe8GsY&>3EoK)(FmC)pOs#66uBbwExg}jnK4$krutO<5#ah0GjA{ET5I-bK zln2o7j`XvxMmbgD!#>3CN<46l4Pl(E`wK#hC#vgxNR)UgAFjgd?4?1-Fc$4XWG1T` zgvquun*;?~t|eyd3;vbfgG21dAmD4*UBGS+!Va5t4;tobj-H)4$hc8D#{a?geuG6X z;UgI4%k$CeXpfNgAF|kQXn(V*f0QrJ^qpw8NV`*yQu5`Qe;n~>4TtUc2ACGh#*#N6 zE*^jEuXX(>d7djth{tL;ai3x9&qGOOHf|-iOOn1v^Ehc%y(lAP`@6>@u1ehLVngS_ zQGwk;qBMV(h2{ilJ}6!yIRZ~%8RCiIuvbya5qMrk3KdK#RuIc57MW+B=-Q^iz_znZ z7a##TSla~%xZ(#8PSe~bG~y*xQZ+YH{`@1n5~r*@C&N3tki0RPzfLbo2tVxjz)7~{ HTS)&89&+h# delta 1570 zcmah}YfM~46rMA?%P!C5u`DkItTt`!!WOWp#wfIuXDQuPOcW$Qc_?pMXtXsLR)QAV zQnr&imJ(=139ZsV2UrUfXnB>i8i^Q{nnq&PHW8IHMkOMidoMKUAD!&onRC8xzH`3W zx!c9GJ#AV;Zh3hLAw)$8Y$Pz6MBvK49>X`VJ_IwNgy;_w;)w(ZA(QTJ{a#Z3%HFK3 zsLHCm_!kPPjd{~3_F4TQB)cMMGs;L(@8TrKT3q1MB5u(IJ##gf*oio^=7gNG8FT<@ zX49I30cp|zz|UGBC-7^AUH6Vsqw0RvFt@ZlzbrRDtLk7yzP8p`@0^#E5{GIv5;;bn zSv0E8OwE@1B_xRGGlP|-9HSRGW`(*0R_`0bE){3d=xA}%m}3%&v0>mVb?=6cJoiQV zpIup5dQmjL;Y*oiz>8(KF0m~}4g31=IQ!MtL#v@uyM#sf8AMZJ7_hzVom#nn0M?jh zM0<)QvDoEG#mN-2nl&Y=S#_O>wHTje$I~{64C}DLzT+U~eT3(Y2r4WCb0E5lP)9x* zRO&CzWz_hjs4Y3*&b~5w@z2kJuMXR*TUoi+C#G(j9Mv$&GU#SAXsF#ehXsT zn_g~qi%#6`aHDM9hn+mUAEF%r?|?H!!a884FLfH(vDn>UrkdQ6!u&GPJ@F6dR&d}^ z_>1zRmCi`M1tRr~L4~V_KzzK%AMBRrQ1ZM;?pSii_FcttvsGiabSn;ei&TJyHc+Vq zxQOi+DHUPEyXdOZd1|+K$cq18->eq1)8RV1Wt+(AR|CKDJZ#`@DR6`xPc$f}7IRTW zh5fs&?P6zdsLD}s4Ad$_)KWR6v;XYjep9l&2P4P82jHzifP&+E8-%zxmb+jOGaD~n`bR?4 zHI9WrSOgV0MEU$>Fb3}|AcUGqD=G^gWE*TK9^>#GhB=_Uz!yg#-pTtq>X;nQjAGKM z=>Q=vhxx--VF&fu%yX_n2Q@y$oyQ=a9*gDHF)-5RWnMT2;eoxeglJx_*q>iOk_OXJ z`DdjsLnQA(Uf@UuzQPt6Pu4w#_%8~6M#JYN9ph{KuQ6z(3Gegzanws1LcCMavvwf= zPlaz8<1^#PZ`i}{O1yzfggAXtT2+B(A^k_Jjr!9(VgkaQy#K(AiRVwiB6PA12Hi<nipm#JNb^%@M>BZDH9Yz{tVp&fcxpA` z0SeynJlx=ilz`!hH-S`NT2?aJJY;2U$!DMSosfa|` zP(tC21!1KWizze};;6*Tpz@2bU5n_Rg^_@F+9%DEY zx^B&yI_@$`<`p%y%VC*k$oYm`Fvn098nUd!_~h~3wnuk%=v(ClfUCge;0o{(a3weZ zuF|V~Yzqp{0CTw^D-5~Bkd=lE7_ur6X{lLO>u(RoN2?%ec_y8d3TA0rZGDn9BYg&C z0f&{1xN_Ou*nakF#;fM}aBgBjN3MARv}Rpf2yKh5l|c*X8gJ-ku4(1YBPO;eo}vBX zI;_-3ch>}wxjGSwhIjZ|x3!UfAvMutBoPg@jknas!lAa-eUWYJlZn>o_VK3mk;IlwNw3U{=`XDeqI8jE?Yrz~DG%leG&w?UHsSnnu~}wf(8!G&bw_i{=W1;M4V5 z5O@g|e8Bpm5(_?KeG$Ndk6B+-VZkTu)waKvX`&OfpN1q!i$zvS>}t$`CMJdaM;I&zK4n zeoXmI0#a)5;x`IN3FEbeYtZ-O6~a9CQFUe>ZT8UoLqJLU?j&v~`KIoqzZ4(;an+-F zv_P`>)bn}NUux-r$=RNaw?dAcA7VL!wYxpp7JCH0q!#5Rfgj*0@^qMla5X9}fgfE4EMMTy;UCTJ6nM!=V6z0CUW#3%3B2$! zu-O9Nz6+&!6XEq)`3*6neV-Ed_t|9{mAGTD!UW@Gf@&)5;0(o2dIysb#FQZ(!tflEBlV(2dTvbU}9s z+=6p!ZWJAP8hfBwB44{cEghHt`VIIK!asdL?|z|v*1~&Xm@Euge%^i&$d0j4w+Iv) zR)>n{iVjZ$*1|5Ijle!#*ggF0*~E9He*n)Gc-=KfyTGd|faeJOSO8LtRvvsAxJSpS zyBfMN+7suXdv%{DXQI=1$3S90j{sU;>>;eD) delta 1598 zcmaKsYiv|S6vt=oy}R9Rcgya&rIp(5r4MOn*)Cg9Q4nf))bMDrOVdDCgq&NvB8u9WhcOGR2(=~SAuk)sKH?@T^(Tl8VPQI-aUbX3k;6+UDF?h>OF9+TV z;qhlYeVPkP1Lz7q3jf`Iz|Q{Y%;pDurz!vLtevuzxz|%|2%5%91B=|5^^GZmb3=Fg z>Z9##d}p93@U_6^>O=nH% zd)c0toBdFeEtW4M#FyZUKb)p)vNppa_H<0ID=a>o%5HRQ;*XAOOXc-1dsV(~ETPZt zv*6fX+j1OG$fr9X#WHk+f@bGwbcBdHRT%Xy5b;8wH3IP+pLn(2Di6P2X;b*B=`@Ag zrgT-Dytkqm3Z5_Ge^#niNSr9SBb&~5vdM{!Tz}`Q)Z})BdTe~zg*xqj#n?9%&oTBF z)4Bk$7ZIYxTiQENI_eGV#4_g;?lNxJOXxzy)oFxFXplOM`VyKs&xH_iv~)DLq80aT zS)j~#4{1v5P2*w-E$!05=f&C@n}{~h2R~ot?OsZVy;kz>0k8teUw;?eFL`1$n9v2* z{V^dqamhoc03J6naYIU)B6;zTU<)KaG9M?=V{JaMaK0B1M-+BqztOXZj&7>?9tmM{ zpnC5c1VpjJw&La39CE_L;{YfFVcXNNkVo>0gE|x;iU6+kJrSv6x zG(*IUnh<^NiRc#i@s^HQJ6iGFEOU$21HKdOf4K*JM{*=YzozS{J@HUd_16tp-Hs?M zdUaOPbG5>k{FEUjg`(=`SHK;TkG*A#h3Ro6P-yg&(O}o@V-J$VTjeij%`)qAaYNyK@bEu8GP0XHE5s&01^dL?F`) zQ1yV2Uryx0wa_d%AhO%ox`eLnir~OR)|@)jh`9K(!2)mK3~%TaW3t1Qd}qtN7msw;t2AGqZfndgG&|RR0$s CnsZJ7 diff --git a/modules/libpref/public/MANIFEST_IDL b/modules/libpref/public/MANIFEST_IDL index cc560983a31..5f3c1daa740 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 153aa392613..7f66c9e4143 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 c810e1919c7..c1dbcb47530 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 d0f219214bc..86aa4627bd7 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,12 +20,17 @@ * 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++ @@ -52,111 +57,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 +252,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 6f14a1e0997..0f8c73cbdee 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 64d63463e04..53ba4a1cd81 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 cfb707c3e87..15396c3a1e3 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,280 @@ 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) + +extern "C" 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 4b7e596b24d..d147e8c7c66 100644 --- a/modules/libpref/src/nsPrefService.cpp +++ b/modules/libpref/src/nsPrefService.cpp @@ -74,7 +74,7 @@ nsPrefService::nsPrefService() NS_INIT_REFCNT(); - rootBranch = new nsPrefBranch("", FALSE); + rootBranch = new nsPrefBranch("", PR_FALSE); mRootBranch = (nsIPrefBranch *)rootBranch; } @@ -323,10 +323,11 @@ static nsresult openPrefFileSpec(nsIFileSpec* aFilespec, PRBool aIsErrorFatal, P nsresult rv; char* readBuf; - // TODO: Validate this entire function, I seriously doubt it does what it is supposed to. - // Note for instance that gErrorOpeningUserPrefs will only be set if the evaluation - // of the config script fails AND aIsErrorFatal is set TRUE... the readBuf test is - // irrelavent because it will bail at the GetFileContents call if it fails. + // TODO: Validate this entire function, I seriously doubt it does what it is + // supposed to. Note for instance that gErrorOpeningUserPrefs will only + // be set if the evaluation of the config script fails AND aIsErrorFatal + // is set to PR_TRUE... the readBuf test is irrelavent because it will + // bail at the GetFileContents call if it fails. // TODO: Convert the rest of this code to nsIFile and avoid this conversion to nsIFileSpec rv = aFilespec->ResolveSymlink(); @@ -706,7 +707,6 @@ extern "C" JSBool pref_InitInitialObjects() } } -done: JS_MaybeGC(gMochaContext); return JS_TRUE; } @@ -724,7 +724,7 @@ extern "C" JSRuntime* PREF_GetJSRuntime() return rt; } } - NS_ASSERTION(NS_SUCCEEDED(rv), "nsJSRuntimeService is missing"); + NS_WARNING("nsJSRuntimeService is missing"); return nsnull; } diff --git a/modules/libpref/src/nsPrefsFactory.cpp b/modules/libpref/src/nsPrefsFactory.cpp index 4f98fc3cebe..31a8023b4ac 100644 --- a/modules/libpref/src/nsPrefsFactory.cpp +++ b/modules/libpref/src/nsPrefsFactory.cpp @@ -27,7 +27,7 @@ #include "nsIPref.h" // remove this when nsPref goes away -extern "C" nsresult nsPrefConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult); +extern "C" NS_IMETHODIMP nsPrefConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult); NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefService, Init) diff --git a/netwerk/cache/src/nsCacheService.cpp b/netwerk/cache/src/nsCacheService.cpp index 3822cb954b3..a9560026138 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 8d7df2d98c7..d7809dfc99c 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 2bbafb8dde1..dc89ffa13be 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 da667618586..cf452be4b22 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 9c4423a9dcb..574bdc22923 100644 --- a/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/webshell/tests/viewer/nsBrowserWindow.cpp @@ -3276,7 +3276,7 @@ nsBrowserWindow::ToggleBoolPrefAndRefresh(const char * aPrefName) PRBool value; prefs->GetBoolPref(aPrefName,&value); prefs->SetBoolPref(aPrefName,!value); - prefs->SavePrefFile(); + prefs->SavePrefFile(nsnull); ForceRefresh(); } @@ -3293,7 +3293,7 @@ nsBrowserWindow::SetBoolPref(const char * aPrefName, PRBool aValue) if (prefs && nsnull != aPrefName) { prefs->SetBoolPref(aPrefName, aValue); - prefs->SavePrefFile(); + prefs->SavePrefFile(nsnull); } } @@ -3307,7 +3307,7 @@ nsBrowserWindow::SetStringPref(const char * aPrefName, const nsString& aValue) { char * prefStr = aValue.ToNewCString(); prefs->SetCharPref(aPrefName, prefStr); - prefs->SavePrefFile(); + prefs->SavePrefFile(nsnull); delete [] prefStr; } @@ -3652,7 +3652,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 79c641bdd68..903e9b8bdff 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 5b92caa9bf9..f91ccc26c09 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 b2137b63168..0c9a967dfc1 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: