Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /** |
michael@0 | 2 | * Helper method to start a single XUL tree test. |
michael@0 | 3 | */ |
michael@0 | 4 | function loadXULTreeAndDoTest(aDoTestFunc, aTreeID, aTreeView) |
michael@0 | 5 | { |
michael@0 | 6 | var doTestFunc = aDoTestFunc ? aDoTestFunc : gXULTreeLoadContext.doTestFunc; |
michael@0 | 7 | var treeID = aTreeID ? aTreeID : gXULTreeLoadContext.treeID; |
michael@0 | 8 | var treeView = aTreeView ? aTreeView : gXULTreeLoadContext.treeView; |
michael@0 | 9 | |
michael@0 | 10 | function loadXULTree(aTreeID, aTreeView) |
michael@0 | 11 | { |
michael@0 | 12 | this.treeNode = getNode(aTreeID); |
michael@0 | 13 | |
michael@0 | 14 | this.eventSeq = [ |
michael@0 | 15 | new invokerChecker(EVENT_REORDER, this.treeNode) |
michael@0 | 16 | ]; |
michael@0 | 17 | |
michael@0 | 18 | this.invoke = function loadXULTree_invoke() |
michael@0 | 19 | { |
michael@0 | 20 | this.treeNode.treeBoxObject.view = aTreeView; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | this.getID = function loadXULTree_getID() |
michael@0 | 24 | { |
michael@0 | 25 | return "Load XUL tree " + prettyName(aTreeID); |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | gXULTreeLoadContext.queue = new eventQueue(); |
michael@0 | 30 | gXULTreeLoadContext.queue.push(new loadXULTree(treeID, treeView)); |
michael@0 | 31 | gXULTreeLoadContext.queue.onFinish = function() |
michael@0 | 32 | { |
michael@0 | 33 | SimpleTest.executeSoon(doTestFunc); |
michael@0 | 34 | return DO_NOT_FINISH_TEST; |
michael@0 | 35 | } |
michael@0 | 36 | gXULTreeLoadContext.queue.invoke(); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * Analogy of addA11yLoadEvent, nice helper to load XUL tree and start the test. |
michael@0 | 41 | */ |
michael@0 | 42 | function addA11yXULTreeLoadEvent(aDoTestFunc, aTreeID, aTreeView) |
michael@0 | 43 | { |
michael@0 | 44 | gXULTreeLoadContext.doTestFunc = aDoTestFunc; |
michael@0 | 45 | gXULTreeLoadContext.treeID = aTreeID; |
michael@0 | 46 | gXULTreeLoadContext.treeView = aTreeView; |
michael@0 | 47 | |
michael@0 | 48 | addA11yLoadEvent(loadXULTreeAndDoTest); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | |
michael@0 | 52 | function nsTableTreeView(aRowCount) |
michael@0 | 53 | { |
michael@0 | 54 | this.__proto__ = new nsTreeView(); |
michael@0 | 55 | |
michael@0 | 56 | for (var idx = 0; idx < aRowCount; idx++) |
michael@0 | 57 | this.mData.push(new treeItem("row" + String(idx) + "_")); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function nsTreeTreeView() |
michael@0 | 61 | { |
michael@0 | 62 | this.__proto__ = new nsTreeView(); |
michael@0 | 63 | |
michael@0 | 64 | this.mData = [ |
michael@0 | 65 | new treeItem("row1"), |
michael@0 | 66 | new treeItem("row2_", true, [new treeItem("row2.1_"), new treeItem("row2.2_")]), |
michael@0 | 67 | new treeItem("row3_", false, [new treeItem("row3.1_"), new treeItem("row3.2_")]), |
michael@0 | 68 | new treeItem("row4") |
michael@0 | 69 | ]; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | function nsTreeView() |
michael@0 | 73 | { |
michael@0 | 74 | this.mTree = null; |
michael@0 | 75 | this.mData = []; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | nsTreeView.prototype = |
michael@0 | 79 | { |
michael@0 | 80 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 81 | // nsITreeView implementation |
michael@0 | 82 | |
michael@0 | 83 | get rowCount() |
michael@0 | 84 | { |
michael@0 | 85 | return this.getRowCountIntl(this.mData); |
michael@0 | 86 | }, |
michael@0 | 87 | setTree: function setTree(aTree) |
michael@0 | 88 | { |
michael@0 | 89 | this.mTree = aTree; |
michael@0 | 90 | }, |
michael@0 | 91 | getCellText: function getCellText(aRow, aCol) |
michael@0 | 92 | { |
michael@0 | 93 | var data = this.getDataForIndex(aRow); |
michael@0 | 94 | if (aCol.id in data.colsText) |
michael@0 | 95 | return data.colsText[aCol.id]; |
michael@0 | 96 | |
michael@0 | 97 | return data.text + aCol.id; |
michael@0 | 98 | }, |
michael@0 | 99 | getCellValue: function getCellValue(aRow, aCol) |
michael@0 | 100 | { |
michael@0 | 101 | var data = this.getDataForIndex(aRow); |
michael@0 | 102 | return data.value; |
michael@0 | 103 | }, |
michael@0 | 104 | getRowProperties: function getRowProperties(aIndex) { return ""; }, |
michael@0 | 105 | getCellProperties: function getCellProperties(aIndex, aCol) |
michael@0 | 106 | { |
michael@0 | 107 | if (!aCol.cycler) |
michael@0 | 108 | return ""; |
michael@0 | 109 | |
michael@0 | 110 | var data = this.getDataForIndex(aIndex); |
michael@0 | 111 | return this.mCyclerStates[data.cyclerState]; |
michael@0 | 112 | }, |
michael@0 | 113 | getColumnProperties: function getColumnProperties(aCol) { return ""; }, |
michael@0 | 114 | getParentIndex: function getParentIndex(aRowIndex) |
michael@0 | 115 | { |
michael@0 | 116 | var info = this.getInfoByIndex(aRowIndex); |
michael@0 | 117 | return info.parentIndex; |
michael@0 | 118 | }, |
michael@0 | 119 | hasNextSibling: function hasNextSibling(aRowIndex, aAfterIndex) { }, |
michael@0 | 120 | getLevel: function getLevel(aIndex) |
michael@0 | 121 | { |
michael@0 | 122 | var info = this.getInfoByIndex(aIndex); |
michael@0 | 123 | return info.level; |
michael@0 | 124 | }, |
michael@0 | 125 | getImageSrc: function getImageSrc(aRow, aCol) {}, |
michael@0 | 126 | getProgressMode: function getProgressMode(aRow, aCol) {}, |
michael@0 | 127 | isContainer: function isContainer(aIndex) |
michael@0 | 128 | { |
michael@0 | 129 | var data = this.getDataForIndex(aIndex); |
michael@0 | 130 | return data.open != undefined; |
michael@0 | 131 | }, |
michael@0 | 132 | isContainerOpen: function isContainerOpen(aIndex) |
michael@0 | 133 | { |
michael@0 | 134 | var data = this.getDataForIndex(aIndex); |
michael@0 | 135 | return data.open; |
michael@0 | 136 | }, |
michael@0 | 137 | isContainerEmpty: function isContainerEmpty(aIndex) |
michael@0 | 138 | { |
michael@0 | 139 | var data = this.getDataForIndex(aIndex); |
michael@0 | 140 | return data.open == undefined; |
michael@0 | 141 | }, |
michael@0 | 142 | isSeparator: function isSeparator(aIndex) {}, |
michael@0 | 143 | isSorted: function isSorted() {}, |
michael@0 | 144 | toggleOpenState: function toggleOpenState(aIndex) |
michael@0 | 145 | { |
michael@0 | 146 | var data = this.getDataForIndex(aIndex); |
michael@0 | 147 | |
michael@0 | 148 | data.open = !data.open; |
michael@0 | 149 | var rowCount = this.getRowCountIntl(data.children); |
michael@0 | 150 | |
michael@0 | 151 | if (data.open) |
michael@0 | 152 | this.mTree.rowCountChanged(aIndex + 1, rowCount); |
michael@0 | 153 | else |
michael@0 | 154 | this.mTree.rowCountChanged(aIndex + 1, -rowCount); |
michael@0 | 155 | }, |
michael@0 | 156 | selectionChanged: function selectionChanged() {}, |
michael@0 | 157 | cycleHeader: function cycleHeader(aCol) {}, |
michael@0 | 158 | cycleCell: function cycleCell(aRow, aCol) |
michael@0 | 159 | { |
michael@0 | 160 | var data = this.getDataForIndex(aRow); |
michael@0 | 161 | data.cyclerState = (data.cyclerState + 1) % 3; |
michael@0 | 162 | |
michael@0 | 163 | this.mTree.invalidateCell(aRow, aCol); |
michael@0 | 164 | }, |
michael@0 | 165 | isEditable: function isEditable(aRow, aCol) |
michael@0 | 166 | { |
michael@0 | 167 | return true; |
michael@0 | 168 | }, |
michael@0 | 169 | isSelectable: function isSelectable(aRow, aCol) {}, |
michael@0 | 170 | setCellText: function setCellText(aRow, aCol, aValue) |
michael@0 | 171 | { |
michael@0 | 172 | var data = this.getDataForIndex(aRow); |
michael@0 | 173 | data.colsText[aCol.id] = aValue; |
michael@0 | 174 | }, |
michael@0 | 175 | setCellValue: function setCellValue(aRow, aCol, aValue) |
michael@0 | 176 | { |
michael@0 | 177 | var data = this.getDataForIndex(aRow); |
michael@0 | 178 | data.value = aValue; |
michael@0 | 179 | |
michael@0 | 180 | this.mTree.invalidateCell(aRow, aCol); |
michael@0 | 181 | }, |
michael@0 | 182 | performAction: function performAction(aAction) {}, |
michael@0 | 183 | performActionOnRow: function performActionOnRow(aAction, aRow) {}, |
michael@0 | 184 | performActionOnCell: function performActionOnCell(aAction, aRow, aCol) {}, |
michael@0 | 185 | |
michael@0 | 186 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 187 | // public implementation |
michael@0 | 188 | |
michael@0 | 189 | appendItem: function appendItem(aText) |
michael@0 | 190 | { |
michael@0 | 191 | this.mData.push(new treeItem(aText)); |
michael@0 | 192 | }, |
michael@0 | 193 | |
michael@0 | 194 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 195 | // private implementation |
michael@0 | 196 | |
michael@0 | 197 | getDataForIndex: function getDataForIndex(aRowIndex) |
michael@0 | 198 | { |
michael@0 | 199 | return this.getInfoByIndex(aRowIndex).data; |
michael@0 | 200 | }, |
michael@0 | 201 | |
michael@0 | 202 | getInfoByIndex: function getInfoByIndex(aRowIndex) |
michael@0 | 203 | { |
michael@0 | 204 | var info = { |
michael@0 | 205 | data: null, |
michael@0 | 206 | parentIndex: -1, |
michael@0 | 207 | level: 0, |
michael@0 | 208 | index: -1 |
michael@0 | 209 | }; |
michael@0 | 210 | |
michael@0 | 211 | this.getInfoByIndexIntl(aRowIndex, info, this.mData, 0); |
michael@0 | 212 | return info; |
michael@0 | 213 | }, |
michael@0 | 214 | |
michael@0 | 215 | getRowCountIntl: function getRowCountIntl(aChildren) |
michael@0 | 216 | { |
michael@0 | 217 | var rowCount = 0; |
michael@0 | 218 | for (var childIdx = 0; childIdx < aChildren.length; childIdx++) { |
michael@0 | 219 | rowCount++; |
michael@0 | 220 | |
michael@0 | 221 | var data = aChildren[childIdx]; |
michael@0 | 222 | if (data.open) |
michael@0 | 223 | rowCount += this.getRowCountIntl(data.children); |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | return rowCount; |
michael@0 | 227 | }, |
michael@0 | 228 | |
michael@0 | 229 | getInfoByIndexIntl: function getInfoByIndexIntl(aRowIdx, aInfo, |
michael@0 | 230 | aChildren, aLevel) |
michael@0 | 231 | { |
michael@0 | 232 | var rowIdx = aRowIdx; |
michael@0 | 233 | for (var childIdx = 0; childIdx < aChildren.length; childIdx++) { |
michael@0 | 234 | var data = aChildren[childIdx]; |
michael@0 | 235 | |
michael@0 | 236 | aInfo.index++; |
michael@0 | 237 | |
michael@0 | 238 | if (rowIdx == 0) { |
michael@0 | 239 | aInfo.data = data; |
michael@0 | 240 | aInfo.level = aLevel; |
michael@0 | 241 | return -1; |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | if (data.open) { |
michael@0 | 245 | var parentIdx = aInfo.index; |
michael@0 | 246 | rowIdx = this.getInfoByIndexIntl(rowIdx - 1, aInfo, data.children, |
michael@0 | 247 | aLevel + 1); |
michael@0 | 248 | |
michael@0 | 249 | if (rowIdx == -1) { |
michael@0 | 250 | if (aInfo.parentIndex == -1) |
michael@0 | 251 | aInfo.parentIndex = parentIdx; |
michael@0 | 252 | return 0; |
michael@0 | 253 | } |
michael@0 | 254 | } else { |
michael@0 | 255 | rowIdx--; |
michael@0 | 256 | } |
michael@0 | 257 | } |
michael@0 | 258 | |
michael@0 | 259 | return rowIdx; |
michael@0 | 260 | }, |
michael@0 | 261 | |
michael@0 | 262 | mCyclerStates: [ |
michael@0 | 263 | "cyclerState1", |
michael@0 | 264 | "cyclerState2", |
michael@0 | 265 | "cyclerState3" |
michael@0 | 266 | ] |
michael@0 | 267 | }; |
michael@0 | 268 | |
michael@0 | 269 | function treeItem(aText, aOpen, aChildren) |
michael@0 | 270 | { |
michael@0 | 271 | this.text = aText; |
michael@0 | 272 | this.colsText = {}; |
michael@0 | 273 | this.open = aOpen; |
michael@0 | 274 | this.value = "true"; |
michael@0 | 275 | this.cyclerState = 0; |
michael@0 | 276 | if (aChildren) |
michael@0 | 277 | this.children = aChildren; |
michael@0 | 278 | } |
michael@0 | 279 | |
michael@0 | 280 | function createAtom(aName) |
michael@0 | 281 | { |
michael@0 | 282 | return Components.classes["@mozilla.org/atom-service;1"] |
michael@0 | 283 | .getService(Components.interfaces.nsIAtomService).getAtom(aName); |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | /** |
michael@0 | 287 | * Used in conjunction with loadXULTreeAndDoTest and addA11yXULTreeLoadEvent. |
michael@0 | 288 | */ |
michael@0 | 289 | var gXULTreeLoadContext = |
michael@0 | 290 | { |
michael@0 | 291 | doTestFunc: null, |
michael@0 | 292 | treeID: null, |
michael@0 | 293 | treeView: null, |
michael@0 | 294 | queue: null |
michael@0 | 295 | }; |