diff --git a/accessible/aom/AccessibleNode.cpp b/accessible/aom/AccessibleNode.cpp index 2fb7583c8925..90d8b69341c0 100644 --- a/accessible/aom/AccessibleNode.cpp +++ b/accessible/aom/AccessibleNode.cpp @@ -30,8 +30,12 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(AccessibleNode) AccessibleNode::AccessibleNode(nsINode* aNode) : mDOMNode(aNode) { - DocAccessible* doc = - GetOrCreateAccService()->GetDocAccessible(mDOMNode->OwnerDoc()); + nsAccessibilityService* accService = GetOrCreateAccService(); + if (!accService) { + return; + } + + DocAccessible* doc = accService->GetDocAccessible(mDOMNode->OwnerDoc()); if (doc) { mIntl = doc->GetAccessible(mDOMNode); } @@ -57,8 +61,11 @@ void AccessibleNode::GetRole(nsAString& aRole) { if (mIntl) { - GetOrCreateAccService()->GetStringRole(mIntl->Role(), aRole); - return; + nsAccessibilityService* accService = GetOrCreateAccService(); + if (accService) { + accService->GetStringRole(mIntl->Role(), aRole); + return; + } } aRole.AssignLiteral("unknown"); @@ -67,15 +74,19 @@ AccessibleNode::GetRole(nsAString& aRole) void AccessibleNode::GetStates(nsTArray& aStates) { - if (mIntl) { - if (!mStates) { - mStates = GetOrCreateAccService()->GetStringStates(mIntl->State()); - } + nsAccessibilityService* accService = GetOrCreateAccService(); + if (!mIntl || !accService) { + aStates.AppendElement(NS_LITERAL_STRING("defunct")); + return; + } + + if (mStates) { aStates = mStates->StringArray(); return; } - aStates.AppendElement(NS_LITERAL_STRING("defunct")); + mStates = accService->GetStringStates(mIntl->State()); + aStates = mStates->StringArray(); } void @@ -106,7 +117,8 @@ AccessibleNode::GetAttributes(nsTArray& aAttributes) bool AccessibleNode::Is(const Sequence& aFlavors) { - if (!mIntl) { + nsAccessibilityService* accService = GetOrCreateAccService(); + if (!mIntl || !accService) { for (const auto& flavor : aFlavors) { if (!flavor.EqualsLiteral("unknown") && !flavor.EqualsLiteral("defunct")) { return false; @@ -116,10 +128,10 @@ AccessibleNode::Is(const Sequence& aFlavors) } nsAutoString role; - GetOrCreateAccService()->GetStringRole(mIntl->Role(), role); + accService->GetStringRole(mIntl->Role(), role); if (!mStates) { - mStates = GetOrCreateAccService()->GetStringStates(mIntl->State()); + mStates = accService->GetStringStates(mIntl->State()); } for (const auto& flavor : aFlavors) { diff --git a/accessible/base/nsAccessibilityService.cpp b/accessible/base/nsAccessibilityService.cpp index 1cf33f196744..97dc6e7fa341 100644 --- a/accessible/base/nsAccessibilityService.cpp +++ b/accessible/base/nsAccessibilityService.cpp @@ -1904,6 +1904,11 @@ nsAccessibilityService::NotifyOfConsumersChange() nsAccessibilityService* GetOrCreateAccService(uint32_t aNewConsumer) { + // Do not initialize accessibility if it is force disabled. + if (PlatformDisabledState() == ePlatformIsDisabled) { + return nullptr; + } + if (!nsAccessibilityService::gAccessibilityService) { RefPtr service = new nsAccessibilityService(); if (!service->Init()) { diff --git a/accessible/xpcom/xpcAccessibilityService.cpp b/accessible/xpcom/xpcAccessibilityService.cpp index 2606d4b366cb..35fee520c685 100644 --- a/accessible/xpcom/xpcAccessibilityService.cpp +++ b/accessible/xpcom/xpcAccessibilityService.cpp @@ -46,7 +46,7 @@ xpcAccessibilityService::AddRef(void) // We want refcount to be > 1 because one reference is added in the XPCOM // accessibility service getter. - if (mRefCnt > 1 && PlatformDisabledState() != ePlatformIsDisabled) { + if (mRefCnt > 1) { GetOrCreateAccService(nsAccessibilityService::eXPCOM); } @@ -280,13 +280,10 @@ NS_GetAccessibilityService(nsIAccessibilityService** aResult) NS_ENSURE_TRUE(aResult, NS_ERROR_NULL_POINTER); *aResult = nullptr; - // Do not initialize accessibility if it is force disabled. - if (PlatformDisabledState() == ePlatformIsDisabled) { + if (!GetOrCreateAccService(nsAccessibilityService::eXPCOM)) { return NS_ERROR_SERVICE_NOT_AVAILABLE; } - GetOrCreateAccService(nsAccessibilityService::eXPCOM); - xpcAccessibilityService* service = new xpcAccessibilityService(); NS_ENSURE_TRUE(service, NS_ERROR_OUT_OF_MEMORY); xpcAccessibilityService::gXPCAccessibilityService = service;