зеркало из https://github.com/mozilla/pjs.git
Bug 225400
Fix leaks of 2 string bundles and an nsInterfaceHashtable. Stop using nsIPref in favor of nsIPrefService Use members instead of pointers for hashtables that always exist Use ContractIDs instead of CIDs r=timeless; sr=jst
This commit is contained in:
Родитель
f539414ef8
Коммит
6a65269048
|
@ -51,7 +51,8 @@
|
|||
#include "nsIDOMWindow.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
@ -61,16 +62,12 @@
|
|||
* see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
|
||||
*/
|
||||
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
||||
nsIStringBundle *nsAccessNode::gStringBundle = 0;
|
||||
nsIStringBundle *nsAccessNode::gKeyStringBundle = 0;
|
||||
nsIDOMNode *nsAccessNode::gLastFocusedNode = 0;
|
||||
PRBool nsAccessNode::gIsAccessibilityActive = PR_FALSE;
|
||||
PRBool nsAccessNode::gIsCacheDisabled = PR_FALSE;
|
||||
|
||||
nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> *nsAccessNode::gGlobalDocAccessibleCache = nsnull;
|
||||
nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> nsAccessNode::gGlobalDocAccessibleCache;
|
||||
|
||||
/*
|
||||
* Class nsAccessNode
|
||||
|
@ -175,24 +172,24 @@ void nsAccessNode::InitXPAccessibility()
|
|||
if (gIsAccessibilityActive) {
|
||||
return;
|
||||
}
|
||||
nsCOMPtr<nsIStringBundleService> stringBundleService(do_GetService(kStringBundleServiceCID));
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> stringBundleService =
|
||||
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
||||
if (stringBundleService) {
|
||||
// Static variables are released in ShutdownAllXPAccessibility();
|
||||
stringBundleService->CreateBundle(ACCESSIBLE_BUNDLE_URL,
|
||||
&gStringBundle);
|
||||
NS_IF_ADDREF(gStringBundle);
|
||||
stringBundleService->CreateBundle(PLATFORM_KEYS_BUNDLE_URL,
|
||||
&gKeyStringBundle);
|
||||
NS_IF_ADDREF(gKeyStringBundle);
|
||||
}
|
||||
|
||||
nsAccessibilityAtoms::AddRefAtoms();
|
||||
|
||||
gGlobalDocAccessibleCache = new nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode>;
|
||||
gGlobalDocAccessibleCache->Init(4); // Initialize for 4 entries
|
||||
gGlobalDocAccessibleCache.Init(4);
|
||||
|
||||
nsCOMPtr<nsIPref> prefService(do_GetService(kPrefCID));
|
||||
if (prefService) {
|
||||
prefService->GetBoolPref("accessibility.disablecache", &gIsCacheDisabled);
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefBranch) {
|
||||
prefBranch->GetBoolPref("accessibility.disablecache", &gIsCacheDisabled);
|
||||
}
|
||||
|
||||
gIsAccessibilityActive = PR_TRUE;
|
||||
|
@ -211,9 +208,7 @@ void nsAccessNode::ShutdownXPAccessibility()
|
|||
NS_IF_RELEASE(gKeyStringBundle);
|
||||
NS_IF_RELEASE(gLastFocusedNode);
|
||||
|
||||
ClearCache(*gGlobalDocAccessibleCache);
|
||||
delete gGlobalDocAccessibleCache;
|
||||
gGlobalDocAccessibleCache = nsnull;
|
||||
ClearCache(gGlobalDocAccessibleCache);
|
||||
|
||||
gIsAccessibilityActive = PR_FALSE;
|
||||
}
|
||||
|
@ -439,12 +434,11 @@ void nsAccessNode::GetDocAccessibleFor(nsIWeakReference *aPresShell,
|
|||
nsIAccessibleDocument **aDocAccessible)
|
||||
{
|
||||
*aDocAccessible = nsnull;
|
||||
NS_ASSERTION(gGlobalDocAccessibleCache, "Global doc cache does not exist");
|
||||
|
||||
nsCOMPtr<nsIAccessNode> accessNode;
|
||||
gGlobalDocAccessibleCache->Get(NS_STATIC_CAST(void*, aPresShell), getter_AddRefs(accessNode));
|
||||
gGlobalDocAccessibleCache.Get(NS_STATIC_CAST(void*, aPresShell), getter_AddRefs(accessNode));
|
||||
if (accessNode) {
|
||||
accessNode->QueryInterface(NS_GET_IID(nsIAccessibleDocument), (void**)aDocAccessible); // addrefs
|
||||
CallQueryInterface(accessNode, aDocAccessible);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,7 +471,5 @@ PLDHashOperator nsAccessNode::ClearCacheEntry(const void* aKey, nsCOMPtr<nsIAcce
|
|||
|
||||
void nsAccessNode::ClearCache(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> &aCache)
|
||||
{
|
||||
aCache.Enumerate(ClearCacheEntry, nsnull);
|
||||
aCache.Enumerate(ClearCacheEntry, nsnull);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ class nsAccessNode: public nsIAccessNode, public nsPIAccessNode
|
|||
static PRBool gIsAccessibilityActive;
|
||||
static PRBool gIsCacheDisabled;
|
||||
|
||||
static nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> *gGlobalDocAccessibleCache;
|
||||
static nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> gGlobalDocAccessibleCache;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -78,8 +78,7 @@
|
|||
// construction
|
||||
//-----------------------------------------------------
|
||||
nsDocAccessible::nsDocAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell):
|
||||
nsBlockAccessible(aDOMNode, aShell),
|
||||
mAccessNodeCache(nsnull), mWnd(nsnull),
|
||||
nsBlockAccessible(aDOMNode, aShell), mWnd(nsnull),
|
||||
mScrollWatchTimer(nsnull), mDocLoadTimer(nsnull),
|
||||
mWebProgress(nsnull), mEditor(nsnull),
|
||||
mBusy(eBusyStateUninitialized),
|
||||
|
@ -103,12 +102,10 @@ nsDocAccessible::nsDocAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell)
|
|||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(gGlobalDocAccessibleCache, "No global doc accessible cache");
|
||||
PutCacheEntry(*gGlobalDocAccessibleCache, mWeakShell, this);
|
||||
PutCacheEntry(gGlobalDocAccessibleCache, mWeakShell, this);
|
||||
|
||||
// XXX aaronl should we use an algorithm for the initial cache size?
|
||||
mAccessNodeCache = new nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode>;
|
||||
mAccessNodeCache->Init(kDefaultCacheSize);
|
||||
mAccessNodeCache.Init(kDefaultCacheSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
@ -310,15 +307,13 @@ NS_IMETHODIMP nsDocAccessible::GetIsEditable(PRBool *aIsEditable)
|
|||
|
||||
NS_IMETHODIMP nsDocAccessible::GetCachedAccessNode(void *aUniqueID, nsIAccessNode **aAccessNode)
|
||||
{
|
||||
NS_ASSERTION(mAccessNodeCache, "No accessibility cache for document");
|
||||
GetCacheEntry(*mAccessNodeCache, aUniqueID, aAccessNode); // Addrefs for us
|
||||
GetCacheEntry(mAccessNodeCache, aUniqueID, aAccessNode); // Addrefs for us
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDocAccessible::CacheAccessNode(void *aUniqueID, nsIAccessNode *aAccessNode)
|
||||
{
|
||||
NS_ASSERTION(mAccessNodeCache, "No accessibility cache for document");
|
||||
PutCacheEntry(*mAccessNodeCache, aUniqueID, aAccessNode);
|
||||
PutCacheEntry(mAccessNodeCache, aUniqueID, aAccessNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -357,10 +352,7 @@ NS_IMETHODIMP nsDocAccessible::Init()
|
|||
|
||||
NS_IMETHODIMP nsDocAccessible::Destroy()
|
||||
{
|
||||
NS_ASSERTION(gGlobalDocAccessibleCache, "No global doc accessible cache");
|
||||
if (gGlobalDocAccessibleCache) {
|
||||
gGlobalDocAccessibleCache->Remove(NS_STATIC_CAST(void*, mWeakShell));
|
||||
}
|
||||
gGlobalDocAccessibleCache.Remove(NS_STATIC_CAST(void*, mWeakShell));
|
||||
return Shutdown();
|
||||
}
|
||||
|
||||
|
@ -386,10 +378,7 @@ NS_IMETHODIMP nsDocAccessible::Shutdown()
|
|||
}
|
||||
mWebProgress = nsnull;
|
||||
|
||||
if (mAccessNodeCache) {
|
||||
ClearCache(*mAccessNodeCache);
|
||||
mAccessNodeCache = nsnull;
|
||||
}
|
||||
ClearCache(mAccessNodeCache);
|
||||
|
||||
mDocument = nsnull;
|
||||
|
||||
|
@ -897,7 +886,7 @@ NS_IMETHODIMP nsDocAccessible::InvalidateCacheSubtree(nsIDOMNode *aStartNode)
|
|||
nsCOMPtr<nsPIAccessNode> privateAccessNode(do_QueryInterface(accessNode));
|
||||
privateAccessNode->Shutdown();
|
||||
// Remove from hash table as well
|
||||
mAccessNodeCache->Remove(uniqueID);
|
||||
mAccessNodeCache.Remove(uniqueID);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ class nsDocAccessible : public nsBlockAccessible,
|
|||
nsIAccessibleDocument **aAccessibleDoc);
|
||||
virtual void CheckForEditor();
|
||||
|
||||
nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> *mAccessNodeCache;
|
||||
nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> mAccessNodeCache;
|
||||
void *mWnd;
|
||||
nsCOMPtr<nsIDocument> mDocument;
|
||||
nsCOMPtr<nsITimer> mScrollWatchTimer;
|
||||
|
|
Загрузка…
Ссылка в новой задаче