Bug 377800 Too many warnings in console for accessibilityr=surkov.alexander
authorginn.chen@sun.com
Fri, 08 Jun 2007 02:09:24 -0700
changeset 2211 101b85d72fc29fb711dbf1dab5d3914241f6ff5f
parent 2210 b0c32fe9eb98460057472e6259a33a610dd0cacd
child 2212 66c05556d28aef09fc498a26ddf03184fc147d69
push idunknown
push userunknown
push dateunknown
bugs377800
milestone1.9a6pre
Bug 377800 Too many warnings in console for accessibilityr=surkov.alexander
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/atk/nsAccessibleWrap.h
accessible/src/atk/nsAppRootAccessible.cpp
accessible/src/atk/nsDocAccessibleWrap.cpp
accessible/src/atk/nsMai.h
accessible/src/atk/nsMaiHyperlink.cpp
accessible/src/atk/nsMaiInterfaceAction.cpp
accessible/src/atk/nsMaiInterfaceComponent.cpp
accessible/src/atk/nsMaiInterfaceDocument.cpp
accessible/src/atk/nsMaiInterfaceEditableText.cpp
accessible/src/atk/nsMaiInterfaceHyperlinkImpl.cpp
accessible/src/atk/nsMaiInterfaceHypertext.cpp
accessible/src/atk/nsMaiInterfaceSelection.cpp
accessible/src/atk/nsMaiInterfaceTable.cpp
accessible/src/atk/nsMaiInterfaceText.cpp
accessible/src/atk/nsMaiInterfaceValue.cpp
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -34,17 +34,16 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsMai.h"
 #include "nsAccessibleWrap.h"
 #include "nsAccessibleEventData.h"
 #include "nsString.h"
 #include "nsAutoPtr.h"
 #include "prprf.h"
 #include "nsRoleMap.h"
 #include "nsStateMap.h"
 
@@ -386,16 +385,26 @@ NS_IMETHODIMP nsAccessibleWrap::GetNativ
 AtkObject *
 nsAccessibleWrap::GetAtkObject(void)
 {
     void *atkObj = nsnull;
     GetNativeInterface(&atkObj);
     return NS_STATIC_CAST(AtkObject *, atkObj);
 }
 
