Bug 1715230 part 4: Stop using RemoteAccessibleWrap! r=morgan
authorJames Teh <jteh@mozilla.com>
Mon, 19 Jul 2021 03:44:10 +0000
changeset 585898 22c51b4e5a354871f9cb5d6427acb422912bca61
parent 585897 e7acb70d7295da077bfa4c4d20a7c5f36e9b4074
child 585899 80e252f66347f1d56dfa814139f040cf72d61ef5
push id38622
push userarchaeopteryx@coole-files.de
push dateMon, 19 Jul 2021 09:39:34 +0000
treeherdermozilla-central@c75f4ae44937 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmorgan
bugs1715230
milestone92.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1715230 part 4: Stop using RemoteAccessibleWrap! r=morgan Previously, when the cache was disabled, we had a RemoteAccessibleWrap for every RemoteAccessible. This is no longer necessary and now only serves as an extra level of indirection and memory waste. We still keep the stub MsaaAccessible to hold the id sent up from content. Differential Revision: https://phabricator.services.mozilla.com/D117528
accessible/ipc/DocAccessibleParent.cpp
accessible/ipc/DocAccessibleParent.h
accessible/ipc/win/RemoteAccessible.cpp
accessible/windows/msaa/MsaaAccessible.cpp
accessible/windows/msaa/MsaaRootAccessible.cpp
accessible/windows/msaa/Platform.cpp
accessible/windows/msaa/nsWinUtils.cpp
dom/ipc/BrowserParent.cpp
--- a/accessible/ipc/DocAccessibleParent.cpp
+++ b/accessible/ipc/DocAccessibleParent.cpp
@@ -136,17 +136,17 @@ uint32_t DocAccessibleParent::AddSubtree
       newChild.GenericTypes(), newChild.RoleMapEntryIndex());
 
   aParent->AddChildAt(aIdxInParent, newProxy);
   mAccessibles.PutEntry(newChild.ID())->mProxy = newProxy;
   ProxyCreated(newProxy);
 
 #if defined(XP_WIN)
   if (!StaticPrefs::accessibility_cache_enabled_AtStartup()) {
-    WrapperFor(newProxy)->GetMsaa()->SetID(newChild.MsaaID());
+    MsaaAccessible::GetFrom(newProxy)->SetID(newChild.MsaaID());
   }
 #endif
 
   mPendingOOPChildDocs.RemoveIf([&](dom::BrowserBridgeParent* bridge) {
     MOZ_ASSERT(bridge->GetBrowserParent(),
                "Pending BrowserBridgeParent should be alive");
     if (bridge->GetEmbedderAccessibleId() != newChild.ID()) {
       return false;
@@ -635,17 +635,17 @@ ipc::IPCResult DocAccessibleParent::AddC
 #  if defined(MOZ_SANDBOX)
             aChildDoc->mDocProxyStream = docHolder.GetPreservedStream();
 #  endif  // defined(MOZ_SANDBOX)
           }
         }
         // Send a COM proxy for the embedder OuterDocAccessible to the embedded
         // document process. This will be returned as the parent of the
         // embedded document.
-        aChildDoc->SendParentCOMProxy(WrapperFor(outerDoc));
+        aChildDoc->SendParentCOMProxy(outerDoc);
         if (nsWinUtils::IsWindowEmulationStarted()) {
           // The embedded document should use the same emulated window handle as
           // its embedder. It will return the embedder document (not a window
           // accessible) as the parent accessible, so we pass a null accessible
           // when sending the window to the embedded document.
           Unused << aChildDoc->SendEmulatedWindow(
               reinterpret_cast<uintptr_t>(mEmulatedWindowHandle), nullptr);
         }
@@ -874,26 +874,26 @@ void DocAccessibleParent::MaybeInitWindo
 
   HWND parentWnd = reinterpret_cast<HWND>(rootDocument->GetNativeWindow());
   DebugOnly<HWND> hWnd = nsWinUtils::CreateNativeWindow(
       kClassNameTabContent, parentWnd, rect.X(), rect.Y(), rect.Width(),
       rect.Height(), isActive, &onCreate);
   MOZ_ASSERT(hWnd);
 }
 
