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-16 23:21:23 +00:00
Родитель ab6ebb6e12
Коммит 61e3c5bebe
1 изменённых файлов: 15 добавлений и 0 удалений

Просмотреть файл

@ -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