+// Get AtkObject from nsIAccessible interface
+/* static */
+AtkObject *
+nsAccessibleWrap::GetAtkObject(nsIAccessible * acc)
+{
+    void *atkObjPtr = nsnull;
+    acc->GetNativeInterface(&atkObjPtr);
+    return atkObjPtr ? ATK_OBJECT(atkObjPtr) : nsnull;    
+}
+
 /* private */
 PRUint16
 nsAccessibleWrap::CreateMaiInterfaces(void)
 {
     PRUint16 interfacesBits = 0;
     
     // Add Interfaces for each nsIAccessible.ext interfaces
 
@@ -702,78 +711,68 @@ finalizeCB(GObject *aObj)
     // finalize of GObjectClass will unref the accessible parent if has
     if (G_OBJECT_CLASS (parent_class)->finalize)
         G_OBJECT_CLASS (parent_class)->finalize(aObj);
 }
 
 const gchar *
 getNameCB(AtkObject *aAtkObj)
 {
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
-      return nsnull;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    if (!accWrap) {
+        return nsnull;
     }
 
+    /* nsIAccessible is responsible for the non-NULL name */
     nsAutoString uniName;
-
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
-
-    /* nsIAccessible is responsible for the non-NULL name */
     nsresult rv = accWrap->GetName(uniName);
     NS_ENSURE_SUCCESS(rv, nsnull);
 
-    if (uniName.Length() > 0) {
-        NS_ConvertUTF8toUTF16 objName(aAtkObj->name);
-        if (!uniName.Equals(objName)) {
-            atk_object_set_name(aAtkObj,
-                                NS_ConvertUTF16toUTF8(uniName).get());
-        }
+    NS_ConvertUTF8toUTF16 objName(aAtkObj->name);
+    if (!uniName.Equals(objName)) {
+        atk_object_set_name(aAtkObj,
+                            NS_ConvertUTF16toUTF8(uniName).get());
     }
     return aAtkObj->name;
 }
 
 const gchar *
 getDescriptionCB(AtkObject *aAtkObj)
 {
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
-      return nsnull;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    if (!accWrap) {
+        return nsnull;
     }
 
-    if (!aAtkObj->description) {
-        gint len;
-        nsAutoString uniDesc;
-
-        nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    /* nsIAccessible is responsible for the non-NULL description */
+    nsAutoString uniDesc;
+    nsresult rv = accWrap->GetDescription(uniDesc);
+    NS_ENSURE_SUCCESS(rv, nsnull);
 
-        /* nsIAccessible is responsible for the non-NULL description */
-        nsresult rv = accWrap->GetDescription(uniDesc);
-        NS_ENSURE_SUCCESS(rv, nsnull);
-        len = uniDesc.Length();
-        if (len > 0) {
-            atk_object_set_description(aAtkObj,
-                                       NS_ConvertUTF16toUTF8(uniDesc).get());
-        }
+    NS_ConvertUTF8toUTF16 objDesc(aAtkObj->description);
+    if (!uniDesc.Equals(objDesc)) {
+        atk_object_set_description(aAtkObj,
+                                   NS_ConvertUTF16toUTF8(uniDesc).get());
     }
     return aAtkObj->description;
 }
 
 AtkRole
 getRoleCB(AtkObject *aAtkObj)
 {
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
-      return ATK_ROLE_INVALID;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    if (!accWrap) {
+        return ATK_ROLE_INVALID;
     }
 
 #ifdef DEBUG_A11Y
-        nsAccessibleWrap *testAccWrap = GetAccessibleWrap(aAtkObj);
-        NS_ASSERTION(nsAccessible::IsTextInterfaceSupportCorrect(testAccWrap), "Does not support nsIAccessibleText when it should");
+    NS_ASSERTION(nsAccessible::IsTextInterfaceSupportCorrect(accWrap), "Does not support nsIAccessibleText when it should");
 #endif
 
     if (aAtkObj->role == ATK_ROLE_INVALID) {
-        nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
-
         PRUint32 accRole, atkRole;
         nsresult rv = accWrap->GetFinalRole(&accRole);
         NS_ENSURE_SUCCESS(rv, ATK_ROLE_INVALID);
 
         atkRole = atkRoleMap[accRole]; // map to the actual value
         NS_ASSERTION(atkRoleMap[nsIAccessibleRole::ROLE_LAST_ENTRY] ==
                      kROLE_ATK_LAST_ENTRY, "ATK role map skewed");
         aAtkObj->role = NS_STATIC_CAST(AtkRole, atkRole);
@@ -816,53 +815,48 @@ GetAttributeSet(nsIAccessible* aAccessib
     }
 
     return objAttributeSet;
 }
 
 AtkAttributeSet *
 getAttributesCB(AtkObject *aAtkObj)
 {
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
-      return nsnull;
-    }
     nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
-    return GetAttributeSet(accWrap);
+    return accWrap ? GetAttributeSet(accWrap) : nsnull;
 }
 
 AtkObject *
 getParentCB(AtkObject *aAtkObj)
 {
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
-      return nsnull;
-    }
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    if (!aAtkObj->accessible_parent) {
+        nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+        if (!accWrap) {
+            return nsnull;
+        }
 
-    nsCOMPtr<nsIAccessible> accParent;
-    nsresult rv = accWrap->GetParent(getter_AddRefs(accParent));
-    if (NS_FAILED(rv) || !accParent)
-        return nsnull;
+        nsCOMPtr<nsIAccessible> accParent;
+        nsresult rv = accWrap->GetParent(getter_AddRefs(accParent));
+        if (NS_FAILED(rv) || !accParent)
+            return nsnull;
 
-    void *parentAtkObj = nsnull;
-    accParent->GetNativeInterface(&parentAtkObj);
-
-    if (parentAtkObj && !aAtkObj->accessible_parent) {
-        atk_object_set_parent(aAtkObj, ATK_OBJECT(parentAtkObj));
+        atk_object_set_parent(aAtkObj,
+                              nsAccessibleWrap::GetAtkObject(accParent));
     }
     return aAtkObj->accessible_parent;
 }
 
 gint
 getChildCountCB(AtkObject *aAtkObj)
 {
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
-      return 0;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    if (!accWrap) {
+        return 0;
     }
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     PRInt32 count = 0;
     nsCOMPtr<nsIAccessibleHyperText> hyperText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText), getter_AddRefs(hyperText));
     if (hyperText) {
         // If HyperText, then number of links matches number of children
         hyperText->GetLinks(&count);
     }
@@ -883,20 +877,20 @@ refChildCB(AtkObject *aAtkObj, gint aChi
     if (aChildIndex < 0) {
       return nsnull;
     }
 
     // XXX Fix this so it is not O(n^2) to walk through the children!
     // Either we can cache the last accessed child so that we can just GetNextSibling()
     // or we should cache an array of children in each nsAccessible
     // (instead of mNextSibling on the children)
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
-      return nsnull;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    if (!accWrap) {
+        return nsnull;
     }
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     nsresult rv;
     nsCOMPtr<nsIAccessible> accChild;
     nsCOMPtr<nsIAccessibleHyperText> hyperText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText), getter_AddRefs(hyperText));
     if (hyperText) {
         // If HyperText, then number of links matches number of children
         nsCOMPtr<nsIAccessibleHyperLink> hyperLink;
@@ -909,39 +903,37 @@ refChildCB(AtkObject *aAtkObj, gint aChi
         if (!accText) {  // Accessible Text that is not HyperText has no children
             rv = accWrap->GetChildAt(aChildIndex, getter_AddRefs(accChild));
         }
     }
 
     if (NS_FAILED(rv) || !accChild)
         return nsnull;
 
-    void* childAtkObjPtr = nsnull;
-    accChild->GetNativeInterface(&childAtkObjPtr);
+    AtkObject* childAtkObj = nsAccessibleWrap::GetAtkObject(accChild);
 
-    NS_ASSERTION(childAtkObjPtr, "Fail to get AtkObj");
-    if (!childAtkObjPtr)
+    NS_ASSERTION(childAtkObj, "Fail to get AtkObj");
+    if (!childAtkObj)
         return nsnull;
     
-    AtkObject* childAtkObj = ATK_OBJECT(childAtkObjPtr);
     //this will addref parent
     atk_object_set_parent(childAtkObj, aAtkObj);
     g_object_ref(childAtkObj);
     return childAtkObj;
 }
 
 gint
 getIndexInParentCB(AtkObject *aAtkObj)
 {
     // We don't use nsIAccessible::GetIndexInParent() because
     // for ATK we don't want to include text leaf nodes as children
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
-      return -1;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    if (!accWrap) {
+        return -1;
     }
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     nsCOMPtr<nsIAccessible> parent;
     accWrap->GetParent(getter_AddRefs(parent));
     if (!parent) {
         return -1; // No parent
     }
 
     nsCOMPtr<nsIAccessible> sibling;
@@ -995,24 +987,23 @@ static void TranslateStates(PRUint32 aSt
 }
 
 AtkStateSet *
 refStateSetCB(AtkObject *aAtkObj)
 {
     AtkStateSet *state_set = nsnull;
     state_set = ATK_OBJECT_CLASS(parent_class)->ref_state_set(aAtkObj);
 
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    if (!accWrap) {
         TranslateStates(nsIAccessibleStates::EXT_STATE_DEFUNCT,
                         gAtkStateMapExt, state_set);
         return state_set;
     }
 
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
-
     // Map states
     PRUint32 accState = 0, accExtState = 0;
     nsresult rv = accWrap->GetFinalState(&accState, &accExtState);
     NS_ENSURE_SUCCESS(rv, state_set);
 
     TranslateStates(accState, gAtkStateMap, state_set);
     TranslateStates(accExtState, gAtkStateMapExt, state_set);
 
@@ -1020,20 +1011,20 @@ refStateSetCB(AtkObject *aAtkObj)
 }
 
 AtkRelationSet *
 refRelationSetCB(AtkObject *aAtkObj)
 {
     AtkRelationSet *relation_set = nsnull;
     relation_set = ATK_OBJECT_CLASS(parent_class)->ref_relation_set(aAtkObj);
 
-    if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
-      return relation_set;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
+    if (!accWrap) {
+        return relation_set;
     }
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     AtkObject *accessible_array[1];
     AtkRelation* relation;
     
     PRUint32 relationType[] = {nsIAccessibleRelation::RELATION_LABELLED_BY,
                                nsIAccessibleRelation::RELATION_LABEL_FOR,
                                nsIAccessibleRelation::RELATION_NODE_CHILD_OF,
                                nsIAccessibleRelation::RELATION_CONTROLLED_BY,
@@ -1049,82 +1040,68 @@ refRelationSetCB(AtkObject *aAtkObj)
         relation = atk_relation_set_get_relation_by_type(relation_set, NS_STATIC_CAST(AtkRelationType, relationType[i]));
         if (relation) {
             atk_relation_set_remove(relation_set, relation);
         }
 
         nsIAccessible* accRelated;
         nsresult rv = accWrap->GetAccessibleRelated(relationType[i], &accRelated);
         if (NS_SUCCEEDED(rv) && accRelated) {
-            void *relatedAtkObj = nsnull;
-            accRelated->GetNativeInterface(&relatedAtkObj);
-            accessible_array[0] = ATK_OBJECT(relatedAtkObj);
+            accessible_array[0] = nsAccessibleWrap::GetAtkObject(accRelated);
             relation = atk_relation_new(accessible_array, 1,
                                         NS_STATIC_CAST(AtkRelationType, relationType[i]));
             atk_relation_set_add(relation_set, relation);
             g_object_unref(relation);
         }
     }
 
     return relation_set;
 }
 
-// Check if aAtkObj is a valid MaiAtkObject
-nsresult
-CheckMaiAtkObject(AtkObject *aAtkObj)
+// Check if aAtkObj is a valid MaiAtkObject, and return the nsAccessibleWrap
+// for it.
+nsAccessibleWrap *GetAccessibleWrap(AtkObject *aAtkObj)
 {
-    NS_ENSURE_ARG(IS_MAI_OBJECT(aAtkObj));
-    nsAccessibleWrap * tmpAccWrap = GetAccessibleWrap(aAtkObj);
+    NS_ENSURE_TRUE(IS_MAI_OBJECT(aAtkObj), nsnull);
+    nsAccessibleWrap *tmpAccWrap = MAI_ATK_OBJECT(aAtkObj)->accWrap;
 
     // Check if AccessibleWrap was deconstructed
     if (tmpAccWrap == nsnull) {
-        return NS_ERROR_NULL_POINTER;
+        return nsnull;
     }
 
+    NS_ENSURE_TRUE(tmpAccWrap->GetAtkObject() == aAtkObj, nsnull);
+
     nsRefPtr<nsApplicationAccessibleWrap> appAccWrap =
         nsAccessNode::GetApplicationAccessible();
     nsAccessibleWrap* tmpAppAccWrap =
         NS_STATIC_CAST(nsAccessibleWrap*, appAccWrap.get());
 
     if (tmpAppAccWrap != tmpAccWrap && !tmpAccWrap->IsValidObject())
-        return NS_ERROR_INVALID_POINTER;
-
-    NS_ENSURE_TRUE(tmpAccWrap->GetAtkObject() == aAtkObj, NS_ERROR_FAILURE);
-    return NS_OK;
-}
+        return nsnull;
 
-// Check if aAtkObj is a valid MaiAtkObject, and return the nsAccessibleWrap
-// for it.
-nsAccessibleWrap *GetAccessibleWrap(AtkObject *aAtkObj)
-{
-    NS_ENSURE_TRUE(IS_MAI_OBJECT(aAtkObj), nsnull);
-    nsAccessibleWrap * tmpAccWrap = MAI_ATK_OBJECT(aAtkObj)->accWrap;
-    NS_ENSURE_TRUE(tmpAccWrap != nsnull, nsnull);
-    NS_ENSURE_TRUE(tmpAccWrap->GetAtkObject() == aAtkObj, nsnull);
     return tmpAccWrap;
 }
 
 NS_IMETHODIMP
 nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
 {
     nsresult rv = nsAccessible::FireAccessibleEvent(aEvent);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIAccessible> accessible;
     aEvent->GetAccessible(getter_AddRefs(accessible));
     NS_ENSURE_TRUE(accessible, NS_ERROR_FAILURE);
 
-    void *atkObjPtr = nsnull;
-    accessible->GetNativeInterface(&atkObjPtr);
-
     PRUint32 type = 0;
     rv = aEvent->GetEventType(&type);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    AtkObject *atkObj = ATK_OBJECT(atkObjPtr);
+    AtkObject *atkObj = nsAccessibleWrap::GetAtkObject(accessible);
+
     // We don't create ATK objects for nsIAccessible plain text leaves,
     // just return NS_OK in such case
     if (!atkObj) {
         NS_ASSERTION(type == nsIAccessibleEvent::EVENT_SHOW ||
                      type == nsIAccessibleEvent::EVENT_HIDE,
                      "Event other than SHOW and HIDE fired for plain text leaves");
         return NS_OK;
     }
--- a/accessible/src/atk/nsAccessibleWrap.h
+++ b/accessible/src/atk/nsAccessibleWrap.h
@@ -95,16 +95,17 @@ public:
     static PRInt32 mAccWrapDeleted;
 #endif
 
     // return the atk object for this nsAccessibleWrap
     NS_IMETHOD GetNativeInterface(void **aOutAccessible);
     NS_IMETHOD FireAccessibleEvent(nsIAccessibleEvent *aEvent);
 
     AtkObject * GetAtkObject(void);
+    static AtkObject * GetAtkObject(nsIAccessible * acc);
 
     PRBool IsValidObject();
     
     // get/set the MaiHyperlink object for this nsAccessibleWrap
     MaiHyperlink* GetMaiHyperlink(PRBool aCreate = PR_TRUE);
     void SetMaiHyperlink(MaiHyperlink* aMaiHyperlink);
 
     static const char * ReturnString(nsAString &aString) {
--- a/accessible/src/atk/nsAppRootAccessible.cpp
+++ b/accessible/src/atk/nsAppRootAccessible.cpp
@@ -586,19 +586,19 @@ nsresult
 nsApplicationAccessibleWrap::AddRootAccessible(nsIAccessible *aRootAccWrap)
 {
     NS_ENSURE_ARG_POINTER(aRootAccWrap);
 
     // add by weak reference
     nsresult rv = nsApplicationAccessible::AddRootAccessible(aRootAccWrap);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    void* atkAccessible;
-    aRootAccWrap->GetNativeInterface(&atkAccessible);
-    atk_object_set_parent((AtkObject*)atkAccessible, mAtkObject);
+    AtkObject *atkAccessible = nsAccessibleWrap::GetAtkObject(aRootAccWrap);
+    atk_object_set_parent(atkAccessible, mAtkObject);
+
     PRUint32 count = 0;
     mChildren->GetLength(&count);
     g_signal_emit_by_name(mAtkObject, "children_changed::add", count - 1,
                           atkAccessible, NULL);
 
 #ifdef MAI_LOGGING
     if (NS_SUCCEEDED(rv)) {
         MAI_LOG_DEBUG(("\nAdd RootAcc=%p OK, count=%d\n",
@@ -619,19 +619,18 @@ nsApplicationAccessibleWrap::RemoveRootA
 
     PRUint32 index = 0;
     nsresult rv = NS_ERROR_FAILURE;
 
     // we must use weak ref to get the index
     nsCOMPtr<nsIWeakReference> weakPtr = do_GetWeakReference(aRootAccWrap);
     rv = mChildren->IndexOf(0, weakPtr, &index);
 
-    void* atkAccessible;
-    aRootAccWrap->GetNativeInterface(&atkAccessible);
-    atk_object_set_parent((AtkObject*)atkAccessible, NULL);
+    AtkObject *atkAccessible = nsAccessibleWrap::GetAtkObject(aRootAccWrap);
+    atk_object_set_parent(atkAccessible, NULL);
     g_signal_emit_by_name(mAtkObject, "children_changed::remove", index,
                           atkAccessible, NULL);
 
 #ifdef MAI_LOGGING
     PRUint32 count = 0;
     mChildren->GetLength(&count);
 
     if (NS_SUCCEEDED(rv)) {
--- a/accessible/src/atk/nsDocAccessibleWrap.cpp
+++ b/accessible/src/atk/nsDocAccessibleWrap.cpp
@@ -73,27 +73,28 @@ NS_IMETHODIMP nsDocAccessibleWrap::FireT
 
     // First fire nsIObserver event for internal xpcom accessibility clients
     nsDocAccessible::FireToolkitEvent(aEvent, aAccessible, aEventData);
 
     nsresult rv = NS_ERROR_FAILURE;
 
     MAI_LOG_DEBUG(("\n\nReceived event: aEvent=%u, obj=0x%x, data=0x%x \n",
                    aEvent, aAccessible, aEventData));
-    void *atkObjPtr = nsnull;
-    aAccessible->GetNativeInterface(&atkObjPtr);
+
+    AtkObject *atkObj = nsAccessibleWrap::GetAtkObject(aAccessible);
+
     // We don't create ATK objects for nsIAccessible plain text leaves,
     // just return NS_OK in such case
-    if (!atkObjPtr) {
+    if (!atkObj) {
       NS_ASSERTION(aEvent == nsIAccessibleEvent::EVENT_SHOW ||
                    aEvent == nsIAccessibleEvent::EVENT_HIDE,
                    "Event other than SHOW and HIDE fired for plain text leaves");
       return NS_OK;
     }
-    AtkObject *atkObj = ATK_OBJECT(atkObjPtr);
+
     nsAccessibleWrap *accWrap = GetAccessibleWrap(atkObj);
 
     AtkTableChange * pAtkTableChange = nsnull;
 
     switch (aEvent) {
     case nsIAccessibleEvent::EVENT_FOCUS:
       {
         MAI_LOG_DEBUG(("\n\nReceived: EVENT_FOCUS\n"));
--- a/accessible/src/atk/nsMai.h
+++ b/accessible/src/atk/nsMai.h
@@ -76,12 +76,11 @@ PR_END_MACRO
 #define IS_MAI_OBJECT(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
                                          MAI_TYPE_ATK_OBJECT))
 #define IS_MAI_OBJECT_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), \
                                          MAI_TYPE_ATK_OBJECT))
 #define MAI_ATK_OBJECT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), \
                                          MAI_TYPE_ATK_OBJECT, \
                                          MaiAtkObjectClass))
 GType mai_atk_object_get_type(void);
-nsresult CheckMaiAtkObject(AtkObject *aAtkObj);
 nsAccessibleWrap *GetAccessibleWrap(AtkObject *aAtkObj);
 
 #endif /* __NS_MAI_H__ */
--- a/accessible/src/atk/nsMaiHyperlink.cpp
+++ b/accessible/src/atk/nsMaiHyperlink.cpp
@@ -241,23 +241,19 @@ getObjectCB(AtkHyperlink *aLink, gint aL
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, nsnull);
 
     nsCOMPtr<nsIAccessible> accObj;
     accHyperlink->GetObject(aLinkIndex, getter_AddRefs(accObj));
     NS_ENSURE_TRUE(accObj, nsnull);
 
-    void *atkObj = nsnull;
-    accObj->GetNativeInterface(&atkObj);
-    if (!atkObj) {
-        return nsnull;
-    }
+    AtkObject *atkObj = nsAccessibleWrap::GetAtkObject(accObj);
     //no need to add ref it, because it is "get" not "ref"
-    return ATK_OBJECT(atkObj);
+    return atkObj;
 }
 
 gint
 getEndIndexCB(AtkHyperlink *aLink)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, -1);
 
--- a/accessible/src/atk/nsMaiInterfaceAction.cpp
+++ b/accessible/src/atk/nsMaiInterfaceAction.cpp
@@ -54,62 +54,67 @@ actionInterfaceInitCB(AtkActionIface *aI
     aIface->get_keybinding = getKeyBindingCB;
     aIface->get_name = getActionNameCB;
 }
 
 gboolean
 doActionCB(AtkAction *aAction, gint aActionIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
  
     nsresult rv = accWrap->DoAction(aActionIndex);
     return (NS_FAILED(rv)) ? FALSE : TRUE;
 }
 
 gint
 getActionCountCB(AtkAction *aAction)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
-    NS_ENSURE_TRUE(accWrap, 0);
+    if (!accWrap)
+        return 0;
 
     PRUint8 num = 0;
     nsresult rv = accWrap->GetNumActions(&num);
     return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gint, num);
 }
 
 const gchar *
 getActionDescriptionCB(AtkAction *aAction, gint aActionIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsAutoString description;
     nsresult rv = accWrap->GetActionDescription(aActionIndex, description);
     NS_ENSURE_SUCCESS(rv, nsnull);
     return nsAccessibleWrap::ReturnString(description);
 }
 
 const gchar *
 getActionNameCB(AtkAction *aAction, gint aActionIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsAutoString autoStr;
     nsresult rv = accWrap->GetActionName(aActionIndex, autoStr);
     NS_ENSURE_SUCCESS(rv, nsnull);
     return nsAccessibleWrap::ReturnString(autoStr);
 }
 
 const gchar *
 getKeyBindingCB(AtkAction *aAction, gint aActionIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     //return all KeyBindings including accesskey and shortcut
     nsAutoString allKeyBinding;
 
     //get accesskey
     nsAutoString accessKey;
     nsresult rv = accWrap->GetKeyboardShortcut(accessKey);
 
--- a/accessible/src/atk/nsMaiInterfaceComponent.cpp
+++ b/accessible/src/atk/nsMaiInterfaceComponent.cpp
@@ -64,36 +64,34 @@ componentInterfaceInitCB(AtkComponentIfa
 }
 
 AtkObject *
 refAccessibleAtPointCB(AtkComponent *aComponent,
                        gint aAccX, gint aAccY,
                        AtkCoordType aCoordType)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     // or ATK_XY_SCREEN  what is definition this in nsIAccessible ???
     if (aCoordType == ATK_XY_WINDOW) {
         /* deal with the coord type */
     }
 
     nsCOMPtr<nsIAccessible> pointAcc;
     accWrap->GetChildAtPoint(aAccX, aAccY, getter_AddRefs(pointAcc));
     if (!pointAcc) {
         return nsnull;
     }
 
-    void *atkObjPtr = nsnull;
-    pointAcc->GetNativeInterface(&atkObjPtr);
-    if (!atkObjPtr) {
-        return nsnull;
+    AtkObject *atkObj = nsAccessibleWrap::GetAtkObject(pointAcc);
+    if (atkObj) {
+        g_object_ref(atkObj);
     }
-    AtkObject *atkObj = ATK_OBJECT(atkObjPtr);
-    g_object_ref(atkObj);
     return atkObj;
 }
 
 void
 getExtentsCB(AtkComponent *aComponent,
              gint *aAccX,
              gint *aAccY,
              gint *aAccWidth,
@@ -146,13 +144,14 @@ getExtentsCB(AtkComponent *aComponent,
     *aAccWidth = nsAccWidth;
     *aAccHeight = nsAccHeight;
 }
 
 gboolean
 grabFocusCB(AtkComponent *aComponent)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsresult rv = accWrap->TakeFocus();
     return (NS_FAILED(rv)) ? FALSE : TRUE;
 }
--- a/accessible/src/atk/nsMaiInterfaceDocument.cpp
+++ b/accessible/src/atk/nsMaiInterfaceDocument.cpp
@@ -62,17 +62,18 @@ documentInterfaceInitCB(AtkDocumentIface
     aIface->get_document_attribute_value = getDocumentAttributeValueCB;
     aIface->get_document_locale = getDocumentLocaleCB;
 }
 
 const gchar *
 getDocumentLocaleCB(AtkDocument *aDocument)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessNode> docAccessNode;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessNode),
                             getter_AddRefs(docAccessNode));
     NS_ENSURE_TRUE(docAccessNode, nsnull);
 
     nsAutoString locale;
     docAccessNode->GetLanguage(locale);
