bug 822664 - only use the doc accessible cache for lifetime management r=surkov

This commit is contained in:
Trevor Saunders 2012-11-02 19:57:58 -04:00
parent e94e7553b3
commit 3968a7f718
5 changed files with 31 additions and 33 deletions

View File

@ -49,7 +49,7 @@ DocManager::GetDocAccessible(nsIDocument* aDocument)
// Ensure CacheChildren is called before we query cache.
ApplicationAcc()->EnsureChildren();
DocAccessible* docAcc = mDocAccessibleCache.GetWeak(aDocument);
DocAccessible* docAcc = GetExistingDocAccessible(aDocument);
if (docAcc)
return docAcc;
@ -181,7 +181,7 @@ DocManager::OnStateChange(nsIWebProgress* aWebProgress,
logging::DocLoad("start document loading", aWebProgress, aRequest, aStateFlags);
#endif
DocAccessible* docAcc = mDocAccessibleCache.GetWeak(document);
DocAccessible* docAcc = GetExistingDocAccessible(document);
if (!docAcc)
return NS_OK;
@ -280,7 +280,7 @@ DocManager::HandleEvent(nsIDOMEvent* aEvent)
// We're allowed to not remove listeners when accessible document is
// shutdown since we don't keep strong reference on chrome event target and
// listeners are removed automatically when chrome event target goes away.
DocAccessible* docAccessible = mDocAccessibleCache.GetWeak(document);
DocAccessible* docAccessible = GetExistingDocAccessible(document);
if (docAccessible)
docAccessible->Shutdown();
@ -312,7 +312,7 @@ DocManager::HandleDOMDocumentLoad(nsIDocument* aDocument,
{
// Document accessible can be created before we were notified the DOM document
// was loaded completely. However if it's not created yet then create it.
DocAccessible* docAcc = mDocAccessibleCache.GetWeak(aDocument);
DocAccessible* docAcc = GetExistingDocAccessible(aDocument);
if (!docAcc) {
docAcc = CreateDocOrRootAccessible(aDocument);
if (!docAcc)

View File

@ -59,14 +59,6 @@ public:
*/
Accessible* FindAccessibleInCache(nsINode* aNode) const;
/**
* Return document accessible from the cache. Convenient method for testing.
*/
inline DocAccessible* GetDocAccessibleFromCache(nsIDocument* aDocument) const
{
return mDocAccessibleCache.GetWeak(aDocument);
}
/**
* Called by document accessible when it gets shutdown.
*/
@ -154,6 +146,18 @@ private:
DocAccessibleHashtable mDocAccessibleCache;
};
/**
* Return the existing document accessible for the document if any.
* Note this returns the doc accessible for the primary pres shell if there is
* more than one.
*/
inline DocAccessible*
GetExistingDocAccessible(const nsIDocument* aDocument)
{
nsIPresShell* ps = aDocument->GetShell();
return ps ? ps->GetDocAccessible() : nullptr;
}
} // namespace a11y
} // namespace mozilla

View File

@ -400,8 +400,7 @@ logging::DocLoad(const char* aMsg, nsIWebProgress* aWebProgress,
}
nsCOMPtr<nsIDocument> documentNode(do_QueryInterface(DOMDocument));
DocAccessible* document =
GetAccService()->GetDocAccessibleFromCache(documentNode);
DocAccessible* document = GetExistingDocAccessible(documentNode);
LogDocInfo(documentNode, document);
@ -425,8 +424,7 @@ logging::DocLoad(const char* aMsg, nsIDocument* aDocumentNode)
{
MsgBegin(sDocLoadTitle, aMsg);
DocAccessible* document =
GetAccService()->GetDocAccessibleFromCache(aDocumentNode);
DocAccessible* document = GetExistingDocAccessible(aDocumentNode);
LogDocInfo(aDocumentNode, document);
MsgEnd();
@ -486,7 +484,7 @@ logging::DocCreate(const char* aMsg, nsIDocument* aDocumentNode,
DocAccessible* aDocument)
{
DocAccessible* document = aDocument ?
aDocument : GetAccService()->GetDocAccessibleFromCache(aDocumentNode);
aDocument : GetExistingDocAccessible(aDocumentNode);
MsgBegin(sDocCreateTitle, aMsg);
LogDocInfo(aDocumentNode, document);
@ -498,7 +496,7 @@ logging::DocDestroy(const char* aMsg, nsIDocument* aDocumentNode,
DocAccessible* aDocument)
{
DocAccessible* document = aDocument ?
aDocument : GetAccService()->GetDocAccessibleFromCache(aDocumentNode);
aDocument : GetExistingDocAccessible(aDocumentNode);
MsgBegin(sDocDestroyTitle, aMsg);
LogDocInfo(aDocumentNode, document);

View File

@ -186,6 +186,7 @@ Accessible*
nsAccessibilityService::GetRootDocumentAccessible(nsIPresShell* aPresShell,
bool aCanCreate)
{
nsIPresShell* ps = aPresShell;
nsIDocument* documentNode = aPresShell->GetDocument();
if (documentNode) {
nsCOMPtr<nsISupports> container = documentNode->GetContainer();
@ -197,11 +198,10 @@ nsAccessibilityService::GetRootDocumentAccessible(nsIPresShell* aPresShell,
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(rootTreeItem));
nsCOMPtr<nsIPresShell> presShell;
docShell->GetPresShell(getter_AddRefs(presShell));
documentNode = presShell->GetDocument();
ps = presShell;
}
return aCanCreate ?
GetDocAccessible(documentNode) : GetDocAccessibleFromCache(documentNode);
return aCanCreate ? GetDocAccessible(ps) : ps->GetDocAccessible();
}
}
return nullptr;
@ -406,15 +406,12 @@ nsAccessibilityService::UpdateImageMap(nsImageFrame* aImageFrame)
void
nsAccessibilityService::PresShellActivated(nsIPresShell* aPresShell)
{
nsIDocument* DOMDoc = aPresShell->GetDocument();
if (DOMDoc) {
DocAccessible* document = GetDocAccessibleFromCache(DOMDoc);
if (document) {
RootAccessible* rootDocument = document->RootAccessible();
NS_ASSERTION(rootDocument, "Entirely broken tree: no root document!");
if (rootDocument)
rootDocument->DocumentActivated(document);
}
DocAccessible* document = aPresShell->GetDocAccessible();
if (document) {
RootAccessible* rootDocument = document->RootAccessible();
NS_ASSERTION(rootDocument, "Entirely broken tree: no root document!");
if (rootDocument)
rootDocument->DocumentActivated(document);
}
}
@ -650,7 +647,7 @@ nsAccessibilityService::GetAccessibleFromCache(nsIDOMNode* aNode,
if (!accessible) {
nsCOMPtr<nsIDocument> document(do_QueryInterface(node));
if (document)
accessible = GetDocAccessibleFromCache(document);
accessible = GetExistingDocAccessible(document);
}
NS_IF_ADDREF(*aAccessible = accessible);

View File

@ -592,8 +592,6 @@ DocAccessible::Shutdown()
logging::DocDestroy("document shutdown", mDocumentNode, this);
#endif
mPresShell->SetDocAccessible(nullptr);
if (mNotificationController) {
mNotificationController->Shutdown();
mNotificationController = nullptr;
@ -629,6 +627,7 @@ DocAccessible::Shutdown()
mVirtualCursor = nullptr;
}
mPresShell->SetDocAccessible(nullptr);
mPresShell = nullptr; // Avoid reentrancy
mDependentIDsHash.Clear();