Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
Bug 659821 Replace nsContentUtils::GetLocalizedStringPref() with Pref…
Browse files Browse the repository at this point in the history
…erences::GetLocalizedC?String() r=roc
  • Loading branch information
masayuki-nakano committed May 27, 2011
1 parent 1f17199 commit 387ea6f
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 52 deletions.
1 change: 0 additions & 1 deletion content/base/public/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ class nsContentUtils
static void SplitExpatName(const PRUnichar *aExpatName, nsIAtom **aPrefix,
nsIAtom **aTagName, PRInt32 *aNameSpaceID);

static nsAdoptingString GetLocalizedStringPref(const char *aPref);
static void RegisterPrefCallback(const char *aPref,
PrefChangedFunc aCallback,
void * aClosure);
Expand Down
20 changes: 1 addition & 19 deletions content/base/src/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2597,24 +2597,6 @@ nsContentUtils::IsDraggableLink(const nsIContent* aContent) {
return aContent->IsLink(getter_AddRefs(absURI));
}

// static
nsAdoptingString
nsContentUtils::GetLocalizedStringPref(const char *aPref)
{
nsAdoptingString result;

if (sPrefBranch) {
nsCOMPtr<nsIPrefLocalizedString> prefLocalString;
sPrefBranch->GetComplexValue(aPref, NS_GET_IID(nsIPrefLocalizedString),
getter_AddRefs(prefLocalString));
if (prefLocalString) {
prefLocalString->GetData(getter_Copies(result));
}
}

return result;
}

// RegisterPrefCallback/UnregisterPrefCallback are for backward compatiblity
// with c-style observers.