@@ -81,17 +82,18 @@ getDocumentLocaleCB(AtkDocument *aDocume
     }
     return nsAccessibleWrap::ReturnString(locale);
 }
 
 const gchar *
 getDocumentTypeCB(AtkDocument *aDocument)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleDocument> accDocument;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleDocument),
                             getter_AddRefs(accDocument));
     NS_ENSURE_TRUE(accDocument, nsnull);
 
     nsAutoString mimeType;
     nsresult rv = accDocument->GetMimeType(mimeType);
@@ -108,17 +110,18 @@ prependToList(GSList *aList, const char 
     atkAttr->value = g_strdup(NS_ConvertUTF16toUTF8(aValue).get());
     return g_slist_prepend(aList, atkAttr);
 }
 
 AtkAttributeSet *
 getDocumentAttributesCB(AtkDocument *aDocument)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleDocument> accDocument;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleDocument),
                             getter_AddRefs(accDocument));
     NS_ENSURE_TRUE(accDocument, nsnull);
 
     // according to atkobject.h, AtkAttributeSet is a GSList
     GSList *attributes = nsnull;
@@ -142,17 +145,18 @@ getDocumentAttributesCB(AtkDocument *aDo
     return attributes;
 }
 
 const gchar *
 getDocumentAttributeValueCB(AtkDocument *aDocument,
                             const gchar *aAttrName)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleDocument> accDocument;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleDocument),
                             getter_AddRefs(accDocument));
     NS_ENSURE_TRUE(accDocument, nsnull);
 
     nsresult rv;
     nsAutoString attrValue;
