зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset d9717604f007
This commit is contained in:
Родитель
a8e04423d1
Коммит
af87370a53
|
@ -69,7 +69,6 @@
|
||||||
#include "nsIPrefBranch2.h"
|
#include "nsIPrefBranch2.h"
|
||||||
#include "mozilla/AutoRestore.h"
|
#include "mozilla/AutoRestore.h"
|
||||||
#include "nsINode.h"
|
#include "nsINode.h"
|
||||||
#include "nsHashtable.h"
|
|
||||||
|
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
|
|
||||||
|
@ -111,7 +110,6 @@ class nsIScriptContext;
|
||||||
class nsIRunnable;
|
class nsIRunnable;
|
||||||
class nsIInterfaceRequestor;
|
class nsIInterfaceRequestor;
|
||||||
template<class E> class nsCOMArray;
|
template<class E> class nsCOMArray;
|
||||||
template<class K, class V> class nsRefPtrHashtable;
|
|
||||||
struct JSRuntime;
|
struct JSRuntime;
|
||||||
class nsIUGenCategory;
|
class nsIUGenCategory;
|
||||||
class nsIWidget;
|
class nsIWidget;
|
||||||
|
@ -121,7 +119,6 @@ class nsPIDOMEventTarget;
|
||||||
class nsIPresShell;
|
class nsIPresShell;
|
||||||
class nsIXPConnectJSObjectHolder;
|
class nsIXPConnectJSObjectHolder;
|
||||||
class nsPrefOldCallback;
|
class nsPrefOldCallback;
|
||||||
class nsPrefObserverHashKey;
|
|
||||||
#ifdef MOZ_XTF
|
#ifdef MOZ_XTF
|
||||||
class nsIXTFService;
|
class nsIXTFService;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1713,8 +1710,7 @@ private:
|
||||||
|
|
||||||
static nsIPrefBranch2 *sPrefBranch;
|
static nsIPrefBranch2 *sPrefBranch;
|
||||||
// For old compatibility of RegisterPrefCallback
|
// For old compatibility of RegisterPrefCallback
|
||||||
static nsRefPtrHashtable<nsPrefObserverHashKey, nsPrefOldCallback>
|
static nsCOMArray<nsPrefOldCallback> *sPrefCallbackList;
|
||||||
*sPrefCallbackTable;
|
|
||||||
|
|
||||||
static bool sImgLoaderInitialized;
|
static bool sImgLoaderInitialized;
|
||||||
static void InitImgLoader();
|
static void InitImgLoader();
|
||||||
|
|
|
@ -262,8 +262,7 @@ PRBool nsContentUtils::sIsHandlingKeyBoardEvent = PR_FALSE;
|
||||||
|
|
||||||
PRBool nsContentUtils::sInitialized = PR_FALSE;
|
PRBool nsContentUtils::sInitialized = PR_FALSE;
|
||||||
|
|
||||||
nsRefPtrHashtable<nsPrefObserverHashKey, nsPrefOldCallback>
|
nsCOMArray<nsPrefOldCallback> *nsContentUtils::sPrefCallbackList = nsnull;
|
||||||
*nsContentUtils::sPrefCallbackTable = nsnull;
|
|
||||||
|
|
||||||
static PLDHashTable sEventListenerManagersHash;
|
static PLDHashTable sEventListenerManagersHash;
|
||||||
|
|
||||||
|
@ -314,95 +313,39 @@ class nsSameOriginChecker : public nsIChannelEventSink,
|
||||||
NS_DECL_NSIINTERFACEREQUESTOR
|
NS_DECL_NSIINTERFACEREQUESTOR
|
||||||
};
|
};
|
||||||
|
|
||||||
class nsPrefObserverHashKey : public PLDHashEntryHdr {
|
|
||||||
public:
|
|
||||||
typedef nsPrefObserverHashKey* KeyType;
|
|
||||||
typedef const nsPrefObserverHashKey* KeyTypePointer;
|
|
||||||
|
|
||||||
static const nsPrefObserverHashKey* KeyToPointer(nsPrefObserverHashKey *aKey)
|
|
||||||
{
|
|
||||||
return aKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PLDHashNumber HashKey(const nsPrefObserverHashKey *aKey)
|
|
||||||
{
|
|
||||||
PRUint32 strHash = nsCRT::HashCode(aKey->mPref.BeginReading(),
|
|
||||||
aKey->mPref.Length());
|
|
||||||
return PR_ROTATE_LEFT32(strHash, 4) ^
|
|
||||||
NS_PTR_TO_UINT32(aKey->mCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsPrefObserverHashKey(const char *aPref, PrefChangedFunc aCallback) :
|
|
||||||
mPref(aPref), mCallback(aCallback) { }
|
|
||||||
|
|
||||||
nsPrefObserverHashKey(const nsPrefObserverHashKey *aOther) :
|
|
||||||
mPref(aOther->mPref), mCallback(aOther->mCallback)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
PRBool KeyEquals(const nsPrefObserverHashKey *aOther) const
|
|
||||||
{
|
|
||||||
return mCallback == aOther->mCallback &&
|
|
||||||
mPref.Equals(aOther->mPref);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsPrefObserverHashKey *GetKey() const
|
|
||||||
{
|
|
||||||
return const_cast<nsPrefObserverHashKey*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum { ALLOW_MEMMOVE = PR_TRUE };
|
|
||||||
|
|
||||||
public:
|
|
||||||
nsCString mPref;
|
|
||||||
PrefChangedFunc mCallback;
|
|
||||||
};
|
|
||||||
|
|
||||||
// For nsContentUtils::RegisterPrefCallback/UnregisterPrefCallback
|
// For nsContentUtils::RegisterPrefCallback/UnregisterPrefCallback
|
||||||
class nsPrefOldCallback : public nsIObserver,
|
class nsPrefOldCallback : public nsIObserver
|
||||||
public nsPrefObserverHashKey
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
NS_DECL_NSIOBSERVER
|
NS_DECL_NSIOBSERVER
|
||||||
|
|
||||||
public:
|
public:
|
||||||
nsPrefOldCallback(const char *aPref, PrefChangedFunc aCallback)
|
nsPrefOldCallback(const char *aPref, PrefChangedFunc aCallback, void *aClosure) : mPref(aPref), mCallback(aCallback), mClosure(aClosure) {
|
||||||
: nsPrefObserverHashKey(aPref, aCallback) { }
|
|
||||||
|
|
||||||
~nsPrefOldCallback() {
|
|
||||||
nsContentUtils::GetPrefBranch()->RemoveObserver(mPref.get(), this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppendClosure(void *aClosure) {
|
PRBool IsEqual(const char *aPref, PrefChangedFunc aCallback, void *aClosure) {
|
||||||
mClosures.AppendElement(aClosure);
|
return aCallback == mCallback &&
|
||||||
}
|
aClosure == mClosure &&
|
||||||
|
mPref.Equals(aPref);
|
||||||
void RemoveClosure(void *aClosure) {
|
|
||||||
mClosures.RemoveElement(aClosure);
|
|
||||||
}
|
|
||||||
|
|
||||||
PRBool HasNoClosures() {
|
|
||||||
return mClosures.Length() == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
nsTObserverArray<void *> mClosures;
|
nsCString mPref;
|
||||||
|
PrefChangedFunc mCallback;
|
||||||
|
void *mClosure;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS1(nsPrefOldCallback, nsIObserver)
|
NS_IMPL_ISUPPORTS1(nsPrefOldCallback, nsIObserver)
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsPrefOldCallback::Observe(nsISupports *aSubject,
|
nsPrefOldCallback::Observe(nsISupports *aSubject,
|
||||||
const char *aTopic,
|
const char *aTopic,
|
||||||
const PRUnichar *aData)
|
const PRUnichar *aData)
|
||||||
{
|
{
|
||||||
NS_ASSERTION(!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID),
|
NS_ASSERTION(!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID),
|
||||||
"invalid topic");
|
"invalid topic");
|
||||||
NS_LossyConvertUTF16toASCII data(aData);
|
mCallback(NS_LossyConvertUTF16toASCII(aData).get(), mClosure);
|
||||||
nsTObserverArray<void *>::ForwardIterator iter(mClosures);
|
|
||||||
while (iter.HasMore()) {
|
|
||||||
mCallback(data.get(), iter.GetNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -1109,9 +1052,16 @@ nsContentUtils::Shutdown()
|
||||||
NS_IF_RELEASE(sStringBundles[i]);
|
NS_IF_RELEASE(sStringBundles[i]);
|
||||||
|
|
||||||
// Clean up c-style's observer
|
// Clean up c-style's observer
|
||||||
if (sPrefCallbackTable) {
|
if (sPrefCallbackList) {
|
||||||
delete sPrefCallbackTable;
|
while (sPrefCallbackList->Count() > 0) {
|
||||||
sPrefCallbackTable = nsnull;
|
nsRefPtr<nsPrefOldCallback> callback = (*sPrefCallbackList)[0];
|
||||||
|
NS_ABORT_IF_FALSE(callback, "Invalid c-style callback is appended");
|
||||||
|
if (sPrefBranch)
|
||||||
|
sPrefBranch->RemoveObserver(callback->mPref.get(), callback);
|
||||||
|
sPrefCallbackList->RemoveObject(callback);
|
||||||
|
}
|
||||||
|
delete sPrefCallbackList;
|
||||||
|
sPrefCallbackList = nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete sPrefCacheData;
|
delete sPrefCacheData;
|
||||||
|
@ -2670,8 +2620,8 @@ nsContentUtils::GetStringPref(const char *aPref)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterPrefCallback/UnregisterPrefCallback are for backward compatiblity
|
// RegisterPrefCallback/UnregisterPrefCallback are backward compatiblity for
|
||||||
// with c-style observers.
|
// c-style observer.
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void
|
void
|
||||||
|
@ -2680,24 +2630,20 @@ nsContentUtils::RegisterPrefCallback(const char *aPref,
|
||||||
void * aClosure)
|
void * aClosure)
|
||||||
{
|
{
|
||||||
if (sPrefBranch) {
|
if (sPrefBranch) {
|
||||||
if (!sPrefCallbackTable) {
|
if (!sPrefCallbackList) {
|
||||||
sPrefCallbackTable =
|
sPrefCallbackList = new nsCOMArray<nsPrefOldCallback> ();
|
||||||
new nsRefPtrHashtable<nsPrefObserverHashKey, nsPrefOldCallback>();
|
if (!sPrefCallbackList)
|
||||||
sPrefCallbackTable->Init();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsPrefObserverHashKey hashKey(aPref, aCallback);
|
nsPrefOldCallback *callback = new nsPrefOldCallback(aPref, aCallback, aClosure);
|
||||||
nsRefPtr<nsPrefOldCallback> callback;
|
|
||||||
sPrefCallbackTable->Get(&hashKey, getter_AddRefs(callback));
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback->AppendClosure(aClosure);
|
if (NS_SUCCEEDED(sPrefBranch->AddObserver(aPref, callback, PR_FALSE))) {
|
||||||
return;
|
sPrefCallbackList->AppendObject(callback);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
callback = new nsPrefOldCallback(aPref, aCallback);
|
// error to get/add nsIPrefBranch2. Destroy callback information
|
||||||
callback->AppendClosure(aClosure);
|
delete callback;
|
||||||
if (NS_SUCCEEDED(sPrefBranch->AddObserver(aPref, callback, PR_FALSE))) {
|
|
||||||
sPrefCallbackTable->Put(callback, callback);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2709,19 +2655,16 @@ nsContentUtils::UnregisterPrefCallback(const char *aPref,
|
||||||
void * aClosure)
|
void * aClosure)
|
||||||
{
|
{
|
||||||
if (sPrefBranch) {
|
if (sPrefBranch) {
|
||||||
if (!sPrefCallbackTable) {
|
if (!sPrefCallbackList)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
nsPrefObserverHashKey hashKey(aPref, aCallback);
|
int i;
|
||||||
nsRefPtr<nsPrefOldCallback> callback;
|
for (i = 0; i < sPrefCallbackList->Count(); i++) {
|
||||||
sPrefCallbackTable->Get(&hashKey, getter_AddRefs(callback));
|
nsRefPtr<nsPrefOldCallback> callback = (*sPrefCallbackList)[i];
|
||||||
|
if (callback && callback->IsEqual(aPref, aCallback, aClosure)) {
|
||||||
if (callback) {
|
sPrefBranch->RemoveObserver(aPref, callback);
|
||||||
callback->RemoveClosure(aClosure);
|
sPrefCallbackList->RemoveObject(callback);
|
||||||
if (callback->HasNoClosures()) {
|
return;
|
||||||
// Delete the callback since its list of closures is empty.
|
|
||||||
sPrefCallbackTable->Remove(callback);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -852,9 +852,9 @@ PREF_UnregisterCallback(const char *pref_node,
|
||||||
|
|
||||||
while (node != NULL)
|
while (node != NULL)
|
||||||
{
|
{
|
||||||
if ( node->func == callback &&
|
if ( strcmp(node->domain, pref_node) == 0 &&
|
||||||
node->data == instance_data &&
|
node->func == callback &&
|
||||||
strcmp(node->domain, pref_node) == 0)
|
node->data == instance_data)
|
||||||
{
|
{
|
||||||
if (gCallbacksInProgress)
|
if (gCallbacksInProgress)
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче