Backout Bug 182954 - Content should use the newer nsIPrefService APIs instead of nsIPref

This commit is contained in:
Makoto Kato 2009-10-26 21:53:41 +09:00
parent b2c357067f
commit 5cbf59e915
2 changed files with 13 additions and 109 deletions

View File

@ -46,6 +46,7 @@
#include "jsnum.h"
#include "nsAString.h"
#include "nsIStatefulFrame.h"
#include "nsIPref.h"
#include "nsINodeInfo.h"
#include "nsNodeInfoManager.h"
#include "nsContentList.h"
@ -59,7 +60,6 @@
#include "nsTArray.h"
#include "nsTextFragment.h"
#include "nsReadableUtils.h"
#include "nsIPrefBranch.h"
struct nsNativeKeyEvent; // Don't include nsINativeKeyBindings.h here: it will force strange compilation error!
@ -99,6 +99,7 @@ class nsIScriptContext;
class nsIRunnable;
class nsIInterfaceRequestor;
template<class E> class nsCOMArray;
class nsIPref;
struct JSRuntime;
class nsICaseConversion;
class nsIUGenCategory;
@ -108,7 +109,6 @@ class nsPIDOMWindow;
class nsPIDOMEventTarget;
class nsIPresShell;
class nsIXPConnectJSObjectHolder;
class nsPrefOldCallback;
#ifdef MOZ_XTF
class nsIXTFService;
#endif
@ -117,11 +117,6 @@ class nsIBidiKeyboard;
#endif
class nsIMIMEHeaderParam;
#ifndef have_PrefChangedFunc_typedef
typedef int (*PR_CALLBACK PrefChangedFunc)(const char *, void *);
#define have_PrefChangedFunc_typedef
#endif
extern const char kLoadAsData[];
enum EventNameType {
@ -1542,9 +1537,8 @@ private:
#endif
static nsIPrefBranch *sPrefBranch;
// For old compatibility of RegisterPrefCallback
// 85-96 callbacks are registered at start up by default
static nsAutoTArray<nsPrefOldCallback*,96> *sPrefCallbackList;
static nsIPref *sPref;
static imgILoader* sImgLoader;
static imgICache* sImgCache;

View File

@ -49,7 +49,6 @@
#include "nsUnicharUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIPrefLocalizedString.h"
#include "nsServiceManagerUtils.h"
#include "nsIScriptGlobalObject.h"
@ -200,6 +199,7 @@ nsIIOService *nsContentUtils::sIOService;
nsIXTFService *nsContentUtils::sXTFService = nsnull;
#endif
nsIPrefBranch *nsContentUtils::sPrefBranch = nsnull;
nsIPref *nsContentUtils::sPref = nsnull;
imgILoader *nsContentUtils::sImgLoader;
imgICache *nsContentUtils::sImgCache;
nsIConsoleService *nsContentUtils::sConsoleService;
@ -230,8 +230,6 @@ JSRuntime *nsAutoGCRoot::sJSScriptRuntime;
PRBool nsContentUtils::sInitialized = PR_FALSE;
nsAutoTArray<nsPrefOldCallback*,96> *nsContentUtils::sPrefCallbackList = nsnull;
static PLDHashTable sEventListenerManagersHash;
class EventListenerManagerMapEntry : public PLDHashEntryHdr
@ -281,43 +279,6 @@ class nsSameOriginChecker : public nsIChannelEventSink,
NS_DECL_NSIINTERFACEREQUESTOR
};
// For nsContentUtils::RegisterPrefCallback/UnregisterPrefCallback
class nsPrefOldCallback : public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
public:
nsPrefOldCallback(const char *aPref, PrefChangedFunc aCallback, void *aClosure) : mPref(aPref), mCallback(aCallback), mClosure(aClosure) {
}
PRBool IsEqual(const char *aPref, PrefChangedFunc aCallback, void *aClosure) {
return mPref.Equals(aPref) &&
aCallback == mCallback &&
aClosure == mClosure;
}
public:
nsCString mPref;
PrefChangedFunc mCallback;
void *mClosure;
};
NS_IMPL_ISUPPORTS1(nsPrefOldCallback, nsIObserver)
NS_IMETHODIMP
nsPrefOldCallback::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
NS_ASSERTION(!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID),
"invalid topic");
mCallback(NS_LossyConvertUTF16toASCII(aData).get(), mClosure);
return NS_OK;
}
// static
nsresult
nsContentUtils::Init()
@ -335,6 +296,9 @@ nsContentUtils::Init()
// It's ok to not have a pref service.
CallGetService(NS_PREFSERVICE_CONTRACTID, &sPrefBranch);
// It's ok to not have prefs too.
CallGetService(NS_PREF_CONTRACTID, &sPref);
rv = NS_GetNameSpaceManager(&sNameSpaceManager);
NS_ENSURE_SUCCESS(rv, rv);
@ -918,24 +882,6 @@ nsContentUtils::Shutdown()
PRUint32 i;
for (i = 0; i < PropertiesFile_COUNT; ++i)
NS_IF_RELEASE(sStringBundles[i]);
// Clean up c-style's observer for compatibility
if (sPrefCallbackList) {
nsCOMPtr<nsIPrefBranch2> prefBranch = do_QueryInterface(sPrefBranch);
PRUint32 count = sPrefCallbackList->Length();
if (prefBranch) {
nsPrefOldCallback *callback;
for (i = 0; i < count; i++) {
callback = sPrefCallbackList->ElementAt(i);
prefBranch->RemoveObserver(callback->mPref.get(), callback);
}
}
delete sPrefCallbackList;
sPrefCallbackList = nsnull;
}
NS_IF_RELEASE(sStringBundleService);
NS_IF_RELEASE(sConsoleService);
NS_IF_RELEASE(sDOMScriptObjectFactory);
@ -956,6 +902,7 @@ nsContentUtils::Shutdown()
NS_IF_RELEASE(sImgLoader);
NS_IF_RELEASE(sImgCache);
NS_IF_RELEASE(sPrefBranch);
NS_IF_RELEASE(sPref);
#ifdef IBMBIDI
NS_IF_RELEASE(sBidiKeyboard);
#endif
@ -2681,34 +2628,14 @@ nsContentUtils::GetStringPref(const char *aPref)
return result;
}
// RegisterPrefCallback/UnregisterPrefCallback are departured API
// for old compatibility.
//
// We should not use this in new code. Use nsIPrefBranch2::AddObserver().
// static
void
nsContentUtils::RegisterPrefCallback(const char *aPref,
PrefChangedFunc aCallback,
void * aClosure)
{
if (sPrefCallbackList == nsnull) {
sPrefCallbackList = new nsAutoTArray<nsPrefOldCallback*,96> ();
if (sPrefCallbackList == nsnull)
return;
}
nsPrefOldCallback *callback = new nsPrefOldCallback(aPref, aCallback, aClosure);
if (callback) {
nsCOMPtr<nsIPrefBranch2> prefBranch = do_QueryInterface(sPrefBranch);
if (prefBranch) {
if (NS_SUCCEEDED(prefBranch->AddObserver(aPref, callback, PR_FALSE))) {
sPrefCallbackList->AppendElement(callback);
return;
}
}
delete callback;
}
if (sPref)
sPref->RegisterCallback(aPref, aCallback, aClosure);
}
// static
@ -2717,25 +2644,8 @@ nsContentUtils::UnregisterPrefCallback(const char *aPref,
PrefChangedFunc aCallback,
void * aClosure)
{
if (!sPrefCallbackList)
return;
PRUint32 count = sPrefCallbackList->Length();
PRUint32 i;
nsPrefOldCallback *callback;
for (i = 0; i < count; i++) {
callback = sPrefCallbackList->ElementAt(i);
if (callback) {
if (callback->IsEqual(aPref, aCallback, aClosure)) {
sPrefCallbackList->RemoveElementAt(i);
nsCOMPtr<nsIPrefBranch2> prefBranch = do_QueryInterface(sPrefBranch);
if (prefBranch)
prefBranch->RemoveObserver(aPref, callback);
return;
}
}
}
if (sPref)
sPref->UnregisterCallback(aPref, aCallback, aClosure);
}
static int