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 "HyperTextAccessibleWrap.h"
9 #include "Accessible-inl.h"
11 #include "nsEventShell.h"
13 #include "mozilla/StaticPtr.h"
15 using namespace mozilla;
16 using namespace mozilla::a11y;
18 StaticRefPtr<Accessible> HyperTextAccessibleWrap::sLastTextChangeAcc;
19 StaticAutoPtr<nsString> HyperTextAccessibleWrap::sLastTextChangeString;
20 uint32_t HyperTextAccessibleWrap::sLastTextChangeStart = 0;
21 uint32_t HyperTextAccessibleWrap::sLastTextChangeEnd = 0;
22 bool HyperTextAccessibleWrap::sLastTextChangeWasInsert = false;
24 NS_IMPL_ISUPPORTS_INHERITED0(HyperTextAccessibleWrap,
25 HyperTextAccessible)
27 STDMETHODIMP
28 HyperTextAccessibleWrap::QueryInterface(REFIID aIID, void** aInstancePtr)
29 {
30 if (!aInstancePtr)
31 return E_FAIL;
33 *aInstancePtr = nullptr;
35 if (IsTextRole()) {
36 if (aIID == IID_IAccessibleText)
37 *aInstancePtr =
38 static_cast<IAccessibleText*>(static_cast<ia2AccessibleText*>(this));
39 else if (aIID == IID_IAccessibleHypertext)
40 *aInstancePtr = static_cast<IAccessibleHypertext*>(this);
41 else if (aIID == IID_IAccessibleEditableText)
42 *aInstancePtr = static_cast<IAccessibleEditableText*>(this);
44 if (*aInstancePtr) {
45 AddRef();
46 return S_OK;
47 }
48 }
50 return AccessibleWrap::QueryInterface(aIID, aInstancePtr);
51 }
53 nsresult
54 HyperTextAccessibleWrap::HandleAccEvent(AccEvent* aEvent)
55 {
56 uint32_t eventType = aEvent->GetEventType();
58 if (eventType == nsIAccessibleEvent::EVENT_TEXT_REMOVED ||
59 eventType == nsIAccessibleEvent::EVENT_TEXT_INSERTED) {
60 Accessible* accessible = aEvent->GetAccessible();
61 if (accessible && accessible->IsHyperText()) {
62 sLastTextChangeAcc = accessible;
63 if (!sLastTextChangeString)
64 sLastTextChangeString = new nsString();
66 AccTextChangeEvent* event = downcast_accEvent(aEvent);
67 event->GetModifiedText(*sLastTextChangeString);
68 sLastTextChangeStart = event->GetStartOffset();
69 sLastTextChangeEnd = sLastTextChangeStart + event->GetLength();
70 sLastTextChangeWasInsert = event->IsTextInserted();
71 }
72 }
74 return HyperTextAccessible::HandleAccEvent(aEvent);
75 }
77 nsresult
78 HyperTextAccessibleWrap::GetModifiedText(bool aGetInsertedText,
79 nsAString& aText,
80 uint32_t* aStartOffset,
81 uint32_t* aEndOffset)
82 {
83 aText.Truncate();
84 *aStartOffset = 0;
85 *aEndOffset = 0;
87 if (!sLastTextChangeAcc)
88 return NS_OK;
90 if (aGetInsertedText != sLastTextChangeWasInsert)
91 return NS_OK;
93 if (sLastTextChangeAcc != this)
94 return NS_OK;
96 *aStartOffset = sLastTextChangeStart;
97 *aEndOffset = sLastTextChangeEnd;
98 aText.Append(*sLastTextChangeString);
100 return NS_OK;
101 }