Bug 1742902: Return the MsaaAccessible when using window emulation with the cache enabled. r=morgan

Previously, we tried to get a COM proxy even when the cache was enabled, which just crashed.
As part of this, use a RefPtr instead of manually managing references.

Differential Revision: https://phabricator.services.mozilla.com/D132104
This commit is contained in:
James Teh 2021-11-29 18:24:30 +00:00
parent e02052c2cc
commit f9fa2783ad

View File

@ -14,6 +14,7 @@
#include "mozilla/a11y/DocAccessibleParent.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_accessibility.h"
#include "nsArrayUtils.h"
#include "nsICSSDeclaration.h"
#include "mozilla/dom/Document.h"
@ -135,25 +136,26 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
// for details).
int32_t objId = static_cast<DWORD>(lParam);
if (objId == OBJID_CLIENT) {
IAccessible* msaaAccessible = nullptr;
RefPtr<IAccessible> msaaAccessible;
DocAccessible* document =
reinterpret_cast<DocAccessible*>(::GetPropW(hWnd, kPropNameDocAcc));
if (document) {
document->GetNativeInterface(
(void**)&msaaAccessible); // does an addref
document->GetNativeInterface(getter_AddRefs(msaaAccessible));
} else {
DocAccessibleParent* docParent = static_cast<DocAccessibleParent*>(
::GetPropW(hWnd, kPropNameDocAccParent));
if (docParent) {
docParent->GetCOMInterface(
(void**)&msaaAccessible); // does an addref
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
msaaAccessible = MsaaAccessible::GetFrom(docParent);
} else {
docParent->GetCOMInterface(getter_AddRefs(msaaAccessible));
}
}
}
if (msaaAccessible) {
LRESULT result =
::LresultFromObject(IID_IAccessible, wParam,
msaaAccessible); // does an addref
msaaAccessible->Release(); // release extra addref
return result;
}
}