Bug 1796734 part 2: Don't try to get the focused LocalAccessible from the Android UI thread. r=morgan

IN subsequent patches, IsFocused will be called when querying the state of a RemoteAccessible and IsFocused calls FocusedAccessible.
A RemoteAccessible can be queried from the Android UI thread (which is different to Gecko's main thread), but it's not safe to deal with LocalAccessibles off the main thread.
Therefore, don't try to call FocusedLocalAccessible in this case.

Differential Revision: https://phabricator.services.mozilla.com/D162177
This commit is contained in:
James Teh 2022-11-18 01:37:06 +00:00
parent fdf8f1eb26
commit 26de9d77df

View File

@ -28,6 +28,7 @@ FocusManager::FocusManager() {}
FocusManager::~FocusManager() {}
LocalAccessible* FocusManager::FocusedLocalAccessible() const {
MOZ_ASSERT(NS_IsMainThread());
if (mActiveItem) {
if (mActiveItem->IsDefunct()) {
MOZ_ASSERT_UNREACHABLE("Stored active item is unbound from document");
@ -49,9 +50,23 @@ LocalAccessible* FocusManager::FocusedLocalAccessible() const {
}
Accessible* FocusManager::FocusedAccessible() const {
#if defined(ANDROID)
// It's not safe to call FocusedLocalAccessible() except on the main thread.
// Android might query RemoteAccessibles on the UI thread, which might call
// FocusedAccessible(). Never try to get the focused LocalAccessible in this
// case.
if (NS_IsMainThread()) {
if (Accessible* focusedAcc = FocusedLocalAccessible()) {
return focusedAcc;
}
} else {
nsAccessibilityService::GetAndroidMonitor().AssertCurrentThreadOwns();
}
#else
if (Accessible* focusedAcc = FocusedLocalAccessible()) {
return focusedAcc;
}
#endif // defined(ANDROID)
if (!XRE_IsParentProcess()) {
// DocAccessibleParent's don't exist in the content