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 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "XULSliderAccessible.h"
8 #include "nsAccessibilityService.h"
9 #include "Role.h"
10 #include "States.h"
12 #include "nsIFrame.h"
13 #include "mozilla/dom/Element.h"
14 #include "mozilla/FloatingPoint.h"
16 using namespace mozilla::a11y;
18 ////////////////////////////////////////////////////////////////////////////////
19 // XULSliderAccessible
20 ////////////////////////////////////////////////////////////////////////////////
22 XULSliderAccessible::
23 XULSliderAccessible(nsIContent* aContent, DocAccessible* aDoc) :
24 AccessibleWrap(aContent, aDoc)
25 {
26 mStateFlags |= eHasNumericValue;
27 }
29 // Accessible
31 role
32 XULSliderAccessible::NativeRole()
33 {
34 return roles::SLIDER;
35 }
37 uint64_t
38 XULSliderAccessible::NativeInteractiveState() const
39 {
40 if (NativelyUnavailable())
41 return states::UNAVAILABLE;
43 nsIContent* sliderElm = GetSliderElement();
44 if (sliderElm) {
45 nsIFrame* frame = sliderElm->GetPrimaryFrame();
46 if (frame && frame->IsFocusable())
47 return states::FOCUSABLE;
48 }
50 return 0;
51 }
53 bool
54 XULSliderAccessible::NativelyUnavailable() const
55 {
56 return mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
57 nsGkAtoms::_true, eCaseMatters);
58 }
60 // nsIAccessible
62 void
63 XULSliderAccessible::Value(nsString& aValue)
64 {
65 GetSliderAttr(nsGkAtoms::curpos, aValue);
66 }
68 uint8_t
69 XULSliderAccessible::ActionCount()
70 {
71 return 1;
72 }
74 NS_IMETHODIMP
75 XULSliderAccessible::GetActionName(uint8_t aIndex, nsAString& aName)
76 {
77 aName.Truncate();
79 NS_ENSURE_ARG(aIndex == 0);
81 aName.AssignLiteral("activate");
82 return NS_OK;
83 }
85 NS_IMETHODIMP
86 XULSliderAccessible::DoAction(uint8_t aIndex)
87 {
88 NS_ENSURE_ARG(aIndex == 0);
90 nsIContent* sliderElm = GetSliderElement();
91 if (sliderElm)
92 DoCommand(sliderElm);
94 return NS_OK;
95 }
97 double
98 XULSliderAccessible::MaxValue() const
99 {
100 double value = AccessibleWrap::MaxValue();
101 return IsNaN(value) ? GetSliderAttr(nsGkAtoms::maxpos) : value;
102 }
104 double
105 XULSliderAccessible::MinValue() const
106 {
107 double value = AccessibleWrap::MinValue();
108 return IsNaN(value) ? GetSliderAttr(nsGkAtoms::minpos) : value;
109 }
111 double
112 XULSliderAccessible::Step() const
113 {
114 double value = AccessibleWrap::Step();
115 return IsNaN(value) ? GetSliderAttr(nsGkAtoms::increment) : value;
116 }
118 double
119 XULSliderAccessible::CurValue() const
120 {
121 double value = AccessibleWrap::CurValue();
122 return IsNaN(value) ? GetSliderAttr(nsGkAtoms::curpos) : value;
123 }
125 bool
126 XULSliderAccessible::SetCurValue(double aValue)
127 {
128 if (AccessibleWrap::SetCurValue(aValue))
129 return true;
131 return SetSliderAttr(nsGkAtoms::curpos, aValue);
132 }
134 bool
135 XULSliderAccessible::CanHaveAnonChildren()
136 {
137 // Do not allow anonymous xul:slider be accessible.
138 return false;
139 }
141 // Utils
143 nsIContent*
144 XULSliderAccessible::GetSliderElement() const
145 {
146 if (!mSliderNode) {
147 // XXX: we depend on anonymous content.
148 mSliderNode = mContent->OwnerDoc()->
149 GetAnonymousElementByAttribute(mContent, nsGkAtoms::anonid,
150 NS_LITERAL_STRING("slider"));
151 }
153 return mSliderNode;
154 }
156 nsresult
157 XULSliderAccessible::GetSliderAttr(nsIAtom* aName, nsAString& aValue) const
158 {
159 aValue.Truncate();
161 if (IsDefunct())
162 return NS_ERROR_FAILURE;
164 nsIContent* sliderElm = GetSliderElement();
165 if (sliderElm)
166 sliderElm->GetAttr(kNameSpaceID_None, aName, aValue);
168 return NS_OK;
169 }
171 nsresult
172 XULSliderAccessible::SetSliderAttr(nsIAtom* aName, const nsAString& aValue)
173 {
174 if (IsDefunct())
175 return NS_ERROR_FAILURE;
177 nsIContent* sliderElm = GetSliderElement();
178 if (sliderElm)
179 sliderElm->SetAttr(kNameSpaceID_None, aName, aValue, true);
181 return NS_OK;
182 }
184 double
185 XULSliderAccessible::GetSliderAttr(nsIAtom* aName) const
186 {
187 nsAutoString attrValue;
188 nsresult rv = GetSliderAttr(aName, attrValue);
189 if (NS_FAILED(rv))
190 return UnspecifiedNaN<double>();
192 nsresult error = NS_OK;
193 double value = attrValue.ToDouble(&error);
194 return NS_FAILED(error) ? UnspecifiedNaN<double>() : value;
195 }
197 bool
198 XULSliderAccessible::SetSliderAttr(nsIAtom* aName, double aValue)
199 {
200 nsAutoString value;
201 value.AppendFloat(aValue);
203 return NS_SUCCEEDED(SetSliderAttr(aName, value));
204 }
207 ////////////////////////////////////////////////////////////////////////////////
208 // XULThumbAccessible
209 ////////////////////////////////////////////////////////////////////////////////
211 XULThumbAccessible::
212 XULThumbAccessible(nsIContent* aContent, DocAccessible* aDoc) :
213 AccessibleWrap(aContent, aDoc)
214 {
215 }
217 ////////////////////////////////////////////////////////////////////////////////
218 // XULThumbAccessible: Accessible
220 role
221 XULThumbAccessible::NativeRole()
222 {
223 return roles::INDICATOR;
224 }