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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "AccCollector.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "Accessible.h" |
michael@0 | 8 | |
michael@0 | 9 | using namespace mozilla::a11y; |
michael@0 | 10 | |
michael@0 | 11 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 12 | // nsAccCollector |
michael@0 | 13 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 14 | |
michael@0 | 15 | AccCollector:: |
michael@0 | 16 | AccCollector(Accessible* aRoot, filters::FilterFuncPtr aFilterFunc) : |
michael@0 | 17 | mFilterFunc(aFilterFunc), mRoot(aRoot), mRootChildIdx(0) |
michael@0 | 18 | { |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | AccCollector::~AccCollector() |
michael@0 | 22 | { |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | uint32_t |
michael@0 | 26 | AccCollector::Count() |
michael@0 | 27 | { |
michael@0 | 28 | EnsureNGetIndex(nullptr); |
michael@0 | 29 | return mObjects.Length(); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | Accessible* |
michael@0 | 33 | AccCollector::GetAccessibleAt(uint32_t aIndex) |
michael@0 | 34 | { |
michael@0 | 35 | Accessible* accessible = mObjects.SafeElementAt(aIndex, nullptr); |
michael@0 | 36 | if (accessible) |
michael@0 | 37 | return accessible; |
michael@0 | 38 | |
michael@0 | 39 | return EnsureNGetObject(aIndex); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | int32_t |
michael@0 | 43 | AccCollector::GetIndexAt(Accessible* aAccessible) |
michael@0 | 44 | { |
michael@0 | 45 | int32_t index = mObjects.IndexOf(aAccessible); |
michael@0 | 46 | if (index != -1) |
michael@0 | 47 | return index; |
michael@0 | 48 | |
michael@0 | 49 | return EnsureNGetIndex(aAccessible); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 53 | // nsAccCollector protected |
michael@0 | 54 | |
michael@0 | 55 | Accessible* |
michael@0 | 56 | AccCollector::EnsureNGetObject(uint32_t aIndex) |
michael@0 | 57 | { |
michael@0 | 58 | uint32_t childCount = mRoot->ChildCount(); |
michael@0 | 59 | while (mRootChildIdx < childCount) { |
michael@0 | 60 | Accessible* child = mRoot->GetChildAt(mRootChildIdx++); |
michael@0 | 61 | if (!(mFilterFunc(child) & filters::eMatch)) |
michael@0 | 62 | continue; |
michael@0 | 63 | |
michael@0 | 64 | AppendObject(child); |
michael@0 | 65 | if (mObjects.Length() - 1 == aIndex) |
michael@0 | 66 | return mObjects[aIndex]; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | return nullptr; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | int32_t |
michael@0 | 73 | AccCollector::EnsureNGetIndex(Accessible* aAccessible) |
michael@0 | 74 | { |
michael@0 | 75 | uint32_t childCount = mRoot->ChildCount(); |
michael@0 | 76 | while (mRootChildIdx < childCount) { |
michael@0 | 77 | Accessible* child = mRoot->GetChildAt(mRootChildIdx++); |
michael@0 | 78 | if (!(mFilterFunc(child) & filters::eMatch)) |
michael@0 | 79 | continue; |
michael@0 | 80 | |
michael@0 | 81 | AppendObject(child); |
michael@0 | 82 | if (child == aAccessible) |
michael@0 | 83 | return mObjects.Length() - 1; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | return -1; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | void |
michael@0 | 90 | AccCollector::AppendObject(Accessible* aAccessible) |
michael@0 | 91 | { |
michael@0 | 92 | mObjects.AppendElement(aAccessible); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 96 | // EmbeddedObjCollector |
michael@0 | 97 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 98 | |
michael@0 | 99 | int32_t |
michael@0 | 100 | EmbeddedObjCollector::GetIndexAt(Accessible* aAccessible) |
michael@0 | 101 | { |
michael@0 | 102 | if (aAccessible->mParent != mRoot) |
michael@0 | 103 | return -1; |
michael@0 | 104 | |
michael@0 | 105 | if (aAccessible->mIndexOfEmbeddedChild != -1) |
michael@0 | 106 | return aAccessible->mIndexOfEmbeddedChild; |
michael@0 | 107 | |
michael@0 | 108 | return mFilterFunc(aAccessible) & filters::eMatch ? |
michael@0 | 109 | EnsureNGetIndex(aAccessible) : -1; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | void |
michael@0 | 113 | EmbeddedObjCollector::AppendObject(Accessible* aAccessible) |
michael@0 | 114 | { |
michael@0 | 115 | aAccessible->mIndexOfEmbeddedChild = mObjects.Length(); |
michael@0 | 116 | mObjects.AppendElement(aAccessible); |
michael@0 | 117 | } |