--- a/accessible/src/atk/nsMaiInterfaceEditableText.cpp
+++ b/accessible/src/atk/nsMaiInterfaceEditableText.cpp
@@ -60,17 +60,18 @@ editableTextInterfaceInitCB(AtkEditableT
 /* static, callbacks for atkeditabletext virutal functions */
 
 gboolean
 setRunAttributesCB(AtkEditableText *aText, AtkAttributeSet *aAttribSet,
                    gint aStartOffset, gint aEndOffset)
 
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleEditableText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, FALSE);
 
     nsCOMPtr<nsISupports> attrSet;
     /* how to insert attributes into nsISupports ??? */
--- a/accessible/src/atk/nsMaiInterfaceHyperlinkImpl.cpp
+++ b/accessible/src/atk/nsMaiInterfaceHyperlinkImpl.cpp
@@ -48,17 +48,18 @@ hyperlinkImplInterfaceInitCB(AtkHyperlin
 
     aIface->get_hyperlink = getHyperlinkCB;
 }
 
 AtkHyperlink*
 getHyperlinkCB(AtkHyperlinkImpl *aImpl)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aImpl));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleHyperLink> accHyperlink;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperLink),
                             getter_AddRefs(accHyperlink));
     NS_ENSURE_TRUE(accHyperlink, nsnull);
     
     MaiHyperlink *maiHyperlink = accWrap->GetMaiHyperlink();
     NS_ENSURE_TRUE(maiHyperlink, nsnull);
