Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "mozilla/mozalloc.h" |
michael@0 | 7 | #include "nsCOMPtr.h" |
michael@0 | 8 | #include "nsDebug.h" |
michael@0 | 9 | #include "nsError.h" |
michael@0 | 10 | #include "nsID.h" |
michael@0 | 11 | #include "nsISupportsUtils.h" |
michael@0 | 12 | #include "nsITransactionManager.h" |
michael@0 | 13 | #include "nsTransactionItem.h" |
michael@0 | 14 | #include "nsTransactionList.h" |
michael@0 | 15 | #include "nsTransactionStack.h" |
michael@0 | 16 | #include "nscore.h" |
michael@0 | 17 | |
michael@0 | 18 | NS_IMPL_ISUPPORTS(nsTransactionList, nsITransactionList) |
michael@0 | 19 | |
michael@0 | 20 | nsTransactionList::nsTransactionList(nsITransactionManager *aTxnMgr, nsTransactionStack *aTxnStack) |
michael@0 | 21 | : mTxnStack(aTxnStack) |
michael@0 | 22 | , mTxnItem(0) |
michael@0 | 23 | { |
michael@0 | 24 | if (aTxnMgr) |
michael@0 | 25 | mTxnMgr = do_GetWeakReference(aTxnMgr); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | nsTransactionList::nsTransactionList(nsITransactionManager *aTxnMgr, nsTransactionItem *aTxnItem) |
michael@0 | 29 | : mTxnStack(0) |
michael@0 | 30 | , mTxnItem(aTxnItem) |
michael@0 | 31 | { |
michael@0 | 32 | if (aTxnMgr) |
michael@0 | 33 | mTxnMgr = do_GetWeakReference(aTxnMgr); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | nsTransactionList::~nsTransactionList() |
michael@0 | 37 | { |
michael@0 | 38 | mTxnStack = 0; |
michael@0 | 39 | mTxnItem = 0; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | /* readonly attribute long numItems; */ |
michael@0 | 43 | NS_IMETHODIMP nsTransactionList::GetNumItems(int32_t *aNumItems) |
michael@0 | 44 | { |
michael@0 | 45 | NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER); |
michael@0 | 46 | |
michael@0 | 47 | *aNumItems = 0; |
michael@0 | 48 | |
michael@0 | 49 | nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr); |
michael@0 | 50 | |
michael@0 | 51 | NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE); |
michael@0 | 52 | |
michael@0 | 53 | nsresult result = NS_OK; |
michael@0 | 54 | |
michael@0 | 55 | if (mTxnStack) |
michael@0 | 56 | *aNumItems = mTxnStack->GetSize(); |
michael@0 | 57 | else if (mTxnItem) |
michael@0 | 58 | result = mTxnItem->GetNumberOfChildren(aNumItems); |
michael@0 | 59 | |
michael@0 | 60 | return result; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | /* boolean itemIsBatch (in long aIndex); */ |
michael@0 | 64 | NS_IMETHODIMP nsTransactionList::ItemIsBatch(int32_t aIndex, bool *aIsBatch) |
michael@0 | 65 | { |
michael@0 | 66 | NS_ENSURE_TRUE(aIsBatch, NS_ERROR_NULL_POINTER); |
michael@0 | 67 | |
michael@0 | 68 | *aIsBatch = false; |
michael@0 | 69 | |
michael@0 | 70 | nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr); |
michael@0 | 71 | |
michael@0 | 72 | NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE); |
michael@0 | 73 | |
michael@0 | 74 | nsRefPtr<nsTransactionItem> item; |
michael@0 | 75 | |
michael@0 | 76 | nsresult result = NS_OK; |
michael@0 | 77 | |
michael@0 | 78 | if (mTxnStack) |
michael@0 | 79 | item = mTxnStack->GetItem(aIndex); |
michael@0 | 80 | else if (mTxnItem) |
michael@0 | 81 | result = mTxnItem->GetChild(aIndex, getter_AddRefs(item)); |
michael@0 | 82 | |
michael@0 | 83 | NS_ENSURE_SUCCESS(result, result); |
michael@0 | 84 | |
michael@0 | 85 | NS_ENSURE_TRUE(item, NS_ERROR_FAILURE); |
michael@0 | 86 | |
michael@0 | 87 | return item->GetIsBatch(aIsBatch); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | /* void getData (in long aIndex, |
michael@0 | 91 | [optional] out unsigned long aLength, |
michael@0 | 92 | [array, size_is (aLength), retval] |
michael@0 | 93 | out nsISupports aData); */ |
michael@0 | 94 | NS_IMETHODIMP nsTransactionList::GetData(int32_t aIndex, |
michael@0 | 95 | uint32_t *aLength, |
michael@0 | 96 | nsISupports ***aData) |
michael@0 | 97 | { |
michael@0 | 98 | nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr); |
michael@0 | 99 | |
michael@0 | 100 | NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE); |
michael@0 | 101 | |
michael@0 | 102 | nsRefPtr<nsTransactionItem> item; |
michael@0 | 103 | |
michael@0 | 104 | if (mTxnStack) { |
michael@0 | 105 | item = mTxnStack->GetItem(aIndex); |
michael@0 | 106 | } else if (mTxnItem) { |
michael@0 | 107 | nsresult result = mTxnItem->GetChild(aIndex, getter_AddRefs(item)); |
michael@0 | 108 | NS_ENSURE_SUCCESS(result, result); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | nsCOMArray<nsISupports>& data = item->GetData(); |
michael@0 | 112 | |
michael@0 | 113 | nsISupports** ret = static_cast<nsISupports**>(NS_Alloc(data.Count() * |
michael@0 | 114 | sizeof(nsISupports*))); |
michael@0 | 115 | |
michael@0 | 116 | for (int32_t i = 0; i < data.Count(); i++) { |
michael@0 | 117 | NS_ADDREF(ret[i] = data[i]); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | *aLength = data.Count(); |
michael@0 | 121 | *aData = ret; |
michael@0 | 122 | |
michael@0 | 123 | return NS_OK; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | /* nsITransaction getItem (in long aIndex); */ |
michael@0 | 127 | NS_IMETHODIMP nsTransactionList::GetItem(int32_t aIndex, nsITransaction **aItem) |
michael@0 | 128 | { |
michael@0 | 129 | NS_ENSURE_TRUE(aItem, NS_ERROR_NULL_POINTER); |
michael@0 | 130 | |
michael@0 | 131 | *aItem = 0; |
michael@0 | 132 | |
michael@0 | 133 | nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr); |
michael@0 | 134 | |
michael@0 | 135 | NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE); |
michael@0 | 136 | |
michael@0 | 137 | nsRefPtr<nsTransactionItem> item; |
michael@0 | 138 | |
michael@0 | 139 | nsresult result = NS_OK; |
michael@0 | 140 | |
michael@0 | 141 | if (mTxnStack) |
michael@0 | 142 | item = mTxnStack->GetItem(aIndex); |
michael@0 | 143 | else if (mTxnItem) |
michael@0 | 144 | result = mTxnItem->GetChild(aIndex, getter_AddRefs(item)); |
michael@0 | 145 | |
michael@0 | 146 | NS_ENSURE_SUCCESS(result, result); |
michael@0 | 147 | |
michael@0 | 148 | NS_ENSURE_TRUE(item, NS_ERROR_FAILURE); |
michael@0 | 149 | |
michael@0 | 150 | *aItem = item->GetTransaction().take(); |
michael@0 | 151 | |
michael@0 | 152 | return NS_OK; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | /* long getNumChildrenForItem (in long aIndex); */ |
michael@0 | 156 | NS_IMETHODIMP nsTransactionList::GetNumChildrenForItem(int32_t aIndex, int32_t *aNumChildren) |
michael@0 | 157 | { |
michael@0 | 158 | NS_ENSURE_TRUE(aNumChildren, NS_ERROR_NULL_POINTER); |
michael@0 | 159 | |
michael@0 | 160 | *aNumChildren = 0; |
michael@0 | 161 | |
michael@0 | 162 | nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr); |
michael@0 | 163 | |
michael@0 | 164 | NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE); |
michael@0 | 165 | |
michael@0 | 166 | nsRefPtr<nsTransactionItem> item; |
michael@0 | 167 | |
michael@0 | 168 | nsresult result = NS_OK; |
michael@0 | 169 | |
michael@0 | 170 | if (mTxnStack) |
michael@0 | 171 | item = mTxnStack->GetItem(aIndex); |
michael@0 | 172 | else if (mTxnItem) |
michael@0 | 173 | result = mTxnItem->GetChild(aIndex, getter_AddRefs(item)); |
michael@0 | 174 | |
michael@0 | 175 | NS_ENSURE_SUCCESS(result, result); |
michael@0 | 176 | |
michael@0 | 177 | NS_ENSURE_TRUE(item, NS_ERROR_FAILURE); |
michael@0 | 178 | |
michael@0 | 179 | return item->GetNumberOfChildren(aNumChildren); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | /* nsITransactionList getChildListForItem (in long aIndex); */ |
michael@0 | 183 | NS_IMETHODIMP nsTransactionList::GetChildListForItem(int32_t aIndex, nsITransactionList **aTxnList) |
michael@0 | 184 | { |
michael@0 | 185 | NS_ENSURE_TRUE(aTxnList, NS_ERROR_NULL_POINTER); |
michael@0 | 186 | |
michael@0 | 187 | *aTxnList = 0; |
michael@0 | 188 | |
michael@0 | 189 | nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr); |
michael@0 | 190 | |
michael@0 | 191 | NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE); |
michael@0 | 192 | |
michael@0 | 193 | nsRefPtr<nsTransactionItem> item; |
michael@0 | 194 | |
michael@0 | 195 | nsresult result = NS_OK; |
michael@0 | 196 | |
michael@0 | 197 | if (mTxnStack) |
michael@0 | 198 | item = mTxnStack->GetItem(aIndex); |
michael@0 | 199 | else if (mTxnItem) |
michael@0 | 200 | result = mTxnItem->GetChild(aIndex, getter_AddRefs(item)); |
michael@0 | 201 | |
michael@0 | 202 | NS_ENSURE_SUCCESS(result, result); |
michael@0 | 203 | |
michael@0 | 204 | NS_ENSURE_TRUE(item, NS_ERROR_FAILURE); |
michael@0 | 205 | |
michael@0 | 206 | *aTxnList = (nsITransactionList *)new nsTransactionList(txMgr, item); |
michael@0 | 207 | |
michael@0 | 208 | NS_ENSURE_TRUE(*aTxnList, NS_ERROR_OUT_OF_MEMORY); |
michael@0 | 209 | |
michael@0 | 210 | NS_ADDREF(*aTxnList); |
michael@0 | 211 | |
michael@0 | 212 | return NS_OK; |
michael@0 | 213 | } |
michael@0 | 214 |