Expand Down Expand Up @@ -4444,7 +4426,7 @@ nsContentUtils::GetLocalizedEllipsis()
{
static PRUnichar sBuf[4] = { 0, 0, 0, 0 };
if (!sBuf[0]) {
nsAutoString tmp(GetLocalizedStringPref("intl.ellipsis"));
nsAdoptingString tmp = Preferences::GetLocalizedString("intl.ellipsis");
PRUint32 len = NS_MIN(PRUint32(tmp.Length()),
PRUint32(NS_ARRAY_LENGTH(sBuf) - 1));
CopyUnicodeTo(tmp, 0, sBuf, len);
Expand Down
7 changes: 4 additions & 3 deletions content/base/src/nsDOMFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "nsStringStream.h"
#include "CheckedInt.h"
#include "nsJSUtils.h"
#include "mozilla/Preferences.h"

#include "plbase64.h"
#include "prmem.h"
Expand Down Expand Up @@ -499,12 +500,12 @@ nsDOMFile::GuessCharset(nsIInputStream *aStream,
"universal_charset_detector");
if (!detector) {
// No universal charset detector, try the default charset detector
const nsAdoptingString& detectorName =
nsContentUtils::GetLocalizedStringPref("intl.charset.detector");
const nsAdoptingCString& detectorName =
Preferences::GetLocalizedCString("intl.charset.detector");
if (!detectorName.IsEmpty()) {
nsCAutoString detectorContractID;
detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE);
AppendUTF16toUTF8(detectorName, detectorContractID);
detectorContractID += detectorName;
detector = do_CreateInstance(detectorContractID.get());
}
}
Expand Down
9 changes: 6 additions & 3 deletions content/base/src/nsDOMFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
#include "nsLayoutStatics.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsFileDataProtocolHandler.h"
#include "mozilla/Preferences.h"

using namespace mozilla;

#define LOAD_STR "load"
#define ERROR_STR "error"
Expand Down Expand Up @@ -684,12 +687,12 @@ nsDOMFileReader::GuessCharset(const char *aFileData,
"universal_charset_detector");
if (!detector) {
// No universal charset detector, try the default charset detector
const nsAdoptingString& detectorName =
nsContentUtils::GetLocalizedStringPref("intl.charset.detector");
const nsAdoptingCString& detectorName =
Preferences::GetLocalizedCString("intl.charset.detector");
if (!detectorName.IsEmpty()) {
nsCAutoString detectorContractID;
detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE);
AppendUTF16toUTF8(detectorName, detectorContractID);
detectorContractID += detectorName;
detector = do_CreateInstance(detectorContractID.get());
}
}
Expand Down
24 changes: 12 additions & 12 deletions content/html/document/src/nsHTMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@
#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
Expand Down Expand Up @@ -184,14 +186,13 @@ static PRBool ConvertToMidasInternalCommand(const nsAString & inCommandID,
static int
MyPrefChangedCallback(const char*aPrefName, void* instance_data)
{
const nsAdoptingString& detector_name =
nsContentUtils::GetLocalizedStringPref("intl.charset.detector");
const nsAdoptingCString& detector_name =
Preferences::GetLocalizedCString("intl.charset.detector");

if (detector_name.Length() > 0) {
if (!detector_name.IsEmpty()) {
PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE,
DETECTOR_CONTRACTID_MAX);
PL_strncat(g_detector_contractid,
NS_ConvertUTF16toUTF8(detector_name).get(),
PL_strncat(g_detector_contractid, detector_name,
DETECTOR_CONTRACTID_MAX);
gPlugDetector = PR_TRUE;
} else {
Expand Down Expand Up @@ -542,11 +543,11 @@ nsHTMLDocument::UseWeakDocTypeDefault(PRInt32& aCharsetSource,
// fallback value in case docshell return error
aCharset.AssignLiteral("ISO-8859-1");

const nsAdoptingString& defCharset =
nsContentUtils::GetLocalizedStringPref("intl.charset.default");
const nsAdoptingCString& defCharset =
Preferences::GetLocalizedCString("intl.charset.default");

if (!defCharset.IsEmpty()) {
LossyCopyUTF16toASCII(defCharset, aCharset);
aCharset = defCharset;
aCharsetSource = kCharsetFromWeakDocTypeDefault;
}
return PR_TRUE;
Expand Down Expand Up @@ -588,14 +589,13 @@ nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell, nsACString& aCharset,

nsresult rv_detect;
if(!gInitDetector) {
const nsAdoptingString& detector_name =
nsContentUtils::GetLocalizedStringPref("intl.charset.detector");
const nsAdoptingCString& detector_name =
Preferences::GetLocalizedCString("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,
NS_ConvertUTF16toUTF8(detector_name).get(),
PL_strncat(g_detector_contractid, detector_name,
DETECTOR_CONTRACTID_MAX);
gPlugDetector = PR_TRUE;
}
Expand Down
5 changes: 4 additions & 1 deletion content/svg/content/src/nsSVGFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
#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)
Expand Down Expand Up @@ -239,7 +242,7 @@ nsSVGFeatures::PassesConditionalProcessingTests(nsIContent *aContent,
value)) {

const nsAutoString acceptLangs(aAcceptLangs ? *aAcceptLangs :
nsContentUtils::GetLocalizedStringPref("intl.accept_languages"));
Preferences::GetLocalizedString("intl.accept_languages"));

// Get our language preferences
if (!acceptLangs.IsEmpty()) {
Expand Down
5 changes: 4 additions & 1 deletion content/svg/content/src/nsSVGSwitchElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include "nsIFrame.h"
#include "nsISVGChildFrame.h"
#include "nsSVGUtils.h"
#include "mozilla/Preferences.h"

using namespace mozilla;

////////////////////////////////////////////////////////////////////////
// implementation
Expand Down Expand Up @@ -162,7 +165,7 @@ nsSVGSwitchElement::FindActiveChild() const
nsGkAtoms::yes, eCaseMatters);

const nsAdoptingString& acceptLangs =
nsContentUtils::GetLocalizedStringPref("intl.accept_languages");
Preferences::GetLocalizedString("intl.accept_languages");

PRUint32 count = GetChildCount();

Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5007,7 +5007,7 @@ nsGlobalWindow::Home()
return NS_OK;

nsAdoptingString homeURL =
nsContentUtils::GetLocalizedStringPref(PREF_BROWSER_STARTUP_HOMEPAGE);
Preferences::GetLocalizedString(PREF_BROWSER_STARTUP_HOMEPAGE);

if (homeURL.IsEmpty()) {
// if all else fails, use this
Expand Down Expand Up @@ -10691,7 +10691,7 @@ nsNavigator::GetLanguage(nsAString& aLanguage)
{
// e.g. "de-de, en-us,en"
const nsAdoptingString& acceptLang =
nsContentUtils::GetLocalizedStringPref("intl.accept_languages");
Preferences::GetLocalizedString("intl.accept_languages");
// take everything before the first "," or ";", without trailing space
nsCharSeparatedTokenizer langTokenizer(acceptLang, ',');
const nsSubstring &firstLangPart = langTokenizer.nextToken();
Expand Down
14 changes: 9 additions & 5 deletions layout/base/nsDocumentViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "nsLayoutCID.h"
#include "nsContentUtils.h"
#include "nsLayoutStylesheetCache.h"
#include "mozilla/Preferences.h"

#include "nsViewsCID.h"
#include "nsIDeviceContextSpec.h"
Expand Down Expand Up @@ -195,6 +196,8 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
//switch to page layout
#include "nsGfxCIID.h"

using namespace mozilla;

#ifdef NS_DEBUG

#undef NOISY_VIEWER
Expand Down Expand Up @@ -2992,13 +2995,14 @@ DocumentViewerImpl::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet)
{
if (mDefaultCharacterSet.IsEmpty())
{
const nsAdoptingString& defCharset =
nsContentUtils::GetLocalizedStringPref("intl.charset.default");
const nsAdoptingCString& defCharset =
Preferences::GetLocalizedCString("intl.charset.default");

if (!defCharset.IsEmpty())
LossyCopyUTF16toASCII(defCharset, mDefaultCharacterSet);
else
if (!defCharset.IsEmpty()) {
mDefaultCharacterSet = defCharset;
} else {
mDefaultCharacterSet.AssignLiteral("ISO-8859-1");
}
}
aDefaultCharacterSet = mDefaultCharacterSet;
return NS_OK;
Expand Down
7 changes: 5 additions & 2 deletions layout/xul/base/src/nsTextBoxFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@
#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"
Expand Down Expand Up @@ -182,7 +185,7 @@ nsTextBoxFrame::AlwaysAppendAccessKey()
gAccessKeyPrefInitialized = PR_TRUE;

const char* prefName = "intl.menuitems.alwaysappendaccesskeys";
nsAdoptingString val = nsContentUtils::GetLocalizedStringPref(prefName);
nsAdoptingString val = Preferences::GetLocalizedString(prefName);
gAlwaysAppendAccessKey = val.Equals(NS_LITERAL_STRING("true"));
}
return gAlwaysAppendAccessKey;
Expand All @@ -196,7 +199,7 @@ nsTextBoxFrame::InsertSeparatorBeforeAccessKey()
gInsertSeparatorPrefInitialized = PR_TRUE;

const char* prefName = "intl.menuitems.insertseparatorbeforeaccesskeys";
nsAdoptingString val = nsContentUtils::GetLocalizedStringPref(prefName);
nsAdoptingString val = Preferences::GetLocalizedString(prefName);
gInsertSeparatorBeforeAccessKey = val.EqualsLiteral("true");
}
return gInsertSeparatorBeforeAccessKey;
Expand Down
9 changes: 6 additions & 3 deletions parser/html/nsHtml5StreamParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
#include "nsHtml5Module.h"
#include "nsHtml5RefPtr.h"
#include "nsIScriptError.h"
#include "mozilla/Preferences.h"

using namespace mozilla;

static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);

Expand Down Expand Up @@ -200,12 +203,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 nsAdoptingString& detectorName =
nsContentUtils::GetLocalizedStringPref("intl.charset.detector");
const nsAdoptingCString& detectorName =
Preferences::GetLocalizedCString("intl.charset.detector");
if (!detectorName.IsEmpty()) {
nsCAutoString detectorContractID;
detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE);
AppendUTF16toUTF8(detectorName, detectorContractID);
detectorContractID += detectorName;
if ((mChardet = do_CreateInstance(detectorContractID.get()))) {
(void) mChardet->Init(this);
mFeedChardet = PR_TRUE;
Expand Down

0 comments on commit 387ea6f

Please sign in to comment.