--- a/accessible/src/atk/nsMaiInterfaceHypertext.cpp
+++ b/accessible/src/atk/nsMaiInterfaceHypertext.cpp
@@ -50,46 +50,46 @@ hypertextInterfaceInitCB(AtkHypertextIfa
     aIface->get_link = getLinkCB;
     aIface->get_n_links = getLinkCountCB;
     aIface->get_link_index = getLinkIndexCB;
 }
 
 AtkHyperlink *
 getLinkCB(AtkHypertext *aText, gint aLinkIndex)
 {
-    nsresult rv;
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleHyperText> hyperText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText),
                             getter_AddRefs(hyperText));
     NS_ENSURE_TRUE(hyperText, nsnull);
 
     nsCOMPtr<nsIAccessibleHyperLink> hyperLink;
-    rv = hyperText->GetLink(aLinkIndex, getter_AddRefs(hyperLink));
+    nsresult rv = hyperText->GetLink(aLinkIndex, getter_AddRefs(hyperLink));
     if (NS_FAILED(rv) || !hyperLink)
         return nsnull;
 
     nsCOMPtr<nsIAccessible> hyperLinkAcc(do_QueryInterface(hyperLink));
-    void *hyperLinkAtkObj = nsnull;
-    hyperLinkAcc->GetNativeInterface(&hyperLinkAtkObj);
-    nsAccessibleWrap *accChild = GetAccessibleWrap(ATK_OBJECT(hyperLinkAtkObj));
+    AtkObject *hyperLinkAtkObj = nsAccessibleWrap::GetAtkObject(hyperLinkAcc);
+    nsAccessibleWrap *accChild = GetAccessibleWrap(hyperLinkAtkObj);
     NS_ENSURE_TRUE(accChild, nsnull);
 
     MaiHyperlink *maiHyperlink = accChild->GetMaiHyperlink();
     NS_ENSURE_TRUE(maiHyperlink, nsnull);
     return maiHyperlink->GetAtkHyperlink();
 }
 
 gint
 getLinkCountCB(AtkHypertext *aText)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleHyperText> accHyperlink;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText),
                             getter_AddRefs(accHyperlink));
     NS_ENSURE_TRUE(accHyperlink, -1);
 
     PRInt32 count = -1;
     nsresult rv = accHyperlink->GetLinks(&count);