-void DocAccessibleParent::SendParentCOMProxy(LocalAccessible* aOuterDoc) {
+void DocAccessibleParent::SendParentCOMProxy(Accessible* aOuterDoc) {
   // Make sure that we're not racing with a tab shutdown
   auto tab = static_cast<dom::BrowserParent*>(Manager());
   MOZ_ASSERT(tab);
   if (tab->IsDestroyed()) {
     return;
   }
 
-  RefPtr<IAccessible> nativeAcc;
-  aOuterDoc->GetNativeInterface(getter_AddRefs(nativeAcc));
+  RefPtr<IDispatch> nativeAcc =
+      already_AddRefed<IDispatch>(MsaaAccessible::NativeAccessible(aOuterDoc));
   if (NS_WARN_IF(!nativeAcc)) {
     // Couldn't get a COM proxy for the outer doc. That probably means it died,
     // but the parent process hasn't received a message to remove it from the
     // RemoteAccessible tree yet.
     return;
   }
 
   RefPtr<IDispatch> wrapped(
--- a/accessible/ipc/DocAccessibleParent.h
+++ b/accessible/ipc/DocAccessibleParent.h
@@ -237,20 +237,19 @@ class DocAccessibleParent : public Remot
 #if defined(XP_WIN)
   void MaybeInitWindowEmulation();
 
   /**
    * Note that an OuterDocAccessible can be created before the
    * DocAccessibleParent or vice versa. Therefore, this must be conditionally
    * called when either of these is created.
    * @param aOuterDoc The OuterDocAccessible to be returned as the parent of
-   *        this document. Only GetNativeInterface() is called on this, so it
-   *        may be a RemoteAccessibleWrap or similar.
+   *        this document.
    */
-  void SendParentCOMProxy(LocalAccessible* aOuterDoc);
+  void SendParentCOMProxy(Accessible* aOuterDoc);
 
   /**
    * Set emulated native window handle for a document.
    * @param aWindowHandle emulated native window handle
    */
   void SetEmulatedWindowHandle(HWND aWindowHandle);
   HWND GetEmulatedWindowHandle() const { return mEmulatedWindowHandle; }
 #endif
--- a/accessible/ipc/win/RemoteAccessible.cpp
+++ b/accessible/ipc/win/RemoteAccessible.cpp
@@ -27,21 +27,20 @@ namespace mozilla {
 namespace a11y {
 
 bool RemoteAccessible::GetCOMInterface(void** aOutAccessible) const {
   if (!aOutAccessible) {
     return false;
   }
 
   if (!mCOMProxy && mSafeToRecurse) {
+    RemoteAccessible* thisPtr = const_cast<RemoteAccessible*>(this);
     // See if we can lazily obtain a COM proxy
-    AccessibleWrap* wrap = WrapperFor(this);
-    MsaaAccessible* msaa = wrap->GetMsaa();
+    MsaaAccessible* msaa = MsaaAccessible::GetFrom(thisPtr);
     bool isDefunct = false;
-    RemoteAccessible* thisPtr = const_cast<RemoteAccessible*>(this);
     // NB: Don't pass CHILDID_SELF here, use the absolute MSAA ID. Otherwise
     // GetIAccessibleFor will recurse into this function and we will just
     // overflow the stack.
     VARIANT realId = {{{VT_I4}}};
     realId.ulVal = msaa->GetExistingID();
     MOZ_DIAGNOSTIC_ASSERT(realId.ulVal != CHILDID_SELF);
     thisPtr->mCOMProxy = msaa->GetIAccessibleFor(realId, &isDefunct);
   }
--- a/accessible/windows/msaa/MsaaAccessible.cpp
+++ b/accessible/windows/msaa/MsaaAccessible.cpp
@@ -38,16 +38,21 @@ MsaaIdGenerator MsaaAccessible::sIDGen;
 ITypeInfo* MsaaAccessible::gTypeInfo = nullptr;
 
 /* static */
 MsaaAccessible* MsaaAccessible::Create(Accessible* aAcc) {
   // If the cache is enabled, this should only ever be called in the parent
   // process.
   MOZ_ASSERT(!StaticPrefs::accessibility_cache_enabled_AtStartup() ||
              XRE_IsParentProcess());
+  if (!StaticPrefs::accessibility_cache_enabled_AtStartup() &&
+      aAcc->IsRemote()) {
+    // MsaaAccessible is just a stub to hold the id in this case.
+    return new MsaaAccessible(aAcc);
+  }
   // The order of some of these is important! For example, when isRoot is true,
   // IsDoc will also be true, so we must check IsRoot first. IsTable/Cell and
   // IsHyperText are a similar case.
   if (aAcc->IsLocal() && aAcc->IsRoot()) {
     return new MsaaRootAccessible(aAcc);
   }
   if (aAcc->IsDoc()) {
     return new MsaaDocAccessible(aAcc);
@@ -90,18 +95,19 @@ void MsaaAccessible::MsaaShutdown() {
   // Accessibles can be shut down twice in some cases. If that happens,
   // MsaaShutdown will also be called twice because AccessibleWrap holds
   // the reference until its destructor is called; see the comments in
   // AccessibleWrap::Shutdown.
   if (!mAcc) {
     return;
   }
 
-  if (mAcc->IsProxy()) {
-    // For RemoteAccessibleWrap, we just need to clear mAcc.
+  if (!StaticPrefs::accessibility_cache_enabled_AtStartup() &&
+      mAcc->IsRemote()) {
+    // This MsaaAccessible is just a stub. We just need to clear mAcc.
     mAcc = nullptr;
     return;
   }
 
   if (mID != kNoID) {
     auto doc = MsaaDocAccessible::GetFromOwned(mAcc);
     MOZ_ASSERT(doc);
     doc->RemoveID(mID);
@@ -128,31 +134,34 @@ void MsaaAccessible::MsaaShutdown() {
     }
     mAssociatedCOMObjectsForDisconnection.Clear();
   }
 
   mAcc = nullptr;
 }
 
 void MsaaAccessible::SetID(uint32_t aID) {
-  MOZ_ASSERT(XRE_IsParentProcess() && mAcc && mAcc->IsProxy());
+  MOZ_ASSERT(XRE_IsParentProcess() && mAcc &&
+             !StaticPrefs::accessibility_cache_enabled_AtStartup());
   mID = aID;
 }
 
 int32_t MsaaAccessible::GetChildIDFor(Accessible* aAccessible) {
   // A child ID of the window is required, when we use NotifyWinEvent,
   // so that the 3rd party application can call back and get the IAccessible
   // the event occurred on.
 
   if (!aAccessible) {
     return 0;
   }
 
-  // Chrome should use mID which has been generated by the content process.
-  if (aAccessible->IsProxy()) {
+  // If the cache is disabled, chrome should use mID which has been generated by
+  // the content process.
+  if (!StaticPrefs::accessibility_cache_enabled_AtStartup() &&
+      aAccessible->IsRemote()) {
     const uint32_t id = MsaaAccessible::GetFrom(aAccessible)->mID;
     MOZ_ASSERT(id != kNoID);
     return id;
   }
 
   auto doc = MsaaDocAccessible::GetFromOwned(aAccessible);
   if (!doc) {
     return 0;
@@ -193,19 +202,18 @@ void MsaaAccessible::ReleaseChildID(NotN
 }
 
 HWND MsaaAccessible::GetHWNDFor(Accessible* aAccessible) {
   if (!aAccessible) {
     return nullptr;
   }
 
   LocalAccessible* localAcc = aAccessible->AsLocal();
-  if (!localAcc || localAcc->IsProxy()) {
-    RemoteAccessible* proxy =
-        localAcc ? localAcc->Proxy() : aAccessible->AsRemote();
+  if (!localAcc) {
+    RemoteAccessible* proxy = aAccessible->AsRemote();
     if (!proxy) {
       return nullptr;
     }
 
     // If window emulation is enabled, retrieve the emulated window from the
     // containing document document proxy.
     if (nsWinUtils::IsWindowEmulationStarted()) {
       DocAccessibleParent* doc = proxy->Document();
@@ -292,39 +300,34 @@ void MsaaAccessible::FireWinEvent(Access
                 "MSAA event map skewed");
 
   NS_ASSERTION(aEventType > 0 && aEventType < ArrayLength(gWinEventMap),
                "invalid event type");
 
   uint32_t winEvent = gWinEventMap[aEventType];
   if (!winEvent) return;
 
-  Accessible* target = aTarget;
-  if (!StaticPrefs::accessibility_cache_enabled_AtStartup() &&
-      target->IsRemote()) {
-    target = WrapperFor(target->AsRemote());
-  }
-  int32_t childID = MsaaAccessible::GetChildIDFor(target);
+  int32_t childID = MsaaAccessible::GetChildIDFor(aTarget);
   if (!childID) return;  // Can't fire an event without a child ID
 
-  HWND hwnd = GetHWNDFor(target);
+  HWND hwnd = GetHWNDFor(aTarget);
   if (!hwnd) {
     return;
   }
 
   if (IsHandlerInvalidationNeeded(winEvent)) {
     AccessibleWrap::InvalidateHandlers();
   }
 
   // Fire MSAA event for client area window.
   ::NotifyWinEvent(winEvent, hwnd, OBJID_CLIENT, childID);
 }
 
 AccessibleWrap* MsaaAccessible::LocalAcc() {
-  if (!mAcc || mAcc->IsRemote() || mAcc->IsProxy()) {
+  if (!mAcc || mAcc->IsRemote()) {
     return nullptr;
   }
   auto acc = static_cast<AccessibleWrap*>(mAcc);
   MOZ_ASSERT(!acc || !acc->IsDefunct(),
              "mAcc defunct but MsaaShutdown wasn't called");
   return acc;
 }
 
@@ -411,25 +414,24 @@ static Accessible* GetAccessibleInSubtre
       return child;
     }
   }
 
   return nullptr;
 }
 
 static already_AddRefed<IDispatch> GetProxiedAccessibleInSubtree(
-    const DocAccessibleParent* aDoc, const VARIANT& aVarChild) {
+    DocAccessibleParent* aDoc, const VARIANT& aVarChild) {
   MOZ_ASSERT(!StaticPrefs::accessibility_cache_enabled_AtStartup());
-  auto wrapper = static_cast<DocRemoteAccessibleWrap*>(WrapperFor(aDoc));
   RefPtr<IAccessible> comProxy;
-  int32_t docWrapperChildId = MsaaAccessible::GetChildIDFor(wrapper);
+  int32_t docWrapperChildId = MsaaAccessible::GetChildIDFor(aDoc);
   // Only document accessible proxies at the top level of their content process
   // are created with a pointer to their COM proxy.
   if (aDoc->IsTopLevelInContentProcess()) {
-    wrapper->GetNativeInterface(getter_AddRefs(comProxy));
+    aDoc->GetCOMInterface(getter_AddRefs(comProxy));
   } else {
     auto tab = static_cast<dom::BrowserParent*>(aDoc->Manager());
     MOZ_ASSERT(tab);
     DocAccessibleParent* topLevelDoc = tab->GetTopLevelDocAccessible();
     MOZ_ASSERT(topLevelDoc && topLevelDoc->IsTopLevelInContentProcess());
     VARIANT docId = {{{VT_I4}}};
     docId.lVal = docWrapperChildId;
     RefPtr<IDispatch> disp = GetProxiedAccessibleInSubtree(topLevelDoc, docId);
@@ -494,39 +496,36 @@ already_AddRefed<IAccessible> MsaaAccess
 
   if (!mAcc) {
     *aIsDefunct = true;
     return nullptr;
   }
 
   AccessibleWrap* localAcc = static_cast<AccessibleWrap*>(mAcc->AsLocal());
   if (varChild.lVal == CHILDID_SELF) {
-    MOZ_ASSERT(!localAcc || !localAcc->IsProxy());
+    MOZ_ASSERT(localAcc ||
+               StaticPrefs::accessibility_cache_enabled_AtStartup());
     result = this;
     return result.forget();
   }
 
-  if (varChild.ulVal != GetExistingID() &&
-      ((localAcc && localAcc->IsProxy())
-           ? nsAccUtils::MustPrune(localAcc->Proxy())
-           : nsAccUtils::MustPrune(mAcc))) {
+  if (varChild.ulVal != GetExistingID() && nsAccUtils::MustPrune(mAcc)) {
     // This accessible should have no subtree in platform, return null for its
     // children.
     return nullptr;
   }
 
   // If the MSAA ID is not a chrome id then we already know that we won't
   // find it here and should look remotely instead. This handles the case when
   // accessible is part of the chrome process and is part of the xul browser
-  // window and the child id points in the content documents. Thus we need to
-  // make sure that it is never called on proxies.
+  // window and the child id points in the content documents.
   // Bug 1422674: We must only handle remote ids here (< 0), not child indices.
   // Child indices (> 0) are handled below for both local and remote children.
-  if (XRE_IsParentProcess() && localAcc && !localAcc->IsProxy() &&
-      varChild.lVal < 0 && !sIDGen.IsChromeID(varChild.lVal)) {
+  if (XRE_IsParentProcess() && localAcc && varChild.lVal < 0 &&
+      !sIDGen.IsChromeID(varChild.lVal)) {
     MOZ_ASSERT(!StaticPrefs::accessibility_cache_enabled_AtStartup());
     if (!localAcc->IsRootForHWND()) {
       // Bug 1422201, 1424657: accChild with a remote id is only valid on the
       // root accessible for an HWND.
       // Otherwise, we might return remote accessibles which aren't descendants
       // of this accessible. This would confuse clients which use accChild to
       // check whether something is a descendant of a document.
       return nullptr;
@@ -562,20 +561,19 @@ already_AddRefed<IAccessible> MsaaAccess
     }
     result = MsaaAccessible::GetFrom(xpAcc);
     return result.forget();
   }
 
   // If lVal negative then it is treated as child ID and we should look for
   // accessible through whole accessible subtree including subdocuments.
   // First see about the case that both this accessible and the target one are
-  // RemoteAccessibleWraps.
-  if (localAcc && localAcc->IsProxy()) {
-    MOZ_ASSERT(!StaticPrefs::accessibility_cache_enabled_AtStartup());
-    DocAccessibleParent* proxyDoc = localAcc->Proxy()->Document();
+  // RemoteAccessibles and the cache is disabled.
+  if (!localAcc && !StaticPrefs::accessibility_cache_enabled_AtStartup()) {
+    DocAccessibleParent* proxyDoc = mAcc->AsRemote()->Document();
     RefPtr<IDispatch> disp = GetProxiedAccessibleInSubtree(proxyDoc, varChild);
     if (!disp) {
       return nullptr;
     }
 
     MOZ_ASSERT(mscom::IsProxy(disp));
     DebugOnly<HRESULT> hr =
         disp->QueryInterface(IID_IAccessible, getter_AddRefs(result));
@@ -704,17 +702,17 @@ already_AddRefed<IAccessible> MsaaAccess
     if (outerDoc->RootAccessible() != root) {
       continue;
     }
 
     RefPtr<IDispatch> disp;
     auto checkDoc = [&aVarChild,
                      &disp](DocAccessibleParent* aRemoteDoc) -> bool {
       uint32_t remoteDocMsaaId =
-          WrapperFor(aRemoteDoc)->GetMsaa()->GetExistingID();
+          MsaaAccessible::GetFrom(aRemoteDoc)->GetExistingID();
       if (!sIDGen.IsSameContentProcessFor(aVarChild.lVal, remoteDocMsaaId)) {
         return true;  // Continue the search.
       }
       if ((disp = GetProxiedAccessibleInSubtree(aRemoteDoc, aVarChild))) {
         return false;  // Found it! Stop traversal!
       }
       return true;  // Continue the search.
     };
@@ -745,23 +743,18 @@ already_AddRefed<IAccessible> MsaaAccess
 
 IDispatch* MsaaAccessible::NativeAccessible(Accessible* aAccessible) {
   if (!aAccessible) {
     NS_WARNING("Not passing in an aAccessible");
     return nullptr;
   }
 
   RefPtr<IDispatch> disp;
-  if (aAccessible->IsProxy()) {
-    MOZ_ASSERT(!StaticPrefs::accessibility_cache_enabled_AtStartup());
-    // This is a RemoteAccessibleWrap. We must use GetNativeInterface in this
-    // case so we return the COM proxy.
-    aAccessible->AsLocal()->GetNativeInterface(getter_AddRefs(disp));
-  } else if (!StaticPrefs::accessibility_cache_enabled_AtStartup() &&
-             aAccessible->IsRemote()) {
+  if (!StaticPrefs::accessibility_cache_enabled_AtStartup() &&
+      aAccessible->IsRemote()) {
     // This is a RemoteAccessible and caching isn't enabled. We must return
     // the COM proxy.
     aAccessible->AsRemote()->GetCOMInterface(getter_AddRefs(disp));
   } else {
     disp = MsaaAccessible::GetFrom(aAccessible);
   }
   IDispatch* rawDisp;
   disp.forget(&rawDisp);
@@ -781,17 +774,16 @@ ITypeInfo* MsaaAccessible::GetTI(LCID lc
   if (FAILED(hr)) return nullptr;
 
   return gTypeInfo;
 }
 
 /* static */
 MsaaAccessible* MsaaAccessible::GetFrom(Accessible* aAcc) {
   if (RemoteAccessible* remoteAcc = aAcc->AsRemote()) {
-    MOZ_ASSERT(StaticPrefs::accessibility_cache_enabled_AtStartup());
     return reinterpret_cast<MsaaAccessible*>(remoteAcc->GetWrapper());
   }
   return static_cast<AccessibleWrap*>(aAcc)->GetMsaa();
 }
 
 // IUnknown methods
 STDMETHODIMP
 MsaaAccessible::QueryInterface(REFIID iid, void** ppv) {
@@ -1555,17 +1547,19 @@ MsaaAccessible::accNavigate(
   HRESULT hr = ResolveChild(varStart, getter_AddRefs(accessible));
   if (FAILED(hr)) {
     return hr;
   }
 
   if (accessible) {
     return accessible->accNavigate(navDir, kVarChildIdSelf, pvarEndUpAt);
   }
-  MOZ_ASSERT(!mAcc->IsProxy());
+  // This should never be called on a RemoteAccessible if the cache is disabled.
+  MOZ_ASSERT(mAcc->IsLocal() ||
+             StaticPrefs::accessibility_cache_enabled_AtStartup());
 
   Accessible* navAccessible = nullptr;
   Maybe<RelationType> xpRelation;
 
 #define RELATIONTYPE(geckoType, stringType, atkType, msaaType, ia2Type) \
   case msaaType:                                                        \
     xpRelation.emplace(RelationType::geckoType);                        \
     break;
--- a/accessible/windows/msaa/MsaaRootAccessible.cpp
+++ b/accessible/windows/msaa/MsaaRootAccessible.cpp
@@ -84,21 +84,21 @@ MsaaRootAccessible::accNavigate(
   if (!pvarEndUpAt) {
     return E_INVALIDARG;
   }
   RootAccessible* rootAcc = RootAcc();
   if (!rootAcc) {
     return CO_E_OBJNOTCONNECTED;
   }
 
-  LocalAccessible* target = nullptr;
+  Accessible* target = nullptr;
   // Get the document in the active tab.
   RemoteAccessible* docProxy = rootAcc->GetPrimaryRemoteTopLevelContentDoc();
   if (docProxy) {
-    target = WrapperFor(docProxy);
+    target = docProxy;
   } else {
     // The base implementation could handle this, but we may as well
     // just handle it here.
     Relation rel = rootAcc->RelationByType(RelationType::EMBEDS);
     target = rel.Next();
   }
 
   if (!target) {
@@ -133,21 +133,17 @@ MsaaRootAccessible::get_accFocus(
   RootAccessible* rootAcc = RootAcc();
   if (!rootAcc) {
     return CO_E_OBJNOTCONNECTED;
   }
   RemoteAccessible* docProxy = rootAcc->GetPrimaryRemoteTopLevelContentDoc();
   if (!docProxy) {
     return hr;
   }
-  LocalAccessible* docAcc = WrapperFor(docProxy);
-  if (!docAcc) {
-    return E_FAIL;
-  }
-  RefPtr<IDispatch> docDisp = NativeAccessible(docAcc);
+  RefPtr<IDispatch> docDisp = NativeAccessible(docProxy);
   if (!docDisp) {
     return E_FAIL;
   }
   RefPtr<IAccessible> docIa;
   hr = docDisp->QueryInterface(IID_IAccessible, (void**)getter_AddRefs(docIa));
   MOZ_ASSERT(SUCCEEDED(hr));
   MOZ_ASSERT(docIa);
 
--- a/accessible/windows/msaa/Platform.cpp
+++ b/accessible/windows/msaa/Platform.cpp
@@ -20,17 +20,16 @@
 #include "mozilla/StaticPrefs_accessibility.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/WindowsVersion.h"
 #include "mozilla/WinHeaderOnlyUtils.h"
 #include "nsAccessibilityService.h"
 #include "nsComponentManagerUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
-#include "ProxyWrappers.h"
 
 #if defined(MOZ_TELEMETRY_REPORTING)
 #  include "mozilla/Telemetry.h"
 #endif  // defined(MOZ_TELEMETRY_REPORTING)
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 using namespace mozilla::mscom;
@@ -68,63 +67,34 @@ void a11y::PlatformShutdown() {
   gRegMiscTlb = nullptr;
 
   if (gInstantiator) {
     gInstantiator = nullptr;
   }
 }
 
 void a11y::ProxyCreated(RemoteAccessible* aProxy) {
-  if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
-    MsaaAccessible* msaa = MsaaAccessible::Create(aProxy);
-    msaa->AddRef();
-    aProxy->SetWrapper(reinterpret_cast<uintptr_t>(msaa));
-    return;
-  }
-
-  AccessibleWrap* wrapper = nullptr;
-  if (aProxy->IsDoc()) {
-    wrapper = new DocRemoteAccessibleWrap(aProxy);
-  } else if (aProxy->IsHyperText()) {
-    wrapper = new HyperTextRemoteAccessibleWrap(aProxy);
-  } else {
-    wrapper = new RemoteAccessibleWrap(aProxy);
-  }
-
-  wrapper->AddRef();
-  aProxy->SetWrapper(reinterpret_cast<uintptr_t>(wrapper));
+  MsaaAccessible* msaa = MsaaAccessible::Create(aProxy);
+  msaa->AddRef();
+  aProxy->SetWrapper(reinterpret_cast<uintptr_t>(msaa));
 }
 
 void a11y::ProxyDestroyed(RemoteAccessible* aProxy) {
+  MsaaAccessible* msaa =
+      reinterpret_cast<MsaaAccessible*>(aProxy->GetWrapper());
+  if (!msaa) {
+    return;
+  }
+  msaa->MsaaShutdown();
+  aProxy->SetWrapper(0);
+  msaa->Release();
+
   if (aProxy->IsDoc() && nsWinUtils::IsWindowEmulationStarted()) {
     aProxy->AsDoc()->SetEmulatedWindowHandle(nullptr);
   }
-
-  if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
-    MsaaAccessible* msaa =
-        reinterpret_cast<MsaaAccessible*>(aProxy->GetWrapper());
-    if (!msaa) {
-      return;
-    }
-    msaa->MsaaShutdown();
-    aProxy->SetWrapper(0);
-    msaa->Release();
-    return;
-  }
-
-  AccessibleWrap* wrapper =
-      reinterpret_cast<AccessibleWrap*>(aProxy->GetWrapper());
-
-  // If aProxy is a document that was created, but
-  // RecvPDocAccessibleConstructor failed then aProxy->GetWrapper() will be
-  // null.
-  if (!wrapper) return;
-  wrapper->Shutdown();
-  aProxy->SetWrapper(0);
-  wrapper->Release();
 }
 
 void a11y::ProxyEvent(RemoteAccessible* aTarget, uint32_t aEventType) {
   MsaaAccessible::FireWinEvent(aTarget, aEventType);
 }
 
 void a11y::ProxyStateChangeEvent(RemoteAccessible* aTarget, uint64_t, bool) {
   MsaaAccessible::FireWinEvent(aTarget, nsIAccessibleEvent::EVENT_STATE_CHANGE);
@@ -155,45 +125,29 @@ void a11y::ProxyCaretMoveEvent(RemoteAcc
                                nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED);
 }
 
 void a11y::ProxyTextChangeEvent(RemoteAccessible* aText, const nsString& aStr,
                                 int32_t aStart, uint32_t aLen, bool aInsert,
                                 bool) {
   uint32_t eventType = aInsert ? nsIAccessibleEvent::EVENT_TEXT_INSERTED
                                : nsIAccessibleEvent::EVENT_TEXT_REMOVED;
-  if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
-    // XXX Call ia2AccessibleText::UpdateTextChangeData once this works for
-    // RemoteAccessible.
-    MsaaAccessible::FireWinEvent(aText, eventType);
-    return;
-  }
-
-  AccessibleWrap* wrapper = WrapperFor(aText);
-  MOZ_ASSERT(wrapper);
-  if (!wrapper) {
-    return;
-  }
-
   static const bool useHandler =
+      !StaticPrefs::accessibility_cache_enabled_AtStartup() &&
       Preferences::GetBool("accessibility.handler.enabled", false) &&
       IsHandlerRegistered();
-
   if (useHandler) {
-    AccessibleWrap::DispatchTextChangeToHandler(wrapper, aInsert, aStr, aStart,
+    AccessibleWrap::DispatchTextChangeToHandler(aText, aInsert, aStr, aStart,
                                                 aLen);
     return;
   }
 
-  auto text = static_cast<HyperTextAccessibleWrap*>(wrapper->AsHyperText());
-  if (text) {
-    ia2AccessibleText::UpdateTextChangeData(text, aInsert, aStr, aStart, aLen);
-  }
-
-  MsaaAccessible::FireWinEvent(wrapper, eventType);
+  // XXX Call ia2AccessibleText::UpdateTextChangeData once that works for
+  // RemoteAccessible.
+  MsaaAccessible::FireWinEvent(aText, eventType);
 }
 
 void a11y::ProxyShowHideEvent(RemoteAccessible* aTarget, RemoteAccessible*,
                               bool aInsert, bool) {
   uint32_t event =
       aInsert ? nsIAccessibleEvent::EVENT_SHOW : nsIAccessibleEvent::EVENT_HIDE;
   MsaaAccessible::FireWinEvent(aTarget, event);
 }
--- a/accessible/windows/msaa/nsWinUtils.cpp
+++ b/accessible/windows/msaa/nsWinUtils.cpp
@@ -14,17 +14,16 @@
 
 #include "mozilla/a11y/DocAccessibleParent.h"
 #include "mozilla/Preferences.h"
 #include "nsArrayUtils.h"
 #include "nsICSSDeclaration.h"
 #include "mozilla/dom/Document.h"
 #include "mozilla/dom/Element.h"
 #include "nsXULAppAPI.h"
-#include "ProxyWrappers.h"
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 using mozilla::dom::Element;
 
 // Window property used by ipc related code in identifying accessible
 // tab windows.
 const wchar_t* kPropNameTabContent = L"AccessibleTabWindow";
@@ -141,18 +140,17 @@ LRESULT CALLBACK WindowProc(HWND hWnd, U
             reinterpret_cast<DocAccessible*>(::GetPropW(hWnd, kPropNameDocAcc));
         if (document) {
           document->GetNativeInterface(
               (void**)&msaaAccessible);  // does an addref
         } else {
           DocAccessibleParent* docParent = static_cast<DocAccessibleParent*>(
               ::GetPropW(hWnd, kPropNameDocAccParent));
           if (docParent) {
-            auto wrapper = WrapperFor(docParent);
-            wrapper->GetNativeInterface(
+            docParent->GetCOMInterface(
                 (void**)&msaaAccessible);  // does an addref
           }
         }
         if (msaaAccessible) {
           LRESULT result =
               ::LresultFromObject(IID_IAccessible, wParam,
                                   msaaAccessible);  // does an addref
           msaaAccessible->Release();                // release extra addref
--- a/dom/ipc/BrowserParent.cpp
+++ b/dom/ipc/BrowserParent.cpp
@@ -1210,17 +1210,17 @@ mozilla::ipc::IPCResult BrowserParent::R
 #  else
       return IPC_OK();
 #  endif
     }
 
 #  ifdef XP_WIN
     MOZ_ASSERT(aDocCOMProxy.IsNull());
     if (!StaticPrefs::accessibility_cache_enabled_AtStartup()) {
-      a11y::WrapperFor(doc)->GetMsaa()->SetID(aMsaaID);
+      a11y::MsaaAccessible::GetFrom(doc)->SetID(aMsaaID);
     }
     if (a11y::nsWinUtils::IsWindowEmulationStarted()) {
       doc->SetEmulatedWindowHandle(parentDoc->GetEmulatedWindowHandle());
     }
 #  else
     Unused << aDoc->SendConstructedInParentProcess();
 #  endif
 
@@ -1237,21 +1237,21 @@ mozilla::ipc::IPCResult BrowserParent::R
       MOZ_ASSERT(!aDocCOMProxy.IsNull());
       RefPtr<IAccessible> proxy(aDocCOMProxy.Get());
       doc->SetCOMInterface(proxy);
     }
 #  endif
     a11y::ProxyCreated(doc);
 #  ifdef XP_WIN
     if (!StaticPrefs::accessibility_cache_enabled_AtStartup()) {
-      // This *must* be called after ProxyCreated because WrapperFor will fail
-      // before that.
-      a11y::AccessibleWrap* wrapper = a11y::WrapperFor(doc);
-      MOZ_ASSERT(wrapper);
-      wrapper->GetMsaa()->SetID(aMsaaID);
+      // This *must* be called after ProxyCreated because
+      // MsaaAccessible::GetFrom will fail before that.
+      a11y::MsaaAccessible* msaa = a11y::MsaaAccessible::GetFrom(doc);
+      MOZ_ASSERT(msaa);
+      msaa->SetID(aMsaaID);
     }
 #  endif
     // It's possible the embedder accessible hasn't been set yet; e.g.
     // a hidden iframe. In that case, embedderDoc will be null and this will
     // be handled when the embedder is set.
     if (a11y::DocAccessibleParent* embedderDoc =
             bridge->GetEmbedderAccessibleDoc()) {
       mozilla::ipc::IPCResult added = embedderDoc->AddChildDoc(bridge);
@@ -1274,17 +1274,17 @@ mozilla::ipc::IPCResult BrowserParent::R
     }
 
     doc->SetTopLevel();
     a11y::DocManager::RemoteDocAdded(doc);
 #  ifdef XP_WIN
     if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
       doc->MaybeInitWindowEmulation();
     } else {
-      a11y::WrapperFor(doc)->GetMsaa()->SetID(aMsaaID);
+      a11y::MsaaAccessible::GetFrom(doc)->SetID(aMsaaID);
       MOZ_ASSERT(!aDocCOMProxy.IsNull());
 
       RefPtr<IAccessible> proxy(aDocCOMProxy.Get());
       doc->SetCOMInterface(proxy);
       doc->MaybeInitWindowEmulation();
       if (a11y::LocalAccessible* outerDoc = doc->OuterDocOfRemoteBrowser()) {
         doc->SendParentCOMProxy(outerDoc);
       }