diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 9935ff3ff5b..55867e4b358 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -561,6 +561,9 @@ public: static void SplitExpatName(const PRUnichar *aExpatName, nsIAtom **aPrefix, nsIAtom **aTagName, PRInt32 *aNameSpaceID); + static nsAdoptingCString GetCharPref(const char *aPref); + static nsAdoptingString GetLocalizedStringPref(const char *aPref); + static nsAdoptingString GetStringPref(const char *aPref); static void RegisterPrefCallback(const char *aPref, PrefChangedFunc aCallback, void * aClosure); diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index ec86b10d58a..26e67a29a70 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -2582,6 +2582,55 @@ nsContentUtils::IsDraggableLink(const nsIContent* aContent) { return aContent->IsLink(getter_AddRefs(absURI)); } +// static +nsAdoptingCString +nsContentUtils::GetCharPref(const char *aPref) +{ + nsAdoptingCString result; + + if (sPrefBranch) { + sPrefBranch->GetCharPref(aPref, getter_Copies(result)); + } + + return result; +} + +// static +nsAdoptingString +nsContentUtils::GetLocalizedStringPref(const char *aPref) +{ + nsAdoptingString result; + + if (sPrefBranch) { + nsCOMPtr prefLocalString; + sPrefBranch->GetComplexValue(aPref, NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(prefLocalString)); + if (prefLocalString) { + prefLocalString->GetData(getter_Copies(result)); + } + } + + return result; +} + +// static +nsAdoptingString +nsContentUtils::GetStringPref(const char *aPref) +{ + nsAdoptingString result; + + if (sPrefBranch) { + nsCOMPtr theString; + sPrefBranch->GetComplexValue(aPref, NS_GET_IID(nsISupportsString), + getter_AddRefs(theString)); + if (theString) { + theString->ToString(getter_Copies(result)); + } + } + + return result; +} + // RegisterPrefCallback/UnregisterPrefCallback are for backward compatiblity // with c-style observers. @@ -4411,7 +4460,7 @@ nsContentUtils::GetLocalizedEllipsis() { static PRUnichar sBuf[4] = { 0, 0, 0, 0 }; if (!sBuf[0]) { - nsAdoptingString tmp = Preferences::GetLocalizedString("intl.ellipsis"); + nsAutoString tmp(GetLocalizedStringPref("intl.ellipsis")); PRUint32 len = NS_MIN(PRUint32(tmp.Length()), PRUint32(NS_ARRAY_LENGTH(sBuf) - 1)); CopyUnicodeTo(tmp, 0, sBuf, len); diff --git a/content/base/src/nsDOMFile.cpp b/content/base/src/nsDOMFile.cpp index 9c4a0b8a2db..24b306f0be7 100644 --- a/content/base/src/nsDOMFile.cpp +++ b/content/base/src/nsDOMFile.cpp @@ -64,7 +64,6 @@ #include "nsStringStream.h" #include "CheckedInt.h" #include "nsJSUtils.h" -#include "mozilla/Preferences.h" #include "plbase64.h" #include "prmem.h" @@ -500,12 +499,12 @@ nsDOMFile::GuessCharset(nsIInputStream *aStream, "universal_charset_detector"); if (!detector) { // No universal charset detector, try the default charset detector - const nsAdoptingCString& detectorName = - Preferences::GetLocalizedCString("intl.charset.detector"); + const nsAdoptingString& detectorName = + nsContentUtils::GetLocalizedStringPref("intl.charset.detector"); if (!detectorName.IsEmpty()) { nsCAutoString detectorContractID; detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE); - detectorContractID += detectorName; + AppendUTF16toUTF8(detectorName, detectorContractID); detector = do_CreateInstance(detectorContractID.get()); } } diff --git a/content/base/src/nsDOMFileReader.cpp b/content/base/src/nsDOMFileReader.cpp index ae3f34b3e6c..a00a5422047 100644 --- a/content/base/src/nsDOMFileReader.cpp +++ b/content/base/src/nsDOMFileReader.cpp @@ -77,9 +77,6 @@ #include "nsLayoutStatics.h" #include "nsIScriptObjectPrincipal.h" #include "nsFileDataProtocolHandler.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; #define LOAD_STR "load" #define ERROR_STR "error" @@ -687,12 +684,12 @@ nsDOMFileReader::GuessCharset(const char *aFileData, "universal_charset_detector"); if (!detector) { // No universal charset detector, try the default charset detector - const nsAdoptingCString& detectorName = - Preferences::GetLocalizedCString("intl.charset.detector"); + const nsAdoptingString& detectorName = + nsContentUtils::GetLocalizedStringPref("intl.charset.detector"); if (!detectorName.IsEmpty()) { nsCAutoString detectorContractID; detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE); - detectorContractID += detectorName; + AppendUTF16toUTF8(detectorName, detectorContractID); detector = do_CreateInstance(detectorContractID.get()); } } diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 8d3c008fe09..a04e80e6654 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -57,9 +57,6 @@ #include "nsIScriptSecurityManager.h" #include "nsIScriptError.h" #include "nsDOMPopStateEvent.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; static const char* const sEventNames[] = { "mousedown", "mouseup", "click", "dblclick", "mouseover", @@ -1091,7 +1088,8 @@ nsDOMEvent::PopupAllowedEventsChanged() nsMemory::Free(sPopupAllowedEvents); } - nsAdoptingCString str = Preferences::GetCString("dom.popup_allowed_events"); + nsAdoptingCString str = + nsContentUtils::GetCharPref("dom.popup_allowed_events"); // We'll want to do this even if str is empty to avoid looking up // this pref all the time if it's not set. diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index a14b86bee3d..6ed2193882e 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -143,9 +143,7 @@ #include "nsHtml5Module.h" #include "prprf.h" #include "mozilla/dom/Element.h" -#include "mozilla/Preferences.h" -using namespace mozilla; using namespace mozilla::dom; #define NS_MAX_DOCUMENT_WRITE_DEPTH 20 @@ -186,13 +184,14 @@ static PRBool ConvertToMidasInternalCommand(const nsAString & inCommandID, static int MyPrefChangedCallback(const char*aPrefName, void* instance_data) { - const nsAdoptingCString& detector_name = - Preferences::GetLocalizedCString("intl.charset.detector"); + const nsAdoptingString& detector_name = + nsContentUtils::GetLocalizedStringPref("intl.charset.detector"); - if (!detector_name.IsEmpty()) { + if (detector_name.Length() > 0) { PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE, DETECTOR_CONTRACTID_MAX); - PL_strncat(g_detector_contractid, detector_name, + PL_strncat(g_detector_contractid, + NS_ConvertUTF16toUTF8(detector_name).get(), DETECTOR_CONTRACTID_MAX); gPlugDetector = PR_TRUE; } else { @@ -543,11 +542,11 @@ nsHTMLDocument::UseWeakDocTypeDefault(PRInt32& aCharsetSource, // fallback value in case docshell return error aCharset.AssignLiteral("ISO-8859-1"); - const nsAdoptingCString& defCharset = - Preferences::GetLocalizedCString("intl.charset.default"); + const nsAdoptingString& defCharset = + nsContentUtils::GetLocalizedStringPref("intl.charset.default"); if (!defCharset.IsEmpty()) { - aCharset = defCharset; + LossyCopyUTF16toASCII(defCharset, aCharset); aCharsetSource = kCharsetFromWeakDocTypeDefault; } return PR_TRUE; @@ -589,13 +588,14 @@ nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell, nsACString& aCharset, nsresult rv_detect; if(!gInitDetector) { - const nsAdoptingCString& detector_name = - Preferences::GetLocalizedCString("intl.charset.detector"); + const nsAdoptingString& detector_name = + nsContentUtils::GetLocalizedStringPref("intl.charset.detector"); if(!detector_name.IsEmpty()) { PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE, DETECTOR_CONTRACTID_MAX); - PL_strncat(g_detector_contractid, detector_name, + PL_strncat(g_detector_contractid, + NS_ConvertUTF16toUTF8(detector_name).get(), DETECTOR_CONTRACTID_MAX); gPlugDetector = PR_TRUE; } diff --git a/content/media/nsAudioStream.cpp b/content/media/nsAudioStream.cpp index 48e1468e1c3..507b96e8498 100644 --- a/content/media/nsAudioStream.cpp +++ b/content/media/nsAudioStream.cpp @@ -59,9 +59,6 @@ extern "C" { } #include "mozilla/TimeStamp.h" #include "nsThreadUtils.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; #if defined(XP_MACOSX) #define SA_PER_STREAM_VOLUME 1 @@ -324,7 +321,8 @@ static mozilla::Mutex* gVolumeScaleLock = nsnull; static double gVolumeScale = 1.0; static int VolumeScaleChanged(const char* aPref, void *aClosure) { - nsAdoptingString value = Preferences::GetString("media.volume_scale"); + nsAdoptingString value = + nsContentUtils::GetStringPref("media.volume_scale"); mozilla::MutexAutoLock lock(*gVolumeScaleLock); if (value.IsEmpty()) { gVolumeScale = 1.0; diff --git a/content/svg/content/src/nsSVGFeatures.cpp b/content/svg/content/src/nsSVGFeatures.cpp index d36adb261a1..748a94ec5c9 100644 --- a/content/svg/content/src/nsSVGFeatures.cpp +++ b/content/svg/content/src/nsSVGFeatures.cpp @@ -56,9 +56,6 @@ #include "nsSVGUtils.h" #include "nsServiceManagerUtils.h" #include "nsIPrefService.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; /*static*/ PRBool nsSVGFeatures::HaveFeature(nsISupports* aObject, const nsAString& aFeature) @@ -242,7 +239,7 @@ nsSVGFeatures::PassesConditionalProcessingTests(nsIContent *aContent, value)) { const nsAutoString acceptLangs(aAcceptLangs ? *aAcceptLangs : - Preferences::GetLocalizedString("intl.accept_languages")); + nsContentUtils::GetLocalizedStringPref("intl.accept_languages")); // Get our language preferences if (!acceptLangs.IsEmpty()) { diff --git a/content/svg/content/src/nsSVGSwitchElement.cpp b/content/svg/content/src/nsSVGSwitchElement.cpp index a727dfbd813..15aa9b062f7 100644 --- a/content/svg/content/src/nsSVGSwitchElement.cpp +++ b/content/svg/content/src/nsSVGSwitchElement.cpp @@ -39,9 +39,6 @@ #include "nsIFrame.h" #include "nsISVGChildFrame.h" #include "nsSVGUtils.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; //////////////////////////////////////////////////////////////////////// // implementation @@ -165,7 +162,7 @@ nsSVGSwitchElement::FindActiveChild() const nsGkAtoms::yes, eCaseMatters); const nsAdoptingString& acceptLangs = - Preferences::GetLocalizedString("intl.accept_languages"); + nsContentUtils::GetLocalizedStringPref("intl.accept_languages"); PRUint32 count = GetChildCount(); diff --git a/content/xbl/src/nsXBLWindowKeyHandler.cpp b/content/xbl/src/nsXBLWindowKeyHandler.cpp index 40cea7d7dd0..49079aa5537 100644 --- a/content/xbl/src/nsXBLWindowKeyHandler.cpp +++ b/content/xbl/src/nsXBLWindowKeyHandler.cpp @@ -70,9 +70,6 @@ #include "nsIPrivateDOMEvent.h" #include "nsISelectionController.h" #include "nsGUIEvent.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; static nsINativeKeyBindings *sNativeEditorBindings = nsnull; @@ -127,7 +124,7 @@ void nsXBLSpecialDocInfo::LoadDocInfo() getter_AddRefs(mHTMLBindings)); const nsAdoptingCString& userHTMLBindingStr = - Preferences::GetCString("dom.userHTMLBindings.uri"); + nsContentUtils::GetCharPref("dom.userHTMLBindings.uri"); if (!userHTMLBindingStr.IsEmpty()) { NS_NewURI(getter_AddRefs(bindingURI), userHTMLBindingStr); if (!bindingURI) { diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 82e7bddd059..0ce1fcbf816 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -920,8 +920,8 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow) } if (gDumpFile == nsnull) { - const nsAdoptingCString& fname = - Preferences::GetCString("browser.dom.window.dump.file"); + const nsAdoptingCString& fname = + nsContentUtils::GetCharPref("browser.dom.window.dump.file"); if (!fname.IsEmpty()) { // if this fails to open, Dump() knows to just go to stdout // on null. @@ -5007,7 +5007,7 @@ nsGlobalWindow::Home() return NS_OK; nsAdoptingString homeURL = - Preferences::GetLocalizedString(PREF_BROWSER_STARTUP_HOMEPAGE); + nsContentUtils::GetLocalizedStringPref(PREF_BROWSER_STARTUP_HOMEPAGE); if (homeURL.IsEmpty()) { // if all else fails, use this @@ -10547,11 +10547,11 @@ nsresult NS_GetNavigatorPlatform(nsAString& aPlatform) { if (!nsContentUtils::IsCallerTrustedForRead()) { - const nsAdoptingString& override = - Preferences::GetString("general.platform.override"); + const nsAdoptingCString& override = + nsContentUtils::GetCharPref("general.platform.override"); if (override) { - aPlatform = override; + CopyUTF8toUTF16(override, aPlatform); return NS_OK; } } @@ -10591,11 +10591,11 @@ nsresult NS_GetNavigatorAppVersion(nsAString& aAppVersion) { if (!nsContentUtils::IsCallerTrustedForRead()) { - const nsAdoptingString& override = - Preferences::GetString("general.appversion.override"); + const nsAdoptingCString& override = + nsContentUtils::GetCharPref("general.appversion.override"); if (override) { - aAppVersion = override; + CopyUTF8toUTF16(override, aAppVersion); return NS_OK; } } @@ -10628,11 +10628,11 @@ nsresult NS_GetNavigatorAppName(nsAString& aAppName) { if (!nsContentUtils::IsCallerTrustedForRead()) { - const nsAdoptingString& override = - Preferences::GetString("general.appname.override"); + const nsAdoptingCString& override = + nsContentUtils::GetCharPref("general.appname.override"); if (override) { - aAppName = override; + CopyUTF8toUTF16(override, aAppName); return NS_OK; } } @@ -10691,7 +10691,7 @@ nsNavigator::GetLanguage(nsAString& aLanguage) { // e.g. "de-de, en-us,en" const nsAdoptingString& acceptLang = - Preferences::GetLocalizedString("intl.accept_languages"); + nsContentUtils::GetLocalizedStringPref("intl.accept_languages"); // take everything before the first "," or ";", without trailing space nsCharSeparatedTokenizer langTokenizer(acceptLang, ','); const nsSubstring &firstLangPart = langTokenizer.nextToken(); @@ -10736,11 +10736,11 @@ NS_IMETHODIMP nsNavigator::GetOscpu(nsAString& aOSCPU) { if (!nsContentUtils::IsCallerTrustedForRead()) { - const nsAdoptingString& override = - Preferences::GetString("general.oscpu.override"); + const nsAdoptingCString& override = + nsContentUtils::GetCharPref("general.oscpu.override"); if (override) { - aOSCPU = override; + CopyUTF8toUTF16(override, aOSCPU); return NS_OK; } } @@ -10791,21 +10791,21 @@ NS_IMETHODIMP nsNavigator::GetProductSub(nsAString& aProductSub) { if (!nsContentUtils::IsCallerTrustedForRead()) { - const nsAdoptingString& override = - Preferences::GetString("general.productSub.override"); + const nsAdoptingCString& override = + nsContentUtils::GetCharPref("general.productSub.override"); if (override) { - aProductSub = override; + CopyUTF8toUTF16(override, aProductSub); return NS_OK; - } + } else { + // 'general.useragent.productSub' backwards compatible with 1.8 branch. + const nsAdoptingCString& override2 = + nsContentUtils::GetCharPref("general.useragent.productSub"); - // 'general.useragent.productSub' backwards compatible with 1.8 branch. - const nsAdoptingString& override2 = - Preferences::GetString("general.useragent.productSub"); - - if (override2) { - aProductSub = override2; - return NS_OK; + if (override2) { + CopyUTF8toUTF16(override2, aProductSub); + return NS_OK; + } } } @@ -10878,11 +10878,11 @@ NS_IMETHODIMP nsNavigator::GetBuildID(nsAString& aBuildID) { if (!nsContentUtils::IsCallerTrustedForRead()) { - const nsAdoptingString& override = - Preferences::GetString("general.buildID.override"); + const nsAdoptingCString& override = + nsContentUtils::GetCharPref("general.buildID.override"); if (override) { - aBuildID = override; + CopyUTF8toUTF16(override, aBuildID); return NS_OK; } } diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index f34f3fbe8ee..98187a4629f 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -76,7 +76,6 @@ #include "nsLayoutCID.h" #include "nsContentUtils.h" #include "nsLayoutStylesheetCache.h" -#include "mozilla/Preferences.h" #include "nsViewsCID.h" #include "nsIDeviceContextSpec.h" @@ -196,8 +195,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset //switch to page layout #include "nsGfxCIID.h" -using namespace mozilla; - #ifdef NS_DEBUG #undef NOISY_VIEWER @@ -2995,14 +2992,13 @@ DocumentViewerImpl::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet) { if (mDefaultCharacterSet.IsEmpty()) { - const nsAdoptingCString& defCharset = - Preferences::GetLocalizedCString("intl.charset.default"); + const nsAdoptingString& defCharset = + nsContentUtils::GetLocalizedStringPref("intl.charset.default"); - if (!defCharset.IsEmpty()) { - mDefaultCharacterSet = defCharset; - } else { + if (!defCharset.IsEmpty()) + LossyCopyUTF16toASCII(defCharset, mDefaultCharacterSet); + else mDefaultCharacterSet.AssignLiteral("ISO-8859-1"); - } } aDefaultCharacterSet = mDefaultCharacterSet; return NS_OK; diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 59b4749f1db..330a1c5e9da 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -125,14 +125,14 @@ using namespace mozilla; using namespace mozilla::dom; static nscolor -MakeColorPref(const nsCString& aColor) +MakeColorPref(const char *colstr) { PRUint32 red, green, blue; nscolor colorref; // 4.x stored RGB color values as a string rather than as an int, // thus we need to do this conversion - PR_sscanf(aColor.get(), "#%02x%02x%02x", &red, &green, &blue); + PR_sscanf(colstr, "#%02x%02x%02x", &red, &green, &blue); colorref = NS_RGB(red, green, blue); return colorref; } @@ -471,7 +471,7 @@ nsPresContext::GetFontPreferences() PRInt32 unit = eUnit_px; nsAdoptingCString cvalue = - Preferences::GetCString("font.size.unit"); + nsContentUtils::GetCharPref("font.size.unit"); if (!cvalue.IsEmpty()) { if (cvalue.Equals("px")) { @@ -521,13 +521,14 @@ nsPresContext::GetFontPreferences() if (eType == eDefaultFont_Variable) { MAKE_FONT_PREF_KEY(pref, "font.name", generic_dot_langGroup); - nsAdoptingString value = Preferences::GetString(pref.get()); + nsAdoptingString value = + nsContentUtils::GetStringPref(pref.get()); if (!value.IsEmpty()) { font->name.Assign(value); } else { MAKE_FONT_PREF_KEY(pref, "font.default.", langGroup); - value = Preferences::GetString(pref.get()); + value = nsContentUtils::GetStringPref(pref.get()); if (!value.IsEmpty()) { mDefaultVariableFont.name.Assign(value); } @@ -569,7 +570,7 @@ nsPresContext::GetFontPreferences() // get font.size-adjust.[generic].[langGroup] // XXX only applicable on GFX ports that handle |font-size-adjust| MAKE_FONT_PREF_KEY(pref, "font.size-adjust", generic_dot_langGroup); - cvalue = Preferences::GetCString(pref.get()); + cvalue = nsContentUtils::GetCharPref(pref.get()); if (!cvalue.IsEmpty()) { font->sizeAdjust = (float)atof(cvalue.get()); } @@ -608,13 +609,14 @@ nsPresContext::GetDocumentColorPreferences() if (usePrefColors) { nsAdoptingCString colorStr = - Preferences::GetCString("browser.display.foreground_color"); + nsContentUtils::GetCharPref("browser.display.foreground_color"); if (!colorStr.IsEmpty()) { mDefaultColor = MakeColorPref(colorStr); } - colorStr = Preferences::GetCString("browser.display.background_color"); + colorStr = + nsContentUtils::GetCharPref("browser.display.background_color"); if (!colorStr.IsEmpty()) { mBackgroundColor = MakeColorPref(colorStr); @@ -666,19 +668,21 @@ nsPresContext::GetUserPreferences() mUnderlineLinks = Preferences::GetBool("browser.underline_anchors", mUnderlineLinks); - nsAdoptingCString colorStr = Preferences::GetCString("browser.anchor_color"); + nsAdoptingCString colorStr = + nsContentUtils::GetCharPref("browser.anchor_color"); if (!colorStr.IsEmpty()) { mLinkColor = MakeColorPref(colorStr); } - colorStr = Preferences::GetCString("browser.active_color"); + colorStr = + nsContentUtils::GetCharPref("browser.active_color"); if (!colorStr.IsEmpty()) { mActiveLinkColor = MakeColorPref(colorStr); } - colorStr = Preferences::GetCString("browser.visited_color"); + colorStr = nsContentUtils::GetCharPref("browser.visited_color"); if (!colorStr.IsEmpty()) { mVisitedLinkColor = MakeColorPref(colorStr); @@ -690,13 +694,14 @@ nsPresContext::GetUserPreferences() mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mBackgroundColor; - colorStr = Preferences::GetCString("browser.display.focus_text_color"); + colorStr = nsContentUtils::GetCharPref("browser.display.focus_text_color"); if (!colorStr.IsEmpty()) { mFocusTextColor = MakeColorPref(colorStr); } - colorStr = Preferences::GetCString("browser.display.focus_background_color"); + colorStr = + nsContentUtils::GetCharPref("browser.display.focus_background_color"); if (!colorStr.IsEmpty()) { mFocusBackgroundColor = MakeColorPref(colorStr); @@ -725,7 +730,7 @@ nsPresContext::GetUserPreferences() // * image animation const nsAdoptingCString& animatePref = - Preferences::GetCString("image.animation_mode"); + nsContentUtils::GetCharPref("image.animation_mode"); if (animatePref.Equals("normal")) mImageAnimationModePref = imgIContainer::kNormalAnimMode; else if (animatePref.Equals("none")) diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index dabf7c0bb01..26454f84eee 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -4052,7 +4052,7 @@ nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays() // "plugins.force.wmode" preference is forcing wmode type for plugins // possible values - "opaque", "transparent", "windowed" - nsAdoptingCString wmodeType = Preferences::GetCString("plugins.force.wmode"); + nsAdoptingCString wmodeType = nsContentUtils::GetCharPref("plugins.force.wmode"); if (!wmodeType.IsEmpty()) { mNumCachedAttrs++; } diff --git a/layout/xul/base/src/nsTextBoxFrame.cpp b/layout/xul/base/src/nsTextBoxFrame.cpp index c5306327703..976f68d965b 100644 --- a/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/layout/xul/base/src/nsTextBoxFrame.cpp @@ -70,15 +70,12 @@ #include "nsCSSRendering.h" #include "nsIReflowCallback.h" #include "nsBoxFrame.h" -#include "mozilla/Preferences.h" #ifdef IBMBIDI #include "nsBidiUtils.h" #include "nsBidiPresUtils.h" #endif // IBMBIDI -using namespace mozilla; - #define CROP_LEFT "left" #define CROP_RIGHT "right" #define CROP_CENTER "center" @@ -185,7 +182,7 @@ nsTextBoxFrame::AlwaysAppendAccessKey() gAccessKeyPrefInitialized = PR_TRUE; const char* prefName = "intl.menuitems.alwaysappendaccesskeys"; - nsAdoptingString val = Preferences::GetLocalizedString(prefName); + nsAdoptingString val = nsContentUtils::GetLocalizedStringPref(prefName); gAlwaysAppendAccessKey = val.Equals(NS_LITERAL_STRING("true")); } return gAlwaysAppendAccessKey; @@ -199,7 +196,7 @@ nsTextBoxFrame::InsertSeparatorBeforeAccessKey() gInsertSeparatorPrefInitialized = PR_TRUE; const char* prefName = "intl.menuitems.insertseparatorbeforeaccesskeys"; - nsAdoptingString val = Preferences::GetLocalizedString(prefName); + nsAdoptingString val = nsContentUtils::GetLocalizedStringPref(prefName); gInsertSeparatorBeforeAccessKey = val.EqualsLiteral("true"); } return gInsertSeparatorBeforeAccessKey; diff --git a/modules/libpref/public/Preferences.h b/modules/libpref/public/Preferences.h index 324636bc283..8ced5254b45 100644 --- a/modules/libpref/public/Preferences.h +++ b/modules/libpref/public/Preferences.h @@ -54,8 +54,6 @@ class nsIFile; class nsCString; class nsString; -class nsAdoptingString; -class nsAdoptingCString; namespace mozilla { @@ -128,11 +126,6 @@ public: return result; } - static nsAdoptingCString GetCString(const char* aPref); - static nsAdoptingString GetString(const char* aPref); - static nsAdoptingCString GetLocalizedCString(const char* aPref); - static nsAdoptingString GetLocalizedString(const char* aPref); - /** * Gets int or bool type pref value with raw return value of nsIPrefBranch. * @@ -159,10 +152,9 @@ public: * @param aResult Must not be NULL. The value is never modified when * these methods fail. */ - static nsresult GetCString(const char* aPref, nsACString* aResult); - static nsresult GetString(const char* aPref, nsAString* aResult); - static nsresult GetLocalizedCString(const char* aPref, nsACString* aResult); - static nsresult GetLocalizedString(const char* aPref, nsAString* aResult); + static nsresult GetChar(const char* aPref, nsCString* aResult); + static nsresult GetChar(const char* aPref, nsString* aResult); + static nsresult GetLocalizedString(const char* aPref, nsString* aResult); /** * Sets various type pref values. @@ -173,10 +165,10 @@ public: { return SetInt(aPref, static_cast(aValue)); } - static nsresult SetCString(const char* aPref, const char* aValue); - static nsresult SetCString(const char* aPref, const nsACString &aValue); - static nsresult SetString(const char* aPref, const PRUnichar* aValue); - static nsresult SetString(const char* aPref, const nsAString &aValue); + static nsresult SetChar(const char* aPref, const char* aValue); + static nsresult SetChar(const char* aPref, const nsCString &aValue); + static nsresult SetChar(const char* aPref, const PRUnichar* aValue); + static nsresult SetChar(const char* aPref, const nsString &aValue); /** * Clears user set pref. diff --git a/modules/libpref/src/Preferences.cpp b/modules/libpref/src/Preferences.cpp index dd8b5e630c1..10167fdd099 100644 --- a/modules/libpref/src/Preferences.cpp +++ b/modules/libpref/src/Preferences.cpp @@ -1019,31 +1019,13 @@ Preferences::GetInt(const char* aPref, PRInt32* aResult) return sPreferences->mRootBranch->GetIntPref(aPref, aResult); } -// static -nsAdoptingCString -Preferences::GetCString(const char* aPref) -{ - nsAdoptingCString result; - GetCString(aPref, &result); - return result; -} - -// static -nsAdoptingString -Preferences::GetString(const char* aPref) -{ - nsAdoptingString result; - GetString(aPref, &result); - return result; -} - // static nsresult -Preferences::GetCString(const char* aPref, nsACString* aResult) +Preferences::GetChar(const char* aPref, nsCString* aResult) { NS_PRECONDITION(aResult, "aResult must not be NULL"); NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE); - nsCAutoString result; + nsAdoptingCString result; nsresult rv = sPreferences->mRootBranch->GetCharPref(aPref, getter_Copies(result)); if (NS_SUCCEEDED(rv)) { @@ -1054,11 +1036,11 @@ Preferences::GetCString(const char* aPref, nsACString* aResult) // static nsresult -Preferences::GetString(const char* aPref, nsAString* aResult) +Preferences::GetChar(const char* aPref, nsString* aResult) { NS_PRECONDITION(aResult, "aResult must not be NULL"); NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE); - nsCAutoString result; + nsAdoptingCString result; nsresult rv = sPreferences->mRootBranch->GetCharPref(aPref, getter_Copies(result)); if (NS_SUCCEEDED(rv)) { @@ -1067,40 +1049,9 @@ Preferences::GetString(const char* aPref, nsAString* aResult) return rv; } -// static -nsAdoptingCString -Preferences::GetLocalizedCString(const char* aPref) -{ - nsAdoptingCString result; - GetLocalizedCString(aPref, &result); - return result; -} - -// static -nsAdoptingString -Preferences::GetLocalizedString(const char* aPref) -{ - nsAdoptingString result; - GetLocalizedString(aPref, &result); - return result; -} - // static nsresult -Preferences::GetLocalizedCString(const char* aPref, nsACString* aResult) -{ - NS_PRECONDITION(aResult, "aResult must not be NULL"); - nsAutoString result; - nsresult rv = GetLocalizedString(aPref, &result); - if (NS_SUCCEEDED(rv)) { - CopyUTF16toUTF8(result, *aResult); - } - return rv; -} - -// static -nsresult -Preferences::GetLocalizedString(const char* aPref, nsAString* aResult) +Preferences::GetLocalizedString(const char* aPref, nsString* aResult) { NS_PRECONDITION(aResult, "aResult must not be NULL"); NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE); @@ -1109,15 +1060,18 @@ Preferences::GetLocalizedString(const char* aPref, nsAString* aResult) NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(prefLocalString)); if (NS_SUCCEEDED(rv)) { - NS_ASSERTION(prefLocalString, "Succeeded but the result is NULL"); - prefLocalString->GetData(getter_Copies(*aResult)); + if (prefLocalString) { + prefLocalString->GetData(getter_Copies(*aResult)); + } else { + aResult->Truncate(); + } } return rv; } // static nsresult -Preferences::SetCString(const char* aPref, const char* aValue) +Preferences::SetChar(const char* aPref, const char* aValue) { NS_ENSURE_TRUE(InitStaticMembers(), PR_FALSE); return sPreferences->mRootBranch->SetCharPref(aPref, aValue); @@ -1125,25 +1079,25 @@ Preferences::SetCString(const char* aPref, const char* aValue) // static nsresult -Preferences::SetCString(const char* aPref, const nsACString &aValue) +Preferences::SetChar(const char* aPref, const nsCString &aValue) { - return SetCString(aPref, PromiseFlatCString(aValue).get()); + return SetChar(aPref, nsPromiseFlatCString(aValue).get()); } // static nsresult -Preferences::SetString(const char* aPref, const PRUnichar* aValue) +Preferences::SetChar(const char* aPref, const PRUnichar* aValue) { NS_ConvertUTF16toUTF8 utf8(aValue); - return SetCString(aPref, utf8.get()); + return SetChar(aPref, utf8.get()); } // static nsresult -Preferences::SetString(const char* aPref, const nsAString &aValue) +Preferences::SetChar(const char* aPref, const nsString &aValue) { NS_ConvertUTF16toUTF8 utf8(aValue); - return SetCString(aPref, utf8.get()); + return SetChar(aPref, utf8.get()); } // static diff --git a/parser/html/nsHtml5StreamParser.cpp b/parser/html/nsHtml5StreamParser.cpp index 40a2a61a271..b4e2ef0ad43 100644 --- a/parser/html/nsHtml5StreamParser.cpp +++ b/parser/html/nsHtml5StreamParser.cpp @@ -52,9 +52,6 @@ #include "nsHtml5Module.h" #include "nsHtml5RefPtr.h" #include "nsIScriptError.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID); @@ -203,12 +200,12 @@ nsHtml5StreamParser::nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor, // Chardet is initialized here even if it turns out to be useless // to make the chardet refcount its observer (nsHtml5StreamParser) // on the main thread. - const nsAdoptingCString& detectorName = - Preferences::GetLocalizedCString("intl.charset.detector"); + const nsAdoptingString& detectorName = + nsContentUtils::GetLocalizedStringPref("intl.charset.detector"); if (!detectorName.IsEmpty()) { nsCAutoString detectorContractID; detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE); - detectorContractID += detectorName; + AppendUTF16toUTF8(detectorName, detectorContractID); if ((mChardet = do_CreateInstance(detectorContractID.get()))) { (void) mChardet->Init(this); mFeedChardet = PR_TRUE; diff --git a/widget/src/cocoa/ComplexTextInputPanel.mm b/widget/src/cocoa/ComplexTextInputPanel.mm index 41b1344a7db..c3748dc71e4 100644 --- a/widget/src/cocoa/ComplexTextInputPanel.mm +++ b/widget/src/cocoa/ComplexTextInputPanel.mm @@ -26,10 +26,9 @@ */ #import "ComplexTextInputPanel.h" - -#include "mozilla/Preferences.h" - -using namespace mozilla; +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsServiceManagerUtils.h" #define kInputWindowHeight 20 @@ -92,10 +91,12 @@ using namespace mozilla; return; } if (sDoCancel < 0) { + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + NS_ENSURE_TRUE(prefs, ); PRBool cancelComposition = PR_FALSE; - static const char* kPrefName = - "ui.plugin.cancel_composition_at_input_source_changed"; - nsresult rv = Preferences::GetBool(kPrefName, &cancelComposition); + nsresult rv = + prefs->GetBoolPref("ui.plugin.cancel_composition_at_input_source_changed", + &cancelComposition); NS_ENSURE_SUCCESS(rv, ); sDoCancel = cancelComposition ? 1 : 0; } diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index 18ef2117845..56d37364289 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -55,12 +55,15 @@ #include "nsCOMPtr.h" #include "nsToolkit.h" #include "nsCRT.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsFontMetrics.h" #include "nsIRegion.h" #include "nsIRollupListener.h" #include "nsIViewManager.h" #include "nsIInterfaceRequestor.h" +#include "nsIServiceManager.h" #include "nsILocalFile.h" #include "nsILocalFileMac.h" #include "nsGfxCIID.h" @@ -87,8 +90,6 @@ #include "LayerManagerOGL.h" #include "GLContext.h" -#include "mozilla/Preferences.h" - #include #include @@ -96,7 +97,6 @@ using namespace mozilla::layers; using namespace mozilla::gl; using namespace mozilla::widget; -using namespace mozilla; #undef DEBUG_IME #undef DEBUG_UPDATE @@ -2938,8 +2938,12 @@ NSEvent* gLastDragMouseDownEvent = nil; if (!gRollupWidget) return; - if (Preferences::GetBool("ui.use_native_popup_windows", PR_FALSE)) { - return; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + PRBool useNativeContextMenus; + nsresult rv = prefs->GetBoolPref("ui.use_native_popup_windows", &useNativeContextMenus); + if (NS_SUCCEEDED(rv) && useNativeContextMenus) + return; } NSWindow *popupWindow = (NSWindow*)gRollupWidget->GetNativeData(NS_NATIVE_WINDOW); @@ -3762,8 +3766,11 @@ NSEvent* gLastDragMouseDownEvent = nil; float scrollDelta = 0; float scrollDeltaPixels = 0; - PRBool checkPixels = - Preferences::GetBool("mousewheel.enable_pixel_scrolling", PR_TRUE); + PRBool checkPixels = PR_TRUE; + + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) + prefs->GetBoolPref("mousewheel.enable_pixel_scrolling", &checkPixels); // Calling deviceDeltaX or deviceDeltaY on theEvent will trigger a Cocoa // assertion and an Objective-C NSInternalInconsistencyException if the diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index b739c3154d8..4cdf91821d6 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -52,8 +52,11 @@ #include "nsIBaseWindow.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIXULWindow.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsToolkit.h" #include "nsPrintfCString.h" +#include "nsIServiceManager.h" #include "nsIDOMWindow.h" #include "nsPIDOMWindow.h" #include "nsIDOMElement.h" @@ -68,15 +71,12 @@ #include "gfxPlatform.h" #include "qcms.h" -#include "mozilla/Preferences.h" - namespace mozilla { namespace layers { class LayerManager; } } using namespace mozilla::layers; -using namespace mozilla; // defined in nsAppShell.mm extern nsCocoaAppModalWindowList *gCocoaAppModalWindowList; @@ -227,7 +227,13 @@ static void FitRectToVisibleAreaForScreen(nsIntRect &aRect, NSScreen *screen) // (native context menus, native tooltips) static PRBool UseNativePopupWindows() { - return Preferences::GetBool("ui.use_native_popup_windows", PR_FALSE); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (!prefs) + return PR_FALSE; + + PRBool useNativePopupWindows; + nsresult rv = prefs->GetBoolPref("ui.use_native_popup_windows", &useNativePopupWindows); + return (NS_SUCCEEDED(rv) && useNativePopupWindows); } nsresult nsCocoaWindow::Create(nsIWidget *aParent, diff --git a/widget/src/cocoa/nsFilePicker.mm b/widget/src/cocoa/nsFilePicker.mm index d63a4324e0c..d4c4594f37e 100644 --- a/widget/src/cocoa/nsFilePicker.mm +++ b/widget/src/cocoa/nsFilePicker.mm @@ -53,11 +53,10 @@ #include "nsIURL.h" #include "nsArrayEnumerator.h" #include "nsIStringBundle.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsCocoaUtils.h" #include "nsToolkit.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; const float kAccessoryViewPadding = 5; const int kSaveTypeControlTag = 1; @@ -93,8 +92,11 @@ static void SetShowHiddenFileState(NSSavePanel* panel) NS_OBJC_BEGIN_TRY_ABORT_BLOCK; PRBool show = PR_FALSE; - if (NS_SUCCEEDED(Preferences::GetBool(kShowHiddenFilesPref, &show))) { - gCallSecretHiddenFileAPI = PR_TRUE; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + nsresult rv = prefs->GetBoolPref(kShowHiddenFilesPref, &show); + if (NS_SUCCEEDED(rv)) + gCallSecretHiddenFileAPI = PR_TRUE; } if (gCallSecretHiddenFileAPI) { @@ -145,8 +147,12 @@ nsFilePicker::InitNative(nsIWidget *aParent, const nsAString& aTitle, mMode = aMode; // read in initial type index from prefs - mSelectedTypeIndex = - Preferences::GetInt(kLastTypeIndexPref, mSelectedTypeIndex); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + int prefIndex; + if (NS_SUCCEEDED(prefs->GetIntPref(kLastTypeIndexPref, &prefIndex))) + mSelectedTypeIndex = prefIndex; + } } NSView* nsFilePicker::GetAccessoryView() @@ -506,7 +512,9 @@ nsFilePicker::PutLocalFile(const nsString& inTitle, const nsString& inDefaultNam if (popupButton) { mSelectedTypeIndex = [popupButton indexOfSelectedItem]; // save out to prefs for initializing other file picker instances - Preferences::SetInt(kLastTypeIndexPref, mSelectedTypeIndex); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) + prefs->SetIntPref(kLastTypeIndexPref, mSelectedTypeIndex); } NSURL* fileURL = [thePanel URL]; diff --git a/widget/src/cocoa/nsPrintSettingsX.mm b/widget/src/cocoa/nsPrintSettingsX.mm index 047fdc1e86d..f9e8d3d4036 100644 --- a/widget/src/cocoa/nsPrintSettingsX.mm +++ b/widget/src/cocoa/nsPrintSettingsX.mm @@ -40,16 +40,17 @@ #include "nsPrintSettingsX.h" #include "nsObjCExceptions.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsServiceManagerUtils.h" + #include "plbase64.h" #include "plstr.h" #include "nsCocoaUtils.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; - -#define MAC_OS_X_PAGE_SETUP_PREFNAME "print.macosx.pagesetup-2" +#define PRINTING_PREF_BRANCH "print." +#define MAC_OS_X_PAGE_SETUP_PREFNAME "macosx.pagesetup-2" NS_IMPL_ISUPPORTS_INHERITED1(nsPrintSettingsX, nsPrintSettings, nsPrintSettingsX) @@ -135,12 +136,19 @@ NS_IMETHODIMP nsPrintSettingsX::ReadPageFormatFromPrefs() { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; - nsCAutoString encodedData; - nsresult rv = - Preferences::GetCString(MAC_OS_X_PAGE_SETUP_PREFNAME, &encodedData); - if (NS_FAILED(rv)) { + nsresult rv; + nsCOMPtr prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + return rv; + nsCOMPtr prefBranch; + rv = prefService->GetBranch(PRINTING_PREF_BRANCH, getter_AddRefs(prefBranch)); + if (NS_FAILED(rv)) + return rv; + + nsXPIDLCString encodedData; + rv = prefBranch->GetCharPref(MAC_OS_X_PAGE_SETUP_PREFNAME, getter_Copies(encodedData)); + if (NS_FAILED(rv)) return rv; - } // decode the base64 char* decodedData = PL_Base64Decode(encodedData.get(), encodedData.Length(), nsnull); @@ -168,17 +176,26 @@ NS_IMETHODIMP nsPrintSettingsX::WritePageFormatToPrefs() if (pageFormat == kPMNoPageFormat) return NS_ERROR_NOT_INITIALIZED; + nsresult rv; + nsCOMPtr prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + return rv; + nsCOMPtr prefBranch; + rv = prefService->GetBranch(PRINTING_PREF_BRANCH, getter_AddRefs(prefBranch)); + if (NS_FAILED(rv)) + return rv; + NSData* data = nil; OSStatus err = ::PMPageFormatCreateDataRepresentation(pageFormat, (CFDataRef*)&data, kPMDataFormatXMLDefault); if (err != noErr) return NS_ERROR_FAILURE; - nsCAutoString encodedData; + nsXPIDLCString encodedData; encodedData.Adopt(PL_Base64Encode((char*)[data bytes], [data length], nsnull)); if (!encodedData.get()) return NS_ERROR_OUT_OF_MEMORY; - return Preferences::SetCString(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData); + return prefBranch->SetCharPref(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData); NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; } diff --git a/widget/src/cocoa/nsToolkit.mm b/widget/src/cocoa/nsToolkit.mm index 9459796adf6..041f29974d1 100644 --- a/widget/src/cocoa/nsToolkit.mm +++ b/widget/src/cocoa/nsToolkit.mm @@ -69,10 +69,8 @@ extern "C" { #include "nsIObserverService.h" #include "nsIServiceManager.h" - -#include "mozilla/Preferences.h" - -using namespace mozilla; +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" // defined in nsChildView.mm extern nsIRollupListener * gRollupListener; @@ -271,8 +269,13 @@ nsToolkit::RegisterForAllProcessMouseEvents() NS_OBJC_BEGIN_TRY_ABORT_BLOCK; // Don't do this for apps that (like Camino) use native context menus. - if (Preferences::GetBool("ui.use_native_popup_windows", PR_FALSE)) { - return; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + PRBool useNativeContextMenus; + nsresult rv = prefs->GetBoolPref("ui.use_native_popup_windows", + &useNativeContextMenus); + if (NS_SUCCEEDED(rv) && useNativeContextMenus) + return; } if (!mEventMonitorHandler) { EventTypeSpec kEvents[] = {{kEventClassMouse, kEventMouseMoved}}; diff --git a/widget/src/gtk2/nsDeviceContextSpecG.cpp b/widget/src/gtk2/nsDeviceContextSpecG.cpp index c84d6686d9f..a840a9a4682 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.cpp +++ b/widget/src/gtk2/nsDeviceContextSpecG.cpp @@ -53,6 +53,8 @@ #include "nsDeviceContextSpecG.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "prenv.h" /* for PR_GetEnv */ #include "nsPrintfCString.h" @@ -69,14 +71,10 @@ #include "nsILocalFile.h" #include "nsTArray.h" -#include "mozilla/Preferences.h" - #include #include #include -using namespace mozilla; - /* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */ #define MAKE_PR_BOOL(val) ((val)?(PR_TRUE):(PR_FALSE)) @@ -195,34 +193,30 @@ private: void SetCharValue( const char *tagname, const char *value ); nsXPIDLCString mPrinterName; + nsCOMPtr mPrefs; }; void nsPrinterFeatures::SetBoolValue( const char *tagname, PRBool value ) { - nsPrintfCString prefName(256, PRINTERFEATURES_PREF ".%s.%s", - mPrinterName.get(), tagname); - Preferences::SetBool(prefName.get(), value); + mPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value); } void nsPrinterFeatures::SetIntValue( const char *tagname, PRInt32 value ) { - nsPrintfCString prefName(256, PRINTERFEATURES_PREF ".%s.%s", - mPrinterName.get(), tagname); - Preferences::SetInt(prefName.get(), value); + mPrefs->SetIntPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value); } void nsPrinterFeatures::SetCharValue( const char *tagname, const char *value ) { - nsPrintfCString prefName(256, PRINTERFEATURES_PREF ".%s.%s", - mPrinterName.get(), tagname); - Preferences::SetCString(prefName.get(), value); + mPrefs->SetCharPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value); } nsPrinterFeatures::nsPrinterFeatures( const char *printername ) { DO_PR_DEBUG_LOG(("nsPrinterFeatures::nsPrinterFeatures('%s')\n", printername)); mPrinterName.Assign(printername); - + mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + SetBoolValue("has_special_printerfeatures", PR_TRUE); } @@ -665,8 +659,8 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::EndDocument() * - Get prefs */ static -nsresult CopyPrinterCharPref(const char *modulename, const char *printername, - const char *prefname, nsCString &return_buf) +nsresult CopyPrinterCharPref(nsIPrefBranch *pref, const char *modulename, const char *printername, + const char *prefname, nsXPIDLCString &return_buf) { DO_PR_DEBUG_LOG(("CopyPrinterCharPref('%s', '%s', '%s')\n", modulename, printername, prefname)); @@ -676,7 +670,7 @@ nsresult CopyPrinterCharPref(const char *modulename, const char *printername, /* Get prefs per printer name and module name */ nsPrintfCString name(512, "print.%s.printer_%s.%s", modulename, printername, prefname); DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = Preferences::GetCString(name.get(), &return_buf); + rv = pref->GetCharPref(name.get(), getter_Copies(return_buf)); } if (NS_FAILED(rv)) { @@ -684,7 +678,7 @@ nsresult CopyPrinterCharPref(const char *modulename, const char *printername, /* Get prefs per printer name */ nsPrintfCString name(512, "print.printer_%s.%s", printername, prefname); DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = Preferences::GetCString(name.get(), &return_buf); + rv = pref->GetCharPref(name.get(), getter_Copies(return_buf)); } if (NS_FAILED(rv)) { @@ -692,14 +686,14 @@ nsresult CopyPrinterCharPref(const char *modulename, const char *printername, /* Get prefs per module name */ nsPrintfCString name(512, "print.%s.%s", modulename, prefname); DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = Preferences::GetCString(name.get(), &return_buf); + rv = pref->GetCharPref(name.get(), getter_Copies(return_buf)); } if (NS_FAILED(rv)) { /* Get prefs */ nsPrintfCString name(512, "print.%s", prefname); DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = Preferences::GetCString(name.get(), &return_buf); + rv = pref->GetCharPref(name.get(), getter_Copies(return_buf)); } } } @@ -775,6 +769,10 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich NS_ENSURE_TRUE(*aPrinterName, NS_ERROR_FAILURE); NS_ENSURE_TRUE(aPrintSettings, NS_ERROR_FAILURE); + nsCOMPtr pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return rv; + nsXPIDLCString fullPrinterName, /* Full name of printer incl. driver-specific prefix */ printerName; /* "Stripped" name of printer */ fullPrinterName.Assign(NS_ConvertUTF16toUTF8(aPrinterName)); @@ -797,16 +795,13 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich #ifdef SET_PRINTER_FEATURES_VIA_PREFS /* Defaults to FALSE */ - nsPrintfCString prefName(256, - PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", - fullPrinterName.get()); - Preferences::SetBool(prefName.get(), PR_FALSE); + pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", fullPrinterName.get()).get(), PR_FALSE); #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ /* Set filename */ - nsCAutoString filename; - if (NS_FAILED(CopyPrinterCharPref(nsnull, printerName, "filename", filename))) { + nsXPIDLCString filename; + if (NS_FAILED(CopyPrinterCharPref(pPrefs, nsnull, printerName, "filename", filename))) { const char *path; if (!(path = PR_GetEnv("PWD"))) @@ -839,9 +834,8 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich printerFeatures.SetCanChangeOrientation(PR_TRUE); #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - nsCAutoString orientation; - if (NS_SUCCEEDED(CopyPrinterCharPref("postscript", printerName, - "orientation", orientation))) { + nsXPIDLCString orientation; + if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "orientation", orientation))) { if (orientation.LowerCaseEqualsLiteral("portrait")) { DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n")); aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation); @@ -897,12 +891,11 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich #ifdef SET_PRINTER_FEATURES_VIA_PREFS printerFeatures.SetCanChangePaperSize(PR_TRUE); #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - nsCAutoString papername; - if (NS_SUCCEEDED(CopyPrinterCharPref("postscript", printerName, - "paper_size", papername))) { + nsXPIDLCString papername; + if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", papername))) { nsPaperSizePS paper; - if (paper.Find(papername.get())) { + if (paper.Find(papername)) { DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g mm/%g mm)\n", paper.Name(), paper.Width_mm(), paper.Height_mm())); aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters); @@ -945,8 +938,8 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ if (hasSpoolerCmd) { - nsCAutoString command; - if (NS_SUCCEEDED(CopyPrinterCharPref("postscript", + nsXPIDLCString command; + if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "print_command", command))) { DO_PR_DEBUG_LOG(("setting default print command to '%s'\n", command.get())); @@ -980,6 +973,11 @@ nsresult GlobalPrinters::InitializeGlobalPrinters () if (!mGlobalPrinterList) return NS_ERROR_OUT_OF_MEMORY; + nsresult rv; + nsCOMPtr pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return rv; + nsPSPrinterList psMgr; if (NS_SUCCEEDED(psMgr.Init()) && psMgr.Enabled()) { /* Get the list of PostScript-module printers */ diff --git a/widget/src/gtk2/nsGtkIMModule.cpp b/widget/src/gtk2/nsGtkIMModule.cpp index 85e85bdc951..5cc0e008311 100644 --- a/widget/src/gtk2/nsGtkIMModule.cpp +++ b/widget/src/gtk2/nsGtkIMModule.cpp @@ -49,16 +49,14 @@ #include "nsGtkIMModule.h" #include "nsWindow.h" -#include "mozilla/Preferences.h" #ifdef MOZ_PLATFORM_MAEMO #include "nsServiceManagerUtils.h" #include "nsIObserverService.h" +#include "nsIPrefService.h" #include "mozilla/Services.h" #endif -using namespace mozilla; - #ifdef PR_LOGGING PRLogModuleInfo* gGtkIMLog = nsnull; @@ -596,11 +594,14 @@ nsGtkIMModule::SetInputMode(nsWindow* aCaller, const IMEContext* aContext) if (mIMEContext.mStatus != nsIWidget::IME_STATUS_DISABLED && mIMEContext.mStatus != nsIWidget::IME_STATUS_PLUGIN) { - PRBool useStrictPolicy = - Preferences::GetBool("content.ime.strict_policy", PR_FALSE); - if (useStrictPolicy && !mIMEContext.FocusMovedByUser() && - mIMEContext.FocusMovedInContentProcess()) { - return NS_OK; + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); + + PRBool useStrictPolicy = PR_FALSE; + if (NS_SUCCEEDED(prefs->GetBoolPref("content.ime.strict_policy", &useStrictPolicy))) { + if (useStrictPolicy && !mIMEContext.FocusMovedByUser() && + mIMEContext.FocusMovedInContentProcess()) { + return NS_OK; + } } } diff --git a/widget/src/gtk2/nsPSPrinters.cpp b/widget/src/gtk2/nsPSPrinters.cpp index d5710faac20..f8c8582efc4 100644 --- a/widget/src/gtk2/nsPSPrinters.cpp +++ b/widget/src/gtk2/nsPSPrinters.cpp @@ -38,19 +38,18 @@ #include "nscore.h" #include "nsCUPSShim.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsPrintfCString.h" #include "nsPSPrinters.h" #include "nsReadableUtils.h" // StringBeginsWith() #include "nsCUPSShim.h" -#include "mozilla/Preferences.h" #include "prlink.h" #include "prenv.h" #include "plstr.h" -using namespace mozilla; - #define NS_CUPS_PRINTER "CUPS/" #define NS_CUPS_PRINTER_LEN (sizeof(NS_CUPS_PRINTER) - 1) @@ -65,12 +64,16 @@ nsPSPrinterList::Init() { nsresult rv; + mPrefSvc = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) + rv = mPrefSvc->GetBranch("print.", getter_AddRefs(mPref)); + NS_ENSURE_SUCCESS(rv, NS_ERROR_NOT_INITIALIZED); + // Should we try cups? - PRBool useCups = - Preferences::GetBool("print.postscript.cups.enabled", PR_TRUE); - if (useCups && !gCupsShim.IsInitialized()) { + PRBool useCups = PR_TRUE; + rv = mPref->GetBoolPref("postscript.cups.enabled", &useCups); + if (useCups && !gCupsShim.IsInitialized()) gCupsShim.Init(); - } return NS_OK; } @@ -84,7 +87,9 @@ nsPSPrinterList::Enabled() return PR_FALSE; // is the PS module enabled? - return Preferences::GetBool("print.postscript.enabled", PR_TRUE); + PRBool setting = PR_TRUE; + mPref->GetBoolPref("postscript.enabled", &setting); + return setting; } @@ -126,10 +131,10 @@ nsPSPrinterList::GetPrinterList(nsTArray& aList) aList.AppendElement( NS_LITERAL_CSTRING(NS_POSTSCRIPT_DRIVER_NAME "default")); - nsCAutoString list(PR_GetEnv("MOZILLA_POSTSCRIPT_PRINTER_LIST")); - if (list.IsEmpty()) { - list = Preferences::GetCString("print.printer_list"); - } + nsXPIDLCString list; + list.Assign(PR_GetEnv("MOZILLA_POSTSCRIPT_PRINTER_LIST")); + if (list.IsEmpty()) + mPref->GetCharPref("printer_list", getter_Copies(list)); if (!list.IsEmpty()) { // For each printer (except "default" which was already added), // construct a string "PostScript/" and append it to the list. diff --git a/widget/src/gtk2/nsPSPrinters.h b/widget/src/gtk2/nsPSPrinters.h index 1bfb8150138..b5cb6ead4cf 100644 --- a/widget/src/gtk2/nsPSPrinters.h +++ b/widget/src/gtk2/nsPSPrinters.h @@ -43,6 +43,8 @@ #include "nsTArray.h" #include "prtypes.h" +class nsIPrefService; +class nsIPrefBranch; class nsCUPSShim; class nsPSPrinterList { @@ -88,6 +90,10 @@ class nsPSPrinterList { * @return The PrinterType value for this name. */ static PrinterType GetPrinterType(const nsACString& aName); + + private: + nsCOMPtr mPrefSvc; + nsCOMPtr mPref; }; #endif /* nsPSPrinters_h___ */ diff --git a/widget/src/gtk2/nsWidgetFactory.cpp b/widget/src/gtk2/nsWidgetFactory.cpp index 34312438370..19641db09d9 100644 --- a/widget/src/gtk2/nsWidgetFactory.cpp +++ b/widget/src/gtk2/nsWidgetFactory.cpp @@ -62,8 +62,8 @@ #include "nsDeviceContextSpecG.h" #endif -#include "mozilla/Preferences.h" - +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsImageToPixbuf.h" #include "nsPrintDialogGTK.h" @@ -81,8 +81,6 @@ #include "nsAutoPtr.h" #include -using namespace mozilla; - /* from nsFilePicker.js */ #define XULFILEPICKER_CID \ { 0x54ae32f8, 0x1dd2, 0x11b2, \ @@ -166,9 +164,17 @@ nsFilePickerConstructor(nsISupports *aOuter, REFNSIID aIID, return NS_ERROR_NO_AGGREGATION; } - PRBool allowPlatformPicker = - Preferences::GetBool("ui.allow_platform_file_picker", PR_TRUE); - + PRBool allowPlatformPicker = PR_TRUE; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + PRBool prefAllow; + nsresult rv = prefs->GetBoolPref("ui.allow_platform_file_picker", + &prefAllow); + if (NS_SUCCEEDED(rv)) { + allowPlatformPicker = prefAllow; + } + } + nsCOMPtr picker; if (allowPlatformPicker && gtk_check_version(2,6,3) == NULL) { picker = new nsFilePicker; diff --git a/widget/src/gtk2/nsWindow.cpp b/widget/src/gtk2/nsWindow.cpp index 6713a0dc4a3..8e40828136b 100644 --- a/widget/src/gtk2/nsWindow.cpp +++ b/widget/src/gtk2/nsWindow.cpp @@ -82,7 +82,6 @@ #include #endif -#include "mozilla/Preferences.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" #include "nsIServiceManager.h" @@ -98,9 +97,6 @@ #include "nsIAccessibleDocument.h" #include "prenv.h" #include "stdlib.h" - -using namespace mozilla; - static PRBool sAccessibilityChecked = PR_FALSE; /* static */ PRBool nsWindow::sAccessibilityEnabled = PR_FALSE; @@ -6155,10 +6151,20 @@ drag_data_received_event_cb(GtkWidget *aWidget, static nsresult initialize_prefs(void) { - gRaiseWindows = - Preferences::GetBool("mozilla.widget.raise-on-setfocus", PR_TRUE); - gDisableNativeTheme = - Preferences::GetBool("mozilla.widget.disable-native-theme", PR_FALSE); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (!prefs) + return NS_OK; + + PRBool val = PR_TRUE; + nsresult rv; + + rv = prefs->GetBoolPref("mozilla.widget.raise-on-setfocus", &val); + if (NS_SUCCEEDED(rv)) + gRaiseWindows = val; + + rv = prefs->GetBoolPref("mozilla.widget.disable-native-theme", &val); + if (NS_SUCCEEDED(rv)) + gDisableNativeTheme = val; return NS_OK; } diff --git a/widget/src/windows/nsTextStore.cpp b/widget/src/windows/nsTextStore.cpp index 457ccfe3e99..26ff1fd5ece 100644 --- a/widget/src/windows/nsTextStore.cpp +++ b/widget/src/windows/nsTextStore.cpp @@ -41,11 +41,10 @@ #include "nscore.h" #include "nsTextStore.h" #include "nsWindow.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "prlog.h" #include "nsPrintfCString.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; /******************************************************************/ /* nsTextStore */ @@ -1332,8 +1331,19 @@ GetLayoutChangeIntervalTime() if (sTime > 0) return PRUint32(sTime); - sTime = NS_MAX(10, - Preferences::GetInt("intl.tsf.on_layout_change_interval", 100)); + sTime = 100; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (!prefs) + return PRUint32(sTime); + nsCOMPtr prefBranch; + prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); + if (!prefBranch) + return PRUint32(sTime); + nsresult rv = + prefBranch->GetIntPref("intl.tsf.on_layout_change_interval", &sTime); + if (NS_FAILED(rv)) + return PRUint32(sTime); + sTime = PR_MAX(10, sTime); return PRUint32(sTime); } @@ -1615,8 +1625,15 @@ nsTextStore::Initialize(void) sTextStoreLog = PR_NewLogModule("nsTextStoreWidgets"); #endif if (!sTsfThreadMgr) { - PRBool enableTsf = - Preferences::GetBool("intl.enable_tsf_support", PR_FALSE); + PRBool enableTsf = PR_TRUE; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + nsCOMPtr prefBranch; + prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); + if (prefBranch && NS_FAILED(prefBranch->GetBoolPref( + "intl.enable_tsf_support", &enableTsf))) + enableTsf = PR_TRUE; + } if (enableTsf) { if (SUCCEEDED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, diff --git a/widget/src/windows/nsWinGesture.cpp b/widget/src/windows/nsWinGesture.cpp index b811666e311..385b75899ec 100644 --- a/widget/src/windows/nsWinGesture.cpp +++ b/widget/src/windows/nsWinGesture.cpp @@ -43,11 +43,11 @@ #include "nscore.h" #include "nsWinGesture.h" #include "nsUXThemeData.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" +#include "nsIServiceManager.h" #include "nsIDOMSimpleGestureEvent.h" #include "nsGUIEvent.h" -#include "mozilla/Preferences.h" - -using namespace mozilla; #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -140,8 +140,17 @@ PRBool nsWinGesture::InitLibrary() // Check to see if we want single finger gesture input. Only do this once // for the app so we don't have to look it up on every window create. - gEnableSingleFingerPanEvents = - Preferences::GetBool("gestures.enable_single_finger_input", PR_FALSE); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + nsCOMPtr prefBranch; + prefs->GetBranch(0, getter_AddRefs(prefBranch)); + if (prefBranch) { + PRBool flag; + if (NS_SUCCEEDED(prefBranch->GetBoolPref("gestures.enable_single_finger_input", &flag)) + && flag) + gEnableSingleFingerPanEvents = PR_TRUE; + } + } return PR_TRUE; } diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 21859e3b741..9b4d3f432ab 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -121,6 +121,9 @@ #include "nsISupportsPrimitives.h" #include "nsIDOMNSUIEvent.h" #include "nsITheme.h" +#include "nsIPrefBranch.h" +#include "nsIPrefBranch2.h" +#include "nsIPrefService.h" #include "nsIObserverService.h" #include "nsIScreenManager.h" #include "imgIContainer.h" @@ -157,7 +160,6 @@ #include "nsWindowGfx.h" #include "gfxWindowsPlatform.h" #include "Layers.h" -#include "mozilla/Preferences.h" #ifdef MOZ_ENABLE_D3D9_LAYER #include "LayerManagerD3D9.h" @@ -210,7 +212,6 @@ using namespace mozilla::widget; using namespace mozilla::layers; -using namespace mozilla; /************************************************************** ************************************************************** @@ -645,13 +646,37 @@ nsWindow::Create(nsIWidget *aParent, // the working set when windows are minimized, but on Vista and up it has // little to no effect. Since this feature has been the source of numerous // bugs over the years, disable it (sTrimOnMinimize=1) on Vista and up. - sTrimOnMinimize = - Preferences::GetBool("config.trim_on_minimize", - (GetWindowsVersion() >= VISTA_VERSION)) ? 1 : 0; - sSwitchKeyboardLayout = - Preferences::GetBool("intl.keyboard.per_window_layout", PR_FALSE); - gDisableNativeTheme = - Preferences::GetBool("mozilla.widget.disable-native-theme", PR_FALSE); + sTrimOnMinimize = 0; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + nsCOMPtr prefBranch; + prefs->GetBranch(0, getter_AddRefs(prefBranch)); + if (prefBranch) { + + PRBool temp; + if (NS_SUCCEEDED(prefBranch->GetBoolPref("config.trim_on_minimize", + &temp))) { + if (temp) { + sTrimOnMinimize = 1; + } + } else if (GetWindowsVersion() >= VISTA_VERSION) { + sTrimOnMinimize = 1; + } + + if (NS_SUCCEEDED(prefBranch->GetBoolPref("intl.keyboard.per_window_layout", + &temp))) + sSwitchKeyboardLayout = temp; + + if (NS_SUCCEEDED(prefBranch->GetBoolPref("mozilla.widget.disable-native-theme", + &temp))) + gDisableNativeTheme = temp; + + if (NS_SUCCEEDED(prefBranch->GetBoolPref("mousewheel.enable_pixel_scrolling", + &temp))) { + sEnablePixelScrolling = temp; + } + } + } } return NS_OK; @@ -3150,14 +3175,17 @@ struct LayerManagerPrefs { static void GetLayerManagerPrefs(LayerManagerPrefs* aManagerPrefs) { - Preferences::GetBool("layers.acceleration.disabled", + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + prefs->GetBoolPref("layers.acceleration.disabled", &aManagerPrefs->mDisableAcceleration); - Preferences::GetBool("layers.acceleration.force-enabled", + prefs->GetBoolPref("layers.acceleration.force-enabled", &aManagerPrefs->mForceAcceleration); - Preferences::GetBool("layers.prefer-opengl", + prefs->GetBoolPref("layers.prefer-opengl", &aManagerPrefs->mPreferOpenGL); - Preferences::GetBool("layers.prefer-d3d9", + prefs->GetBoolPref("layers.prefer-d3d9", &aManagerPrefs->mPreferD3D9); + } const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED"); aManagerPrefs->mAccelerateByDefault = @@ -3329,8 +3357,16 @@ nsWindow::OnDefaultButtonLoaded(const nsIntRect &aButtonRect) return NS_OK; } - PRBool isAlwaysSnapCursor = - Preferences::GetBool("ui.cursor_snapping.always_enabled", PR_FALSE); + PRBool isAlwaysSnapCursor = PR_FALSE; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + nsCOMPtr prefBranch; + prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); + if (prefBranch) { + prefBranch->GetBoolPref("ui.cursor_snapping.always_enabled", + &isAlwaysSnapCursor); + } + } if (!isAlwaysSnapCursor) { BOOL snapDefaultButton; @@ -4625,10 +4661,16 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM &wParam, LPARAM &lParam, // Changing nsIPrefBranch entry which triggers callbacks // and flows into calling mDeviceContext->FlushFontCache() // to update the font cache in all the instance of Browsers - const char* kPrefName = "font.internaluseonly.changed"; - PRBool fontInternalChange = - Preferences::GetBool(kPrefName, PR_FALSE); - Preferences::SetBool(kPrefName, !fontInternalChange); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefs) { + nsCOMPtr fiPrefs; + prefs->GetBranch("font.internaluseonly.", getter_AddRefs(fiPrefs)); + if (fiPrefs) { + PRBool fontInternalChange = PR_FALSE; + fiPrefs->GetBoolPref("changed", &fontInternalChange); + fiPrefs->SetBoolPref("changed", !fontInternalChange); + } + } } } //if (NS_SUCCEEDED(rv)) } @@ -6301,9 +6343,6 @@ nsWindow::InitMouseWheelScrollData() // See the comments for the case sMouseWheelScrollLines > WHEEL_DELTA. sMouseWheelScrollChars = WHEEL_PAGESCROLL; } - - sEnablePixelScrolling = - Preferences::GetBool("mousewheel.enable_pixel_scrolling", PR_TRUE); } /* static */ @@ -7676,8 +7715,15 @@ PRBool nsWindow::OnScroll(UINT aMsg, WPARAM aWParam, LPARAM aLParam) { static PRInt8 sMouseWheelEmulation = -1; if (sMouseWheelEmulation < 0) { - PRBool emulate = - Preferences::GetBool("mousewheel.emulate_at_wm_scroll", PR_FALSE); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + NS_ENSURE_TRUE(prefs, PR_FALSE); + nsCOMPtr prefBranch; + prefs->GetBranch(0, getter_AddRefs(prefBranch)); + NS_ENSURE_TRUE(prefBranch, PR_FALSE); + PRBool emulate; + nsresult rv = + prefBranch->GetBoolPref("mousewheel.emulate_at_wm_scroll", &emulate); + NS_ENSURE_SUCCESS(rv, PR_FALSE); sMouseWheelEmulation = PRInt8(emulate); } @@ -8040,8 +8086,10 @@ nsWindow::GetRootAccessible() static int accForceDisable = -1; if (accForceDisable == -1) { - const char* kPrefName = "accessibility.win32.force_disabled"; - if (Preferences::GetBool(kPrefName, PR_FALSE)) { + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + PRBool b = PR_FALSE; + nsresult rv = prefs->GetBoolPref("accessibility.win32.force_disabled", &b); + if (NS_SUCCEEDED(rv) && b) { accForceDisable = 1; } else { accForceDisable = 0; @@ -8745,11 +8793,17 @@ PRBool nsWindow::CanTakeFocus() void nsWindow::GetMainWindowClass(nsAString& aClass) { - NS_PRECONDITION(aClass.IsEmpty(), "aClass should be empty string"); - nsresult rv = Preferences::GetString("ui.window_class_override", &aClass); - if (NS_FAILED(rv) || aClass.IsEmpty()) { - aClass.AssignASCII(sDefaultMainWindowClass); + nsresult rv; + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv) && prefs) { + nsXPIDLCString name; + rv = prefs->GetCharPref("ui.window_class_override", getter_Copies(name)); + if (NS_SUCCEEDED(rv) && !name.IsEmpty()) { + aClass.AssignASCII(name.get()); + return; + } } + aClass.AssignASCII(sDefaultMainWindowClass); } /** @@ -8769,15 +8823,20 @@ PRBool nsWindow::GetInputWorkaroundPref(const char* aPrefName, return aValueIfAutomatic; } - PRInt32 lHackValue = 0; - if (NS_SUCCEEDED(Preferences::GetInt(aPrefName, &lHackValue))) { - switch (lHackValue) { - case 0: // disabled - return PR_FALSE; - case 1: // enabled - return PR_TRUE; - default: // -1: autodetect - break; + nsresult rv; + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv) && prefs) { + PRInt32 lHackValue; + rv = prefs->GetIntPref(aPrefName, &lHackValue); + if (NS_SUCCEEDED(rv)) { + switch (lHackValue) { + case 0: // disabled + return PR_FALSE; + case 1: // enabled + return PR_TRUE; + default: // -1: autodetect + break; + } } } return aValueIfAutomatic; diff --git a/widget/src/xpwidgets/GfxInfoBase.cpp b/widget/src/xpwidgets/GfxInfoBase.cpp index 2205e938495..15878c7b4c1 100644 --- a/widget/src/xpwidgets/GfxInfoBase.cpp +++ b/widget/src/xpwidgets/GfxInfoBase.cpp @@ -197,14 +197,13 @@ RemovePrefForFeature(PRInt32 aFeature) static bool GetPrefValueForDriverVersion(nsCString& aVersion) { - return NS_SUCCEEDED(Preferences::GetCString(SUGGESTED_VERSION_PREF, - &aVersion)); + return NS_SUCCEEDED(Preferences::GetChar(SUGGESTED_VERSION_PREF, &aVersion)); } static void -SetPrefValueForDriverVersion(const nsAString& aVersion) +SetPrefValueForDriverVersion(const nsString& aVersion) { - Preferences::SetString(SUGGESTED_VERSION_PREF, aVersion); + Preferences::SetChar(SUGGESTED_VERSION_PREF, aVersion); } static void diff --git a/widget/src/xpwidgets/nsPrintOptionsImpl.cpp b/widget/src/xpwidgets/nsPrintOptionsImpl.cpp index 8152eb1289e..cd9e3aadcff 100644 --- a/widget/src/xpwidgets/nsPrintOptionsImpl.cpp +++ b/widget/src/xpwidgets/nsPrintOptionsImpl.cpp @@ -308,7 +308,7 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName, #define GETSTRPREF(_prefname, _retval) \ NS_SUCCEEDED( \ - Preferences::GetString( \ + Preferences::GetChar( \ GetPrefName(_prefname, aPrinterName), _retval \ ) \ ) @@ -623,7 +623,7 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName, DUMP_DBL(kWriteStr, kPrintPaperHeight, height); WritePrefDouble(GetPrefName(kPrintPaperHeight, aPrinterName), height); DUMP_STR(kWriteStr, kPrintPaperName, name); - Preferences::SetString(GetPrefName(kPrintPaperName, aPrinterName), name); + Preferences::SetChar(GetPrefName(kPrintPaperName, aPrinterName), name); } } @@ -652,48 +652,48 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName, if (aFlags & nsIPrintSettings::kInitSaveHeaderLeft) { if (NS_SUCCEEDED(aPS->GetHeaderStrLeft(&uStr))) { DUMP_STR(kWriteStr, kPrintHeaderStrLeft, uStr); - Preferences::SetString(GetPrefName(kPrintHeaderStrLeft, aPrinterName), - uStr); + Preferences::SetChar(GetPrefName(kPrintHeaderStrLeft, aPrinterName), + uStr); } } if (aFlags & nsIPrintSettings::kInitSaveHeaderCenter) { if (NS_SUCCEEDED(aPS->GetHeaderStrCenter(&uStr))) { DUMP_STR(kWriteStr, kPrintHeaderStrCenter, uStr); - Preferences::SetString(GetPrefName(kPrintHeaderStrCenter, aPrinterName), - uStr); + Preferences::SetChar(GetPrefName(kPrintHeaderStrCenter, aPrinterName), + uStr); } } if (aFlags & nsIPrintSettings::kInitSaveHeaderRight) { if (NS_SUCCEEDED(aPS->GetHeaderStrRight(&uStr))) { DUMP_STR(kWriteStr, kPrintHeaderStrRight, uStr); - Preferences::SetString(GetPrefName(kPrintHeaderStrRight, aPrinterName), - uStr); + Preferences::SetChar(GetPrefName(kPrintHeaderStrRight, aPrinterName), + uStr); } } if (aFlags & nsIPrintSettings::kInitSaveFooterLeft) { if (NS_SUCCEEDED(aPS->GetFooterStrLeft(&uStr))) { DUMP_STR(kWriteStr, kPrintFooterStrLeft, uStr); - Preferences::SetString(GetPrefName(kPrintFooterStrLeft, aPrinterName), - uStr); + Preferences::SetChar(GetPrefName(kPrintFooterStrLeft, aPrinterName), + uStr); } } if (aFlags & nsIPrintSettings::kInitSaveFooterCenter) { if (NS_SUCCEEDED(aPS->GetFooterStrCenter(&uStr))) { DUMP_STR(kWriteStr, kPrintFooterStrCenter, uStr); - Preferences::SetString(GetPrefName(kPrintFooterStrCenter, aPrinterName), - uStr); + Preferences::SetChar(GetPrefName(kPrintFooterStrCenter, aPrinterName), + uStr); } } if (aFlags & nsIPrintSettings::kInitSaveFooterRight) { if (NS_SUCCEEDED(aPS->GetFooterStrRight(&uStr))) { DUMP_STR(kWriteStr, kPrintFooterStrRight, uStr); - Preferences::SetString(GetPrefName(kPrintFooterStrRight, aPrinterName), - uStr); + Preferences::SetChar(GetPrefName(kPrintFooterStrRight, aPrinterName), + uStr); } } @@ -728,7 +728,7 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName, if (aFlags & nsIPrintSettings::kInitSavePlexName) { if (NS_SUCCEEDED(aPS->GetPlexName(&uStr))) { DUMP_STR(kWriteStr, kPrintPlexName, uStr); - Preferences::SetString(GetPrefName(kPrintPlexName, aPrinterName), uStr); + Preferences::SetChar(GetPrefName(kPrintPlexName, aPrinterName), uStr); } } @@ -743,15 +743,15 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName, if (aFlags & nsIPrintSettings::kInitSaveColorspace) { if (NS_SUCCEEDED(aPS->GetColorspace(&uStr))) { DUMP_STR(kWriteStr, kPrintColorspace, uStr); - Preferences::SetString(GetPrefName(kPrintColorspace, aPrinterName), uStr); + Preferences::SetChar(GetPrefName(kPrintColorspace, aPrinterName), uStr); } } if (aFlags & nsIPrintSettings::kInitSaveResolutionName) { if (NS_SUCCEEDED(aPS->GetResolutionName(&uStr))) { DUMP_STR(kWriteStr, kPrintResolutionName, uStr); - Preferences::SetString(GetPrefName(kPrintResolutionName, aPrinterName), - uStr); + Preferences::SetChar(GetPrefName(kPrintResolutionName, aPrinterName), + uStr); } } @@ -772,7 +772,7 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName, if (aFlags & nsIPrintSettings::kInitSavePrintCommand) { if (NS_SUCCEEDED(aPS->GetPrintCommand(&uStr))) { DUMP_STR(kWriteStr, kPrintCommand, uStr); - Preferences::SetString(GetPrefName(kPrintCommand, aPrinterName), uStr); + Preferences::SetChar(GetPrefName(kPrintCommand, aPrinterName), uStr); } } @@ -781,7 +781,7 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName, && aPrinterName.IsEmpty()) { if (NS_SUCCEEDED(aPS->GetPrinterName(&uStr))) { DUMP_STR(kWriteStr, kPrinterName, uStr); - Preferences::SetString(kPrinterName, uStr); + Preferences::SetChar(kPrinterName, uStr); } } @@ -795,7 +795,7 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName, if (aFlags & nsIPrintSettings::kInitSaveToFileName) { if (NS_SUCCEEDED(aPS->GetToFileName(&uStr))) { DUMP_STR(kWriteStr, kPrintToFileName, uStr); - Preferences::SetString(GetPrefName(kPrintToFileName, aPrinterName), uStr); + Preferences::SetChar(GetPrefName(kPrintToFileName, aPrinterName), uStr); } } @@ -906,7 +906,7 @@ nsPrintOptions::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName) // Look up the printer from the last print job nsAutoString lastPrinterName; - Preferences::GetString(kPrinterName, &lastPrinterName); + Preferences::GetChar(kPrinterName, &lastPrinterName); if (!lastPrinterName.IsEmpty()) { // Verify it's still a valid printer nsCOMPtr printers; @@ -1096,7 +1096,7 @@ nsPrintOptions::ReadPrefDouble(const char * aPrefId, double& aVal) NS_ENSURE_ARG_POINTER(aPrefId); nsCAutoString str; - nsresult rv = Preferences::GetCString(aPrefId, &str); + nsresult rv = Preferences::GetChar(aPrefId, &str); if (NS_SUCCEEDED(rv) && !str.IsEmpty()) { aVal = atof(str.get()); } @@ -1111,7 +1111,7 @@ nsPrintOptions::WritePrefDouble(const char * aPrefId, double aVal) nsPrintfCString str("%6.2f", aVal); NS_ENSURE_TRUE(!str.IsEmpty(), NS_ERROR_FAILURE); - return Preferences::SetCString(aPrefId, str); + return Preferences::SetChar(aPrefId, str); } void @@ -1119,9 +1119,9 @@ nsPrintOptions::ReadInchesToTwipsPref(const char * aPrefId, PRInt32& aTwips, const char * aMarginPref) { nsCAutoString str; - nsresult rv = Preferences::GetCString(aPrefId, &str); + nsresult rv = Preferences::GetChar(aPrefId, &str); if (NS_FAILED(rv) || str.IsEmpty()) { - rv = Preferences::GetCString(aMarginPref, &str); + rv = Preferences::GetChar(aMarginPref, &str); } if (NS_SUCCEEDED(rv) && !str.IsEmpty()) { nsAutoString justStr; @@ -1143,7 +1143,7 @@ nsPrintOptions::WriteInchesFromTwipsPref(const char * aPrefId, PRInt32 aTwips) nsCAutoString inchesStr; inchesStr.AppendFloat(inches); - Preferences::SetCString(aPrefId, inchesStr); + Preferences::SetChar(aPrefId, inchesStr); } void @@ -1175,7 +1175,7 @@ nsPrintOptions::ReadJustification(const char * aPrefId, PRInt16& aJust, { aJust = aInitValue; nsAutoString justStr; - if (NS_SUCCEEDED(Preferences::GetString(aPrefId, &justStr))) { + if (NS_SUCCEEDED(Preferences::GetChar(aPrefId, &justStr))) { if (justStr.EqualsASCII(kJustRight)) { aJust = nsIPrintSettings::kJustRight; } else if (justStr.EqualsASCII(kJustCenter)) { @@ -1192,15 +1192,15 @@ nsPrintOptions::WriteJustification(const char * aPrefId, PRInt16 aJust) { switch (aJust) { case nsIPrintSettings::kJustLeft: - Preferences::SetCString(aPrefId, kJustLeft); + Preferences::SetChar(aPrefId, kJustLeft); break; case nsIPrintSettings::kJustCenter: - Preferences::SetCString(aPrefId, kJustCenter); + Preferences::SetChar(aPrefId, kJustCenter); break; case nsIPrintSettings::kJustRight: - Preferences::SetCString(aPrefId, kJustRight); + Preferences::SetChar(aPrefId, kJustRight); break; } //switch } diff --git a/widget/src/xpwidgets/nsXPLookAndFeel.cpp b/widget/src/xpwidgets/nsXPLookAndFeel.cpp index 594b481d070..e9a213ebcd9 100644 --- a/widget/src/xpwidgets/nsXPLookAndFeel.cpp +++ b/widget/src/xpwidgets/nsXPLookAndFeel.cpp @@ -259,7 +259,7 @@ void nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName) { nsAutoString colorStr; - nsresult rv = Preferences::GetString(prefName, &colorStr); + nsresult rv = Preferences::GetChar(prefName, &colorStr); if (NS_FAILED(rv)) { return; } @@ -314,7 +314,7 @@ void nsXPLookAndFeel::InitColorFromPref(PRInt32 i) { nsAutoString colorStr; - nsresult rv = Preferences::GetString(sColorPrefs[i], &colorStr); + nsresult rv = Preferences::GetChar(sColorPrefs[i], &colorStr); if (NS_FAILED(rv) || colorStr.IsEmpty()) { return; }