@@ -97,17 +97,18 @@ getLinkCountCB(AtkHypertext *aText)
 
     return count;
 }
 
 gint
 getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleHyperText> accHyperlink;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText),
                             getter_AddRefs(accHyperlink));
     NS_ENSURE_TRUE(accHyperlink, -1);
 
     PRInt32 index = -1;
     nsresult rv = accHyperlink->GetLinkIndex(aCharIndex, &index);
--- a/accessible/src/atk/nsMaiInterfaceSelection.cpp
+++ b/accessible/src/atk/nsMaiInterfaceSelection.cpp
@@ -55,118 +55,123 @@ selectionInterfaceInitCB(AtkSelectionIfa
     aIface->remove_selection = removeSelectionCB;
     aIface->select_all_selection = selectAllSelectionCB;
 }
 
 gboolean
 addSelectionCB(AtkSelection *aSelection, gint i)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleSelectable> accSelection;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
                             getter_AddRefs(accSelection));
     NS_ENSURE_TRUE(accSelection, FALSE);
 
     return NS_SUCCEEDED(accSelection->AddChildToSelection(i));
 }
 
 gboolean
 clearSelectionCB(AtkSelection *aSelection)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleSelectable> accSelection;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
                             getter_AddRefs(accSelection));
     NS_ENSURE_TRUE(accSelection, FALSE);
 
     return NS_SUCCEEDED(accSelection->ClearSelection());
 }
 
 AtkObject *
 refSelectionCB(AtkSelection *aSelection, gint i)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleSelectable> accSelection;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
                             getter_AddRefs(accSelection));
     NS_ENSURE_TRUE(accSelection, nsnull);
 
     nsCOMPtr<nsIAccessible> accSelect;
     accSelection->RefSelection(i, getter_AddRefs(accSelect));
     if (!accSelect) {
         return nsnull;
     }
-    void *atkObjPtr = nsnull;
-    accSelect->GetNativeInterface(&atkObjPtr);
-    if (!atkObjPtr) {
-        return nsnull;
+
+    AtkObject *atkObj = nsAccessibleWrap::GetAtkObject(accSelect);
+    if (atkObj) {
+        g_object_ref(atkObj);
     }
-    AtkObject *atkObj = ATK_OBJECT(atkObjPtr);
-    g_object_ref(atkObj);
     return atkObj;
 }
 
 gint
 getSelectionCountCB(AtkSelection *aSelection)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleSelectable> accSelection;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
                             getter_AddRefs(accSelection));
     NS_ENSURE_TRUE(accSelection, -1);
 
     PRInt32 num = 0;
     nsresult rv = accSelection->GetSelectionCount(&num);
     return (NS_FAILED(rv)) ? -1 : num;
 }
 
 gboolean
 isChildSelectedCB(AtkSelection *aSelection, gint i)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleSelectable> accSelection;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
                             getter_AddRefs(accSelection));
     NS_ENSURE_TRUE(accSelection, FALSE);
 
     PRBool result = FALSE;
     nsresult rv = accSelection->IsChildSelected(i, &result);
     return (NS_FAILED(rv)) ? FALSE : result;
 }
 
 gboolean
 removeSelectionCB(AtkSelection *aSelection, gint i)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleSelectable> accSelection;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
                             getter_AddRefs(accSelection));
     NS_ENSURE_TRUE(accSelection, FALSE);
 
     nsresult rv = accSelection->RemoveChildFromSelection(i);
     return (NS_FAILED(rv)) ? FALSE : TRUE;
 }
 
 gboolean
 selectAllSelectionCB(AtkSelection *aSelection)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleSelectable> accSelection;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
                             getter_AddRefs(accSelection));
     NS_ENSURE_TRUE(accSelection, FALSE);
 
     PRBool result = FALSE;
     nsresult rv = accSelection->SelectAllSelection(&result);
--- a/accessible/src/atk/nsMaiInterfaceTable.cpp
+++ b/accessible/src/atk/nsMaiInterfaceTable.cpp
@@ -67,43 +67,42 @@ tableInterfaceInitCB(AtkTableIface *aIfa
     aIface->is_selected = isCellSelectedCB;
 }
 
 /* static */
 AtkObject*
 refAtCB(AtkTable *aTable, gint aRow, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, nsnull);
 
     nsCOMPtr<nsIAccessible> cell;
     nsresult rv = accTable->CellRefAt(aRow, aColumn,getter_AddRefs(cell));
     if (NS_FAILED(rv) || !cell)
         return nsnull;
 
