1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DocAccessibleChild.h"
#include "nsAccessibilityService.h"
#include "LocalAccessible-inl.h"
#include "mozilla/a11y/PlatformChild.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/Document.h"
#include "mozilla/StaticPrefs_accessibility.h"
#include "RootAccessible.h"
namespace mozilla {
namespace a11y {
static StaticAutoPtr<PlatformChild> sPlatformChild;
DocAccessibleChild::DocAccessibleChild(DocAccessible* aDoc, IProtocol* aManager)
: DocAccessibleChildBase(aDoc), mEmulatedWindowHandle(nullptr) {
MOZ_COUNT_CTOR_INHERITED(DocAccessibleChild, DocAccessibleChildBase);
if (!sPlatformChild) {
sPlatformChild = new PlatformChild();
ClearOnShutdown(&sPlatformChild, ShutdownPhase::XPCOMShutdown);
}
SetManager(aManager);
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
// If the cache is enabled, we don't need to care whether this is
// constructed in the parent process. We must still set this flag because we
// defer sending any events unless it is set.
SetConstructedInParentProcess();
}
}
DocAccessibleChild::~DocAccessibleChild() {
MOZ_COUNT_DTOR_INHERITED(DocAccessibleChild, DocAccessibleChildBase);
}
void DocAccessibleChild::Shutdown() {
if (IsConstructedInParentProcess()) {
DocAccessibleChildBase::Shutdown();
return;
}
PushDeferredEvent(MakeUnique<SerializedShutdown>(this));
DetachDocument();
}
ipc::IPCResult DocAccessibleChild::RecvParentCOMProxy(
const IDispatchHolder& aParentCOMProxy) {
MOZ_ASSERT(!aParentCOMProxy.IsNull());
mParentProxy.reset(const_cast<IDispatchHolder&>(aParentCOMProxy).Release());
SetConstructedInParentProcess();
for (uint32_t i = 0, l = mDeferredEvents.Length(); i < l; ++i) {
mDeferredEvents[i]->Dispatch();
}
mDeferredEvents.Clear();
return IPC_OK();
}
ipc::IPCResult DocAccessibleChild::RecvEmulatedWindow(
const WindowsHandle& aEmulatedWindowHandle,
const IDispatchHolder& aEmulatedWindowCOMProxy) {
mEmulatedWindowHandle = reinterpret_cast<HWND>(aEmulatedWindowHandle);
if (!aEmulatedWindowCOMProxy.IsNull()) {
MOZ_ASSERT(!mEmulatedWindowProxy);
mEmulatedWindowProxy.reset(
const_cast<IDispatchHolder&>(aEmulatedWindowCOMProxy).Release());
}
return IPC_OK();
}
ipc::IPCResult DocAccessibleChild::RecvTopLevelDocCOMProxy(
const IAccessibleHolder& aCOMProxy) {
MOZ_ASSERT(!aCOMProxy.IsNull());
mTopLevelDocProxy.reset(const_cast<IAccessibleHolder&>(aCOMProxy).Release());
return IPC_OK();
}
HWND DocAccessibleChild::GetNativeWindowHandle() const {
if (mEmulatedWindowHandle) {
return mEmulatedWindowHandle;
}
auto browser = static_cast<dom::BrowserChild*>(Manager());
MOZ_ASSERT(browser);
// Iframe documents use the same window handle as their top level document.
auto topDoc = static_cast<DocAccessibleChild*>(
browser->GetTopLevelDocAccessibleChild());
MOZ_ASSERT(topDoc);
if (topDoc != this && topDoc->mEmulatedWindowHandle) {
return topDoc->mEmulatedWindowHandle;
}
return reinterpret_cast<HWND>(browser->GetNativeWindowHandle());
}
void DocAccessibleChild::PushDeferredEvent(UniquePtr<DeferredEvent> aEvent) {
DocAccessibleChild* topLevelIPCDoc = nullptr;
if (mDoc && mDoc->IsRoot()) {
topLevelIPCDoc = this;
} else {
auto browserChild = static_cast<dom::BrowserChild*>(Manager());
if (!browserChild) {
return;
}
topLevelIPCDoc = static_cast<DocAccessibleChild*>(
browserChild->GetTopLevelDocAccessibleChild());
}
if (topLevelIPCDoc) {
topLevelIPCDoc->mDeferredEvents.AppendElement(std::move(aEvent));
}
}
bool DocAccessibleChild::SendEvent(const uint64_t& aID, const uint32_t& aType) {
if (IsConstructedInParentProcess()) {
return PDocAccessibleChild::SendEvent(aID, aType);
}
PushDeferredEvent(MakeUnique<SerializedEvent>(this, aID, aType));
return false;
}
void DocAccessibleChild::MaybeSendShowEvent(ShowEventData& aData,
bool aFromUser) {
if (IsConstructedInParentProcess()) {
Unused << SendShowEvent(aData, aFromUser);
return;
}
PushDeferredEvent(MakeUnique<SerializedShow>(this, aData, aFromUser));
}
bool DocAccessibleChild::SendHideEvent(const uint64_t& aRootID,
const bool& aFromUser) {
if (IsConstructedInParentProcess()) {
return PDocAccessibleChild::SendHideEvent(aRootID, aFromUser);
}
PushDeferredEvent(MakeUnique<SerializedHide>(this, aRootID, aFromUser));
return true;
}
bool DocAccessibleChild::SendStateChangeEvent(const uint64_t& aID,
const uint64_t& aState,
const bool& aEnabled) {
if (IsConstructedInParentProcess()) {
return PDocAccessibleChild::SendStateChangeEvent(aID, aState, aEnabled);
}
PushDeferredEvent(
MakeUnique<SerializedStateChange>(this, aID, aState, aEnabled));
return true;
}
LayoutDeviceIntRect DocAccessibleChild::GetCaretRectFor(const uint64_t& aID) {
LocalAccessible* target;
if (aID) {
target = reinterpret_cast<LocalAccessible*>(aID);
} else {
target = mDoc;
}
MOZ_ASSERT(target);
HyperTextAccessible* text = target->AsHyperText();
if (!text) {
return LayoutDeviceIntRect();
}
nsIWidget* widget = nullptr;
return text->GetCaretRect(&widget);
}
bool DocAccessibleChild::SendFocusEvent(const uint64_t& aID) {
return SendFocusEvent(aID, GetCaretRectFor(aID));
}
bool DocAccessibleChild::SendFocusEvent(const uint64_t& aID,
const LayoutDeviceIntRect& aCaretRect) {
if (IsConstructedInParentProcess()) {
return PDocAccessibleChild::SendFocusEvent(aID, aCaretRect);
}
PushDeferredEvent(MakeUnique<SerializedFocus>(this, aID, aCaretRect));
return true;
}
bool DocAccessibleChild::SendCaretMoveEvent(const uint64_t& aID,
const int32_t& aOffset,
const bool& aIsSelectionCollapsed,
const bool& aIsAtEndOfLine,
const int32_t& aGranularity) {
return SendCaretMoveEvent(aID, GetCaretRectFor(aID), aOffset,
aIsSelectionCollapsed, aIsAtEndOfLine,
aGranularity);
}
bool DocAccessibleChild::SendCaretMoveEvent(
const uint64_t& aID, const LayoutDeviceIntRect& aCaretRect,
const int32_t& aOffset, const bool& aIsSelectionCollapsed,
const bool& aIsAtEndOfLine, const int32_t& aGranularity) {
if (IsConstructedInParentProcess()) {
return PDocAccessibleChild::SendCaretMoveEvent(
aID, aCaretRect, aOffset, aIsSelectionCollapsed, aIsAtEndOfLine,
aGranularity);
}
PushDeferredEvent(MakeUnique<SerializedCaretMove>(
this, aID, aCaretRect, aOffset, aIsSelectionCollapsed, aIsAtEndOfLine,
aGranularity));
return true;
}
bool DocAccessibleChild::SendTextChangeEvent(
const uint64_t& aID, const nsString& aStr, const int32_t& aStart,
const uint32_t& aLen, const bool& aIsInsert, const bool& aFromUser,
const bool aDoSync) {
if (IsConstructedInParentProcess()) {
if (aDoSync) {
// The AT is going to need to reenter content while the event is being
// dispatched synchronously.
return PDocAccessibleChild::SendSyncTextChangeEvent(
aID, aStr, aStart, aLen, aIsInsert, aFromUser);
}
return PDocAccessibleChild::SendTextChangeEvent(aID, aStr, aStart, aLen,
aIsInsert, aFromUser);
}
PushDeferredEvent(MakeUnique<SerializedTextChange>(
this, aID, aStr, aStart, aLen, aIsInsert, aFromUser));
return true;
}
bool DocAccessibleChild::SendSelectionEvent(const uint64_t& aID,
const uint64_t& aWidgetID,
const uint32_t& aType) {
if (IsConstructedInParentProcess()) {
return PDocAccessibleChild::SendSelectionEvent(aID, aWidgetID, aType);
}
PushDeferredEvent(
MakeUnique<SerializedSelection>(this, aID, aWidgetID, aType));
return true;
}
bool DocAccessibleChild::SendRoleChangedEvent(const a11y::role& aRole,
uint8_t aRoleMapEntryIndex) {
if (IsConstructedInParentProcess()) {
return PDocAccessibleChild::SendRoleChangedEvent(aRole, aRoleMapEntryIndex);
}
PushDeferredEvent(
MakeUnique<SerializedRoleChanged>(this, aRole, aRoleMapEntryIndex));
return true;
}
bool DocAccessibleChild::SendScrollingEvent(const uint64_t& aID,
const uint64_t& aType,
const uint32_t& aScrollX,
const uint32_t& aScrollY,
const uint32_t& aMaxScrollX,
const uint32_t& aMaxScrollY) {
if (IsConstructedInParentProcess()) {
return PDocAccessibleChild::SendScrollingEvent(
aID, aType, aScrollX, aScrollY, aMaxScrollX, aMaxScrollY);
}
PushDeferredEvent(MakeUnique<SerializedScrolling>(
this, aID, aType, aScrollX, aScrollY, aMaxScrollX, aMaxScrollY));
return true;
}
bool DocAccessibleChild::ConstructChildDocInParentProcess(
DocAccessibleChild* aNewChildDoc, uint64_t aUniqueID, uint32_t aMsaaID) {
if (IsConstructedInParentProcess()) {
// We may send the constructor immediately
auto browserChild = static_cast<dom::BrowserChild*>(Manager());
MOZ_ASSERT(browserChild);
bool result = browserChild->SendPDocAccessibleConstructor(
aNewChildDoc, this, aUniqueID,
aNewChildDoc->mDoc->DocumentNode()->GetBrowsingContext(), aMsaaID,
IAccessibleHolder());
if (result) {
aNewChildDoc->SetConstructedInParentProcess();
}
return result;
}
PushDeferredEvent(MakeUnique<SerializedChildDocConstructor>(
aNewChildDoc, this, aUniqueID,
aNewChildDoc->mDoc->DocumentNode()->GetBrowsingContext(), aMsaaID));
return true;
}
bool DocAccessibleChild::SendBindChildDoc(DocAccessibleChild* aChildDoc,
const uint64_t& aNewParentID) {
if (IsConstructedInParentProcess()) {
return DocAccessibleChildBase::SendBindChildDoc(aChildDoc, aNewParentID);
}
PushDeferredEvent(
MakeUnique<SerializedBindChildDoc>(this, aChildDoc, aNewParentID));
return true;
}
ipc::IPCResult DocAccessibleChild::RecvRestoreFocus() {
FocusMgr()->ForceFocusEvent();
return IPC_OK();
}
void DocAccessibleChild::SetEmbedderOnBridge(dom::BrowserBridgeChild* aBridge,
uint64_t aID) {
DocAccessibleChild* doc = aID ? this : nullptr;
if (IsConstructedInParentProcess()) {
MOZ_ASSERT(CanSend());
aBridge->SetEmbedderAccessible(doc, aID);
return;
}
// Even though this doesn't fire an event, we must ensure this is sent in
// the correct order with insertions/removals, which are deferred until
// we are notified about parent process construction. Otherwise, the
// parent process might bind a child document to the wrong accessible if
// ids get reused.
PushDeferredEvent(MakeUnique<SerializedSetEmbedder>(aBridge, doc, aID));
}
} // namespace a11y
} // namespace mozilla
|