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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "ia2AccessibleRelation.h"
10 #include "Relation.h"
11 #include "nsIAccessibleRelation.h"
12 #include "nsID.h"
14 #include "AccessibleRelation_i.c"
16 using namespace mozilla::a11y;
18 ia2AccessibleRelation::ia2AccessibleRelation(RelationType aType, Relation* aRel) :
19 mType(aType)
20 {
21 Accessible* target = nullptr;
22 while ((target = aRel->Next()))
23 mTargets.AppendElement(target);
24 }
26 // IUnknown
28 IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleRelation)
29 IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleRelation)
30 IMPL_IUNKNOWN_QUERY_IFACE(IUnknown)
31 IMPL_IUNKNOWN_QUERY_TAIL
33 // IAccessibleRelation
35 STDMETHODIMP
36 ia2AccessibleRelation::get_relationType(BSTR* aRelationType)
37 {
38 A11Y_TRYBLOCK_BEGIN
40 if (!aRelationType)
41 return E_INVALIDARG;
43 *aRelationType = nullptr;
45 #define RELATIONTYPE(geckoType, geckoTypeName, atkType, msaaType, ia2Type) \
46 case RelationType::geckoType: \
47 *aRelationType = ::SysAllocString(ia2Type); \
48 break;
50 switch (mType) {
51 #include "RelationTypeMap.h"
52 }
54 return *aRelationType ? S_OK : E_OUTOFMEMORY;
56 A11Y_TRYBLOCK_END
57 }
59 STDMETHODIMP
60 ia2AccessibleRelation::get_localizedRelationType(BSTR *aLocalizedRelationType)
61 {
62 A11Y_TRYBLOCK_BEGIN
64 if (!aLocalizedRelationType)
65 return E_INVALIDARG;
67 *aLocalizedRelationType = nullptr;
68 return E_NOTIMPL;
70 A11Y_TRYBLOCK_END
71 }
73 STDMETHODIMP
74 ia2AccessibleRelation::get_nTargets(long *aNTargets)
75 {
76 A11Y_TRYBLOCK_BEGIN
78 if (!aNTargets)
79 return E_INVALIDARG;
81 *aNTargets = mTargets.Length();
82 return S_OK;
84 A11Y_TRYBLOCK_END
85 }
87 STDMETHODIMP
88 ia2AccessibleRelation::get_target(long aTargetIndex, IUnknown **aTarget)
89 {
90 A11Y_TRYBLOCK_BEGIN
92 if (aTargetIndex < 0 || (uint32_t)aTargetIndex >= mTargets.Length() || !aTarget)
93 return E_INVALIDARG;
95 AccessibleWrap* target =
96 static_cast<AccessibleWrap*>(mTargets[aTargetIndex].get());
97 *aTarget = static_cast<IAccessible*>(target);
98 (*aTarget)->AddRef();
100 return S_OK;
102 A11Y_TRYBLOCK_END
103 }
105 STDMETHODIMP
106 ia2AccessibleRelation::get_targets(long aMaxTargets, IUnknown **aTargets,
107 long *aNTargets)
108 {
109 A11Y_TRYBLOCK_BEGIN
111 if (!aNTargets || !aTargets)
112 return E_INVALIDARG;
114 *aNTargets = 0;
115 long maxTargets = mTargets.Length();
116 if (maxTargets > aMaxTargets)
117 maxTargets = aMaxTargets;
119 for (long idx = 0; idx < maxTargets; idx++)
120 get_target(idx, aTargets + idx);
122 *aNTargets = maxTargets;
123 return S_OK;
125 A11Y_TRYBLOCK_END
126 }