-    void *cellAtkObjPtr = nsnull;
-    cell->GetNativeInterface(&cellAtkObjPtr);
-    if (!cellAtkObjPtr)
-        return nsnull;
-
-    AtkObject *cellAtkObj = ATK_OBJECT(cellAtkObjPtr);
-    g_object_ref(cellAtkObj);
+    AtkObject *cellAtkObj = nsAccessibleWrap::GetAtkObject(cell);
+    if (cellAtkObj) {
+        g_object_ref(cellAtkObj);
+    }
     return cellAtkObj;
 }
 
 gint
 getIndexAtCB(AtkTable *aTable, gint aRow, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 index;
     nsresult rv = accTable->GetIndexAt(aRow, aColumn, &index);
@@ -111,17 +110,18 @@ getIndexAtCB(AtkTable *aTable, gint aRow
 
     return NS_STATIC_CAST(gint, index);
 }
 
 gint
 getColumnAtIndexCB(AtkTable *aTable, gint aIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 col;
     nsresult rv = accTable->GetColumnAtIndex(aIndex, &col);
@@ -129,17 +129,18 @@ getColumnAtIndexCB(AtkTable *aTable, gin
 
     return NS_STATIC_CAST(gint, col);
 }
 
 gint
 getRowAtIndexCB(AtkTable *aTable, gint aIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 row;
     nsresult rv = accTable->GetRowAtIndex(aIndex, &row);
@@ -147,17 +148,18 @@ getRowAtIndexCB(AtkTable *aTable, gint a
 
     return NS_STATIC_CAST(gint, row);
 }
 
 gint
 getColumnCountCB(AtkTable *aTable)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 count;
     nsresult rv = accTable->GetColumns(&count);
@@ -165,17 +167,18 @@ getColumnCountCB(AtkTable *aTable)
 
     return NS_STATIC_CAST(gint, count);
 }
 
 gint
 getRowCountCB(AtkTable *aTable)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 count;
     nsresult rv = accTable->GetRows(&count);
@@ -184,17 +187,18 @@ getRowCountCB(AtkTable *aTable)
     return NS_STATIC_CAST(gint, count);
 }
 
 gint
 getColumnExtentAtCB(AtkTable *aTable,
                     gint aRow, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 extent;
     nsresult rv = accTable->GetColumnExtentAt(aRow, aColumn, &extent);
@@ -203,17 +207,18 @@ getColumnExtentAtCB(AtkTable *aTable,
     return NS_STATIC_CAST(gint, extent);
 }
 
 gint
 getRowExtentAtCB(AtkTable *aTable,
                  gint aRow, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 extent;
     nsresult rv = accTable->GetRowExtentAt(aRow, aColumn, &extent);
@@ -221,38 +226,38 @@ getRowExtentAtCB(AtkTable *aTable,
 
     return NS_STATIC_CAST(gint, extent);
 }
 
 AtkObject*
 getCaptionCB(AtkTable *aTable)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, nsnull);
 
     nsCOMPtr<nsIAccessible> caption;
     nsresult rv = accTable->GetCaption(getter_AddRefs(caption));
     if (NS_FAILED(rv) || !caption)
         return nsnull;
 
-    void *captionAtkObj = nsnull;
-    caption->GetNativeInterface(&captionAtkObj);
-    return ATK_OBJECT(captionAtkObj);
+    return nsAccessibleWrap::GetAtkObject(caption);
 }
 
 const gchar*
 getColumnDescriptionCB(AtkTable *aTable, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, nsnull);
 
     nsAutoString autoStr;
     nsresult rv = accTable->GetColumnDescription(aColumn, autoStr);
@@ -260,17 +265,18 @@ getColumnDescriptionCB(AtkTable *aTable,
 
     return nsAccessibleWrap::ReturnString(autoStr);
 }
 
 AtkObject*
 getColumnHeaderCB(AtkTable *aTable, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, nsnull);
 
     nsCOMPtr<nsIAccessibleTable> header;
     nsresult rv = accTable->GetColumnHeader(getter_AddRefs(header));
@@ -285,26 +291,25 @@ getColumnHeaderCB(AtkTable *aTable, gint
     //
     // 2. "GetColumnHeader" defined in nsIAccessibleTable returns
     // nsXULTreeColumnsAccessibleWrap, which exports nsIAccessibleTable and is
     // "ROLE_LIST".
     nsCOMPtr<nsIAccessible> accHeader;
     header->CellRefAt(0, aColumn, getter_AddRefs(accHeader));
     NS_ENSURE_TRUE(accHeader, nsnull);
 
-    void *headerAtkObj = nsnull;
-    accHeader->GetNativeInterface(&headerAtkObj);
-    return ATK_OBJECT(headerAtkObj);
+    return nsAccessibleWrap::GetAtkObject(accHeader);
 }
 
 const gchar*
 getRowDescriptionCB(AtkTable *aTable, gint aRow)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, nsnull);
 
     nsAutoString autoStr;
     nsresult rv = accTable->GetRowDescription(aRow, autoStr);
@@ -312,47 +317,47 @@ getRowDescriptionCB(AtkTable *aTable, gi
 
     return nsAccessibleWrap::ReturnString(autoStr);
 }
 
 AtkObject*
 getRowHeaderCB(AtkTable *aTable, gint aRow)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, nsnull);
 
     nsCOMPtr<nsIAccessibleTable> header;
     nsresult rv = accTable->GetRowHeader(getter_AddRefs(header));
     NS_ENSURE_SUCCESS(rv, nsnull);
 
     nsCOMPtr<nsIAccessible> accHeader(do_QueryInterface(header));
     NS_ENSURE_TRUE(accHeader, nsnull);
 
-    void *headerAtkObj = nsnull;
-    accHeader->GetNativeInterface(&headerAtkObj);
-    return ATK_OBJECT(headerAtkObj);
+    return nsAccessibleWrap::GetAtkObject(accHeader);
 }
 
 AtkObject*
 getSummaryCB(AtkTable *aTable)
 {
     /* ??? in nsIAccessibleTable, it returns a nsAString */
     return nsnull;
 }
 
 gint
 getSelectedColumnsCB(AtkTable *aTable, gint **aSelected)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, 0);
+    if (!accWrap)
+        return 0;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, 0);
 
     PRUint32 size = 0;
     PRInt32 *columns = NULL;
@@ -376,17 +381,18 @@ getSelectedColumnsCB(AtkTable *aTable, g
     *aSelected = atkColumns;
     return size;
 }
 
 gint
 getSelectedRowsCB(AtkTable *aTable, gint **aSelected)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, 0);
+    if (!accWrap)
+        return 0;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, 0);
 
     PRUint32 size = 0;
     PRInt32 *rows = NULL;
@@ -410,49 +416,52 @@ getSelectedRowsCB(AtkTable *aTable, gint
     *aSelected = atkRows;
     return size;
 }
 
 gboolean
 isColumnSelectedCB(AtkTable *aTable, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, FALSE);
 
     PRBool outValue;
     nsresult rv = accTable->IsColumnSelected(aColumn, &outValue);
     return NS_FAILED(rv) ? FALSE : NS_STATIC_CAST(gboolean, outValue);
 }
 
 gboolean
 isRowSelectedCB(AtkTable *aTable, gint aRow)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, FALSE);
 
     PRBool outValue;
     nsresult rv = accTable->IsRowSelected(aRow, &outValue);
     return NS_FAILED(rv) ? FALSE : NS_STATIC_CAST(gboolean, outValue);
 }
 
 gboolean
 isCellSelectedCB(AtkTable *aTable, gint aRow, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, FALSE);
 
     PRBool outValue;
     nsresult rv = accTable->IsCellSelected(aRow, aColumn, &outValue);
--- a/accessible/src/atk/nsMaiInterfaceText.cpp
+++ b/accessible/src/atk/nsMaiInterfaceText.cpp
@@ -84,17 +84,18 @@ void ConvertTexttoAsterisks(nsAccessible
             aString.Replace(i, 1, NS_LITERAL_STRING("*"));
     }
 }
 
 gchar *
 getTextCB(AtkText *aText, gint aStartOffset, gint aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, nsnull);
 
     nsAutoString autoStr;
     nsresult rv = accText->GetText(aStartOffset, aEndOffset, autoStr);
