From 0b15fe5e75498b75443d5d18354c2de0115fdcbf Mon Sep 17 00:00:00 2001 From: "aaronleventhal@moonset.net" Date: Mon, 11 Feb 2008 04:12:17 -0800 Subject: [PATCH] Bug 416753. Crashes in GetState(). r=surkov, a=schrep --- .../src/html/nsHTMLFormControlAccessible.cpp | 22 ++++++++++++++----- .../src/xul/nsXULFormControlAccessible.cpp | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/accessible/src/html/nsHTMLFormControlAccessible.cpp b/accessible/src/html/nsHTMLFormControlAccessible.cpp index bab71cbb2bb0..661b321a0a0f 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -106,6 +106,8 @@ nsHTMLCheckboxAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) { nsresult rv = nsFormControlAccessible::GetState(aState, aExtraState); NS_ENSURE_SUCCESS(rv, rv); + if (!mDOMNode) + return NS_OK; *aState |= nsIAccessibleStates::STATE_CHECKABLE; @@ -133,6 +135,8 @@ nsHTMLRadioButtonAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) { nsresult rv = nsAccessibleWrap::GetState(aState, aExtraState); NS_ENSURE_SUCCESS(rv, rv); + if (!mDOMNode) + return NS_OK; *aState |= nsIAccessibleStates::STATE_CHECKABLE; @@ -249,11 +253,13 @@ NS_IMETHODIMP nsHTMLButtonAccessible::DoAction(PRUint8 index) NS_IMETHODIMP nsHTMLButtonAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) { - nsCOMPtr element(do_QueryInterface(mDOMNode)); - NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); - nsresult rv = nsHyperTextAccessibleWrap::GetState(aState, aExtraState); NS_ENSURE_SUCCESS(rv, rv); + if (!mDOMNode) + return NS_OK; + + nsCOMPtr element(do_QueryInterface(mDOMNode)); + NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); nsAutoString buttonType; element->GetAttribute(NS_LITERAL_STRING("type"), buttonType); @@ -350,11 +356,13 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetRole(PRUint32 *_retval) NS_IMETHODIMP nsHTML4ButtonAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) { - nsCOMPtr element(do_QueryInterface(mDOMNode)); - NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); // Button accessible shut down - nsresult rv = nsHyperTextAccessibleWrap::GetState(aState, aExtraState); NS_ENSURE_SUCCESS(rv, rv); + if (!mDOMNode) + return NS_OK; + + nsCOMPtr element(do_QueryInterface(mDOMNode)); + NS_ASSERTION(element, "No element for button's dom node!"); *aState |= nsIAccessibleStates::STATE_FOCUSABLE; @@ -432,6 +440,8 @@ nsHTMLTextFieldAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) { nsresult rv = nsHyperTextAccessibleWrap::GetState(aState, aExtraState); NS_ENSURE_SUCCESS(rv, rv); + if (!mDOMNode) + return NS_OK; // can be focusable, focused, protected. readonly, unavailable, selected nsCOMPtr content(do_QueryInterface(mDOMNode)); diff --git a/accessible/src/xul/nsXULFormControlAccessible.cpp b/accessible/src/xul/nsXULFormControlAccessible.cpp index 49cf82b0bc31..10c37c098fa2 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.cpp +++ b/accessible/src/xul/nsXULFormControlAccessible.cpp @@ -796,10 +796,10 @@ already_AddRefed nsXULTextFieldAccessible::GetInputField() NS_IMETHODIMP nsXULTextFieldAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) { - NS_ENSURE_TRUE(mDOMNode, NS_ERROR_FAILURE); - nsresult rv = nsHyperTextAccessibleWrap::GetState(aState, aExtraState); NS_ENSURE_SUCCESS(rv, rv); + if (!mDOMNode) + return NS_OK; nsCOMPtr inputField = GetInputField(); NS_ENSURE_TRUE(inputField, NS_ERROR_FAILURE);