Bug 1957314 part 1: nsAccUtils::GetLiveRegionSetting: Don't assume the accessibility service is running. r=morgan

Some tests (e.g. Marionette and WPT) can start the accessibility service in a content process without starting it in the parent process.
When this happens, the content process will still send the accessibility tree, events, etc. to the parent process via IPDL, and the parent process will create the RemoteAccessible tree.
However, the accessibility service still isn't running in the parent process unless a client instantiates it.
Previously, nsAccUtils::GetLiveRegionSetting assumed the accessibility service was running without checking.
UIA calls this method when firing certain events, so this was causing a crash.
To fix this, just null check it.
In future, we may wish to consider not firing events if the service isn't running or some other broader solution for this situation, but I don't think it's worth investing in that now, especially as this is only relevant to tests.

I also added an assertion for the presence of the service in nsAccUtils::SetLiveContainerAttributes.
Because this is only used for setting attributes, callers already check that the service exists before calling this, but an assertion should help enforce this.

Differential Revision: https://phabricator.services.mozilla.com/D244275
This commit is contained in:
James Teh
2025-04-28 00:15:57 +00:00
parent 81b5dcb3c6
commit a8d5b9aaf3

View File

@@ -91,6 +91,7 @@ void nsAccUtils::SetLiveContainerAttributes(AccAttributes* aAttributes,
if (live.IsEmpty()) {
// aria-live wasn't explicitly set. See if an aria-live value is implied
// by an ARIA role or markup element.
MOZ_ASSERT(GetAccService());
if (roleMap) {
GetLiveAttrValue(roleMap->liveAttRule, live);
} else if (nsStaticAtom* value = GetAccService()->MarkupAttribute(
@@ -456,8 +457,10 @@ void nsAccUtils::GetLiveRegionSetting(Accessible* aAcc, nsAString& aLive) {
// by an ARIA role or markup element.
if (const nsRoleMapEntry* roleMap = aAcc->ARIARoleMap()) {
GetLiveAttrValue(roleMap->liveAttRule, aLive);
} else if (nsStaticAtom* value =
GetAccService()->MarkupAttribute(aAcc, nsGkAtoms::aria_live)) {
} else if (nsStaticAtom* value = GetAccService()
? GetAccService()->MarkupAttribute(
aAcc, nsGkAtoms::aria_live)
: nullptr) {
value->ToString(aLive);
}
}