@@ -108,17 +109,18 @@ getTextCB(AtkText *aText, gint aStartOff
 }
 
 gchar *
 getTextAfterOffsetCB(AtkText *aText, gint aOffset,
                      AtkTextBoundary aBoundaryType,
                      gint *aStartOffset, gint *aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, nsnull);
 
     nsAutoString autoStr;
     PRInt32 startOffset = 0, endOffset = 0;
@@ -136,17 +138,18 @@ getTextAfterOffsetCB(AtkText *aText, gin
 }
 
 gchar *
 getTextAtOffsetCB(AtkText *aText, gint aOffset,
                   AtkTextBoundary aBoundaryType,
                   gint *aStartOffset, gint *aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, nsnull);
 
     nsAutoString autoStr;
     PRInt32 startOffset = 0, endOffset = 0;
@@ -162,17 +165,18 @@ getTextAtOffsetCB(AtkText *aText, gint a
     NS_ConvertUTF16toUTF8 cautoStr(autoStr);
     return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nsnull;
 }
 
 gunichar
 getCharacterAtOffsetCB(AtkText *aText, gint aOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, 0);
+    if (!accWrap)
+        return 0;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, 0);
 
     /* PRUnichar is unsigned short in Mozilla */
     /* gnuichar is guint32 in glib */
@@ -191,17 +195,18 @@ getCharacterAtOffsetCB(AtkText *aText, g
 }
 
 gchar *
 getTextBeforeOffsetCB(AtkText *aText, gint aOffset,
                       AtkTextBoundary aBoundaryType,
                       gint *aStartOffset, gint *aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, nsnull);
 
     nsAutoString autoStr;
     PRInt32 startOffset = 0, endOffset = 0;
@@ -217,17 +222,18 @@ getTextBeforeOffsetCB(AtkText *aText, gi
     NS_ConvertUTF16toUTF8 cautoStr(autoStr);
     return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nsnull;
 }
 
 gint
 getCaretOffsetCB(AtkText *aText)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, 0);
+    if (!accWrap)
+        return 0;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, 0);
 
     PRInt32 offset;
     nsresult rv = accText->GetCaretOffset(&offset);
@@ -235,17 +241,18 @@ getCaretOffsetCB(AtkText *aText)
 }
 
 AtkAttributeSet *
 getRunAttributesCB(AtkText *aText, gint aOffset,
                    gint *aStartOffset,
                    gint *aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, nsnull);
 
     nsCOMPtr<nsIAccessible> accessibleWithAttrs;
     PRInt32 startOffset = 0, endOffset = 0;
@@ -336,17 +343,18 @@ getRangeExtentsCB(AtkText *aText, gint a
     NS_ASSERTION(NS_SUCCEEDED(rv),
                  "MaiInterfaceText::GetRangeExtents, failed\n");
 }
 
 gint
 getCharacterCountCB(AtkText *aText)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, 0);
+    if (!accWrap)
+        return 0;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, 0);
 
     PRInt32 count = 0;
     nsresult rv = accText->GetCharacterCount(&count);
@@ -354,17 +362,18 @@ getCharacterCountCB(AtkText *aText)
 }
 
 gint
 getOffsetAtPointCB(AtkText *aText,
                    gint aX, gint aY,
                    AtkCoordType aCoords)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, -1);
+    if (!accWrap)
+        return -1;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, -1);
 
     PRInt32 offset = 0;
     PRUint32 geckoCoordType;
@@ -376,34 +385,36 @@ getOffsetAtPointCB(AtkText *aText,
     accText->GetOffsetAtPoint(aX, aY, geckoCoordType, &offset);
     return NS_STATIC_CAST(gint, offset);
 }
 
 gint
 getTextSelectionCountCB(AtkText *aText)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
 
     PRInt32 selectionCount;
     nsresult rv = accText->GetSelectionCount(&selectionCount);
  
     return NS_FAILED(rv) ? 0 : selectionCount;
 }
 
 gchar *
 getTextSelectionCB(AtkText *aText, gint aSelectionNum,
                    gint *aStartOffset, gint *aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, nsnull);
+    if (!accWrap)
+        return nsnull;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, nsnull);
 
     PRInt32 startOffset = 0, endOffset = 0;
     nsresult rv = accText->GetSelectionBounds(aSelectionNum,
@@ -419,67 +430,71 @@ getTextSelectionCB(AtkText *aText, gint 
 
 // set methods
 gboolean
 addTextSelectionCB(AtkText *aText,
                    gint aStartOffset,
                    gint aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, FALSE);
 
     nsresult rv = accText->AddSelection(aStartOffset, aEndOffset);
 
     return NS_SUCCEEDED(rv) ? TRUE : FALSE;
 }
 
 gboolean
 removeTextSelectionCB(AtkText *aText,
                       gint aSelectionNum)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, FALSE);
 
     nsresult rv = accText->RemoveSelection(aSelectionNum);
 
     return NS_SUCCEEDED(rv) ? TRUE : FALSE;
 }
 
 gboolean
 setTextSelectionCB(AtkText *aText, gint aSelectionNum,
                    gint aStartOffset, gint aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, FALSE);
 
     nsresult rv = accText->SetSelectionBounds(aSelectionNum,
                                               aStartOffset, aEndOffset);
     return NS_SUCCEEDED(rv) ? TRUE : FALSE;
 }
 
 gboolean
 setCaretOffsetCB(AtkText *aText, gint aOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, FALSE);
 
     nsresult rv = accText->SetCaretOffset(aOffset);
     return NS_SUCCEEDED(rv) ? TRUE : FALSE;
--- a/accessible/src/atk/nsMaiInterfaceValue.cpp
+++ b/accessible/src/atk/nsMaiInterfaceValue.cpp
@@ -137,17 +137,18 @@ getMinimumIncrementCB(AtkValue *obj, GVa
     g_value_init (minimumIncrement, G_TYPE_DOUBLE);
     g_value_set_double (minimumIncrement, accDouble);
 }
 
 gboolean
 setCurrentValueCB(AtkValue *obj, const GValue *value)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(obj));
-    NS_ENSURE_TRUE(accWrap, FALSE);
+    if (!accWrap)
+        return FALSE;
 
     nsCOMPtr<nsIAccessibleValue> accValue;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleValue),
                             getter_AddRefs(accValue));
     NS_ENSURE_TRUE(accValue, FALSE);
 
     double accDouble =g_value_get_double (value);
     return !NS_FAILED(accValue->SetCurrentValue(accDouble));