From fb89b95276a1bc402f9fb7a6dd98da49253358b9 Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Thu, 19 Nov 2009 12:42:18 +1300 Subject: [PATCH] Bug 529442. Don't hold a frame pointer in nsAccessibilityService::GetAccessible. r=roc,dbolter --- .../src/base/nsAccessibilityService.cpp | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/accessible/src/base/nsAccessibilityService.cpp b/accessible/src/base/nsAccessibilityService.cpp index 8567bc3a123..df05ef6b63e 100644 --- a/accessible/src/base/nsAccessibilityService.cpp +++ b/accessible/src/base/nsAccessibilityService.cpp @@ -1334,7 +1334,7 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, // that can flush layout, either directly, or via DOM manipulation, or some // CSS styles like :hover. We use the weak frame checks to avoid calling // methods on a dead frame pointer. - nsWeakFrame weakFrame = *aFrameHint; + nsWeakFrame weakFrame(*aFrameHint); #ifdef DEBUG_A11Y // Please leave this in for now, it's a convenient debugging method @@ -1460,8 +1460,10 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, *aIsHidden = PR_TRUE; } - if (*aIsHidden) + if (*aIsHidden) { + *aFrameHint = weakFrame.GetFrame(); return NS_OK; + } /** * Attempt to create an accessible based on what we know @@ -1475,13 +1477,17 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, if (renderedWhitespace.IsEmpty()) { // Really empty -- nothing is rendered *aIsHidden = PR_TRUE; + *aFrameHint = weakFrame.GetFrame(); return NS_OK; } } if (weakFrame.IsAlive()) { weakFrame.GetFrame()->GetAccessible(getter_AddRefs(newAcc)); } - return InitAccessible(newAcc, aAccessible, nsnull); + + nsresult rv = InitAccessible(newAcc, aAccessible, nsnull); + *aFrameHint = weakFrame.GetFrame(); + return rv; } PRBool isHTML = content->IsHTML(); @@ -1498,12 +1504,16 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::name, name); if (!name.IsEmpty()) { *aIsHidden = PR_TRUE; + *aFrameHint = weakFrame.GetFrame(); return NS_OK; } nsresult rv = CreateHyperTextAccessible(weakFrame.GetFrame(), getter_AddRefs(newAcc)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + *aFrameHint = weakFrame.GetFrame(); + return rv; + } } nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(aNode); @@ -1512,6 +1522,7 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, // Only create accessible for role of "presentation" if it is focusable -- // in that case we need an accessible in case it gets focused, we // don't want focus ever to be 'lost' + *aFrameHint = weakFrame.GetFrame(); return NS_OK; } @@ -1569,6 +1580,7 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, // presentation if they aren't focusable and have not explicit ARIA // role (don't create accessibles for them unless they need to fire // focus events). + *aFrameHint = weakFrame.GetFrame(); return NS_OK; } @@ -1616,7 +1628,10 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, nsresult rv = CreateHTMLAccessibleByMarkup(weakFrame.GetFrame(), aWeakShell, aNode, getter_AddRefs(newAcc)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + *aFrameHint = weakFrame.GetFrame(); + return rv; + } if (!newAcc) { // Do not create accessible object subtrees for non-rendered table @@ -1634,6 +1649,7 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, // XXX This is not the ideal place for this code, but right now there // is no better place: *aIsHidden = PR_TRUE; + *aFrameHint = weakFrame.GetFrame(); return NS_OK; } f->GetAccessible(getter_AddRefs(newAcc)); // Try using frame to do it @@ -1645,7 +1661,10 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, // Elements may implement nsIAccessibleProvider via XBL. This allows them to // say what kind of accessible to create. nsresult rv = GetAccessibleByType(aNode, getter_AddRefs(newAcc)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + *aFrameHint = weakFrame.GetFrame(); + return rv; + } } if (!newAcc) { @@ -1688,7 +1707,9 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, } } - return InitAccessible(newAcc, aAccessible, roleMapEntry); + nsresult rv = InitAccessible(newAcc, aAccessible, roleMapEntry); + *aFrameHint = weakFrame.GetFrame(); + return rv; } PRBool