summaryrefslogtreecommitdiffstats
path: root/accessible/ipc/win
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--accessible/ipc/win/COMPtrTypes.cpp74
-rw-r--r--accessible/ipc/win/COMPtrTypes.h77
-rw-r--r--accessible/ipc/win/DocAccessibleChild.cpp320
-rw-r--r--accessible/ipc/win/DocAccessibleChild.h369
-rw-r--r--accessible/ipc/win/HandlerProvider.cpp974
-rw-r--r--accessible/ipc/win/HandlerProvider.h145
-rw-r--r--accessible/ipc/win/IAccessible32.manifest11
-rw-r--r--accessible/ipc/win/IAccessible64.manifest10
-rw-r--r--accessible/ipc/win/PDocAccessible.ipdl112
-rw-r--r--accessible/ipc/win/PlatformChild.cpp87
-rw-r--r--accessible/ipc/win/PlatformChild.h39
-rw-r--r--accessible/ipc/win/ProxyAccessible.cpp816
-rw-r--r--accessible/ipc/win/ProxyAccessible.h61
-rw-r--r--accessible/ipc/win/handler/AccessibleHandler.cpp2144
-rw-r--r--accessible/ipc/win/handler/AccessibleHandler.def11
-rw-r--r--accessible/ipc/win/handler/AccessibleHandler.h336
-rw-r--r--accessible/ipc/win/handler/AccessibleHandler.rc5
-rw-r--r--accessible/ipc/win/handler/AccessibleHandlerControl.cpp205
-rw-r--r--accessible/ipc/win/handler/AccessibleHandlerControl.h97
-rw-r--r--accessible/ipc/win/handler/HandlerChildEnumerator.cpp170
-rw-r--r--accessible/ipc/win/handler/HandlerChildEnumerator.h51
-rw-r--r--accessible/ipc/win/handler/HandlerData.acf11
-rw-r--r--accessible/ipc/win/handler/HandlerData.idl212
-rw-r--r--accessible/ipc/win/handler/HandlerDataCleanup.h95
-rw-r--r--accessible/ipc/win/handler/HandlerRelation.cpp138
-rw-r--r--accessible/ipc/win/handler/HandlerRelation.h46
-rw-r--r--accessible/ipc/win/handler/HandlerTextLeaf.cpp337
-rw-r--r--accessible/ipc/win/handler/HandlerTextLeaf.h110
-rw-r--r--accessible/ipc/win/handler/moz.build128
-rw-r--r--accessible/ipc/win/moz.build72
-rw-r--r--accessible/ipc/win/typelib/Accessible.idl16
-rw-r--r--accessible/ipc/win/typelib/moz.build16
32 files changed, 7295 insertions, 0 deletions
diff --git a/accessible/ipc/win/COMPtrTypes.cpp b/accessible/ipc/win/COMPtrTypes.cpp
new file mode 100644
index 0000000000..cea8dac926
--- /dev/null
+++ b/accessible/ipc/win/COMPtrTypes.cpp
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/a11y/COMPtrTypes.h"
+
+#include <utility>
+
+#include "MainThreadUtils.h"
+#include "mozilla/Assertions.h"
+#include "mozilla/Preferences.h"
+#include "mozilla/RefPtr.h"
+#include "mozilla/a11y/Accessible.h"
+#include "mozilla/a11y/HandlerProvider.h"
+#include "mozilla/a11y/Platform.h"
+#include "mozilla/mscom/MainThreadHandoff.h"
+#include "mozilla/mscom/Utils.h"
+#include "nsXULAppAPI.h"
+
+using mozilla::mscom::MainThreadHandoff;
+using mozilla::mscom::ProxyUniquePtr;
+using mozilla::mscom::STAUniquePtr;
+
+namespace mozilla {
+namespace a11y {
+
+IAccessibleHolder CreateHolderFromAccessible(NotNull<Accessible*> aAccToWrap) {
+ MOZ_ASSERT(NS_IsMainThread());
+
+ STAUniquePtr<IAccessible> iaToProxy;
+ aAccToWrap->GetNativeInterface(mscom::getter_AddRefs(iaToProxy));
+ MOZ_DIAGNOSTIC_ASSERT(iaToProxy);
+ if (!iaToProxy) {
+ return nullptr;
+ }
+
+ static const bool useHandler =
+ Preferences::GetBool("accessibility.handler.enabled", false) &&
+ IsHandlerRegistered();
+
+ RefPtr<HandlerProvider> payload;
+ if (useHandler) {
+ payload = new HandlerProvider(IID_IAccessible,
+ mscom::ToInterceptorTargetPtr(iaToProxy));
+ }
+
+ ProxyUniquePtr<IAccessible> intercepted;
+ HRESULT hr = MainThreadHandoff::WrapInterface(
+ std::move(iaToProxy), payload,
+ (IAccessible**)mscom::getter_AddRefs(intercepted));
+ MOZ_ASSERT(SUCCEEDED(hr));
+ if (FAILED(hr)) {
+ return nullptr;
+ }
+
+ return IAccessibleHolder(std::move(intercepted));
+}
+
+IHandlerControlHolder CreateHolderFromHandlerControl(
+ mscom::ProxyUniquePtr<IHandlerControl> aHandlerControl) {
+ MOZ_ASSERT(aHandlerControl);
+ MOZ_ASSERT(XRE_IsContentProcess());
+ MOZ_ASSERT(NS_IsMainThread());
+ if (!aHandlerControl) {
+ return nullptr;
+ }
+
+ return IHandlerControlHolder(std::move(aHandlerControl));
+}
+
+} // namespace a11y
+} // namespace mozilla
diff --git a/accessible/ipc/win/COMPtrTypes.h b/accessible/ipc/win/COMPtrTypes.h
new file mode 100644
index 0000000000..b1d86eff7e
--- /dev/null
+++ b/accessible/ipc/win/COMPtrTypes.h
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_COMPtrTypes_h
+#define mozilla_a11y_COMPtrTypes_h
+
+#include "mozilla/a11y/AccessibleHandler.h"
+#include "mozilla/a11y/Compatibility.h"
+#include "mozilla/Attributes.h"
+#include "mozilla/mscom/ActivationContext.h"
+#include "mozilla/mscom/COMPtrHolder.h"
+#include "mozilla/NotNull.h"
+
+#include <oleacc.h>
+
+namespace mozilla {
+namespace a11y {
+
+class MOZ_RAII IAccessibleEnvironment : public mscom::ProxyStream::Environment {
+ public:
+ IAccessibleEnvironment() = default;
+
+ bool Push() override {
+ mActCtxRgn = GetActCtx();
+ return !!mActCtxRgn;
+ }
+
+ bool Pop() override { return mActCtxRgn.Deactivate(); }
+
+ private:
+ static const mscom::ActivationContext& GetActCtx() {
+ static const mscom::ActivationContext sActCtx(
+ Compatibility::GetActCtxResourceId());
+ MOZ_DIAGNOSTIC_ASSERT(sActCtx);
+ return sActCtx;
+ }
+
+ private:
+ mscom::ActivationContextRegion mActCtxRgn;
+};
+
+} // namespace a11y
+
+namespace mscom {
+namespace detail {
+
+template <>
+struct EnvironmentSelector<IAccessible> {
+ typedef a11y::IAccessibleEnvironment Type;
+};
+
+} // namespace detail
+} // namespace mscom
+
+namespace a11y {
+
+typedef mozilla::mscom::COMPtrHolder<IAccessible, IID_IAccessible>
+ IAccessibleHolder;
+typedef mozilla::mscom::COMPtrHolder<IDispatch, IID_IDispatch> IDispatchHolder;
+
+class Accessible;
+
+IAccessibleHolder CreateHolderFromAccessible(NotNull<Accessible*> aAccToWrap);
+
+typedef mozilla::mscom::COMPtrHolder<IHandlerControl, IID_IHandlerControl>
+ IHandlerControlHolder;
+
+IHandlerControlHolder CreateHolderFromHandlerControl(
+ mscom::ProxyUniquePtr<IHandlerControl> aHandlerControl);
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_COMPtrTypes_h
diff --git a/accessible/ipc/win/DocAccessibleChild.cpp b/accessible/ipc/win/DocAccessibleChild.cpp
new file mode 100644
index 0000000000..6663256fba
--- /dev/null
+++ b/accessible/ipc/win/DocAccessibleChild.cpp
@@ -0,0 +1,320 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "DocAccessibleChild.h"
+
+#include "nsAccessibilityService.h"
+#include "Accessible-inl.h"
+#include "mozilla/a11y/PlatformChild.h"
+#include "mozilla/ClearOnShutdown.h"
+#include "RootAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+static StaticAutoPtr<PlatformChild> sPlatformChild;
+
+DocAccessibleChild::DocAccessibleChild(DocAccessible* aDoc, IProtocol* aManager)
+ : DocAccessibleChildBase(aDoc), mEmulatedWindowHandle(nullptr) {
+ MOZ_COUNT_CTOR_INHERITED(DocAccessibleChild, DocAccessibleChildBase);
+ if (!sPlatformChild) {
+ sPlatformChild = new PlatformChild();
+ ClearOnShutdown(&sPlatformChild, ShutdownPhase::Shutdown);
+ }
+
+ SetManager(aManager);
+}
+
+DocAccessibleChild::~DocAccessibleChild() {
+ MOZ_COUNT_DTOR_INHERITED(DocAccessibleChild, DocAccessibleChildBase);
+}
+
+void DocAccessibleChild::Shutdown() {
+ if (IsConstructedInParentProcess()) {
+ DocAccessibleChildBase::Shutdown();
+ return;
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedShutdown>(this));
+ DetachDocument();
+}
+
+ipc::IPCResult DocAccessibleChild::RecvParentCOMProxy(
+ const IDispatchHolder& aParentCOMProxy) {
+ MOZ_ASSERT(!aParentCOMProxy.IsNull());
+ mParentProxy.reset(const_cast<IDispatchHolder&>(aParentCOMProxy).Release());
+ SetConstructedInParentProcess();
+
+ for (uint32_t i = 0, l = mDeferredEvents.Length(); i < l; ++i) {
+ mDeferredEvents[i]->Dispatch();
+ }
+
+ mDeferredEvents.Clear();
+
+ return IPC_OK();
+}
+
+ipc::IPCResult DocAccessibleChild::RecvEmulatedWindow(
+ const WindowsHandle& aEmulatedWindowHandle,
+ const IDispatchHolder& aEmulatedWindowCOMProxy) {
+ mEmulatedWindowHandle = reinterpret_cast<HWND>(aEmulatedWindowHandle);
+ if (!aEmulatedWindowCOMProxy.IsNull()) {
+ MOZ_ASSERT(!mEmulatedWindowProxy);
+ mEmulatedWindowProxy.reset(
+ const_cast<IDispatchHolder&>(aEmulatedWindowCOMProxy).Release());
+ }
+
+ return IPC_OK();
+}
+
+ipc::IPCResult DocAccessibleChild::RecvTopLevelDocCOMProxy(
+ const IAccessibleHolder& aCOMProxy) {
+ MOZ_ASSERT(!aCOMProxy.IsNull());
+ mTopLevelDocProxy.reset(const_cast<IAccessibleHolder&>(aCOMProxy).Release());
+ return IPC_OK();
+}
+
+HWND DocAccessibleChild::GetNativeWindowHandle() const {
+ if (mEmulatedWindowHandle) {
+ return mEmulatedWindowHandle;
+ }
+
+ auto browser = static_cast<dom::BrowserChild*>(Manager());
+ MOZ_ASSERT(browser);
+ // Iframe documents use the same window handle as their top level document.
+ auto topDoc = static_cast<DocAccessibleChild*>(
+ browser->GetTopLevelDocAccessibleChild());
+ MOZ_ASSERT(topDoc);
+ if (topDoc != this && topDoc->mEmulatedWindowHandle) {
+ return topDoc->mEmulatedWindowHandle;
+ }
+
+ return reinterpret_cast<HWND>(browser->GetNativeWindowHandle());
+}
+
+void DocAccessibleChild::PushDeferredEvent(UniquePtr<DeferredEvent> aEvent) {
+ DocAccessibleChild* topLevelIPCDoc = nullptr;
+
+ if (mDoc && mDoc->IsRoot()) {
+ topLevelIPCDoc = this;
+ } else {
+ auto browserChild = static_cast<dom::BrowserChild*>(Manager());
+ if (!browserChild) {
+ return;
+ }
+
+ topLevelIPCDoc = static_cast<DocAccessibleChild*>(
+ browserChild->GetTopLevelDocAccessibleChild());
+ }
+
+ if (topLevelIPCDoc) {
+ topLevelIPCDoc->mDeferredEvents.AppendElement(std::move(aEvent));
+ }
+}
+
+bool DocAccessibleChild::SendEvent(const uint64_t& aID, const uint32_t& aType) {
+ if (IsConstructedInParentProcess()) {
+ return PDocAccessibleChild::SendEvent(aID, aType);
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedEvent>(this, aID, aType));
+ return false;
+}
+
+void DocAccessibleChild::MaybeSendShowEvent(ShowEventData& aData,
+ bool aFromUser) {
+ if (IsConstructedInParentProcess()) {
+ Unused << SendShowEvent(aData, aFromUser);
+ return;
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedShow>(this, aData, aFromUser));
+}
+
+bool DocAccessibleChild::SendHideEvent(const uint64_t& aRootID,
+ const bool& aFromUser) {
+ if (IsConstructedInParentProcess()) {
+ return PDocAccessibleChild::SendHideEvent(aRootID, aFromUser);
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedHide>(this, aRootID, aFromUser));
+ return true;
+}
+
+bool DocAccessibleChild::SendStateChangeEvent(const uint64_t& aID,
+ const uint64_t& aState,
+ const bool& aEnabled) {
+ if (IsConstructedInParentProcess()) {
+ return PDocAccessibleChild::SendStateChangeEvent(aID, aState, aEnabled);
+ }
+
+ PushDeferredEvent(
+ MakeUnique<SerializedStateChange>(this, aID, aState, aEnabled));
+ return true;
+}
+
+LayoutDeviceIntRect DocAccessibleChild::GetCaretRectFor(const uint64_t& aID) {
+ Accessible* target;
+
+ if (aID) {
+ target = reinterpret_cast<Accessible*>(aID);
+ } else {
+ target = mDoc;
+ }
+
+ MOZ_ASSERT(target);
+
+ HyperTextAccessible* text = target->AsHyperText();
+ if (!text) {
+ return LayoutDeviceIntRect();
+ }
+
+ nsIWidget* widget = nullptr;
+ return text->GetCaretRect(&widget);
+}
+
+bool DocAccessibleChild::SendFocusEvent(const uint64_t& aID) {
+ return SendFocusEvent(aID, GetCaretRectFor(aID));
+}
+
+bool DocAccessibleChild::SendFocusEvent(const uint64_t& aID,
+ const LayoutDeviceIntRect& aCaretRect) {
+ if (IsConstructedInParentProcess()) {
+ return PDocAccessibleChild::SendFocusEvent(aID, aCaretRect);
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedFocus>(this, aID, aCaretRect));
+ return true;
+}
+
+bool DocAccessibleChild::SendCaretMoveEvent(const uint64_t& aID,
+ const int32_t& aOffset,
+ const bool& aIsSelectionCollapsed) {
+ return SendCaretMoveEvent(aID, GetCaretRectFor(aID), aOffset,
+ aIsSelectionCollapsed);
+}
+
+bool DocAccessibleChild::SendCaretMoveEvent(
+ const uint64_t& aID, const LayoutDeviceIntRect& aCaretRect,
+ const int32_t& aOffset, const bool& aIsSelectionCollapsed) {
+ if (IsConstructedInParentProcess()) {
+ return PDocAccessibleChild::SendCaretMoveEvent(aID, aCaretRect, aOffset,
+ aIsSelectionCollapsed);
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedCaretMove>(
+ this, aID, aCaretRect, aOffset, aIsSelectionCollapsed));
+ return true;
+}
+
+bool DocAccessibleChild::SendTextChangeEvent(
+ const uint64_t& aID, const nsString& aStr, const int32_t& aStart,
+ const uint32_t& aLen, const bool& aIsInsert, const bool& aFromUser,
+ const bool aDoSync) {
+ if (IsConstructedInParentProcess()) {
+ if (aDoSync) {
+ // The AT is going to need to reenter content while the event is being
+ // dispatched synchronously.
+ return PDocAccessibleChild::SendSyncTextChangeEvent(
+ aID, aStr, aStart, aLen, aIsInsert, aFromUser);
+ }
+ return PDocAccessibleChild::SendTextChangeEvent(aID, aStr, aStart, aLen,
+ aIsInsert, aFromUser);
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedTextChange>(
+ this, aID, aStr, aStart, aLen, aIsInsert, aFromUser));
+ return true;
+}
+
+bool DocAccessibleChild::SendSelectionEvent(const uint64_t& aID,
+ const uint64_t& aWidgetID,
+ const uint32_t& aType) {
+ if (IsConstructedInParentProcess()) {
+ return PDocAccessibleChild::SendSelectionEvent(aID, aWidgetID, aType);
+ }
+
+ PushDeferredEvent(
+ MakeUnique<SerializedSelection>(this, aID, aWidgetID, aType));
+ return true;
+}
+
+bool DocAccessibleChild::SendRoleChangedEvent(const a11y::role& aRole) {
+ if (IsConstructedInParentProcess()) {
+ return PDocAccessibleChild::SendRoleChangedEvent(aRole);
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedRoleChanged>(this, aRole));
+ return true;
+}
+
+bool DocAccessibleChild::SendScrollingEvent(const uint64_t& aID,
+ const uint64_t& aType,
+ const uint32_t& aScrollX,
+ const uint32_t& aScrollY,
+ const uint32_t& aMaxScrollX,
+ const uint32_t& aMaxScrollY) {
+ if (IsConstructedInParentProcess()) {
+ return PDocAccessibleChild::SendScrollingEvent(
+ aID, aType, aScrollX, aScrollY, aMaxScrollX, aMaxScrollY);
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedScrolling>(
+ this, aID, aType, aScrollX, aScrollY, aMaxScrollX, aMaxScrollY));
+ return true;
+}
+
+bool DocAccessibleChild::ConstructChildDocInParentProcess(
+ DocAccessibleChild* aNewChildDoc, uint64_t aUniqueID, uint32_t aMsaaID) {
+ if (IsConstructedInParentProcess()) {
+ // We may send the constructor immediately
+ auto browserChild = static_cast<dom::BrowserChild*>(Manager());
+ MOZ_ASSERT(browserChild);
+ bool result = browserChild->SendPDocAccessibleConstructor(
+ aNewChildDoc, this, aUniqueID, aMsaaID, IAccessibleHolder());
+ if (result) {
+ aNewChildDoc->SetConstructedInParentProcess();
+ }
+ return result;
+ }
+
+ PushDeferredEvent(MakeUnique<SerializedChildDocConstructor>(
+ aNewChildDoc, this, aUniqueID, aMsaaID));
+ return true;
+}
+
+bool DocAccessibleChild::SendBindChildDoc(DocAccessibleChild* aChildDoc,
+ const uint64_t& aNewParentID) {
+ if (IsConstructedInParentProcess()) {
+ return DocAccessibleChildBase::SendBindChildDoc(aChildDoc, aNewParentID);
+ }
+
+ PushDeferredEvent(
+ MakeUnique<SerializedBindChildDoc>(this, aChildDoc, aNewParentID));
+ return true;
+}
+
+ipc::IPCResult DocAccessibleChild::RecvRestoreFocus() {
+ FocusMgr()->ForceFocusEvent();
+ return IPC_OK();
+}
+
+void DocAccessibleChild::SetEmbedderOnBridge(dom::BrowserBridgeChild* aBridge,
+ uint64_t aID) {
+ if (CanSend()) {
+ aBridge->SendSetEmbedderAccessible(this, aID);
+ } else {
+ // This DocAccessibleChild hasn't sent the constructor to the parent
+ // process yet. This happens if the top level document hasn't received its
+ // parent COM proxy yet, in which case sending constructors for child
+ // documents gets deferred. We must also defer sending this as an embedder.
+ MOZ_ASSERT(!IsConstructedInParentProcess());
+ PushDeferredEvent(MakeUnique<SerializedSetEmbedder>(aBridge, this, aID));
+ }
+}
+
+} // namespace a11y
+} // namespace mozilla
diff --git a/accessible/ipc/win/DocAccessibleChild.h b/accessible/ipc/win/DocAccessibleChild.h
new file mode 100644
index 0000000000..d47a410016
--- /dev/null
+++ b/accessible/ipc/win/DocAccessibleChild.h
@@ -0,0 +1,369 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_DocAccessibleChild_h
+#define mozilla_a11y_DocAccessibleChild_h
+
+#include "mozilla/a11y/COMPtrTypes.h"
+#include "mozilla/a11y/DocAccessibleChildBase.h"
+#include "mozilla/dom/BrowserBridgeChild.h"
+#include "mozilla/dom/BrowserChild.h"
+#include "mozilla/mscom/Ptr.h"
+
+namespace mozilla {
+namespace a11y {
+
+/*
+ * These objects handle content side communication for an accessible document,
+ * and their lifetime is the same as the document they represent.
+ */
+class DocAccessibleChild : public DocAccessibleChildBase {
+ public:
+ DocAccessibleChild(DocAccessible* aDoc, IProtocol* aManager);
+ ~DocAccessibleChild();
+
+ virtual void Shutdown() override;
+
+ virtual ipc::IPCResult RecvParentCOMProxy(
+ const IDispatchHolder& aParentCOMProxy) override;
+ virtual ipc::IPCResult RecvEmulatedWindow(
+ const WindowsHandle& aEmulatedWindowHandle,
+ const IDispatchHolder& aEmulatedWindowCOMProxy) override;
+ virtual ipc::IPCResult RecvTopLevelDocCOMProxy(
+ const IAccessibleHolder& aCOMProxy) override;
+ virtual ipc::IPCResult RecvRestoreFocus() override;
+
+ HWND GetNativeWindowHandle() const;
+ IDispatch* GetEmulatedWindowIAccessible() const {
+ return mEmulatedWindowProxy.get();
+ }
+
+ IDispatch* GetParentIAccessible() const { return mParentProxy.get(); }
+ IAccessible* GetTopLevelDocIAccessible() const {
+ return mTopLevelDocProxy.get();
+ }
+
+ bool SendEvent(const uint64_t& aID, const uint32_t& type);
+ bool SendHideEvent(const uint64_t& aRootID, const bool& aFromUser);
+ bool SendStateChangeEvent(const uint64_t& aID, const uint64_t& aState,
+ const bool& aEnabled);
+ bool SendCaretMoveEvent(const uint64_t& aID, const int32_t& aOffset,
+ const bool& aIsSelectionCollapsed);
+ bool SendCaretMoveEvent(const uint64_t& aID,
+ const LayoutDeviceIntRect& aCaretRect,
+ const int32_t& aOffset,
+ const bool& aIsSelectionCollapsed);
+ bool SendFocusEvent(const uint64_t& aID);
+ bool SendFocusEvent(const uint64_t& aID,
+ const LayoutDeviceIntRect& aCaretRect);
+ bool SendTextChangeEvent(const uint64_t& aID, const nsString& aStr,
+ const int32_t& aStart, const uint32_t& aLen,
+ const bool& aIsInsert, const bool& aFromUser,
+ const bool aDoSync = false);
+ bool SendSelectionEvent(const uint64_t& aID, const uint64_t& aWidgetID,
+ const uint32_t& aType);
+ bool SendRoleChangedEvent(const a11y::role& aRole);
+ bool SendScrollingEvent(const uint64_t& aID, const uint64_t& aType,
+ const uint32_t& aScrollX, const uint32_t& aScrollY,
+ const uint32_t& aMaxScrollX,
+ const uint32_t& aMaxScrollY);
+
+ bool ConstructChildDocInParentProcess(DocAccessibleChild* aNewChildDoc,
+ uint64_t aUniqueID, uint32_t aMsaaID);
+
+ bool SendBindChildDoc(DocAccessibleChild* aChildDoc,
+ const uint64_t& aNewParentID);
+
+ /**
+ * Set the embedder accessible on a BrowserBridgeChild to an accessible in
+ * this document.
+ * Sending this will be deferred if this DocAccessibleChild hasn't been
+ * constructed in the parent process yet.
+ */
+ void SetEmbedderOnBridge(dom::BrowserBridgeChild* aBridge, uint64_t aID);
+
+ protected:
+ virtual void MaybeSendShowEvent(ShowEventData& aData,
+ bool aFromUser) override;
+
+ private:
+ void RemoveDeferredConstructor();
+
+ LayoutDeviceIntRect GetCaretRectFor(const uint64_t& aID);
+
+ /**
+ * DocAccessibleChild should not fire events until it has asynchronously
+ * received the COM proxy for its parent. OTOH, content a11y may still be
+ * attempting to fire events during this window of time. If this object does
+ * not yet have its parent proxy, instead of immediately sending the events to
+ * our parent, we enqueue them to mDeferredEvents. As soon as
+ * RecvParentCOMProxy is called, we play back mDeferredEvents.
+ */
+ struct DeferredEvent {
+ void Dispatch() { Dispatch(mTarget); }
+
+ virtual ~DeferredEvent() {}
+
+ protected:
+ explicit DeferredEvent(DocAccessibleChild* aTarget) : mTarget(aTarget) {}
+
+ virtual void Dispatch(DocAccessibleChild* aIPCDoc) = 0;
+
+ private:
+ DocAccessibleChild* mTarget;
+ };
+
+ void PushDeferredEvent(UniquePtr<DeferredEvent> aEvent);
+
+ struct SerializedShow final : public DeferredEvent {
+ SerializedShow(DocAccessibleChild* aTarget, ShowEventData& aEventData,
+ bool aFromUser)
+ : DeferredEvent(aTarget),
+ mEventData(aEventData.ID(), aEventData.Idx(),
+ nsTArray<AccessibleData>(), aEventData.EventSuppressed()),
+ mFromUser(aFromUser) {
+ // Since IPDL doesn't generate a move constructor for ShowEventData,
+ // we move NewTree manually (ugh). We still construct with an empty
+ // NewTree above so that the compiler catches any changes made to the
+ // ShowEventData structure in IPDL.
+ mEventData.NewTree() = std::move(aEventData.NewTree());
+ }
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendShowEvent(mEventData, mFromUser);
+ }
+
+ ShowEventData mEventData;
+ bool mFromUser;
+ };
+
+ struct SerializedHide final : public DeferredEvent {
+ SerializedHide(DocAccessibleChild* aTarget, uint64_t aRootID,
+ bool aFromUser)
+ : DeferredEvent(aTarget), mRootID(aRootID), mFromUser(aFromUser) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendHideEvent(mRootID, mFromUser);
+ }
+
+ uint64_t mRootID;
+ bool mFromUser;
+ };
+
+ struct SerializedStateChange final : public DeferredEvent {
+ SerializedStateChange(DocAccessibleChild* aTarget, uint64_t aID,
+ uint64_t aState, bool aEnabled)
+ : DeferredEvent(aTarget),
+ mID(aID),
+ mState(aState),
+ mEnabled(aEnabled) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendStateChangeEvent(mID, mState, mEnabled);
+ }
+
+ uint64_t mID;
+ uint64_t mState;
+ bool mEnabled;
+ };
+
+ struct SerializedCaretMove final : public DeferredEvent {
+ SerializedCaretMove(DocAccessibleChild* aTarget, uint64_t aID,
+ const LayoutDeviceIntRect& aCaretRect, int32_t aOffset,
+ bool aIsSelectionCollapsed)
+ : DeferredEvent(aTarget),
+ mID(aID),
+ mCaretRect(aCaretRect),
+ mOffset(aOffset),
+ mIsSelectionCollapsed(aIsSelectionCollapsed) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendCaretMoveEvent(mID, mCaretRect, mOffset,
+ mIsSelectionCollapsed);
+ }
+
+ uint64_t mID;
+ LayoutDeviceIntRect mCaretRect;
+ int32_t mOffset;
+ bool mIsSelectionCollapsed;
+ };
+
+ struct SerializedFocus final : public DeferredEvent {
+ SerializedFocus(DocAccessibleChild* aTarget, uint64_t aID,
+ const LayoutDeviceIntRect& aCaretRect)
+ : DeferredEvent(aTarget), mID(aID), mCaretRect(aCaretRect) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendFocusEvent(mID, mCaretRect);
+ }
+
+ uint64_t mID;
+ LayoutDeviceIntRect mCaretRect;
+ };
+
+ struct SerializedTextChange final : public DeferredEvent {
+ SerializedTextChange(DocAccessibleChild* aTarget, uint64_t aID,
+ const nsString& aStr, int32_t aStart, uint32_t aLen,
+ bool aIsInsert, bool aFromUser)
+ : DeferredEvent(aTarget),
+ mID(aID),
+ mStr(aStr),
+ mStart(aStart),
+ mLen(aLen),
+ mIsInsert(aIsInsert),
+ mFromUser(aFromUser) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendTextChangeEvent(mID, mStr, mStart, mLen, mIsInsert,
+ mFromUser, false);
+ }
+
+ uint64_t mID;
+ nsString mStr;
+ int32_t mStart;
+ uint32_t mLen;
+ bool mIsInsert;
+ bool mFromUser;
+ };
+
+ struct SerializedSelection final : public DeferredEvent {
+ SerializedSelection(DocAccessibleChild* aTarget, uint64_t aID,
+ uint64_t aWidgetID, uint32_t aType)
+ : DeferredEvent(aTarget),
+ mID(aID),
+ mWidgetID(aWidgetID),
+ mType(aType) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendSelectionEvent(mID, mWidgetID, mType);
+ }
+
+ uint64_t mID;
+ uint64_t mWidgetID;
+ uint32_t mType;
+ };
+
+ struct SerializedRoleChanged final : public DeferredEvent {
+ explicit SerializedRoleChanged(DocAccessibleChild* aTarget,
+ a11y::role aRole)
+ : DeferredEvent(aTarget), mRole(aRole) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendRoleChangedEvent(mRole);
+ }
+
+ a11y::role mRole;
+ };
+
+ struct SerializedScrolling final : public DeferredEvent {
+ explicit SerializedScrolling(DocAccessibleChild* aTarget, uint64_t aID,
+ uint64_t aType, uint32_t aScrollX,
+ uint32_t aScrollY, uint32_t aMaxScrollX,
+ uint32_t aMaxScrollY)
+ : DeferredEvent(aTarget),
+ mID(aID),
+ mType(aType),
+ mScrollX(aScrollX),
+ mScrollY(aScrollY),
+ mMaxScrollX(aMaxScrollX),
+ mMaxScrollY(aMaxScrollY) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendScrollingEvent(mID, mType, mScrollX, mScrollY,
+ mMaxScrollX, mMaxScrollY);
+ }
+
+ uint64_t mID;
+ uint64_t mType;
+ uint32_t mScrollX;
+ uint32_t mScrollY;
+ uint32_t mMaxScrollX;
+ uint32_t mMaxScrollY;
+ };
+
+ struct SerializedEvent final : public DeferredEvent {
+ SerializedEvent(DocAccessibleChild* aTarget, uint64_t aID, uint32_t aType)
+ : DeferredEvent(aTarget), mID(aID), mType(aType) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override {
+ Unused << aIPCDoc->SendEvent(mID, mType);
+ }
+
+ uint64_t mID;
+ uint32_t mType;
+ };
+
+ struct SerializedChildDocConstructor final : public DeferredEvent {
+ SerializedChildDocConstructor(DocAccessibleChild* aIPCDoc,
+ DocAccessibleChild* aParentIPCDoc,
+ uint64_t aUniqueID, uint32_t aMsaaID)
+ : DeferredEvent(aParentIPCDoc),
+ mIPCDoc(aIPCDoc),
+ mUniqueID(aUniqueID),
+ mMsaaID(aMsaaID) {}
+
+ void Dispatch(DocAccessibleChild* aParentIPCDoc) override {
+ auto browserChild =
+ static_cast<dom::BrowserChild*>(aParentIPCDoc->Manager());
+ MOZ_ASSERT(browserChild);
+ Unused << browserChild->SendPDocAccessibleConstructor(
+ mIPCDoc, aParentIPCDoc, mUniqueID, mMsaaID, IAccessibleHolder());
+ mIPCDoc->SetConstructedInParentProcess();
+ }
+
+ DocAccessibleChild* mIPCDoc;
+ uint64_t mUniqueID;
+ uint32_t mMsaaID;
+ };
+
+ friend struct SerializedChildDocConstructor;
+
+ struct SerializedBindChildDoc final : public DeferredEvent {
+ SerializedBindChildDoc(DocAccessibleChild* aParentDoc,
+ DocAccessibleChild* aChildDoc, uint64_t aNewParentID)
+ : DeferredEvent(aParentDoc),
+ mChildDoc(aChildDoc),
+ mNewParentID(aNewParentID) {}
+
+ void Dispatch(DocAccessibleChild* aParentIPCDoc) override {
+ Unused << aParentIPCDoc->SendBindChildDoc(mChildDoc, mNewParentID);
+ }
+
+ DocAccessibleChild* mChildDoc;
+ uint64_t mNewParentID;
+ };
+
+ struct SerializedShutdown final : public DeferredEvent {
+ explicit SerializedShutdown(DocAccessibleChild* aTarget)
+ : DeferredEvent(aTarget) {}
+
+ void Dispatch(DocAccessibleChild* aIPCDoc) override { aIPCDoc->Shutdown(); }
+ };
+
+ struct SerializedSetEmbedder final : public DeferredEvent {
+ SerializedSetEmbedder(dom::BrowserBridgeChild* aBridge,
+ DocAccessibleChild* aDoc, uint64_t aID)
+ : DeferredEvent(aDoc), mBridge(aBridge), mID(aID) {}
+
+ void Dispatch(DocAccessibleChild* aDoc) override {
+ Unused << mBridge->SendSetEmbedderAccessible(aDoc, mID);
+ }
+
+ RefPtr<dom::BrowserBridgeChild> mBridge;
+ uint64_t mID;
+ };
+
+ mscom::ProxyUniquePtr<IDispatch> mParentProxy;
+ mscom::ProxyUniquePtr<IDispatch> mEmulatedWindowProxy;
+ mscom::ProxyUniquePtr<IAccessible> mTopLevelDocProxy;
+ nsTArray<UniquePtr<DeferredEvent>> mDeferredEvents;
+ HWND mEmulatedWindowHandle;
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_DocAccessibleChild_h
diff --git a/accessible/ipc/win/HandlerProvider.cpp b/accessible/ipc/win/HandlerProvider.cpp
new file mode 100644
index 0000000000..6e8e5e52c3
--- /dev/null
+++ b/accessible/ipc/win/HandlerProvider.cpp
@@ -0,0 +1,974 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/a11y/HandlerProvider.h"
+
+#include <memory.h>
+
+#include <utility>
+
+#include "Accessible2_3.h"
+#include "AccessibleApplication.h"
+#include "AccessibleDocument.h"
+#include "AccessibleEditableText.h"
+#include "AccessibleImage.h"
+#include "AccessibleRelation.h"
+#include "AccessibleTable.h"
+#include "AccessibleTable2.h"
+#include "AccessibleTableCell.h"
+#include "HandlerData.h"
+#include "HandlerData_i.c"
+#include "ISimpleDOM.h"
+#include "mozilla/Assertions.h"
+#include "mozilla/UniquePtr.h"
+#include "mozilla/a11y/AccessibleWrap.h"
+#include "mozilla/dom/ContentChild.h"
+#include "mozilla/mscom/AgileReference.h"
+#include "mozilla/mscom/FastMarshaler.h"
+#include "mozilla/mscom/Interceptor.h"
+#include "mozilla/mscom/MainThreadHandoff.h"
+#include "mozilla/mscom/MainThreadInvoker.h"
+#include "mozilla/mscom/Ptr.h"
+#include "mozilla/mscom/StructStream.h"
+#include "mozilla/mscom/Utils.h"
+#include "nsTArray.h"
+#include "nsThreadUtils.h"
+#include "uiautomation.h"
+
+namespace mozilla {
+namespace a11y {
+
+HandlerProvider::HandlerProvider(REFIID aIid,
+ mscom::InterceptorTargetPtr<IUnknown> aTarget)
+ : mRefCnt(0),
+ mMutex("mozilla::a11y::HandlerProvider::mMutex"),
+ mTargetUnkIid(aIid),
+ mTargetUnk(std::move(aTarget)),
+ mPayloadMutex("mozilla::a11y::HandlerProvider::mPayloadMutex") {}
+
+HRESULT
+HandlerProvider::QueryInterface(REFIID riid, void** ppv) {
+ if (!ppv) {
+ return E_INVALIDARG;
+ }
+
+ if (riid == IID_IUnknown || riid == IID_IGeckoBackChannel) {
+ RefPtr<IUnknown> punk(static_cast<IGeckoBackChannel*>(this));
+ punk.forget(ppv);
+ return S_OK;
+ }
+
+ if (riid == IID_IMarshal) {
+ if (!mFastMarshalUnk) {
+ HRESULT hr =
+ mscom::FastMarshaler::Create(static_cast<IGeckoBackChannel*>(this),
+ getter_AddRefs(mFastMarshalUnk));
+ if (FAILED(hr)) {
+ return hr;
+ }
+ }
+
+ return mFastMarshalUnk->QueryInterface(riid, ppv);
+ }
+
+ return E_NOINTERFACE;
+}
+
+ULONG
+HandlerProvider::AddRef() { return ++mRefCnt; }
+
+ULONG
+HandlerProvider::Release() {
+ ULONG result = --mRefCnt;
+ if (!result) {
+ delete this;
+ }
+ return result;
+}
+
+HRESULT
+HandlerProvider::GetHandler(NotNull<CLSID*> aHandlerClsid) {
+ if (!IsTargetInterfaceCacheable()) {
+ return E_NOINTERFACE;
+ }
+
+ *aHandlerClsid = CLSID_AccessibleHandler;
+ return S_OK;
+}
+
+void HandlerProvider::GetAndSerializePayload(
+ const MutexAutoLock&, NotNull<mscom::IInterceptor*> aInterceptor) {
+ MOZ_ASSERT(mscom::IsCurrentThreadMTA());
+
+ if (mSerializer) {
+ return;
+ }
+
+ IA2PayloadPtr payload;
+ { // Scope for lock
+ MutexAutoLock lock(mPayloadMutex);
+ if (mPayload) {
+ // The payload was already built by prebuildPayload() called during a
+ // bulk fetch operation.
+ payload = std::move(mPayload);
+ }
+ }
+
+ if (!payload) {
+ // We don't have a pre-built payload, so build it now.
+ payload.reset(new IA2Payload());
+ if (!mscom::InvokeOnMainThread(
+ "HandlerProvider::BuildInitialIA2Data", this,
+ &HandlerProvider::BuildInitialIA2Data,
+ std::forward<NotNull<mscom::IInterceptor*>>(aInterceptor),
+ std::forward<StaticIA2Data*>(&payload->mStaticData),
+ std::forward<DynamicIA2Data*>(&payload->mDynamicData)) ||
+ !payload->mDynamicData.mUniqueId) {
+ return;
+ }
+ }
+
+ // But we set mGeckoBackChannel on the current thread which resides in the
+ // MTA. This is important to ensure that COM always invokes
+ // IGeckoBackChannel methods in an MTA background thread.
+ RefPtr<IGeckoBackChannel> payloadRef(this);
+ // AddRef/Release pair for this reference is handled by payloadRef
+ payload->mGeckoBackChannel = this;
+
+ mSerializer = MakeUnique<mscom::StructToStream>(*payload, &IA2Payload_Encode);
+}
+
+HRESULT
+HandlerProvider::GetHandlerPayloadSize(
+ NotNull<mscom::IInterceptor*> aInterceptor,
+ NotNull<DWORD*> aOutPayloadSize) {
+ MOZ_ASSERT(mscom::IsCurrentThreadMTA());
+
+ if (!IsTargetInterfaceCacheable()) {
+ // No handler, so no payload for this instance.
+ return E_NOTIMPL;
+ }
+
+ MutexAutoLock lock(mMutex);
+
+ GetAndSerializePayload(lock, aInterceptor);
+
+ if (!mSerializer || !(*mSerializer)) {
+ // Failed payload serialization is non-fatal
+ *aOutPayloadSize = mscom::StructToStream::GetEmptySize();
+ return S_OK;
+ }
+
+ *aOutPayloadSize = mSerializer->GetSize();
+ return S_OK;
+}
+
+void HandlerProvider::BuildStaticIA2Data(
+ NotNull<mscom::IInterceptor*> aInterceptor, StaticIA2Data* aOutData) {
+ MOZ_ASSERT(aOutData);
+ MOZ_ASSERT(NS_IsMainThread());
+ MOZ_ASSERT(mTargetUnk);
+ MOZ_ASSERT(IsTargetInterfaceCacheable());
+
+ // Include interfaces the client is likely to request.
+ // This is cheap here and saves multiple cross-process calls later.
+ // These interfaces must be released in ReleaseStaticIA2DataInterfaces!
+
+ // If the target is already an IAccessible2, this pointer is redundant.
+ // However, the target might be an IAccessibleHyperlink, etc., in which
+ // case the client will almost certainly QI for IAccessible2.
+ HRESULT hr = aInterceptor->GetInterceptorForIID(NEWEST_IA2_IID,
+ (void**)&aOutData->mIA2);
+ if (FAILED(hr)) {
+ // IA2 should always be present, so something has
+ // gone very wrong if this fails.
+ aOutData->mIA2 = nullptr;
+ return;
+ }
+
+ // Some of these interfaces aren't present on all accessibles,
+ // so it's not a failure if these interfaces can't be fetched.
+ hr = aInterceptor->GetInterceptorForIID(IID_IAccessibleHypertext2,
+ (void**)&aOutData->mIAHypertext);
+ if (FAILED(hr)) {
+ aOutData->mIAHypertext = nullptr;
+ }
+
+ hr = aInterceptor->GetInterceptorForIID(IID_IAccessibleHyperlink,
+ (void**)&aOutData->mIAHyperlink);
+ if (FAILED(hr)) {
+ aOutData->mIAHyperlink = nullptr;
+ }
+
+ hr = aInterceptor->GetInterceptorForIID(IID_IAccessibleTable,
+ (void**)&aOutData->mIATable);
+ if (FAILED(hr)) {
+ aOutData->mIATable = nullptr;
+ }
+
+ hr = aInterceptor->GetInterceptorForIID(IID_IAccessibleTable2,
+ (void**)&aOutData->mIATable2);
+ if (FAILED(hr)) {
+ aOutData->mIATable2 = nullptr;
+ }
+
+ hr = aInterceptor->GetInterceptorForIID(IID_IAccessibleTableCell,
+ (void**)&aOutData->mIATableCell);
+ if (FAILED(hr)) {
+ aOutData->mIATableCell = nullptr;
+ }
+}
+
+void HandlerProvider::BuildDynamicIA2Data(DynamicIA2Data* aOutIA2Data,
+ bool aMarshaledByCom) {
+ MOZ_ASSERT(aOutIA2Data);
+ MOZ_ASSERT(NS_IsMainThread());
+ MOZ_ASSERT(IsTargetInterfaceCacheable());
+
+ if (!mTargetUnk) {
+ return;
+ }
+
+ RefPtr<NEWEST_IA2_INTERFACE> target;
+ HRESULT hr =
+ mTargetUnk.get()->QueryInterface(NEWEST_IA2_IID, getter_AddRefs(target));
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = E_UNEXPECTED;
+
+ auto hasFailed = [&hr]() -> bool { return FAILED(hr); };
+
+ auto cleanup = [aOutIA2Data, aMarshaledByCom]() -> void {
+ CleanupDynamicIA2Data(*aOutIA2Data, aMarshaledByCom);
+ };
+
+ mscom::ExecuteWhen<decltype(hasFailed), decltype(cleanup)> onFail(hasFailed,
+ cleanup);
+
+ // When allocating memory to be returned to the client, you *must* use
+ // allocMem, not CoTaskMemAlloc!
+ auto allocMem = [aMarshaledByCom](size_t aSize) {
+ if (aMarshaledByCom) {
+ return ::CoTaskMemAlloc(aSize);
+ }
+ // We use midl_user_allocate rather than CoTaskMemAlloc because this
+ // struct is being marshaled by RPC, not COM.
+ return ::midl_user_allocate(aSize);
+ };
+
+ const VARIANT kChildIdSelf = {VT_I4};
+ VARIANT varVal;
+
+ hr = target->accLocation(&aOutIA2Data->mLeft, &aOutIA2Data->mTop,
+ &aOutIA2Data->mWidth, &aOutIA2Data->mHeight,
+ kChildIdSelf);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->get_accRole(kChildIdSelf, &aOutIA2Data->mRole);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->get_accState(kChildIdSelf, &varVal);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ aOutIA2Data->mState = varVal.lVal;
+
+ hr = target->get_accKeyboardShortcut(kChildIdSelf,
+ &aOutIA2Data->mKeyboardShortcut);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->get_accName(kChildIdSelf, &aOutIA2Data->mName);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->get_accDescription(kChildIdSelf, &aOutIA2Data->mDescription);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->get_accDefaultAction(kChildIdSelf, &aOutIA2Data->mDefaultAction);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->get_accChildCount(&aOutIA2Data->mChildCount);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->get_accValue(kChildIdSelf, &aOutIA2Data->mValue);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->get_states(&aOutIA2Data->mIA2States);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->get_attributes(&aOutIA2Data->mAttributes);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ HWND hwnd;
+ hr = target->get_windowHandle(&hwnd);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ aOutIA2Data->mHwnd = PtrToLong(hwnd);
+
+ hr = target->get_locale(&aOutIA2Data->mIA2Locale);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ hr = target->role(&aOutIA2Data->mIA2Role);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ RefPtr<IAccessibleAction> action;
+ // It is not an error if this fails.
+ hr = mTargetUnk.get()->QueryInterface(IID_IAccessibleAction,
+ getter_AddRefs(action));
+ if (SUCCEEDED(hr)) {
+ hr = action->nActions(&aOutIA2Data->mNActions);
+ if (FAILED(hr)) {
+ return;
+ }
+ }
+
+ RefPtr<IAccessibleTableCell> cell;
+ // It is not an error if this fails.
+ hr = mTargetUnk.get()->QueryInterface(IID_IAccessibleTableCell,
+ getter_AddRefs(cell));
+ if (SUCCEEDED(hr)) {
+ hr = cell->get_rowColumnExtents(
+ &aOutIA2Data->mRowIndex, &aOutIA2Data->mColumnIndex,
+ &aOutIA2Data->mRowExtent, &aOutIA2Data->mColumnExtent,
+ &aOutIA2Data->mCellIsSelected);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ // Because the same headers can apply to many cells, include the ids of
+ // header cells, rather than the actual objects. Otherwise, we might
+ // end up marshaling the same objects (and their payloads) many times.
+ IUnknown** headers = nullptr;
+ hr = cell->get_rowHeaderCells(&headers, &aOutIA2Data->mNRowHeaderCells);
+ if (FAILED(hr)) {
+ return;
+ }
+ if (aOutIA2Data->mNRowHeaderCells > 0) {
+ aOutIA2Data->mRowHeaderCellIds = static_cast<long*>(
+ allocMem(sizeof(long) * aOutIA2Data->mNRowHeaderCells));
+ for (long i = 0; i < aOutIA2Data->mNRowHeaderCells; ++i) {
+ RefPtr<IAccessible2> headerAcc;
+ hr = headers[i]->QueryInterface(IID_IAccessible2,
+ getter_AddRefs(headerAcc));
+ MOZ_ASSERT(SUCCEEDED(hr));
+ headers[i]->Release();
+ hr = headerAcc->get_uniqueID(&aOutIA2Data->mRowHeaderCellIds[i]);
+ MOZ_ASSERT(SUCCEEDED(hr));
+ }
+ }
+ ::CoTaskMemFree(headers);
+
+ hr = cell->get_columnHeaderCells(&headers,
+ &aOutIA2Data->mNColumnHeaderCells);
+ if (FAILED(hr)) {
+ return;
+ }
+ if (aOutIA2Data->mNColumnHeaderCells > 0) {
+ aOutIA2Data->mColumnHeaderCellIds = static_cast<long*>(
+ allocMem(sizeof(long) * aOutIA2Data->mNColumnHeaderCells));
+ for (long i = 0; i < aOutIA2Data->mNColumnHeaderCells; ++i) {
+ RefPtr<IAccessible2> headerAcc;
+ hr = headers[i]->QueryInterface(IID_IAccessible2,
+ getter_AddRefs(headerAcc));
+ MOZ_ASSERT(SUCCEEDED(hr));
+ headers[i]->Release();
+ hr = headerAcc->get_uniqueID(&aOutIA2Data->mColumnHeaderCellIds[i]);
+ MOZ_ASSERT(SUCCEEDED(hr));
+ }
+ }
+ ::CoTaskMemFree(headers);
+ }
+
+ // NB: get_uniqueID should be the final property retrieved in this method,
+ // as its presence is used to determine whether the rest of this data
+ // retrieval was successful.
+ hr = target->get_uniqueID(&aOutIA2Data->mUniqueId);
+}
+
+void HandlerProvider::BuildInitialIA2Data(
+ NotNull<mscom::IInterceptor*> aInterceptor, StaticIA2Data* aOutStaticData,
+ DynamicIA2Data* aOutDynamicData) {
+ BuildStaticIA2Data(aInterceptor, aOutStaticData);
+ if (!aOutStaticData->mIA2) {
+ return;
+ }
+ BuildDynamicIA2Data(aOutDynamicData);
+}
+
+bool HandlerProvider::IsTargetInterfaceCacheable() {
+ return MarshalAs(mTargetUnkIid) == NEWEST_IA2_IID ||
+ mTargetUnkIid == IID_IAccessibleHyperlink;
+}
+
+HRESULT
+HandlerProvider::WriteHandlerPayload(NotNull<mscom::IInterceptor*> aInterceptor,
+ NotNull<IStream*> aStream) {
+ if (!IsTargetInterfaceCacheable()) {
+ // No handler, so no payload for this instance.
+ return E_NOTIMPL;
+ }
+
+ MutexAutoLock lock(mMutex);
+
+ if (!mSerializer || !(*mSerializer)) {
+ // Failed payload serialization is non-fatal
+ mscom::StructToStream emptyStruct;
+ return emptyStruct.Write(aStream);
+ }
+
+ HRESULT hr = mSerializer->Write(aStream);
+
+ mSerializer.reset();
+
+ return hr;
+}
+
+REFIID
+HandlerProvider::MarshalAs(REFIID aIid) {
+ static_assert(&NEWEST_IA2_IID == &IID_IAccessible2_3,
+ "You have modified NEWEST_IA2_IID. This code needs updating.");
+ if (aIid == IID_IDispatch || aIid == IID_IAccessible ||
+ aIid == IID_IAccessible2 || aIid == IID_IAccessible2_2 ||
+ aIid == IID_IAccessible2_3) {
+ // This should always be the newest IA2 interface ID
+ return NEWEST_IA2_IID;
+ }
+ // Otherwise we juse return the identity.
+ return aIid;
+}
+
+HRESULT
+HandlerProvider::DisconnectHandlerRemotes() {
+ // If a handlerProvider call is pending on another thread,
+ // CoDisconnectObject won't release this HandlerProvider immediately.
+ // However, the interceptor and its target (mTargetUnk) might be destroyed.
+ mTargetUnk = nullptr;
+
+ IUnknown* unk = static_cast<IGeckoBackChannel*>(this);
+ return ::CoDisconnectObject(unk, 0);
+}
+
+HRESULT
+HandlerProvider::IsInterfaceMaybeSupported(REFIID aIid) {
+ static_assert(&NEWEST_IA2_IID == &IID_IAccessible2_3,
+ "You have modified NEWEST_IA2_IID. This code needs updating.");
+ if (aIid == IID_IUnknown || aIid == IID_IDispatch ||
+ aIid == IID_IAccessible || aIid == IID_IServiceProvider ||
+ aIid == IID_IEnumVARIANT || aIid == IID_IAccessible2 ||
+ aIid == IID_IAccessible2_2 || aIid == IID_IAccessible2_3 ||
+ aIid == IID_IAccessibleAction || aIid == IID_IAccessibleApplication ||
+ aIid == IID_IAccessibleComponent || aIid == IID_IAccessibleDocument ||
+ aIid == IID_IAccessibleEditableText || aIid == IID_IAccessibleHyperlink ||
+ aIid == IID_IAccessibleHypertext || aIid == IID_IAccessibleHypertext2 ||
+ aIid == IID_IAccessibleImage || aIid == IID_IAccessibleRelation ||
+ aIid == IID_IAccessibleTable || aIid == IID_IAccessibleTable2 ||
+ aIid == IID_IAccessibleTableCell || aIid == IID_IAccessibleText ||
+ aIid == IID_IAccessibleValue || aIid == IID_ISimpleDOMNode ||
+ aIid == IID_ISimpleDOMDocument || aIid == IID_ISimpleDOMText ||
+ aIid == IID_IAccessibleEx || aIid == IID_IRawElementProviderSimple) {
+ return S_OK;
+ }
+ return E_NOINTERFACE;
+}
+
+REFIID
+HandlerProvider::GetEffectiveOutParamIid(REFIID aCallIid, ULONG aCallMethod) {
+ if (aCallIid == IID_IAccessibleTable || aCallIid == IID_IAccessibleTable2 ||
+ aCallIid == IID_IAccessibleDocument ||
+ aCallIid == IID_IAccessibleTableCell ||
+ aCallIid == IID_IAccessibleRelation) {
+ return NEWEST_IA2_IID;
+ }
+
+ // IAccessible2_2::accessibleWithCaret
+ static_assert(&NEWEST_IA2_IID == &IID_IAccessible2_3,
+ "You have modified NEWEST_IA2_IID. This code needs updating.");
+ if ((aCallIid == IID_IAccessible2_2 || aCallIid == IID_IAccessible2_3) &&
+ aCallMethod == 47) {
+ return NEWEST_IA2_IID;
+ }
+
+ // IAccessible::get_accSelection
+ if ((aCallIid == IID_IAccessible || aCallIid == IID_IAccessible2 ||
+ aCallIid == IID_IAccessible2_2 || aCallIid == IID_IAccessible2_3) &&
+ aCallMethod == 19) {
+ return IID_IEnumVARIANT;
+ }
+
+ MOZ_ASSERT(false);
+ return IID_IUnknown;
+}
+
+HRESULT
+HandlerProvider::NewInstance(
+ REFIID aIid, mscom::InterceptorTargetPtr<IUnknown> aTarget,
+ NotNull<mscom::IHandlerProvider**> aOutNewPayload) {
+ RefPtr<IHandlerProvider> newPayload(
+ new HandlerProvider(aIid, std::move(aTarget)));
+ newPayload.forget(aOutNewPayload.get());
+ return S_OK;
+}
+
+void HandlerProvider::SetHandlerControlOnMainThread(
+ DWORD aPid, mscom::ProxyUniquePtr<IHandlerControl> aCtrl) {
+ MOZ_ASSERT(NS_IsMainThread());
+
+ auto content = dom::ContentChild::GetSingleton();
+ MOZ_ASSERT(content);
+
+ IHandlerControlHolder holder(
+ CreateHolderFromHandlerControl(std::move(aCtrl)));
+ Unused << content->SendA11yHandlerControl(aPid, holder);
+}
+
+HRESULT
+HandlerProvider::put_HandlerControl(long aPid, IHandlerControl* aCtrl) {
+ MOZ_ASSERT(mscom::IsCurrentThreadMTA());
+
+ if (!aCtrl) {
+ return E_INVALIDARG;
+ }
+
+ auto ptrProxy = mscom::ToProxyUniquePtr(aCtrl);
+
+ if (!mscom::InvokeOnMainThread(
+ "HandlerProvider::SetHandlerControlOnMainThread", this,
+ &HandlerProvider::SetHandlerControlOnMainThread,
+ static_cast<DWORD>(aPid), std::move(ptrProxy))) {
+ return E_FAIL;
+ }
+
+ return S_OK;
+}
+
+HRESULT
+HandlerProvider::Refresh(DynamicIA2Data* aOutData) {
+ MOZ_ASSERT(mscom::IsCurrentThreadMTA());
+
+ if (!mTargetUnk) {
+ return CO_E_OBJNOTCONNECTED;
+ }
+
+ if (!mscom::InvokeOnMainThread("HandlerProvider::BuildDynamicIA2Data", this,
+ &HandlerProvider::BuildDynamicIA2Data,
+ std::forward<DynamicIA2Data*>(aOutData),
+ /* aMarshaledByCom */ true)) {
+ return E_FAIL;
+ }
+
+ if (!aOutData->mUniqueId) {
+ // BuildDynamicIA2Data failed.
+ if (!mTargetUnk) {
+ // Even though we checked this before, the accessible can be shut down
+ // before BuildDynamicIA2Data executes on the main thread.
+ return CO_E_OBJNOTCONNECTED;
+ }
+ return E_FAIL;
+ }
+
+ return S_OK;
+}
+
+void HandlerProvider::PrebuildPayload(
+ NotNull<mscom::IInterceptor*> aInterceptor) {
+ MOZ_ASSERT(NS_IsMainThread());
+ MutexAutoLock lock(mPayloadMutex);
+ mPayload.reset(new IA2Payload());
+ BuildInitialIA2Data(aInterceptor, &mPayload->mStaticData,
+ &mPayload->mDynamicData);
+ if (!mPayload->mDynamicData.mUniqueId) {
+ // Building the payload failed.
+ mPayload.reset();
+ }
+}
+
+template <typename Interface>
+HRESULT HandlerProvider::ToWrappedObject(Interface** aObj) {
+ MOZ_ASSERT(NS_IsMainThread());
+ mscom::STAUniquePtr<Interface> inObj(*aObj);
+ RefPtr<HandlerProvider> hprov = new HandlerProvider(
+ __uuidof(Interface), mscom::ToInterceptorTargetPtr(inObj));
+ HRESULT hr =
+ mscom::MainThreadHandoff::WrapInterface(std::move(inObj), hprov, aObj);
+ if (FAILED(hr)) {
+ *aObj = nullptr;
+ return hr;
+ }
+ // Build the payload for this object now to avoid a cross-thread call when
+ // marshaling it later.
+ RefPtr<mscom::IInterceptor> interceptor;
+ hr = (*aObj)->QueryInterface(mscom::IID_IInterceptor,
+ getter_AddRefs(interceptor));
+ MOZ_ASSERT(SUCCEEDED(hr));
+ // Even though we created a new HandlerProvider, that won't be used if
+ // there's an existing Interceptor. Therefore, we must get the
+ // HandlerProvider from the Interceptor.
+ RefPtr<mscom::IInterceptorSink> interceptorSink;
+ interceptor->GetEventSink(getter_AddRefs(interceptorSink));
+ MOZ_ASSERT(interceptorSink);
+ RefPtr<mscom::IMainThreadHandoff> handoff;
+ hr = interceptorSink->QueryInterface(mscom::IID_IMainThreadHandoff,
+ getter_AddRefs(handoff));
+ // If a11y Interceptors stop using MainThreadHandoff as their event sink, we
+ // *really* want to know about it ASAP.
+ MOZ_DIAGNOSTIC_ASSERT(SUCCEEDED(hr),
+ "A11y Interceptor isn't using MainThreadHandoff");
+ RefPtr<mscom::IHandlerProvider> usedIHprov;
+ handoff->GetHandlerProvider(getter_AddRefs(usedIHprov));
+ MOZ_ASSERT(usedIHprov);
+ auto usedHprov = static_cast<HandlerProvider*>(usedIHprov.get());
+ usedHprov->PrebuildPayload(WrapNotNull(interceptor));
+ return hr;
+}
+
+void HandlerProvider::GetAllTextInfoMainThread(
+ BSTR* aText, IAccessibleHyperlink*** aHyperlinks, long* aNHyperlinks,
+ IA2TextSegment** aAttribRuns, long* aNAttribRuns, HRESULT* result) {
+ MOZ_ASSERT(aText);
+ MOZ_ASSERT(aHyperlinks);
+ MOZ_ASSERT(aNHyperlinks);
+ MOZ_ASSERT(aAttribRuns);
+ MOZ_ASSERT(aNAttribRuns);
+ MOZ_ASSERT(NS_IsMainThread());
+
+ if (!mTargetUnk) {
+ *result = CO_E_OBJNOTCONNECTED;
+ return;
+ }
+
+ RefPtr<IAccessibleHypertext2> ht;
+ HRESULT hr =
+ mTargetUnk->QueryInterface(IID_IAccessibleHypertext2, getter_AddRefs(ht));
+ if (FAILED(hr)) {
+ *result = hr;
+ return;
+ }
+
+ hr = ht->get_text(0, IA2_TEXT_OFFSET_LENGTH, aText);
+ if (FAILED(hr)) {
+ *result = hr;
+ return;
+ }
+
+ if (hr == S_FALSE) {
+ // No text.
+ *aHyperlinks = nullptr;
+ *aNHyperlinks = 0;
+ *aAttribRuns = nullptr;
+ *aNAttribRuns = 0;
+ *result = S_FALSE;
+ return;
+ }
+
+ hr = ht->get_hyperlinks(aHyperlinks, aNHyperlinks);
+ if (FAILED(hr)) {
+ *aHyperlinks = nullptr;
+ // -1 signals to the handler that it should call hyperlinks itself.
+ *aNHyperlinks = -1;
+ }
+ // We must wrap these hyperlinks in an interceptor.
+ for (long index = 0; index < *aNHyperlinks; ++index) {
+ ToWrappedObject(&(*aHyperlinks)[index]);
+ }
+
+ // Fetch all attribute runs.
+ nsTArray<IA2TextSegment> attribRuns;
+ long end = 0;
+ long length = ::SysStringLen(*aText);
+ while (end < length) {
+ long offset = end;
+ long start;
+ BSTR attribs;
+ // The (exclusive) end of the last run is the start of the next run.
+ hr = ht->get_attributes(offset, &start, &end, &attribs);
+ // Bug 1421873: Gecko can return end <= offset in some rare cases, which
+ // isn't valid. This is perhaps because the text mutated during the loop
+ // for some reason, making this offset invalid.
+ if (FAILED(hr) || end <= offset) {
+ break;
+ }
+ attribRuns.AppendElement(IA2TextSegment({attribs, start, end}));
+ }
+
+ // Put the attribute runs in a COM array.
+ *aNAttribRuns = attribRuns.Length();
+ *aAttribRuns = static_cast<IA2TextSegment*>(
+ ::CoTaskMemAlloc(sizeof(IA2TextSegment) * *aNAttribRuns));
+ for (long index = 0; index < *aNAttribRuns; ++index) {
+ (*aAttribRuns)[index] = attribRuns[index];
+ }
+
+ *result = S_OK;
+}
+
+HRESULT
+HandlerProvider::get_AllTextInfo(BSTR* aText,
+ IAccessibleHyperlink*** aHyperlinks,
+ long* aNHyperlinks,
+ IA2TextSegment** aAttribRuns,
+ long* aNAttribRuns) {
+ MOZ_ASSERT(mscom::IsCurrentThreadMTA());
+
+ if (!mTargetUnk) {
+ return CO_E_OBJNOTCONNECTED;
+ }
+
+ HRESULT hr;
+ if (!mscom::InvokeOnMainThread(
+ "HandlerProvider::GetAllTextInfoMainThread", this,
+ &HandlerProvider::GetAllTextInfoMainThread,
+ std::forward<BSTR*>(aText),
+ std::forward<IAccessibleHyperlink***>(aHyperlinks),
+ std::forward<long*>(aNHyperlinks),
+ std::forward<IA2TextSegment**>(aAttribRuns),
+ std::forward<long*>(aNAttribRuns), std::forward<HRESULT*>(&hr))) {
+ return E_FAIL;
+ }
+
+ return hr;
+}
+
+void HandlerProvider::GetRelationsInfoMainThread(IARelationData** aRelations,
+ long* aNRelations,
+ HRESULT* hr) {
+ MOZ_ASSERT(aRelations);
+ MOZ_ASSERT(aNRelations);
+ MOZ_ASSERT(NS_IsMainThread());
+
+ if (!mTargetUnk) {
+ *hr = CO_E_OBJNOTCONNECTED;
+ return;
+ }
+
+ RefPtr<NEWEST_IA2_INTERFACE> acc;
+ *hr = mTargetUnk.get()->QueryInterface(NEWEST_IA2_IID, getter_AddRefs(acc));
+ if (FAILED(*hr)) {
+ return;
+ }
+
+ *hr = acc->get_nRelations(aNRelations);
+ if (FAILED(*hr)) {
+ return;
+ }
+
+ auto rawRels = MakeUnique<IAccessibleRelation*[]>(*aNRelations);
+ *hr = acc->get_relations(*aNRelations, rawRels.get(), aNRelations);
+ if (FAILED(*hr)) {
+ return;
+ }
+
+ *aRelations = static_cast<IARelationData*>(
+ ::CoTaskMemAlloc(sizeof(IARelationData) * *aNRelations));
+ for (long index = 0; index < *aNRelations; ++index) {
+ IAccessibleRelation* rawRel = rawRels[index];
+ IARelationData& relData = (*aRelations)[index];
+ *hr = rawRel->get_relationType(&relData.mType);
+ if (FAILED(*hr)) {
+ relData.mType = nullptr;
+ }
+ *hr = rawRel->get_nTargets(&relData.mNTargets);
+ if (FAILED(*hr)) {
+ relData.mNTargets = -1;
+ }
+ rawRel->Release();
+ }
+
+ *hr = S_OK;
+}
+
+HRESULT
+HandlerProvider::get_RelationsInfo(IARelationData** aRelations,
+ long* aNRelations) {
+ MOZ_ASSERT(mscom::IsCurrentThreadMTA());
+
+ if (!mTargetUnk) {
+ return CO_E_OBJNOTCONNECTED;
+ }
+
+ HRESULT hr;
+ if (!mscom::InvokeOnMainThread(
+ "HandlerProvider::GetRelationsInfoMainThread", this,
+ &HandlerProvider::GetRelationsInfoMainThread,
+ std::forward<IARelationData**>(aRelations),
+ std::forward<long*>(aNRelations), std::forward<HRESULT*>(&hr))) {
+ return E_FAIL;
+ }
+
+ return hr;
+}
+
+// Helper function for GetAllChildrenMainThread.
+static bool SetChildDataForTextLeaf(NEWEST_IA2_INTERFACE* acc,
+ AccChildData& data) {
+ const VARIANT kChildIdSelf = {VT_I4};
+ VARIANT varVal;
+
+ // 1. Check whether this is a text leaf.
+
+ // 1.1. A text leaf always has ROLE_SYSTEM_TEXT or ROLE_SYSTEM_WHITESPACE.
+ HRESULT hr = acc->get_accRole(kChildIdSelf, &varVal);
+ if (FAILED(hr)) {
+ return false;
+ }
+ if (varVal.vt != VT_I4) {
+ return false;
+ }
+ long role = varVal.lVal;
+ if (role != ROLE_SYSTEM_TEXT && role != ROLE_SYSTEM_WHITESPACE) {
+ return false;
+ }
+
+ // 1.2. A text leaf doesn't support IAccessibleText.
+ RefPtr<IAccessibleText> iaText;
+ hr = acc->QueryInterface(IID_IAccessibleText, getter_AddRefs(iaText));
+ if (SUCCEEDED(hr)) {
+ return false;
+ }
+
+ // 1.3. A text leaf doesn't have children.
+ long count;
+ hr = acc->get_accChildCount(&count);
+ if (FAILED(hr) || count != 0) {
+ return false;
+ }
+
+ // 2. Update |data| with the data for this text leaf.
+ // Because marshaling objects is more expensive than marshaling other data,
+ // we just marshal the data we need for text leaf children, rather than
+ // marshaling the full accessible object.
+
+ // |data| has already been zeroed, so we don't need to do anything if these
+ // calls fail.
+ acc->get_accName(kChildIdSelf, &data.mText);
+ data.mTextRole = role;
+ acc->get_uniqueID(&data.mTextId);
+ acc->get_accState(kChildIdSelf, &varVal);
+ data.mTextState = varVal.lVal;
+ acc->accLocation(&data.mTextLeft, &data.mTextTop, &data.mTextWidth,
+ &data.mTextHeight, kChildIdSelf);
+
+ return true;
+}
+
+void HandlerProvider::GetAllChildrenMainThread(AccChildData** aChildren,
+ ULONG* aNChildren, HRESULT* hr) {
+ MOZ_ASSERT(aChildren);
+ MOZ_ASSERT(aNChildren);
+ MOZ_ASSERT(NS_IsMainThread());
+
+ if (!mTargetUnk) {
+ *hr = CO_E_OBJNOTCONNECTED;
+ return;
+ }
+
+ RefPtr<NEWEST_IA2_INTERFACE> acc;
+ *hr = mTargetUnk.get()->QueryInterface(NEWEST_IA2_IID, getter_AddRefs(acc));
+ if (FAILED(*hr)) {
+ return;
+ }
+
+ long count;
+ *hr = acc->get_accChildCount(&count);
+ if (FAILED(*hr)) {
+ return;
+ }
+ MOZ_ASSERT(count >= 0);
+
+ if (count == 0) {
+ *aChildren = nullptr;
+ *aNChildren = 0;
+ return;
+ }
+
+ RefPtr<IEnumVARIANT> enumVar;
+ *hr = mTargetUnk.get()->QueryInterface(IID_IEnumVARIANT,
+ getter_AddRefs(enumVar));
+ if (FAILED(*hr)) {
+ return;
+ }
+
+ auto rawChildren = MakeUnique<VARIANT[]>(count);
+ *hr = enumVar->Next((ULONG)count, rawChildren.get(), aNChildren);
+ if (FAILED(*hr)) {
+ *aChildren = nullptr;
+ *aNChildren = 0;
+ return;
+ }
+
+ *aChildren = static_cast<AccChildData*>(
+ ::CoTaskMemAlloc(sizeof(AccChildData) * *aNChildren));
+ for (ULONG index = 0; index < *aNChildren; ++index) {
+ (*aChildren)[index] = {};
+ AccChildData& child = (*aChildren)[index];
+
+ MOZ_ASSERT(rawChildren[index].vt == VT_DISPATCH);
+ MOZ_ASSERT(rawChildren[index].pdispVal);
+ RefPtr<NEWEST_IA2_INTERFACE> childAcc;
+ *hr = rawChildren[index].pdispVal->QueryInterface(NEWEST_IA2_IID,
+ getter_AddRefs(childAcc));
+ rawChildren[index].pdispVal->Release();
+ MOZ_ASSERT(SUCCEEDED(*hr));
+ if (FAILED(*hr)) {
+ continue;
+ }
+
+ if (!SetChildDataForTextLeaf(childAcc, child)) {
+ // This isn't a text leaf. Marshal the accessible.
+ childAcc.forget(&child.mAccessible);
+ // We must wrap this accessible in an Interceptor.
+ ToWrappedObject(&child.mAccessible);
+ }
+ }
+
+ *hr = S_OK;
+}
+
+HRESULT
+HandlerProvider::get_AllChildren(AccChildData** aChildren, ULONG* aNChildren) {
+ MOZ_ASSERT(mscom::IsCurrentThreadMTA());
+
+ HRESULT hr;
+ if (!mscom::InvokeOnMainThread(
+ "HandlerProvider::GetAllChildrenMainThread", this,
+ &HandlerProvider::GetAllChildrenMainThread,
+ std::forward<AccChildData**>(aChildren),
+ std::forward<ULONG*>(aNChildren), std::forward<HRESULT*>(&hr))) {
+ return E_FAIL;
+ }
+
+ return hr;
+}
+
+} // namespace a11y
+} // namespace mozilla
diff --git a/accessible/ipc/win/HandlerProvider.h b/accessible/ipc/win/HandlerProvider.h
new file mode 100644
index 0000000000..bfaa58667d
--- /dev/null
+++ b/accessible/ipc/win/HandlerProvider.h
@@ -0,0 +1,145 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_HandlerProvider_h
+#define mozilla_a11y_HandlerProvider_h
+
+#include "mozilla/a11y/AccessibleHandler.h"
+#include "mozilla/a11y/HandlerDataCleanup.h"
+#include "mozilla/AlreadyAddRefed.h"
+#include "mozilla/Atomics.h"
+#include "mozilla/mscom/IHandlerProvider.h"
+#include "mozilla/mscom/Ptr.h"
+#include "mozilla/mscom/StructStream.h"
+#include "mozilla/Mutex.h"
+#include "mozilla/UniquePtr.h"
+#include "HandlerData.h"
+
+struct NEWEST_IA2_INTERFACE;
+
+namespace mozilla {
+
+namespace mscom {
+
+class StructToStream;
+
+} // namespace mscom
+
+namespace a11y {
+
+class HandlerProvider final : public IGeckoBackChannel,
+ public mscom::IHandlerProvider {
+ public:
+ HandlerProvider(REFIID aIid, mscom::InterceptorTargetPtr<IUnknown> aTarget);
+
+ // IUnknown
+ STDMETHODIMP QueryInterface(REFIID riid, void** ppv) override;
+ STDMETHODIMP_(ULONG) AddRef() override;
+ STDMETHODIMP_(ULONG) Release() override;
+
+ // IHandlerProvider
+ STDMETHODIMP GetHandler(NotNull<CLSID*> aHandlerClsid) override;
+ STDMETHODIMP GetHandlerPayloadSize(NotNull<mscom::IInterceptor*> aInterceptor,
+ NotNull<DWORD*> aOutPayloadSize) override;
+ STDMETHODIMP WriteHandlerPayload(NotNull<mscom::IInterceptor*> aInterceptor,
+ NotNull<IStream*> aStream) override;
+ STDMETHODIMP_(REFIID) MarshalAs(REFIID aIid) override;
+ STDMETHODIMP DisconnectHandlerRemotes() override;
+ STDMETHODIMP IsInterfaceMaybeSupported(REFIID aIid) override;
+ STDMETHODIMP_(REFIID)
+ GetEffectiveOutParamIid(REFIID aCallIid, ULONG aCallMethod) override;
+ STDMETHODIMP NewInstance(
+ REFIID aIid, mscom::InterceptorTargetPtr<IUnknown> aTarget,
+ NotNull<mscom::IHandlerProvider**> aOutNewPayload) override;
+
+ // IGeckoBackChannel
+ STDMETHODIMP put_HandlerControl(long aPid, IHandlerControl* aCtrl) override;
+ STDMETHODIMP Refresh(DynamicIA2Data* aOutData) override;
+ STDMETHODIMP get_AllTextInfo(BSTR* aText, IAccessibleHyperlink*** aHyperlinks,
+ long* aNHyperlinks, IA2TextSegment** aAttribRuns,
+ long* aNAttribRuns) override;
+ STDMETHODIMP get_RelationsInfo(IARelationData** aRelations,
+ long* aNRelations) override;
+ STDMETHODIMP get_AllChildren(AccChildData** aChildren,
+ ULONG* aNChildren) override;
+
+ private:
+ ~HandlerProvider() = default;
+
+ void SetHandlerControlOnMainThread(
+ DWORD aPid, mscom::ProxyUniquePtr<IHandlerControl> aCtrl);
+ void GetAndSerializePayload(const MutexAutoLock&,
+ NotNull<mscom::IInterceptor*> aInterceptor);
+ void BuildStaticIA2Data(NotNull<mscom::IInterceptor*> aInterceptor,
+ StaticIA2Data* aOutData);
+ /**
+ * Pass true for aMarshaledByCom if this struct is being directly marshaled as
+ * an out parameter of a COM method, currently only
+ * IGeckoBackChannel::Refresh.
+ * When aMarshaledByCom is false, this means the struct is being marshaled
+ * by RPC encoding functions. This means we must allocate memory differently,
+ * even though we're using this as part of a COM handler payload.
+ */
+ void BuildDynamicIA2Data(DynamicIA2Data* aOutIA2Data,
+ bool aMarshaledByCom = false);
+ void BuildInitialIA2Data(NotNull<mscom::IInterceptor*> aInterceptor,
+ StaticIA2Data* aOutStaticData,
+ DynamicIA2Data* aOutDynamicData);
+ bool IsTargetInterfaceCacheable();
+
+ /**
+ * Build the payload for later marshaling.
+ * This is intended to be used during a bulk fetch operation and must only be
+ * called from the main thread.
+ */
+ void PrebuildPayload(NotNull<mscom::IInterceptor*> aInterceptor);
+
+ // Replace a raw object from the main thread with a wrapped, intercepted
+ // object suitable for calling from the MTA.
+ // The reference to the original object is adopted; i.e. you should not
+ // separately release it.
+ // This is intended for objects returned from method calls on the main thread.
+ template <typename Interface>
+ HRESULT ToWrappedObject(Interface** aObj);
+ void GetAllTextInfoMainThread(BSTR* aText,
+ IAccessibleHyperlink*** aHyperlinks,
+ long* aNHyperlinks,
+ IA2TextSegment** aAttribRuns,
+ long* aNAttribRuns, HRESULT* result);
+ void GetRelationsInfoMainThread(IARelationData** aRelations,
+ long* aNRelations, HRESULT* result);
+ void GetAllChildrenMainThread(AccChildData** aChildren, ULONG* aNChildren,
+ HRESULT* result);
+
+ Atomic<uint32_t> mRefCnt;
+ Mutex mMutex; // Protects mSerializer
+ const IID mTargetUnkIid;
+ mscom::InterceptorTargetPtr<IUnknown>
+ mTargetUnk; // Constant, main thread only
+ UniquePtr<mscom::StructToStream> mSerializer;
+ RefPtr<IUnknown> mFastMarshalUnk;
+
+ struct IA2PayloadDeleter {
+ void operator()(IA2Payload* aPayload) {
+ // When CoMarshalInterface writes interfaces out to a stream, it AddRefs.
+ // Therefore, we must release our references after this.
+ ReleaseStaticIA2DataInterfaces(aPayload->mStaticData);
+ CleanupDynamicIA2Data(aPayload->mDynamicData);
+ delete aPayload;
+ }
+ };
+ using IA2PayloadPtr = UniquePtr<IA2Payload, IA2PayloadDeleter>;
+
+ // Used when the payload is built prior to marshaling the object by a bulk
+ // fetch operation. See prebuildPayload().
+ IA2PayloadPtr mPayload;
+ Mutex mPayloadMutex; // Protects mPayload
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_HandlerProvider_h
diff --git a/accessible/ipc/win/IAccessible32.manifest b/accessible/ipc/win/IAccessible32.manifest
new file mode 100644
index 0000000000..e80ae3e9d4
--- /dev/null
+++ b/accessible/ipc/win/IAccessible32.manifest
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <assemblyIdentity type="win32" name="Mozilla.Firefox.xul" version="1.0.0.0" />
+ <file name="xul.dll" />
+ <comInterfaceExternalProxyStub
+ iid="{618736E0-3C3D-11CF-810C-00AA00389B71}"
+ proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
+ name="IAccessible"
+ tlbid="{1EA4DBF0-3C3B-11CF-810C-00AA00389B71}"
+ />
+</assembly>
diff --git a/accessible/ipc/win/IAccessible64.manifest b/accessible/ipc/win/IAccessible64.manifest
new file mode 100644
index 0000000000..f1672e4844
--- /dev/null
+++ b/accessible/ipc/win/IAccessible64.manifest
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <assemblyIdentity type="win32" name="Mozilla.Firefox.xul" version="1.0.0.0" />
+ <file name="xul.dll" />
+ <comInterfaceExternalProxyStub
+ iid="{618736E0-3C3D-11CF-810C-00AA00389B71}"
+ proxyStubClsid32="{03022430-ABC4-11D0-BDE2-00AA001A1953}"
+ name="IAccessible"
+ />
+</assembly>
diff --git a/accessible/ipc/win/PDocAccessible.ipdl b/accessible/ipc/win/PDocAccessible.ipdl
new file mode 100644
index 0000000000..82fecdc54a
--- /dev/null
+++ b/accessible/ipc/win/PDocAccessible.ipdl
@@ -0,0 +1,112 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+include protocol PFileDescriptorSet;
+include protocol PBrowser;
+
+include "mozilla/GfxMessageUtils.h";
+
+using mozilla::a11y::role from "mozilla/a11y/IPCTypes.h";
+using mozilla::a11y::IAccessibleHolder from "mozilla/a11y/IPCTypes.h";
+using mozilla::a11y::IDispatchHolder from "mozilla/a11y/IPCTypes.h";
+using mozilla::WindowsHandle from "mozilla/ipc/IPCTypes.h";
+using mozilla::LayoutDeviceIntRect from "Units.h";
+
+namespace mozilla {
+namespace a11y {
+
+struct AccessibleData
+{
+ uint64_t ID;
+ int32_t MsaaID;
+ role Role;
+ uint32_t ChildrenCount;
+ uint32_t Interfaces;
+};
+
+struct ShowEventData
+{
+ uint64_t ID;
+ uint32_t Idx;
+ AccessibleData[] NewTree;
+ bool EventSuppressed;
+};
+
+struct Attribute
+{
+ nsCString Name;
+ nsString Value;
+};
+
+sync protocol PDocAccessible
+{
+ manager PBrowser;
+
+parent:
+ async Shutdown();
+
+ /*
+ * Notify the parent process the document in the child process is firing an
+ * event.
+ */
+ async Event(uint64_t aID, uint32_t type);
+ async ShowEvent(ShowEventData data, bool aFromUser);
+ async HideEvent(uint64_t aRootID, bool aFromUser);
+ async StateChangeEvent(uint64_t aID, uint64_t aState, bool aEnabled);
+ async CaretMoveEvent(uint64_t aID, LayoutDeviceIntRect aCaretRect,
+ int32_t aOffset, bool aIsSelectionCollapsed);
+ async TextChangeEvent(uint64_t aID, nsString aStr, int32_t aStart, uint32_t aLen,
+ bool aIsInsert, bool aFromUser);
+ sync SyncTextChangeEvent(uint64_t aID, nsString aStr, int32_t aStart,
+ uint32_t aLen, bool aIsInsert, bool aFromUser);
+ async SelectionEvent(uint64_t aID, uint64_t aWidgetID, uint32_t aType);
+ async RoleChangedEvent(role aRole);
+ async FocusEvent(uint64_t aID, LayoutDeviceIntRect aCaretRect);
+ async VirtualCursorChangeEvent(uint64_t aID,
+ uint64_t aOldPosition,
+ int32_t aOldStartOffset, int32_t aOldEndOffset,
+ uint64_t aPosition,
+ int32_t aStartOffset, int32_t aEndOffset,
+ int16_t aReason, int16_t aBoundaryType,
+ bool aFromUservcEvent);
+ async ScrollingEvent(uint64_t aID, uint64_t aType,
+ uint32_t aScrollX, uint32_t aScrollY,
+ uint32_t aMaxScrollX, uint32_t aMaxScrollY);
+
+ /*
+ * Tell the parent document to bind the existing document as a new child
+ * document.
+ */
+ async BindChildDoc(PDocAccessible aChildDoc, uint64_t aID);
+
+ sync GetWindowedPluginIAccessible(WindowsHandle aHwnd)
+ returns (IAccessibleHolder aPluginCOMProxy);
+
+child:
+ /**
+ * We use IDispatchHolder instead of IAccessibleHolder for the following two
+ * methods because of sandboxing. IAccessible::get_accParent returns the parent
+ * as an IDispatch. COM is not smart enough to understand that IAccessible is
+ * derived from IDispatch, so during marshaling it attempts to QueryInterface
+ * on the parent's proxy for IDispatch. This will fail with E_ACCESSDENIED
+ * thanks to the sandbox. We can avoid this entirely by just giving content
+ * the correct interface to begin with: IDispatch.
+ */
+ async ParentCOMProxy(IDispatchHolder aParentCOMProxy);
+ async EmulatedWindow(WindowsHandle aEmulatedWindowHandle,
+ IDispatchHolder aEmulatedWindowCOMProxy);
+ async TopLevelDocCOMProxy(IAccessibleHolder aCOMProxy);
+ /*
+ * Called as a result of focus shifting from chrome to content
+ * elements through keyboard navigation.
+ */
+ async RestoreFocus();
+
+ async __delete__();
+};
+
+}
+}
diff --git a/accessible/ipc/win/PlatformChild.cpp b/accessible/ipc/win/PlatformChild.cpp
new file mode 100644
index 0000000000..5c4c190e5a
--- /dev/null
+++ b/accessible/ipc/win/PlatformChild.cpp
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/a11y/AccessibleHandler.h"
+#include "mozilla/a11y/Compatibility.h"
+#include "mozilla/a11y/PlatformChild.h"
+#include "mozilla/mscom/EnsureMTA.h"
+#include "mozilla/mscom/InterceptorLog.h"
+
+#include "Accessible2.h"
+#include "Accessible2_2.h"
+#include "AccessibleHypertext2.h"
+#include "AccessibleTable2.h"
+#include "AccessibleTableCell.h"
+
+#include "AccessibleDocument_i.c"
+#include "AccessibleHypertext2_i.c"
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * Unfortunately the COM interceptor does not intrinsically handle array
+ * outparams. Instead we manually define the relevant metadata here, and
+ * register it in a call to mozilla::mscom::RegisterArrayData.
+ * @see mozilla::mscom::ArrayData
+ */
+static const mozilla::mscom::ArrayData sPlatformChildArrayData[] = {
+ {IID_IEnumVARIANT, 3, 1, VT_DISPATCH, IID_IDispatch, 2},
+ {IID_IAccessible2, 30, 1, VT_UNKNOWN | VT_BYREF, IID_IAccessibleRelation,
+ 2},
+ {IID_IAccessibleRelation, 7, 1, VT_UNKNOWN | VT_BYREF, NEWEST_IA2_IID, 2},
+ {IID_IAccessible2_2, 48, 2, VT_UNKNOWN | VT_BYREF, NEWEST_IA2_IID, 3,
+ mozilla::mscom::ArrayData::Flag::eAllocatedByServer},
+ {IID_IAccessibleTableCell, 4, 0, VT_UNKNOWN | VT_BYREF, NEWEST_IA2_IID, 1,
+ mozilla::mscom::ArrayData::Flag::eAllocatedByServer},
+ {IID_IAccessibleTableCell, 7, 0, VT_UNKNOWN | VT_BYREF, NEWEST_IA2_IID, 1,
+ mozilla::mscom::ArrayData::Flag::eAllocatedByServer},
+ {IID_IAccessibleHypertext2, 25, 0, VT_UNKNOWN | VT_BYREF,
+ IID_IAccessibleHyperlink, 1,
+ mozilla::mscom::ArrayData::Flag::eAllocatedByServer},
+ {IID_IAccessibleTable2, 12, 0, VT_UNKNOWN | VT_BYREF, NEWEST_IA2_IID, 1,
+ mozilla::mscom::ArrayData::Flag::eAllocatedByServer}};
+
+// Type libraries are thread-neutral, so we can register those from any
+// apartment. OTOH, proxies must be registered from within the apartment where
+// we intend to instantiate them. Therefore RegisterProxy() must be called
+// via EnsureMTA.
+PlatformChild::PlatformChild()
+ : mIA2Proxy(mozilla::mscom::RegisterProxy(L"ia2marshal.dll")),
+ mAccTypelib(mozilla::mscom::RegisterTypelib(
+ L"oleacc.dll",
+ mozilla::mscom::RegistrationFlags::eUseSystemDirectory)),
+ mMiscTypelib(mozilla::mscom::RegisterTypelib(L"Accessible.tlb")),
+ mSdnTypelib(mozilla::mscom::RegisterTypelib(L"AccessibleMarshal.dll")) {
+ WORD actCtxResourceId = Compatibility::GetActCtxResourceId();
+
+ mozilla::mscom::MTADeletePtr<mozilla::mscom::ActivationContextRegion>
+ tmpActCtxMTA;
+ mozilla::mscom::EnsureMTA([actCtxResourceId, &tmpActCtxMTA]() -> void {
+ tmpActCtxMTA.reset(
+ new mozilla::mscom::ActivationContextRegion(actCtxResourceId));
+ });
+ mActCtxMTA = std::move(tmpActCtxMTA);
+
+ mozilla::mscom::InterceptorLog::Init();
+ mozilla::mscom::RegisterArrayData(sPlatformChildArrayData);
+
+ UniquePtr<mozilla::mscom::RegisteredProxy> customProxy;
+ mozilla::mscom::EnsureMTA([&customProxy]() -> void {
+ customProxy = mozilla::mscom::RegisterProxy();
+ });
+ mCustomProxy = std::move(customProxy);
+
+ // IA2 needs to be registered in both the main thread's STA as well as the MTA
+ UniquePtr<mozilla::mscom::RegisteredProxy> ia2ProxyMTA;
+ mozilla::mscom::EnsureMTA([&ia2ProxyMTA]() -> void {
+ ia2ProxyMTA = mozilla::mscom::RegisterProxy(L"ia2marshal.dll");
+ });
+ mIA2ProxyMTA = std::move(ia2ProxyMTA);
+}
+
+} // namespace a11y
+} // namespace mozilla
diff --git a/accessible/ipc/win/PlatformChild.h b/accessible/ipc/win/PlatformChild.h
new file mode 100644
index 0000000000..a175d6f453
--- /dev/null
+++ b/accessible/ipc/win/PlatformChild.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_PlatformChild_h
+#define mozilla_a11y_PlatformChild_h
+
+#include "mozilla/mscom/ActivationContext.h"
+#include "mozilla/mscom/Ptr.h"
+#include "mozilla/mscom/Registration.h"
+
+namespace mozilla {
+namespace a11y {
+
+class PlatformChild {
+ public:
+ PlatformChild();
+
+ PlatformChild(PlatformChild&) = delete;
+ PlatformChild(PlatformChild&&) = delete;
+ PlatformChild& operator=(PlatformChild&) = delete;
+ PlatformChild& operator=(PlatformChild&&) = delete;
+
+ private:
+ mscom::MTADeletePtr<mozilla::mscom::ActivationContextRegion> mActCtxMTA;
+ UniquePtr<mozilla::mscom::RegisteredProxy> mCustomProxy;
+ UniquePtr<mozilla::mscom::RegisteredProxy> mIA2Proxy;
+ UniquePtr<mozilla::mscom::RegisteredProxy> mIA2ProxyMTA;
+ UniquePtr<mozilla::mscom::RegisteredProxy> mAccTypelib;
+ UniquePtr<mozilla::mscom::RegisteredProxy> mMiscTypelib;
+ UniquePtr<mozilla::mscom::RegisteredProxy> mSdnTypelib;
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_PlatformChild_h
diff --git a/accessible/ipc/win/ProxyAccessible.cpp b/accessible/ipc/win/ProxyAccessible.cpp
new file mode 100644
index 0000000000..bcf388e603
--- /dev/null
+++ b/accessible/ipc/win/ProxyAccessible.cpp
@@ -0,0 +1,816 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "Accessible2.h"
+#include "ProxyAccessible.h"
+#include "ia2AccessibleRelation.h"
+#include "ia2AccessibleValue.h"
+#include "IGeckoCustom.h"
+#include "mozilla/a11y/DocAccessibleParent.h"
+#include "DocAccessible.h"
+#include "mozilla/a11y/DocManager.h"
+#include "mozilla/dom/Element.h"
+#include "mozilla/dom/BrowserParent.h"
+#include "mozilla/Unused.h"
+#include "mozilla/a11y/Platform.h"
+#include "RelationType.h"
+#include "mozilla/a11y/Role.h"
+
+#include <comutil.h>
+
+static const VARIANT kChildIdSelf = {{{VT_I4}}};
+
+namespace mozilla {
+namespace a11y {
+
+bool ProxyAccessible::GetCOMInterface(void** aOutAccessible) const {
+ if (!aOutAccessible) {
+ return false;
+ }
+
+ if (!mCOMProxy && mSafeToRecurse) {
+ // See if we can lazily obtain a COM proxy
+ AccessibleWrap* wrap = WrapperFor(this);
+ bool isDefunct = false;
+ ProxyAccessible* thisPtr = const_cast<ProxyAccessible*>(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 = wrap->GetExistingID();
+ MOZ_DIAGNOSTIC_ASSERT(realId.ulVal != CHILDID_SELF);
+ thisPtr->mCOMProxy = wrap->GetIAccessibleFor(realId, &isDefunct);
+ }
+
+ RefPtr<IAccessible> addRefed = mCOMProxy;
+ addRefed.forget(aOutAccessible);
+ return !!mCOMProxy;
+}
+
+/**
+ * Specializations of this template map an IAccessible type to its IID
+ */
+template <typename Interface>
+struct InterfaceIID {};
+
+template <>
+struct InterfaceIID<IAccessibleValue> {
+ static REFIID Value() { return IID_IAccessibleValue; }
+};
+
+template <>
+struct InterfaceIID<IAccessibleText> {
+ static REFIID Value() { return IID_IAccessibleText; }
+};
+
+template <>
+struct InterfaceIID<IAccessibleHyperlink> {
+ static REFIID Value() { return IID_IAccessibleHyperlink; }
+};
+
+template <>
+struct InterfaceIID<IGeckoCustom> {
+ static REFIID Value() { return IID_IGeckoCustom; }
+};
+
+template <>
+struct InterfaceIID<IAccessible2_2> {
+ static REFIID Value() { return IID_IAccessible2_2; }
+};
+
+/**
+ * Get the COM proxy for this proxy accessible and QueryInterface it with the
+ * correct IID
+ */
+template <typename Interface>
+static already_AddRefed<Interface> QueryInterface(
+ const ProxyAccessible* aProxy) {
+ RefPtr<IAccessible> acc;
+ if (!aProxy->GetCOMInterface((void**)getter_AddRefs(acc))) {
+ return nullptr;
+ }
+
+ RefPtr<Interface> acc2;
+ if (FAILED(acc->QueryInterface(InterfaceIID<Interface>::Value(),
+ (void**)getter_AddRefs(acc2)))) {
+ return nullptr;
+ }
+
+ return acc2.forget();
+}
+
+static ProxyAccessible* GetProxyFor(DocAccessibleParent* aDoc,
+ IUnknown* aCOMProxy) {
+ RefPtr<IGeckoCustom> custom;
+ if (FAILED(aCOMProxy->QueryInterface(IID_IGeckoCustom,
+ (void**)getter_AddRefs(custom)))) {
+ return nullptr;
+ }
+
+ uint64_t id;
+ if (FAILED(custom->get_ID(&id))) {
+ return nullptr;
+ }
+
+ return aDoc->GetAccessible(id);
+}
+
+uint32_t ProxyAccessible::Name(nsString& aName) const {
+ /* The return values here exist only to match behvaiour required
+ * by the header declaration of this function. On Mac, we'd like
+ * to return the associated ENameValueFlag, but we don't have
+ * access to that here, so we return a dummy eNameOK value instead.
+ */
+ aName.Truncate();
+ RefPtr<IAccessible> acc;
+ if (!GetCOMInterface((void**)getter_AddRefs(acc))) {
+ return eNameOK;
+ }
+
+ BSTR result;
+ HRESULT hr = acc->get_accName(kChildIdSelf, &result);
+ _bstr_t resultWrap(result, false);
+ if (FAILED(hr)) {
+ return eNameOK;
+ }
+ aName = (wchar_t*)resultWrap;
+ return eNameOK;
+}
+
+void ProxyAccessible::Value(nsString& aValue) const {
+ aValue.Truncate();
+ RefPtr<IAccessible> acc;
+ if (!GetCOMInterface((void**)getter_AddRefs(acc))) {
+ return;
+ }
+
+ BSTR result;
+ HRESULT hr = acc->get_accValue(kChildIdSelf, &result);
+ _bstr_t resultWrap(result, false);
+ if (FAILED(hr)) {
+ return;
+ }
+ aValue = (wchar_t*)resultWrap;
+}
+
+double ProxyAccessible::Step() {
+ RefPtr<IGeckoCustom> custom = QueryInterface<IGeckoCustom>(this);
+ if (!custom) {
+ return 0;
+ }
+
+ double increment;
+ HRESULT hr = custom->get_minimumIncrement(&increment);
+ if (FAILED(hr)) {
+ return 0;
+ }
+
+ return increment;
+}
+
+void ProxyAccessible::Description(nsString& aDesc) const {
+ aDesc.Truncate();
+ RefPtr<IAccessible> acc;
+ if (!GetCOMInterface((void**)getter_AddRefs(acc))) {
+ return;
+ }
+
+ BSTR result;
+ HRESULT hr = acc->get_accDescription(kChildIdSelf, &result);
+ _bstr_t resultWrap(result, false);
+ if (FAILED(hr)) {
+ return;
+ }
+ aDesc = (wchar_t*)resultWrap;
+}
+
+uint64_t ProxyAccessible::State() const {
+ RefPtr<IGeckoCustom> custom = QueryInterface<IGeckoCustom>(this);
+ if (!custom) {
+ return 0;
+ }
+
+ uint64_t state;
+ HRESULT hr = custom->get_mozState(&state);
+ if (FAILED(hr)) {
+ return 0;
+ }
+ return state;
+}
+
+nsIntRect ProxyAccessible::Bounds() {
+ nsIntRect rect;
+
+ RefPtr<IAccessible> acc;
+ if (!GetCOMInterface((void**)getter_AddRefs(acc))) {
+ return rect;
+ }
+
+ long left;
+ long top;
+ long width;
+ long height;
+ HRESULT hr = acc->accLocation(&left, &top, &width, &height, kChildIdSelf);
+ if (FAILED(hr)) {
+ return rect;
+ }
+ rect.SetRect(left, top, width, height);
+ return rect;
+}
+
+nsIntRect ProxyAccessible::BoundsInCSSPixels() {
+ RefPtr<IGeckoCustom> custom = QueryInterface<IGeckoCustom>(this);
+ if (!custom) {
+ return nsIntRect();
+ }
+
+ nsIntRect rect;
+ Unused << custom->get_boundsInCSSPixels(&rect.x, &rect.y, &rect.width,
+ &rect.height);
+ return rect;
+}
+
+void ProxyAccessible::Language(nsString& aLocale) {
+ aLocale.Truncate();
+
+ RefPtr<IAccessible> acc;
+ if (!GetCOMInterface((void**)getter_AddRefs(acc))) {
+ return;
+ }
+
+ RefPtr<IAccessible2> acc2;
+ if (FAILED(acc->QueryInterface(IID_IAccessible2,
+ (void**)getter_AddRefs(acc2)))) {
+ return;
+ }
+
+ IA2Locale locale;
+ HRESULT hr = acc2->get_locale(&locale);
+
+ _bstr_t langWrap(locale.language, false);
+ _bstr_t countryWrap(locale.country, false);
+ _bstr_t variantWrap(locale.variant, false);
+
+ if (FAILED(hr)) {
+ return;
+ }
+
+ // The remaining code should essentially be the inverse of the
+ // ia2Accessible::get_locale conversion to IA2Locale.
+
+ if (!!variantWrap) {
+ aLocale = (wchar_t*)variantWrap;
+ return;
+ }
+
+ if (!!langWrap) {
+ aLocale = (wchar_t*)langWrap;
+ if (!!countryWrap) {
+ aLocale += L"-";
+ aLocale += (wchar_t*)countryWrap;
+ }
+ }
+}
+
+static bool IsEscapedChar(const wchar_t c) {
+ return c == L'\\' || c == L':' || c == ',' || c == '=' || c == ';';
+}
+
+static bool ConvertBSTRAttributesToArray(const nsAString& aStr,
+ nsTArray<Attribute>* aAttrs) {
+ if (!aAttrs) {
+ return false;
+ }
+
+ enum { eName = 0, eValue = 1, eNumStates } state;
+ nsAutoString tokens[eNumStates];
+ auto itr = aStr.BeginReading(), end = aStr.EndReading();
+
+ state = eName;
+ while (itr != end) {
+ switch (*itr) {
+ case L'\\':
+ // Skip the backslash so that we're looking at the escaped char
+ ++itr;
+ if (itr == end || !IsEscapedChar(*itr)) {
+ // Invalid state
+ return false;
+ }
+ break;
+ case L':':
+ if (state != eName) {
+ // Bad, should be looking at name
+ return false;
+ }
+ state = eValue;
+ ++itr;
+ continue;
+ case L';':
+ if (state != eValue) {
+ // Bad, should be looking at value
+ return false;
+ }
+ state = eName;
+ aAttrs->AppendElement(
+ Attribute(NS_ConvertUTF16toUTF8(tokens[eName]), tokens[eValue]));
+ tokens[eName].Truncate();
+ tokens[eValue].Truncate();
+ ++itr;
+ continue;
+ default:
+ break;
+ }
+ tokens[state] += *itr;
+ ++itr;
+ }
+ return true;
+}
+
+void ProxyAccessible::Attributes(nsTArray<Attribute>* aAttrs) const {
+ aAttrs->Clear();
+
+ RefPtr<IAccessible> acc;
+ if (!GetCOMInterface((void**)getter_AddRefs(acc))) {
+ return;
+ }
+
+ RefPtr<IAccessible2> acc2;
+ if (FAILED(acc->QueryInterface(IID_IAccessible2,
+ (void**)getter_AddRefs(acc2)))) {
+ return;
+ }
+
+ BSTR attrs;
+ HRESULT hr = acc2->get_attributes(&attrs);
+ _bstr_t attrsWrap(attrs, false);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ ConvertBSTRAttributesToArray(
+ nsDependentString((wchar_t*)attrs, attrsWrap.length()), aAttrs);
+}
+
+nsTArray<ProxyAccessible*> ProxyAccessible::RelationByType(
+ RelationType aType) const {
+ RefPtr<IAccessible2_2> acc = QueryInterface<IAccessible2_2>(this);
+ if (!acc) {
+ return nsTArray<ProxyAccessible*>();
+ }
+
+ _bstr_t relationType;
+ for (uint32_t idx = 0; idx < ArrayLength(sRelationTypePairs); idx++) {
+ if (aType == sRelationTypePairs[idx].first) {
+ relationType = sRelationTypePairs[idx].second;
+ break;
+ }
+ }
+
+ if (!relationType) {
+ return nsTArray<ProxyAccessible*>();
+ }
+
+ IUnknown** targets;
+ long nTargets = 0;
+ HRESULT hr =
+ acc->get_relationTargetsOfType(relationType, 0, &targets, &nTargets);
+ if (FAILED(hr)) {
+ return nsTArray<ProxyAccessible*>();
+ }
+
+ nsTArray<ProxyAccessible*> proxies;
+ for (long idx = 0; idx < nTargets; idx++) {
+ IUnknown* target = targets[idx];
+ proxies.AppendElement(GetProxyFor(Document(), target));
+ target->Release();
+ }
+ CoTaskMemFree(targets);
+
+ return proxies;
+}
+
+double ProxyAccessible::CurValue() {
+ RefPtr<IAccessibleValue> acc = QueryInterface<IAccessibleValue>(this);
+ if (!acc) {
+ return UnspecifiedNaN<double>();
+ }
+
+ VARIANT currentValue;
+ HRESULT hr = acc->get_currentValue(&currentValue);
+ if (FAILED(hr) || currentValue.vt != VT_R8) {
+ return UnspecifiedNaN<double>();
+ }
+
+ return currentValue.dblVal;
+}
+
+bool ProxyAccessible::SetCurValue(double aValue) {
+ RefPtr<IAccessibleValue> acc = QueryInterface<IAccessibleValue>(this);
+ if (!acc) {
+ return false;
+ }
+
+ VARIANT currentValue;
+ VariantInit(&currentValue);
+ currentValue.vt = VT_R8;
+ currentValue.dblVal = aValue;
+ HRESULT hr = acc->setCurrentValue(currentValue);
+ return SUCCEEDED(hr);
+}
+
+double ProxyAccessible::MinValue() {
+ RefPtr<IAccessibleValue> acc = QueryInterface<IAccessibleValue>(this);
+ if (!acc) {
+ return UnspecifiedNaN<double>();
+ }
+
+ VARIANT minimumValue;
+ HRESULT hr = acc->get_minimumValue(&minimumValue);
+ if (FAILED(hr) || minimumValue.vt != VT_R8) {
+ return UnspecifiedNaN<double>();
+ }
+
+ return minimumValue.dblVal;
+}
+
+double ProxyAccessible::MaxValue() {
+ RefPtr<IAccessibleValue> acc = QueryInterface<IAccessibleValue>(this);
+ if (!acc) {
+ return UnspecifiedNaN<double>();
+ }
+
+ VARIANT maximumValue;
+ HRESULT hr = acc->get_maximumValue(&maximumValue);
+ if (FAILED(hr) || maximumValue.vt != VT_R8) {
+ return UnspecifiedNaN<double>();
+ }
+
+ return maximumValue.dblVal;
+}
+
+static IA2TextBoundaryType GetIA2TextBoundary(
+ AccessibleTextBoundary aGeckoBoundaryType) {
+ switch (aGeckoBoundaryType) {
+ case nsIAccessibleText::BOUNDARY_CHAR:
+ return IA2_TEXT_BOUNDARY_CHAR;
+ case nsIAccessibleText::BOUNDARY_WORD_START:
+ return IA2_TEXT_BOUNDARY_WORD;
+ case nsIAccessibleText::BOUNDARY_LINE_START:
+ return IA2_TEXT_BOUNDARY_LINE;
+ case nsIAccessibleText::BOUNDARY_PARAGRAPH:
+ return IA2_TEXT_BOUNDARY_PARAGRAPH;
+ default:
+ MOZ_CRASH();
+ }
+}
+
+int32_t ProxyAccessible::OffsetAtPoint(int32_t aX, int32_t aY,
+ uint32_t aCoordinateType) {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return -1;
+ }
+
+ IA2CoordinateType coordType;
+ if (aCoordinateType ==
+ nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE) {
+ coordType = IA2_COORDTYPE_SCREEN_RELATIVE;
+ } else if (aCoordinateType ==
+ nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE) {
+ coordType = IA2_COORDTYPE_PARENT_RELATIVE;
+ } else {
+ MOZ_CRASH("unsupported coord type");
+ }
+
+ long offset;
+ HRESULT hr = acc->get_offsetAtPoint(
+ static_cast<long>(aX), static_cast<long>(aY), coordType, &offset);
+ if (FAILED(hr)) {
+ return -1;
+ }
+
+ return static_cast<int32_t>(offset);
+}
+
+bool ProxyAccessible::TextSubstring(int32_t aStartOffset, int32_t aEndOffset,
+ nsString& aText) const {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return false;
+ }
+
+ BSTR result;
+ HRESULT hr = acc->get_text(static_cast<long>(aStartOffset),
+ static_cast<long>(aEndOffset), &result);
+ if (FAILED(hr)) {
+ return false;
+ }
+
+ _bstr_t resultWrap(result, false);
+ aText = (wchar_t*)result;
+
+ return true;
+}
+
+void ProxyAccessible::GetTextBeforeOffset(int32_t aOffset,
+ AccessibleTextBoundary aBoundaryType,
+ nsString& aText,
+ int32_t* aStartOffset,
+ int32_t* aEndOffset) {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return;
+ }
+
+ BSTR result;
+ long start, end;
+ HRESULT hr = acc->get_textBeforeOffset(
+ aOffset, GetIA2TextBoundary(aBoundaryType), &start, &end, &result);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ _bstr_t resultWrap(result, false);
+ *aStartOffset = start;
+ *aEndOffset = end;
+ aText = (wchar_t*)result;
+}
+
+void ProxyAccessible::GetTextAfterOffset(int32_t aOffset,
+ AccessibleTextBoundary aBoundaryType,
+ nsString& aText, int32_t* aStartOffset,
+ int32_t* aEndOffset) {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return;
+ }
+
+ BSTR result;
+ long start, end;
+ HRESULT hr = acc->get_textAfterOffset(
+ aOffset, GetIA2TextBoundary(aBoundaryType), &start, &end, &result);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ _bstr_t resultWrap(result, false);
+ aText = (wchar_t*)result;
+ *aStartOffset = start;
+ *aEndOffset = end;
+}
+
+void ProxyAccessible::GetTextAtOffset(int32_t aOffset,
+ AccessibleTextBoundary aBoundaryType,
+ nsString& aText, int32_t* aStartOffset,
+ int32_t* aEndOffset) {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return;
+ }
+
+ BSTR result;
+ long start, end;
+ HRESULT hr = acc->get_textAtOffset(aOffset, GetIA2TextBoundary(aBoundaryType),
+ &start, &end, &result);
+ if (FAILED(hr)) {
+ return;
+ }
+
+ _bstr_t resultWrap(result, false);
+ aText = (wchar_t*)result;
+ *aStartOffset = start;
+ *aEndOffset = end;
+}
+
+bool ProxyAccessible::AddToSelection(int32_t aStartOffset, int32_t aEndOffset) {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return false;
+ }
+
+ return SUCCEEDED(acc->addSelection(static_cast<long>(aStartOffset),
+ static_cast<long>(aEndOffset)));
+}
+
+bool ProxyAccessible::RemoveFromSelection(int32_t aSelectionNum) {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return false;
+ }
+
+ return SUCCEEDED(acc->removeSelection(static_cast<long>(aSelectionNum)));
+}
+
+int32_t ProxyAccessible::CaretOffset() {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return -1;
+ }
+
+ long offset;
+ HRESULT hr = acc->get_caretOffset(&offset);
+ if (FAILED(hr)) {
+ return -1;
+ }
+
+ return static_cast<int32_t>(offset);
+}
+
+void ProxyAccessible::SetCaretOffset(int32_t aOffset) {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return;
+ }
+
+ acc->setCaretOffset(static_cast<long>(aOffset));
+}
+
+/**
+ * aScrollType should be one of the nsIAccessiblescrollType constants.
+ */
+void ProxyAccessible::ScrollSubstringTo(int32_t aStartOffset,
+ int32_t aEndOffset,
+ uint32_t aScrollType) {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return;
+ }
+
+ acc->scrollSubstringTo(static_cast<long>(aStartOffset),
+ static_cast<long>(aEndOffset),
+ static_cast<IA2ScrollType>(aScrollType));
+}
+
+/**
+ * aCoordinateType is one of the nsIAccessibleCoordinateType constants.
+ */
+void ProxyAccessible::ScrollSubstringToPoint(int32_t aStartOffset,
+ int32_t aEndOffset,
+ uint32_t aCoordinateType,
+ int32_t aX, int32_t aY) {
+ RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
+ if (!acc) {
+ return;
+ }
+
+ IA2CoordinateType coordType;
+ if (aCoordinateType ==
+ nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE) {
+ coordType = IA2_COORDTYPE_SCREEN_RELATIVE;
+ } else if (aCoordinateType ==
+ nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE) {
+ coordType = IA2_COORDTYPE_PARENT_RELATIVE;
+ } else {
+ MOZ_CRASH("unsupported coord type");
+ }
+
+ acc->scrollSubstringToPoint(static_cast<long>(aStartOffset),
+ static_cast<long>(aEndOffset), coordType,
+ static_cast<long>(aX), static_cast<long>(aY));
+}
+
+uint32_t ProxyAccessible::StartOffset(bool* aOk) {
+ RefPtr<IAccessibleHyperlink> acc = QueryInterface<IAccessibleHyperlink>(this);
+ if (!acc) {
+ *aOk = false;
+ return 0;
+ }
+
+ long startOffset;
+ *aOk = SUCCEEDED(acc->get_startIndex(&startOffset));
+ return static_cast<uint32_t>(startOffset);
+}
+
+uint32_t ProxyAccessible::EndOffset(bool* aOk) {
+ RefPtr<IAccessibleHyperlink> acc = QueryInterface<IAccessibleHyperlink>(this);
+ if (!acc) {
+ *aOk = false;
+ return 0;
+ }
+
+ long endOffset;
+ *aOk = SUCCEEDED(acc->get_endIndex(&endOffset));
+ return static_cast<uint32_t>(endOffset);
+}
+
+bool ProxyAccessible::IsLinkValid() {
+ RefPtr<IAccessibleHyperlink> acc = QueryInterface<IAccessibleHyperlink>(this);
+ if (!acc) {
+ return false;
+ }
+
+ boolean valid;
+ if (FAILED(acc->get_valid(&valid))) {
+ return false;
+ }
+
+ return valid;
+}
+
+uint32_t ProxyAccessible::AnchorCount(bool* aOk) {
+ *aOk = false;
+ RefPtr<IGeckoCustom> custom = QueryInterface<IGeckoCustom>(this);
+ if (!custom) {
+ return 0;
+ }
+
+ long count;
+ if (FAILED(custom->get_anchorCount(&count))) {
+ return 0;
+ }
+
+ *aOk = true;
+ return count;
+}
+
+ProxyAccessible* ProxyAccessible::AnchorAt(uint32_t aIdx) {
+ RefPtr<IAccessibleHyperlink> link =
+ QueryInterface<IAccessibleHyperlink>(this);
+ if (!link) {
+ return nullptr;
+ }
+
+ VARIANT anchor;
+ if (FAILED(link->get_anchor(aIdx, &anchor))) {
+ return nullptr;
+ }
+
+ MOZ_ASSERT(anchor.vt == VT_UNKNOWN);
+ ProxyAccessible* proxyAnchor = GetProxyFor(Document(), anchor.punkVal);
+ anchor.punkVal->Release();
+ return proxyAnchor;
+}
+
+void ProxyAccessible::DOMNodeID(nsString& aID) {
+ aID.Truncate();
+ RefPtr<IGeckoCustom> custom = QueryInterface<IGeckoCustom>(this);
+ if (!custom) {
+ return;
+ }
+
+ BSTR result;
+ HRESULT hr = custom->get_DOMNodeID(&result);
+ _bstr_t resultWrap(result, false);
+ if (FAILED(hr)) {
+ return;
+ }
+ aID = (wchar_t*)resultWrap;
+}
+
+void ProxyAccessible::TakeFocus() {
+ RefPtr<IAccessible> acc;
+ if (!GetCOMInterface((void**)getter_AddRefs(acc))) {
+ return;
+ }
+ acc->accSelect(SELFLAG_TAKEFOCUS, kChildIdSelf);
+}
+
+ProxyAccessible* ProxyAccessible::ChildAtPoint(
+ int32_t aX, int32_t aY, Accessible::EWhichChildAtPoint aWhichChild) {
+ RefPtr<IAccessible2_2> target = QueryInterface<IAccessible2_2>(this);
+ if (!target) {
+ return nullptr;
+ }
+ DocAccessibleParent* doc = Document();
+ ProxyAccessible* proxy = this;
+ // accHitTest only does direct children, but we might want the deepest child.
+ for (;;) {
+ VARIANT childVar;
+ if (FAILED(target->accHitTest(aX, aY, &childVar)) ||
+ childVar.vt == VT_EMPTY) {
+ return nullptr;
+ }
+ if (childVar.vt == VT_I4 && childVar.lVal == CHILDID_SELF) {
+ break;
+ }
+ MOZ_ASSERT(childVar.vt == VT_DISPATCH && childVar.pdispVal);
+ target = nullptr;
+ childVar.pdispVal->QueryInterface(IID_IAccessible2_2,
+ getter_AddRefs(target));
+ childVar.pdispVal->Release();
+ if (!target) {
+ return nullptr;
+ }
+ // We can't always use GetProxyFor because it can't cross document
+ // boundaries.
+ if (proxy->ChildrenCount() == 1) {
+ proxy = proxy->ChildAt(0);
+ if (proxy->IsDoc()) {
+ // We're crossing into a child document.
+ doc = proxy->AsDoc();
+ }
+ } else {
+ proxy = GetProxyFor(doc, target);
+ }
+ if (aWhichChild == Accessible::eDirectChild) {
+ break;
+ }
+ }
+ return proxy;
+}
+
+} // namespace a11y
+} // namespace mozilla
diff --git a/accessible/ipc/win/ProxyAccessible.h b/accessible/ipc/win/ProxyAccessible.h
new file mode 100644
index 0000000000..cadd248579
--- /dev/null
+++ b/accessible/ipc/win/ProxyAccessible.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_ProxyAccessible_h
+#define mozilla_a11y_ProxyAccessible_h
+
+#include "Accessible.h"
+#include "mozilla/a11y/ProxyAccessibleBase.h"
+#include "mozilla/a11y/Role.h"
+#include "nsString.h"
+#include "nsTArray.h"
+#include "nsRect.h"
+
+#include <oleacc.h>
+
+namespace mozilla {
+namespace a11y {
+
+class ProxyAccessible : public ProxyAccessibleBase<ProxyAccessible> {
+ public:
+ ProxyAccessible(uint64_t aID, ProxyAccessible* aParent,
+ DocAccessibleParent* aDoc, role aRole, uint32_t aInterfaces)
+ : ProxyAccessibleBase(aID, aParent, aDoc, aRole, aInterfaces),
+ mSafeToRecurse(true) {
+ MOZ_COUNT_CTOR(ProxyAccessible);
+ }
+
+ MOZ_COUNTED_DTOR(ProxyAccessible)
+
+#include "mozilla/a11y/ProxyAccessibleShared.h"
+
+ bool GetCOMInterface(void** aOutAccessible) const;
+ void SetCOMInterface(const RefPtr<IAccessible>& aIAccessible) {
+ if (aIAccessible) {
+ mCOMProxy = aIAccessible;
+ } else {
+ // If we were supposed to be receiving an interface (hence the call to
+ // this function), but the interface turns out to be null, then we're
+ // broken for some reason.
+ mSafeToRecurse = false;
+ }
+ }
+
+ protected:
+ explicit ProxyAccessible(DocAccessibleParent* aThisAsDoc)
+ : ProxyAccessibleBase(aThisAsDoc) {
+ MOZ_COUNT_CTOR(ProxyAccessible);
+ }
+
+ private:
+ RefPtr<IAccessible> mCOMProxy;
+ bool mSafeToRecurse;
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
diff --git a/accessible/ipc/win/handler/AccessibleHandler.cpp b/accessible/ipc/win/handler/AccessibleHandler.cpp
new file mode 100644
index 0000000000..90d98abee8
--- /dev/null
+++ b/accessible/ipc/win/handler/AccessibleHandler.cpp
@@ -0,0 +1,2144 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(MOZILLA_INTERNAL_API)
+# error This code is NOT for internal Gecko use!
+#endif // defined(MOZILLA_INTERNAL_API)
+
+#include "AccessibleHandler.h"
+#include "AccessibleHandlerControl.h"
+#include "HandlerChildEnumerator.h"
+#include "HandlerRelation.h"
+
+#include "Factory.h"
+#include "mozilla/ArrayUtils.h"
+#include "mozilla/a11y/HandlerDataCleanup.h"
+#include "mozilla/mscom/Registration.h"
+#include "mozilla/UniquePtr.h"
+
+#include <objbase.h>
+#include <uiautomation.h>
+#include <winreg.h>
+
+#include "AccessibleHypertext.h"
+#include "AccessibleHypertext2.h"
+#include "AccessibleRole.h"
+#include "Accessible2_i.c"
+#include "Accessible2_2_i.c"
+#include "Accessible2_3_i.c"
+#include "AccessibleAction_i.c"
+#include "AccessibleHyperlink_i.c"
+#include "AccessibleHypertext_i.c"
+#include "AccessibleHypertext2_i.c"
+#include "AccessibleTable_i.c"
+#include "AccessibleTable2_i.c"
+#include "AccessibleTableCell_i.c"
+#include "AccessibleText_i.c"
+
+namespace mozilla {
+namespace a11y {
+
+// Must be kept in sync with kClassNameTabContent in
+// accessible/windows/msaa/nsWinUtils.h.
+const WCHAR kEmulatedWindowClassName[] = L"MozillaContentWindowClass";
+const uint32_t kEmulatedWindowClassNameNChars =
+ sizeof(kEmulatedWindowClassName) / sizeof(WCHAR);
+// Mask to get the content process portion of a Windows accessible unique id.
+// This is bits 24 through 30 (LSB 0) of the id. This must be kept in sync
+// with kNumContentProcessIDBits in accessible/windows/msaa/MsaaIdGenerator.cpp.
+const uint32_t kIdContentProcessMask = 0x7F000000;
+
+static mscom::Factory<AccessibleHandler> sHandlerFactory;
+
+HRESULT
+AccessibleHandler::Create(IUnknown* aOuter, REFIID aIid, void** aOutInterface) {
+ if (!aOutInterface || !aOuter || aIid != IID_IUnknown) {
+ return E_INVALIDARG;
+ }
+
+ *aOutInterface = nullptr;
+
+ HRESULT hr;
+ RefPtr<AccessibleHandler> handler(new AccessibleHandler(aOuter, &hr));
+ if (!handler) {
+ return E_OUTOFMEMORY;
+ }
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return handler->InternalQueryInterface(aIid, aOutInterface);
+}
+
+AccessibleHandler::AccessibleHandler(IUnknown* aOuter, HRESULT* aResult)
+ : mscom::Handler(aOuter, aResult),
+ mDispatch(nullptr),
+ mIA2PassThru(nullptr),
+ mServProvPassThru(nullptr),
+ mIAHyperlinkPassThru(nullptr),
+ mIATableCellPassThru(nullptr),
+ mIAHypertextPassThru(nullptr),
+ mCachedData(),
+ mCachedDynamicDataMarshaledByCom(false),
+ mCacheGen(0),
+ mCachedHyperlinks(nullptr),
+ mCachedNHyperlinks(-1),
+ mCachedTextAttribRuns(nullptr),
+ mCachedNTextAttribRuns(-1),
+ mCachedRelations(nullptr),
+ mCachedNRelations(-1),
+ mIsEmulatedWindow(false) {
+ RefPtr<AccessibleHandlerControl> ctl(gControlFactory.GetOrCreateSingleton());
+ MOZ_ASSERT(ctl);
+ if (!ctl) {
+ if (aResult) {
+ *aResult = E_UNEXPECTED;
+ }
+ return;
+ }
+
+ mCacheGen = ctl->GetCacheGen();
+}
+
+AccessibleHandler::~AccessibleHandler() {
+ CleanupDynamicIA2Data(mCachedData.mDynamicData,
+ mCachedDynamicDataMarshaledByCom);
+ if (mCachedData.mGeckoBackChannel) {
+ mCachedData.mGeckoBackChannel->Release();
+ }
+ ClearTextCache();
+ ClearRelationCache();
+}
+
+HRESULT
+AccessibleHandler::ResolveIA2() {
+ if (mIA2PassThru) {
+ return S_OK;
+ }
+
+ RefPtr<IUnknown> proxy(GetProxy());
+ if (!proxy) {
+ return E_UNEXPECTED;
+ }
+
+ HRESULT hr = proxy->QueryInterface(NEWEST_IA2_IID,
+ reinterpret_cast<void**>(&mIA2PassThru));
+ if (SUCCEEDED(hr)) {
+ // mIA2PassThru is a weak reference (see comments in AccesssibleHandler.h)
+ mIA2PassThru->Release();
+ }
+
+ return hr;
+}
+
+HRESULT
+AccessibleHandler::ResolveIAHyperlink() {
+ if (mIAHyperlinkPassThru) {
+ return S_OK;
+ }
+
+ RefPtr<IUnknown> proxy(GetProxy());
+ if (!proxy) {
+ return E_UNEXPECTED;
+ }
+
+ HRESULT hr =
+ proxy->QueryInterface(IID_IAccessibleHyperlink,
+ reinterpret_cast<void**>(&mIAHyperlinkPassThru));
+ if (SUCCEEDED(hr)) {
+ // mIAHyperlinkPassThru is a weak reference
+ // (see comments in AccesssibleHandler.h)
+ mIAHyperlinkPassThru->Release();
+ }
+
+ return hr;
+}
+
+HRESULT
+AccessibleHandler::ResolveIATableCell() {
+ if (mIATableCellPassThru) {
+ return S_OK;
+ }
+
+ RefPtr<IUnknown> proxy(GetProxy());
+ if (!proxy) {
+ return E_UNEXPECTED;
+ }
+
+ HRESULT hr =
+ proxy->QueryInterface(IID_IAccessibleTableCell,
+ reinterpret_cast<void**>(&mIATableCellPassThru));
+ if (SUCCEEDED(hr)) {
+ // mIATableCellPassThru is a weak reference
+ // (see comments in AccesssibleHandler.h)
+ mIATableCellPassThru->Release();
+ }
+
+ return hr;
+}
+
+HRESULT
+AccessibleHandler::ResolveIAHypertext() {
+ if (mIAHypertextPassThru) {
+ return S_OK;
+ }
+
+ RefPtr<IUnknown> proxy(GetProxy());
+ if (!proxy) {
+ return E_UNEXPECTED;
+ }
+
+ HRESULT hr =
+ proxy->QueryInterface(IID_IAccessibleHypertext2,
+ reinterpret_cast<void**>(&mIAHypertextPassThru));
+ if (SUCCEEDED(hr)) {
+ // mIAHypertextPassThru is a weak reference
+ // (see comments in AccessibleHandler.h)
+ mIAHypertextPassThru->Release();
+ }
+
+ return hr;
+}
+
+HRESULT
+AccessibleHandler::MaybeUpdateCachedData() {
+ RefPtr<AccessibleHandlerControl> ctl(gControlFactory.GetOrCreateSingleton());
+ if (!ctl) {
+ return E_OUTOFMEMORY;
+ }
+
+ uint32_t gen = ctl->GetCacheGen();
+ if (gen == mCacheGen) {
+ // Cache is already up to date.
+ return S_OK;
+ }
+
+ if (!mCachedData.mGeckoBackChannel) {
+ return E_POINTER;
+ }
+
+ // While we're making the outgoing COM call below, an incoming COM call can
+ // be handled which calls ReadHandlerPayload or re-enters this function.
+ // Therefore, we mustn't update the cached data directly lest it be mutated
+ // elsewhere before the outgoing COM call returns and cause corruption or
+ // memory leaks. Instead, pass a temporary struct and update the cached data
+ // only after this call completes.
+ DynamicIA2Data newData;
+ HRESULT hr = mCachedData.mGeckoBackChannel->Refresh(&newData);
+ if (SUCCEEDED(hr)) {
+ // Clean up the old data.
+ CleanupDynamicIA2Data(mCachedData.mDynamicData,
+ mCachedDynamicDataMarshaledByCom);
+ mCachedData.mDynamicData = newData;
+ mCachedDynamicDataMarshaledByCom = true;
+ // We just updated the cache, so update this object's cache generation
+ // so we only update the cache again after the next change.
+ mCacheGen = gen;
+ }
+ return hr;
+}
+
+HRESULT
+AccessibleHandler::GetAllTextInfo(BSTR* aText) {
+ MOZ_ASSERT(mCachedData.mGeckoBackChannel);
+
+ ClearTextCache();
+
+ return mCachedData.mGeckoBackChannel->get_AllTextInfo(
+ aText, &mCachedHyperlinks, &mCachedNHyperlinks, &mCachedTextAttribRuns,
+ &mCachedNTextAttribRuns);
+}
+
+void AccessibleHandler::ClearTextCache() {
+ if (mCachedNHyperlinks >= 0) {
+ // We cached hyperlinks, but the caller never retrieved them.
+ for (long index = 0; index < mCachedNHyperlinks; ++index) {
+ mCachedHyperlinks[index]->Release();
+ }
+ // mCachedHyperlinks might already be null if there are no hyperlinks.
+ if (mCachedHyperlinks) {
+ ::CoTaskMemFree(mCachedHyperlinks);
+ mCachedHyperlinks = nullptr;
+ }
+ mCachedNHyperlinks = -1;
+ }
+
+ if (mCachedTextAttribRuns) {
+ for (long index = 0; index < mCachedNTextAttribRuns; ++index) {
+ if (mCachedTextAttribRuns[index].text) {
+ // The caller never requested this attribute run.
+ ::SysFreeString(mCachedTextAttribRuns[index].text);
+ }
+ }
+ // This array is internal to us, so we must always free it.
+ ::CoTaskMemFree(mCachedTextAttribRuns);
+ mCachedTextAttribRuns = nullptr;
+ mCachedNTextAttribRuns = -1;
+ }
+}
+
+HRESULT
+AccessibleHandler::GetRelationsInfo() {
+ MOZ_ASSERT(mCachedData.mGeckoBackChannel);
+
+ ClearRelationCache();
+
+ return mCachedData.mGeckoBackChannel->get_RelationsInfo(&mCachedRelations,
+ &mCachedNRelations);
+}
+
+void AccessibleHandler::ClearRelationCache() {
+ if (mCachedNRelations == -1) {
+ // No cache; nothing to do.
+ return;
+ }
+
+ // We cached relations, but the client never retrieved them.
+ if (mCachedRelations) {
+ for (long index = 0; index < mCachedNRelations; ++index) {
+ IARelationData& relData = mCachedRelations[index];
+ if (relData.mType) {
+ ::SysFreeString(relData.mType);
+ }
+ }
+ // This array is internal to us, so we must always free it.
+ ::CoTaskMemFree(mCachedRelations);
+ mCachedRelations = nullptr;
+ }
+ mCachedNRelations = -1;
+}
+
+HRESULT
+AccessibleHandler::ResolveIDispatch() {
+ if (mDispatch) {
+ return S_OK;
+ }
+
+ HRESULT hr;
+
+ if (!mDispatchUnk) {
+ RefPtr<AccessibleHandlerControl> ctl(
+ gControlFactory.GetOrCreateSingleton());
+ if (!ctl) {
+ return E_OUTOFMEMORY;
+ }
+
+ RefPtr<ITypeInfo> typeinfo;
+ hr = ctl->GetHandlerTypeInfo(getter_AddRefs(typeinfo));
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ hr = ::CreateStdDispatch(GetOuter(),
+ static_cast<NEWEST_IA2_INTERFACE*>(this), typeinfo,
+ getter_AddRefs(mDispatchUnk));
+ if (FAILED(hr)) {
+ return hr;
+ }
+ }
+
+ hr = mDispatchUnk->QueryInterface(IID_IDispatch,
+ reinterpret_cast<void**>(&mDispatch));
+ if (SUCCEEDED(hr)) {
+ // mDispatch is weak (see comments in AccessibleHandler.h)
+ mDispatch->Release();
+ }
+
+ return hr;
+}
+
+HRESULT
+AccessibleHandler::QueryHandlerInterface(IUnknown* aProxyUnknown, REFIID aIid,
+ void** aOutInterface) {
+ MOZ_ASSERT(aProxyUnknown);
+
+ static_assert(&NEWEST_IA2_IID == &IID_IAccessible2_3,
+ "You have modified NEWEST_IA2_IID. This code needs updating.");
+ if (aIid == IID_IDispatch || aIid == IID_IAccessible2_3 ||
+ aIid == IID_IAccessible2_2 || aIid == IID_IAccessible2 ||
+ aIid == IID_IAccessible) {
+ RefPtr<NEWEST_IA2_INTERFACE> ia2(static_cast<NEWEST_IA2_INTERFACE*>(this));
+ ia2.forget(aOutInterface);
+ return S_OK;
+ }
+
+ if (aIid == IID_IServiceProvider) {
+ RefPtr<IServiceProvider> svcProv(static_cast<IServiceProvider*>(this));
+ svcProv.forget(aOutInterface);
+ return S_OK;
+ }
+
+ if (HasPayload()) {
+ // The proxy manager caches interfaces marshaled in the payload
+ // and returns them on QI without a cross-process call.
+ // However, it doesn't know about interfaces which don't exist.
+ // We can determine this from the payload.
+ if (((aIid == IID_IAccessibleText || aIid == IID_IAccessibleHypertext ||
+ aIid == IID_IAccessibleHypertext2) &&
+ !mCachedData.mStaticData.mIAHypertext) ||
+ ((aIid == IID_IAccessibleAction || aIid == IID_IAccessibleHyperlink) &&
+ !mCachedData.mStaticData.mIAHyperlink) ||
+ (aIid == IID_IAccessibleTable && !mCachedData.mStaticData.mIATable) ||
+ (aIid == IID_IAccessibleTable2 && !mCachedData.mStaticData.mIATable2) ||
+ (aIid == IID_IAccessibleTableCell &&
+ !mCachedData.mStaticData.mIATableCell)) {
+ // We already know this interface is not available, so don't query
+ // the proxy, thus avoiding a pointless cross-process call.
+ // If we return E_NOINTERFACE here, mscom::Handler will try the COM
+ // proxy. S_FALSE signals that the proxy should not be tried.
+ return S_FALSE;
+ }
+ }
+
+ if (aIid == IID_IAccessibleAction || aIid == IID_IAccessibleHyperlink) {
+ RefPtr<IAccessibleHyperlink> iaLink(
+ static_cast<IAccessibleHyperlink*>(this));
+ iaLink.forget(aOutInterface);
+ return S_OK;
+ }
+
+ if (aIid == IID_IAccessibleTableCell) {
+ RefPtr<IAccessibleTableCell> iaCell(
+ static_cast<IAccessibleTableCell*>(this));
+ iaCell.forget(aOutInterface);
+ return S_OK;
+ }
+
+ if (aIid == IID_IAccessibleText || aIid == IID_IAccessibleHypertext ||
+ aIid == IID_IAccessibleHypertext2) {
+ RefPtr<IAccessibleHypertext2> iaHt(
+ static_cast<IAccessibleHypertext2*>(this));
+ iaHt.forget(aOutInterface);
+ return S_OK;
+ }
+
+ if (aIid == IID_IProvideClassInfo) {
+ RefPtr<IProvideClassInfo> clsInfo(this);
+ clsInfo.forget(aOutInterface);
+ return S_OK;
+ }
+
+ if (aIid == IID_IEnumVARIANT && mCachedData.mGeckoBackChannel) {
+ if (mCachedData.mDynamicData.mChildCount == 0) {
+ return E_NOINTERFACE;
+ }
+ if (mCachedData.mDynamicData.mIA2Role == IA2_ROLE_INTERNAL_FRAME &&
+ mCachedData.mDynamicData.mChildCount == 1) {
+ // This is for an iframe. HandlerChildEnumerator works fine for iframes
+ // rendered in the same content process. However, for out-of-process
+ // iframes, HandlerProvider::get_AllChildren (called by
+ // HandlerChildEnumerator) will fail. This is because we only send down
+ // an IDispatch COM proxy for the embedded document, but get_AllChildren
+ // will try to QueryInterface this to IAccessible2 to reduce QI calls
+ // from the parent process. Because the content process is sandboxed,
+ // it can't make the outgoing COM call to QI the proxy from IDispatch to
+ // IAccessible2 and so it fails.
+ // Since an iframe only has one child anyway, we don't need the bulk fetch
+ // optimization offered by HandlerChildEnumerator or even IEnumVARIANT.
+ // Therefore, we explicitly tell the client this interface is not
+ // supported, which will cause the oleacc AccessibleChildren function
+ // to fall back to accChild.
+ // If we return E_NOINTERFACE here, mscom::Handler will try the COM
+ // proxy. S_FALSE signals that the proxy should not be tried.
+ return S_FALSE;
+ }
+ RefPtr<IEnumVARIANT> childEnum(
+ new HandlerChildEnumerator(this, mCachedData.mGeckoBackChannel));
+ childEnum.forget(aOutInterface);
+ return S_OK;
+ }
+
+ return E_NOINTERFACE;
+}
+
+HRESULT
+AccessibleHandler::ReadHandlerPayload(IStream* aStream, REFIID aIid) {
+ if (!aStream) {
+ return E_INVALIDARG;
+ }
+
+ mscom::StructFromStream deserializer(aStream);
+ if (!deserializer) {
+ return E_FAIL;
+ }
+ if (deserializer.IsEmpty()) {
+ return S_FALSE;
+ }
+
+ // QueryHandlerInterface might get called while we deserialize the payload,
+ // but that checks the interface pointers in the payload to determine what
+ // interfaces are available. Therefore, deserialize into a temporary struct
+ // and update mCachedData only after deserialization completes.
+ // The decoding functions can misbehave if their target memory is not zeroed
+ // beforehand, so ensure we do that.
+ IA2Payload newData{};
+ if (!deserializer.Read(&newData, &IA2Payload_Decode)) {
+ return E_FAIL;
+ }
+ // Clean up the old data.
+ CleanupDynamicIA2Data(mCachedData.mDynamicData,
+ mCachedDynamicDataMarshaledByCom);
+ mCachedData = newData;
+ mCachedDynamicDataMarshaledByCom = false;
+
+ // These interfaces have been aggregated into the proxy manager.
+ // The proxy manager will resolve these interfaces now on QI,
+ // so we can release these pointers.
+ // However, we don't null them out because we use their presence
+ // to determine whether the interface is available
+ // so as to avoid pointless cross-proc QI calls returning E_NOINTERFACE.
+ // Note that if pointers to other objects (in contrast to
+ // interfaces of *this* object) are added in future, we should not release
+ // those pointers.
+ ReleaseStaticIA2DataInterfaces(mCachedData.mStaticData);
+
+ WCHAR className[kEmulatedWindowClassNameNChars];
+ if (mCachedData.mDynamicData.mHwnd &&
+ ::GetClassName(
+ reinterpret_cast<HWND>(uintptr_t(mCachedData.mDynamicData.mHwnd)),
+ className, kEmulatedWindowClassNameNChars) > 0 &&
+ wcscmp(className, kEmulatedWindowClassName) == 0) {
+ mIsEmulatedWindow = true;
+ }
+
+ if (!mCachedData.mGeckoBackChannel) {
+ return S_OK;
+ }
+
+ RefPtr<AccessibleHandlerControl> ctl(gControlFactory.GetOrCreateSingleton());
+ if (!ctl) {
+ return E_OUTOFMEMORY;
+ }
+
+ if (mCachedData.mDynamicData.mIA2Role == ROLE_SYSTEM_COLUMNHEADER ||
+ mCachedData.mDynamicData.mIA2Role == ROLE_SYSTEM_ROWHEADER) {
+ // Because the same headers can apply to many cells, handler payloads
+ // include the ids of header cells, rather than potentially marshaling the
+ // same objects many times. We need to cache header cells here so we can
+ // get them by id later.
+ ctl->CacheAccessible(mCachedData.mDynamicData.mUniqueId, this);
+ }
+
+ return ctl->Register(WrapNotNull(mCachedData.mGeckoBackChannel));
+}
+
+REFIID
+AccessibleHandler::MarshalAs(REFIID aIid) {
+ static_assert(&NEWEST_IA2_IID == &IID_IAccessible2_3,
+ "You have modified NEWEST_IA2_IID. This code needs updating.");
+ if (aIid == IID_IAccessible2_3 || aIid == IID_IAccessible2_2 ||
+ aIid == IID_IAccessible2 || aIid == IID_IAccessible ||
+ aIid == IID_IDispatch) {
+ return NEWEST_IA2_IID;
+ }
+
+ return aIid;
+}
+
+HRESULT
+AccessibleHandler::GetMarshalInterface(REFIID aMarshalAsIid,
+ NotNull<IUnknown*> aProxy,
+ NotNull<IID*> aOutIid,
+ NotNull<IUnknown**> aOutUnk) {
+ if (aMarshalAsIid == NEWEST_IA2_IID) {
+ *aOutIid = IID_IAccessible;
+ } else {
+ *aOutIid = aMarshalAsIid;
+ }
+
+ return aProxy->QueryInterface(
+ aMarshalAsIid,
+ reinterpret_cast<void**>(static_cast<IUnknown**>(aOutUnk)));
+}
+
+HRESULT
+AccessibleHandler::GetHandlerPayloadSize(REFIID aIid, DWORD* aOutPayloadSize) {
+ if (!aOutPayloadSize) {
+ return E_INVALIDARG;
+ }
+
+ // If we're sending the payload to somebody else, we'd better make sure that
+ // it is up to date. If the cache update fails then we'll return a 0 payload
+ // size so that we don't transfer obsolete data.
+ if (FAILED(MaybeUpdateCachedData())) {
+ *aOutPayloadSize = mscom::StructToStream::GetEmptySize();
+ return S_OK;
+ }
+
+ mSerializer =
+ MakeUnique<mscom::StructToStream>(mCachedData, &IA2Payload_Encode);
+ if (!mSerializer) {
+ return E_FAIL;
+ }
+
+ *aOutPayloadSize = mSerializer->GetSize();
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::WriteHandlerPayload(IStream* aStream, REFIID aIid) {
+ if (!aStream) {
+ return E_INVALIDARG;
+ }
+
+ if (!mSerializer) {
+ return E_UNEXPECTED;
+ }
+
+ HRESULT hr = mSerializer->Write(aStream);
+ mSerializer.reset();
+ return hr;
+}
+
+HRESULT
+AccessibleHandler::QueryInterface(REFIID riid, void** ppv) {
+ return Handler::QueryInterface(riid, ppv);
+}
+
+ULONG
+AccessibleHandler::AddRef() { return Handler::AddRef(); }
+
+ULONG
+AccessibleHandler::Release() { return Handler::Release(); }
+
+HRESULT
+AccessibleHandler::GetTypeInfoCount(UINT* pctinfo) {
+ HRESULT hr = ResolveIDispatch();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mDispatch->GetTypeInfoCount(pctinfo);
+}
+
+HRESULT
+AccessibleHandler::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) {
+ HRESULT hr = ResolveIDispatch();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mDispatch->GetTypeInfo(iTInfo, lcid, ppTInfo);
+}
+
+HRESULT
+AccessibleHandler::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
+ LCID lcid, DISPID* rgDispId) {
+ HRESULT hr = ResolveIDispatch();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mDispatch->GetIDsOfNames(riid, rgszNames, cNames, lcid, rgDispId);
+}
+
+HRESULT
+AccessibleHandler::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
+ WORD wFlags, DISPPARAMS* pDispParams,
+ VARIANT* pVarResult, EXCEPINFO* pExcepInfo,
+ UINT* puArgErr) {
+ HRESULT hr = ResolveIDispatch();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mDispatch->Invoke(dispIdMember, riid, lcid, wFlags, pDispParams,
+ pVarResult, pExcepInfo, puArgErr);
+}
+
+#define BEGIN_CACHE_ACCESS \
+ { \
+ HRESULT hr; \
+ if (FAILED(hr = MaybeUpdateCachedData())) { \
+ return hr; \
+ } \
+ }
+
+#define GET_FIELD(member, assignTo) \
+ { assignTo = mCachedData.mDynamicData.member; }
+
+#define GET_BSTR(member, assignTo) \
+ { assignTo = CopyBSTR(mCachedData.mDynamicData.member); }
+
+/*** IAccessible ***/
+
+HRESULT
+AccessibleHandler::get_accParent(IDispatch** ppdispParent) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accParent(ppdispParent);
+}
+
+HRESULT
+AccessibleHandler::get_accChildCount(long* pcountChildren) {
+ if (!pcountChildren) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accChildCount(pcountChildren);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mChildCount, *pcountChildren);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_accChild(VARIANT varChild, IDispatch** ppdispChild) {
+ if (!ppdispChild) {
+ return E_INVALIDARG;
+ }
+ // Unlikely, but we might as well optimize for it
+ if (varChild.vt == VT_I4 && varChild.lVal == CHILDID_SELF) {
+ RefPtr<IDispatch> disp(this);
+ disp.forget(ppdispChild);
+ return S_OK;
+ }
+
+ if (mIsEmulatedWindow && varChild.vt == VT_I4 && varChild.lVal < 0 &&
+ (varChild.lVal & kIdContentProcessMask) !=
+ (mCachedData.mDynamicData.mUniqueId & kIdContentProcessMask)) {
+ // Window emulation is enabled and the target id is in a different
+ // process to this accessible.
+ // When window emulation is enabled, each tab document gets its own HWND.
+ // OOP iframes get the same HWND as their tab document and fire events with
+ // that HWND. However, the root accessible for the HWND (the tab document)
+ // can't return accessibles for OOP iframes. Therefore, we must get the root
+ // accessible from the main HWND and call accChild on that instead.
+ // We don't need an oleacc proxy, so send WM_GETOBJECT directly instead of
+ // calling AccessibleObjectFromEvent.
+ HWND rootHwnd = GetParent(
+ reinterpret_cast<HWND>(uintptr_t(mCachedData.mDynamicData.mHwnd)));
+ MOZ_ASSERT(rootHwnd);
+ LRESULT lresult = ::SendMessage(rootHwnd, WM_GETOBJECT, 0, OBJID_CLIENT);
+ if (lresult > 0) {
+ RefPtr<IAccessible2_3> rootAcc;
+ HRESULT hr = ::ObjectFromLresult(lresult, IID_IAccessible2_3, 0,
+ getter_AddRefs(rootAcc));
+ if (hr == S_OK) {
+ return rootAcc->get_accChild(varChild, ppdispChild);
+ }
+ }
+ }
+
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accChild(varChild, ppdispChild);
+}
+
+HRESULT
+AccessibleHandler::get_accName(VARIANT varChild, BSTR* pszName) {
+ if (!pszName) {
+ return E_INVALIDARG;
+ }
+
+ if (varChild.lVal != CHILDID_SELF || !HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accName(varChild, pszName);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_BSTR(mName, *pszName);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_accValue(VARIANT varChild, BSTR* pszValue) {
+ if (!pszValue) {
+ return E_INVALIDARG;
+ }
+
+ if (varChild.lVal != CHILDID_SELF || !HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accValue(varChild, pszValue);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_BSTR(mValue, *pszValue);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_accDescription(VARIANT varChild, BSTR* pszDescription) {
+ if (!pszDescription) {
+ return E_INVALIDARG;
+ }
+
+ if (varChild.lVal != CHILDID_SELF || !HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accDescription(varChild, pszDescription);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_BSTR(mDescription, *pszDescription);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_accRole(VARIANT varChild, VARIANT* pvarRole) {
+ if (!pvarRole) {
+ return E_INVALIDARG;
+ }
+
+ if (varChild.lVal != CHILDID_SELF || !HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accRole(varChild, pvarRole);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ return ::VariantCopy(pvarRole, &mCachedData.mDynamicData.mRole);
+}
+
+HRESULT
+AccessibleHandler::get_accState(VARIANT varChild, VARIANT* pvarState) {
+ if (!pvarState) {
+ return E_INVALIDARG;
+ }
+
+ if (varChild.lVal != CHILDID_SELF || !HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accState(varChild, pvarState);
+ }
+
+ pvarState->vt = VT_I4;
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mState, pvarState->lVal);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_accHelp(VARIANT varChild, BSTR* pszHelp) {
+ // This matches what AccessibleWrap does
+ if (!pszHelp) {
+ return E_INVALIDARG;
+ }
+ *pszHelp = nullptr;
+ return S_FALSE;
+}
+
+HRESULT
+AccessibleHandler::get_accHelpTopic(BSTR* pszHelpFile, VARIANT varChild,
+ long* pidTopic) {
+ // This matches what AccessibleWrap does
+ if (!pszHelpFile || !pidTopic) {
+ return E_INVALIDARG;
+ }
+ *pszHelpFile = nullptr;
+ *pidTopic = 0;
+ return S_FALSE;
+}
+
+HRESULT
+AccessibleHandler::get_accKeyboardShortcut(VARIANT varChild,
+ BSTR* pszKeyboardShortcut) {
+ if (!pszKeyboardShortcut) {
+ return E_INVALIDARG;
+ }
+
+ if (varChild.lVal != CHILDID_SELF || !HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accKeyboardShortcut(varChild, pszKeyboardShortcut);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_BSTR(mKeyboardShortcut, *pszKeyboardShortcut);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_accFocus(VARIANT* pvarChild) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accFocus(pvarChild);
+}
+
+HRESULT
+AccessibleHandler::get_accSelection(VARIANT* pvarChildren) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accSelection(pvarChildren);
+}
+
+HRESULT
+AccessibleHandler::get_accDefaultAction(VARIANT varChild,
+ BSTR* pszDefaultAction) {
+ if (!pszDefaultAction) {
+ return E_INVALIDARG;
+ }
+
+ if (varChild.lVal != CHILDID_SELF || !HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accDefaultAction(varChild, pszDefaultAction);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_BSTR(mDefaultAction, *pszDefaultAction);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::accSelect(long flagsSelect, VARIANT varChild) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->accSelect(flagsSelect, varChild);
+}
+
+HRESULT
+AccessibleHandler::accLocation(long* pxLeft, long* pyTop, long* pcxWidth,
+ long* pcyHeight, VARIANT varChild) {
+ if (varChild.lVal != CHILDID_SELF || !HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->accLocation(pxLeft, pyTop, pcxWidth, pcyHeight,
+ varChild);
+ }
+
+ if (!pxLeft || !pyTop || !pcxWidth || !pcyHeight) {
+ return E_INVALIDARG;
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mLeft, *pxLeft);
+ GET_FIELD(mTop, *pyTop);
+ GET_FIELD(mWidth, *pcxWidth);
+ GET_FIELD(mHeight, *pcyHeight);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::accNavigate(long navDir, VARIANT varStart,
+ VARIANT* pvarEndUpAt) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->accNavigate(navDir, varStart, pvarEndUpAt);
+}
+
+HRESULT
+AccessibleHandler::accHitTest(long xLeft, long yTop, VARIANT* pvarChild) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->accHitTest(xLeft, yTop, pvarChild);
+}
+
+HRESULT
+AccessibleHandler::accDoDefaultAction(VARIANT varChild) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->accDoDefaultAction(varChild);
+}
+
+HRESULT
+AccessibleHandler::put_accName(VARIANT varChild, BSTR szName) {
+ // This matches AccessibleWrap
+ return E_NOTIMPL;
+}
+
+HRESULT
+AccessibleHandler::put_accValue(VARIANT varChild, BSTR szValue) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->put_accValue(varChild, szValue);
+}
+
+/*** IAccessible2 ***/
+
+HRESULT
+AccessibleHandler::get_nRelations(long* nRelations) {
+ if (!nRelations) {
+ return E_INVALIDARG;
+ }
+
+ HRESULT hr;
+ if (mCachedData.mGeckoBackChannel) {
+ // If the caller wants nRelations, they will almost certainly want the
+ // actual relations too.
+ hr = GetRelationsInfo();
+ if (SUCCEEDED(hr)) {
+ *nRelations = mCachedNRelations;
+ return S_OK;
+ }
+ // We fall back to a normal call if this fails.
+ }
+
+ hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_nRelations(nRelations);
+}
+
+HRESULT
+AccessibleHandler::get_relation(long relationIndex,
+ IAccessibleRelation** relation) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_relation(relationIndex, relation);
+}
+
+HRESULT
+AccessibleHandler::get_relations(long maxRelations,
+ IAccessibleRelation** relations,
+ long* nRelations) {
+ if (maxRelations == 0 || !relations || !nRelations) {
+ return E_INVALIDARG;
+ }
+
+ // We currently only support retrieval of *all* cached relations at once.
+ if (mCachedNRelations != -1 && maxRelations >= mCachedNRelations) {
+ for (long index = 0; index < mCachedNRelations; ++index) {
+ IARelationData& relData = mCachedRelations[index];
+ RefPtr<IAccessibleRelation> hrel(new HandlerRelation(this, relData));
+ hrel.forget(&relations[index]);
+ }
+ *nRelations = mCachedNRelations;
+ // Clean up the cache, since we only cache for one call.
+ // We don't use ClearRelationCache here because that scans for data to free
+ // in the array and we don't we need that. The HandlerRelation instances
+ // will handle freeing of the data.
+ ::CoTaskMemFree(mCachedRelations);
+ mCachedRelations = nullptr;
+ mCachedNRelations = -1;
+ return S_OK;
+ }
+
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_relations(maxRelations, relations, nRelations);
+}
+
+HRESULT
+AccessibleHandler::role(long* role) {
+ if (!role) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->role(role);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mIA2Role, *role);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::scrollTo(IA2ScrollType scrollType) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->scrollTo(scrollType);
+}
+
+HRESULT
+AccessibleHandler::scrollToPoint(IA2CoordinateType coordinateType, long x,
+ long y) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->scrollToPoint(coordinateType, x, y);
+}
+
+HRESULT
+AccessibleHandler::get_groupPosition(long* groupLevel,
+ long* similarItemsInGroup,
+ long* positionInGroup) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_groupPosition(groupLevel, similarItemsInGroup,
+ positionInGroup);
+}
+
+HRESULT
+AccessibleHandler::get_states(AccessibleStates* states) {
+ if (!states) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_states(states);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mIA2States, *states);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_extendedRole(BSTR* extendedRole) {
+ // This matches ia2Accessible
+ if (!extendedRole) {
+ return E_INVALIDARG;
+ }
+ *extendedRole = nullptr;
+ return E_NOTIMPL;
+}
+
+HRESULT
+AccessibleHandler::get_localizedExtendedRole(BSTR* localizedExtendedRole) {
+ // This matches ia2Accessible
+ if (!localizedExtendedRole) {
+ return E_INVALIDARG;
+ }
+ *localizedExtendedRole = nullptr;
+ return E_NOTIMPL;
+}
+
+HRESULT
+AccessibleHandler::get_nExtendedStates(long* nExtendedStates) {
+ // This matches ia2Accessible
+ if (!nExtendedStates) {
+ return E_INVALIDARG;
+ }
+ *nExtendedStates = 0;
+ return E_NOTIMPL;
+}
+
+HRESULT
+AccessibleHandler::get_extendedStates(long maxExtendedStates,
+ BSTR** extendedStates,
+ long* nExtendedStates) {
+ // This matches ia2Accessible
+ if (!extendedStates || !nExtendedStates) {
+ return E_INVALIDARG;
+ }
+ *extendedStates = nullptr;
+ *nExtendedStates = 0;
+ return E_NOTIMPL;
+}
+
+HRESULT
+AccessibleHandler::get_localizedExtendedStates(long maxLocalizedExtendedStates,
+ BSTR** localizedExtendedStates,
+ long* nLocalizedExtendedStates) {
+ // This matches ia2Accessible
+ if (!localizedExtendedStates || !nLocalizedExtendedStates) {
+ return E_INVALIDARG;
+ }
+ *localizedExtendedStates = nullptr;
+ *nLocalizedExtendedStates = 0;
+ return E_NOTIMPL;
+}
+
+HRESULT
+AccessibleHandler::get_uniqueID(long* uniqueID) {
+ if (!uniqueID) {
+ return E_INVALIDARG;
+ }
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_uniqueID(uniqueID);
+ }
+ *uniqueID = mCachedData.mDynamicData.mUniqueId;
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_windowHandle(HWND* windowHandle) {
+ if (!windowHandle) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_windowHandle(windowHandle);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ long hwnd = 0;
+ GET_FIELD(mHwnd, hwnd);
+ *windowHandle = reinterpret_cast<HWND>(uintptr_t(hwnd));
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_indexInParent(long* indexInParent) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_indexInParent(indexInParent);
+}
+
+HRESULT
+AccessibleHandler::get_locale(IA2Locale* locale) {
+ if (!locale) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_locale(locale);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_BSTR(mIA2Locale.language, locale->language);
+ GET_BSTR(mIA2Locale.country, locale->country);
+ GET_BSTR(mIA2Locale.variant, locale->variant);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_attributes(BSTR* attributes) {
+ if (!attributes) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_attributes(attributes);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_BSTR(mAttributes, *attributes);
+ return S_OK;
+}
+
+/*** IAccessible2_2 ***/
+
+HRESULT
+AccessibleHandler::get_attribute(BSTR name, VARIANT* attribute) {
+ // Not yet implemented by ia2Accessible.
+ // Once ia2Accessible implements this, we could either pass it through
+ // or we could extract these individually from cached mAttributes.
+ // The latter should be considered if traffic warrants it.
+ return E_NOTIMPL;
+}
+
+HRESULT
+AccessibleHandler::get_accessibleWithCaret(IUnknown** accessible,
+ long* caretOffset) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_accessibleWithCaret(accessible, caretOffset);
+}
+
+HRESULT
+AccessibleHandler::get_relationTargetsOfType(BSTR type, long maxTargets,
+ IUnknown*** targets,
+ long* nTargets) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_relationTargetsOfType(type, maxTargets, targets,
+ nTargets);
+}
+
+/*** IAccessible2_3 ***/
+
+HRESULT
+AccessibleHandler::get_selectionRanges(IA2Range** ranges, long* nRanges) {
+ HRESULT hr = ResolveIA2();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIA2PassThru->get_selectionRanges(ranges, nRanges);
+}
+
+/*** IServiceProvider ***/
+
+HRESULT
+AccessibleHandler::QueryService(REFGUID aServiceId, REFIID aIid,
+ void** aOutInterface) {
+ static_assert(&NEWEST_IA2_IID == &IID_IAccessible2_3,
+ "You have modified NEWEST_IA2_IID. This code needs updating.");
+ /* We're taking advantage of the fact that we are implementing IA2 as part
+ of our own object to implement this just like a QI. */
+ if (aIid == IID_IAccessible2_3 || aIid == IID_IAccessible2_2 ||
+ aIid == IID_IAccessible2) {
+ RefPtr<NEWEST_IA2_INTERFACE> ia2(this);
+ ia2.forget(aOutInterface);
+ return S_OK;
+ }
+
+ // JAWS uses QueryService for these, but QI will work just fine and we can
+ // thus avoid a cross-process call. More importantly, if QS is used, the
+ // handler won't get used for that object, so our caching won't be used.
+ if (aIid == IID_IAccessibleAction || aIid == IID_IAccessibleText) {
+ return InternalQueryInterface(aIid, aOutInterface);
+ }
+
+ for (uint32_t i = 0; i < ArrayLength(kUnsupportedServices); ++i) {
+ if (aServiceId == kUnsupportedServices[i]) {
+ return E_NOINTERFACE;
+ }
+ }
+
+ if (!mServProvPassThru) {
+ RefPtr<IUnknown> proxy(GetProxy());
+ if (!proxy) {
+ return E_UNEXPECTED;
+ }
+
+ HRESULT hr = proxy->QueryInterface(
+ IID_IServiceProvider, reinterpret_cast<void**>(&mServProvPassThru));
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ // mServProvPassThru is a weak reference (see comments in
+ // AccessibleHandler.h)
+ mServProvPassThru->Release();
+ }
+
+ return mServProvPassThru->QueryService(aServiceId, aIid, aOutInterface);
+}
+
+/*** IProvideClassInfo ***/
+
+HRESULT
+AccessibleHandler::GetClassInfo(ITypeInfo** aOutTypeInfo) {
+ RefPtr<AccessibleHandlerControl> ctl(gControlFactory.GetOrCreateSingleton());
+ if (!ctl) {
+ return E_OUTOFMEMORY;
+ }
+
+ return ctl->GetHandlerTypeInfo(aOutTypeInfo);
+}
+
+/*** IAccessibleAction ***/
+
+HRESULT
+AccessibleHandler::nActions(long* nActions) {
+ if (!nActions) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->nActions(nActions);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mNActions, *nActions);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::doAction(long actionIndex) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->doAction(actionIndex);
+}
+
+HRESULT
+AccessibleHandler::get_description(long actionIndex, BSTR* description) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->get_description(actionIndex, description);
+}
+
+HRESULT
+AccessibleHandler::get_keyBinding(long actionIndex, long nMaxBindings,
+ BSTR** keyBindings, long* nBindings) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->get_keyBinding(actionIndex, nMaxBindings,
+ keyBindings, nBindings);
+}
+
+HRESULT
+AccessibleHandler::get_name(long actionIndex, BSTR* name) {
+ if (!name) {
+ return E_INVALIDARG;
+ }
+
+ if (HasPayload()) {
+ if (actionIndex >= mCachedData.mDynamicData.mNActions) {
+ // Action does not exist.
+ return E_INVALIDARG;
+ }
+
+ if (actionIndex == 0) {
+ // same as accDefaultAction.
+ GET_BSTR(mDefaultAction, *name);
+ return S_OK;
+ }
+ }
+
+ // At this point, there's either no payload or actionIndex is > 0.
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->get_name(actionIndex, name);
+}
+
+HRESULT
+AccessibleHandler::get_localizedName(long actionIndex, BSTR* localizedName) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->get_localizedName(actionIndex, localizedName);
+}
+
+/*** IAccessibleHyperlink ***/
+
+HRESULT
+AccessibleHandler::get_anchor(long index, VARIANT* anchor) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->get_anchor(index, anchor);
+}
+
+HRESULT
+AccessibleHandler::get_anchorTarget(long index, VARIANT* anchorTarget) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->get_anchorTarget(index, anchorTarget);
+}
+
+HRESULT
+AccessibleHandler::get_startIndex(long* index) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->get_startIndex(index);
+}
+
+HRESULT
+AccessibleHandler::get_endIndex(long* index) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->get_endIndex(index);
+}
+
+HRESULT
+AccessibleHandler::get_valid(boolean* valid) {
+ HRESULT hr = ResolveIAHyperlink();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIAHyperlinkPassThru->get_valid(valid);
+}
+
+/*** IAccessibleTableCell ***/
+
+HRESULT
+AccessibleHandler::get_columnExtent(long* nColumnsSpanned) {
+ if (!nColumnsSpanned) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIATableCell();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIATableCellPassThru->get_columnExtent(nColumnsSpanned);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mColumnExtent, *nColumnsSpanned);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_columnHeaderCells(IUnknown*** cellAccessibles,
+ long* nColumnHeaderCells) {
+ if (!cellAccessibles || !nColumnHeaderCells) {
+ return E_INVALIDARG;
+ }
+
+ HRESULT hr = S_OK;
+ if (HasPayload()) {
+ RefPtr<AccessibleHandlerControl> ctl(
+ gControlFactory.GetOrCreateSingleton());
+ if (!ctl) {
+ return E_OUTOFMEMORY;
+ }
+ *nColumnHeaderCells = mCachedData.mDynamicData.mNColumnHeaderCells;
+ *cellAccessibles = static_cast<IUnknown**>(
+ ::CoTaskMemAlloc(sizeof(IUnknown*) * *nColumnHeaderCells));
+ long i;
+ for (i = 0; i < *nColumnHeaderCells; ++i) {
+ RefPtr<AccessibleHandler> headerAcc;
+ hr = ctl->GetCachedAccessible(
+ mCachedData.mDynamicData.mColumnHeaderCellIds[i],
+ getter_AddRefs(headerAcc));
+ if (FAILED(hr)) {
+ break;
+ }
+ hr = headerAcc->QueryInterface(IID_IUnknown,
+ (void**)&(*cellAccessibles)[i]);
+ if (FAILED(hr)) {
+ break;
+ }
+ }
+ if (SUCCEEDED(hr)) {
+ return S_OK;
+ }
+ // If we failed to get any of the headers from the cache, don't use the
+ // cache at all. We need to clean up anything we did so far.
+ long failedHeader = i;
+ for (i = 0; i < failedHeader; ++i) {
+ (*cellAccessibles)[i]->Release();
+ }
+ ::CoTaskMemFree(*cellAccessibles);
+ *cellAccessibles = nullptr;
+ }
+
+ hr = ResolveIATableCell();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIATableCellPassThru->get_columnHeaderCells(cellAccessibles,
+ nColumnHeaderCells);
+}
+
+HRESULT
+AccessibleHandler::get_columnIndex(long* columnIndex) {
+ if (!columnIndex) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIATableCell();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIATableCellPassThru->get_columnIndex(columnIndex);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mColumnIndex, *columnIndex);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_rowExtent(long* nRowsSpanned) {
+ if (!nRowsSpanned) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIATableCell();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIATableCellPassThru->get_rowExtent(nRowsSpanned);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mRowExtent, *nRowsSpanned);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_rowHeaderCells(IUnknown*** cellAccessibles,
+ long* nRowHeaderCells) {
+ if (!cellAccessibles || !nRowHeaderCells) {
+ return E_INVALIDARG;
+ }
+
+ HRESULT hr = S_OK;
+ if (HasPayload()) {
+ RefPtr<AccessibleHandlerControl> ctl(
+ gControlFactory.GetOrCreateSingleton());
+ if (!ctl) {
+ return E_OUTOFMEMORY;
+ }
+ *nRowHeaderCells = mCachedData.mDynamicData.mNRowHeaderCells;
+ *cellAccessibles = static_cast<IUnknown**>(
+ ::CoTaskMemAlloc(sizeof(IUnknown*) * *nRowHeaderCells));
+ long i;
+ for (i = 0; i < *nRowHeaderCells; ++i) {
+ RefPtr<AccessibleHandler> headerAcc;
+ hr = ctl->GetCachedAccessible(
+ mCachedData.mDynamicData.mRowHeaderCellIds[i],
+ getter_AddRefs(headerAcc));
+ if (FAILED(hr)) {
+ break;
+ }
+ hr = headerAcc->QueryInterface(IID_IUnknown,
+ (void**)&(*cellAccessibles)[i]);
+ if (FAILED(hr)) {
+ break;
+ }
+ }
+ if (SUCCEEDED(hr)) {
+ return S_OK;
+ }
+ // If we failed to get any of the headers from the cache, don't use the
+ // cache at all. We need to clean up anything we did so far.
+ long failedHeader = i;
+ for (i = 0; i < failedHeader; ++i) {
+ (*cellAccessibles)[i]->Release();
+ }
+ ::CoTaskMemFree(*cellAccessibles);
+ *cellAccessibles = nullptr;
+ }
+
+ hr = ResolveIATableCell();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIATableCellPassThru->get_rowHeaderCells(cellAccessibles,
+ nRowHeaderCells);
+}
+
+HRESULT
+AccessibleHandler::get_rowIndex(long* rowIndex) {
+ if (!rowIndex) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIATableCell();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIATableCellPassThru->get_rowIndex(rowIndex);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mRowIndex, *rowIndex);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_isSelected(boolean* isSelected) {
+ if (!isSelected) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIATableCell();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIATableCellPassThru->get_isSelected(isSelected);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mCellIsSelected, *isSelected);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_rowColumnExtents(long* row, long* column,
+ long* rowExtents, long* columnExtents,
+ boolean* isSelected) {
+ if (!row || !column || !rowExtents || !columnExtents || !isSelected) {
+ return E_INVALIDARG;
+ }
+
+ if (!HasPayload()) {
+ HRESULT hr = ResolveIATableCell();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ return mIATableCellPassThru->get_rowColumnExtents(
+ row, column, rowExtents, columnExtents, isSelected);
+ }
+
+ BEGIN_CACHE_ACCESS;
+ GET_FIELD(mRowIndex, *row);
+ GET_FIELD(mColumnIndex, *column);
+ GET_FIELD(mRowExtent, *rowExtents);
+ GET_FIELD(mColumnExtent, *columnExtents);
+ GET_FIELD(mCellIsSelected, *isSelected);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandler::get_table(IUnknown** table) {
+ HRESULT hr = ResolveIATableCell();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIATableCellPassThru->get_table(table);
+}
+
+/*** IAccessibleText ***/
+
+HRESULT
+AccessibleHandler::addSelection(long startOffset, long endOffset) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->addSelection(startOffset, endOffset);
+}
+
+HRESULT
+AccessibleHandler::get_attributes(long offset, long* startOffset,
+ long* endOffset, BSTR* textAttributes) {
+ if (!startOffset || !endOffset || !textAttributes) {
+ return E_INVALIDARG;
+ }
+
+ if (mCachedNTextAttribRuns >= 0) {
+ // We have cached attributes.
+ for (long index = 0; index < mCachedNTextAttribRuns; ++index) {
+ auto& attribRun = mCachedTextAttribRuns[index];
+ if (attribRun.start <= offset && offset < attribRun.end) {
+ *startOffset = attribRun.start;
+ *endOffset = attribRun.end;
+ *textAttributes = attribRun.text;
+ // The caller will clean this up.
+ // (We only keep each cached attribute run for one call.)
+ attribRun.text = nullptr;
+ // The cache for this run is now invalid, so don't visit it again.
+ attribRun.end = 0;
+ return S_OK;
+ }
+ }
+ }
+
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_attributes(offset, startOffset, endOffset,
+ textAttributes);
+}
+
+HRESULT
+AccessibleHandler::get_caretOffset(long* offset) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_caretOffset(offset);
+}
+
+HRESULT
+AccessibleHandler::get_characterExtents(long offset,
+ enum IA2CoordinateType coordType,
+ long* x, long* y, long* width,
+ long* height) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_characterExtents(offset, coordType, x, y,
+ width, height);
+}
+
+HRESULT
+AccessibleHandler::get_nSelections(long* nSelections) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_nSelections(nSelections);
+}
+
+HRESULT
+AccessibleHandler::get_offsetAtPoint(long x, long y,
+ enum IA2CoordinateType coordType,
+ long* offset) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_offsetAtPoint(x, y, coordType, offset);
+}
+
+HRESULT
+AccessibleHandler::get_selection(long selectionIndex, long* startOffset,
+ long* endOffset) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_selection(selectionIndex, startOffset,
+ endOffset);
+}
+
+HRESULT
+AccessibleHandler::get_text(long startOffset, long endOffset, BSTR* text) {
+ if (!text) {
+ return E_INVALIDARG;
+ }
+
+ HRESULT hr;
+ if (mCachedData.mGeckoBackChannel && startOffset == 0 &&
+ endOffset == IA2_TEXT_OFFSET_LENGTH) {
+ // If the caller is retrieving all text, they will probably want all
+ // hyperlinks and attributes as well.
+ hr = GetAllTextInfo(text);
+ if (SUCCEEDED(hr)) {
+ return hr;
+ }
+ // We fall back to a normal call if this fails.
+ }
+
+ hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_text(startOffset, endOffset, text);
+}
+
+HRESULT
+AccessibleHandler::get_textBeforeOffset(long offset,
+ enum IA2TextBoundaryType boundaryType,
+ long* startOffset, long* endOffset,
+ BSTR* text) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_textBeforeOffset(
+ offset, boundaryType, startOffset, endOffset, text);
+}
+
+HRESULT
+AccessibleHandler::get_textAfterOffset(long offset,
+ enum IA2TextBoundaryType boundaryType,
+ long* startOffset, long* endOffset,
+ BSTR* text) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_textAfterOffset(
+ offset, boundaryType, startOffset, endOffset, text);
+}
+
+HRESULT
+AccessibleHandler::get_textAtOffset(long offset,
+ enum IA2TextBoundaryType boundaryType,
+ long* startOffset, long* endOffset,
+ BSTR* text) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_textAtOffset(offset, boundaryType,
+ startOffset, endOffset, text);
+}
+
+HRESULT
+AccessibleHandler::removeSelection(long selectionIndex) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->removeSelection(selectionIndex);
+}
+
+HRESULT
+AccessibleHandler::setCaretOffset(long offset) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->setCaretOffset(offset);
+}
+
+HRESULT
+AccessibleHandler::setSelection(long selectionIndex, long startOffset,
+ long endOffset) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->setSelection(selectionIndex, startOffset,
+ endOffset);
+}
+
+HRESULT
+AccessibleHandler::get_nCharacters(long* nCharacters) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_nCharacters(nCharacters);
+}
+
+HRESULT
+AccessibleHandler::scrollSubstringTo(long startIndex, long endIndex,
+ enum IA2ScrollType scrollType) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->scrollSubstringTo(startIndex, endIndex,
+ scrollType);
+}
+
+HRESULT
+AccessibleHandler::scrollSubstringToPoint(long startIndex, long endIndex,
+ enum IA2CoordinateType coordinateType,
+ long x, long y) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->scrollSubstringToPoint(startIndex, endIndex,
+ coordinateType, x, y);
+}
+
+HRESULT
+AccessibleHandler::get_newText(IA2TextSegment* newText) {
+ if (!newText) {
+ return E_INVALIDARG;
+ }
+
+ RefPtr<AccessibleHandlerControl> ctl(gControlFactory.GetSingleton());
+ MOZ_ASSERT(ctl);
+ if (!ctl) {
+ return S_OK;
+ }
+
+ long id;
+ HRESULT hr = this->get_uniqueID(&id);
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return ctl->GetNewText(id, WrapNotNull(newText));
+}
+
+HRESULT
+AccessibleHandler::get_oldText(IA2TextSegment* oldText) {
+ if (!oldText) {
+ return E_INVALIDARG;
+ }
+
+ RefPtr<AccessibleHandlerControl> ctl(gControlFactory.GetSingleton());
+ MOZ_ASSERT(ctl);
+ if (!ctl) {
+ return S_OK;
+ }
+
+ long id;
+ HRESULT hr = this->get_uniqueID(&id);
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return ctl->GetOldText(id, WrapNotNull(oldText));
+}
+
+/*** IAccessibleHypertext ***/
+
+HRESULT
+AccessibleHandler::get_nHyperlinks(long* hyperlinkCount) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_nHyperlinks(hyperlinkCount);
+}
+
+HRESULT
+AccessibleHandler::get_hyperlink(long index, IAccessibleHyperlink** hyperlink) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_hyperlink(index, hyperlink);
+}
+
+HRESULT
+AccessibleHandler::get_hyperlinkIndex(long charIndex, long* hyperlinkIndex) {
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_hyperlinkIndex(charIndex, hyperlinkIndex);
+}
+
+/*** IAccessibleHypertext2 ***/
+
+HRESULT
+AccessibleHandler::get_hyperlinks(IAccessibleHyperlink*** hyperlinks,
+ long* nHyperlinks) {
+ if (!hyperlinks || !nHyperlinks) {
+ return E_INVALIDARG;
+ }
+
+ if (mCachedNHyperlinks >= 0) {
+ // We have cached hyperlinks.
+ *hyperlinks = mCachedHyperlinks;
+ *nHyperlinks = mCachedNHyperlinks;
+ // The client will clean these up. (We only keep the cache for one call.)
+ mCachedHyperlinks = nullptr;
+ mCachedNHyperlinks = -1;
+ return mCachedNHyperlinks == 0 ? S_FALSE : S_OK;
+ }
+
+ HRESULT hr = ResolveIAHypertext();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return mIAHypertextPassThru->get_hyperlinks(hyperlinks, nHyperlinks);
+}
+
+} // namespace a11y
+} // namespace mozilla
+
+extern "C" HRESULT __stdcall ProxyDllCanUnloadNow();
+
+extern "C" HRESULT __stdcall DllCanUnloadNow() {
+ return mozilla::mscom::Module::CanUnload() && ProxyDllCanUnloadNow();
+}
+
+extern "C" HRESULT __stdcall ProxyDllGetClassObject(REFCLSID aClsid,
+ REFIID aIid,
+ LPVOID* aOutInterface);
+
+extern "C" HRESULT __stdcall DllGetClassObject(REFCLSID aClsid, REFIID aIid,
+ LPVOID* aOutInterface) {
+ if (aClsid == CLSID_AccessibleHandler) {
+ return mozilla::a11y::sHandlerFactory.QueryInterface(aIid, aOutInterface);
+ }
+ return ProxyDllGetClassObject(aClsid, aIid, aOutInterface);
+}
+
+extern "C" BOOL WINAPI ProxyDllMain(HINSTANCE aInstDll, DWORD aReason,
+ LPVOID aReserved);
+
+BOOL WINAPI DllMain(HINSTANCE aInstDll, DWORD aReason, LPVOID aReserved) {
+ if (aReason == DLL_PROCESS_ATTACH) {
+ DisableThreadLibraryCalls((HMODULE)aInstDll);
+ }
+ // This is required for ProxyDllRegisterServer to work correctly
+ return ProxyDllMain(aInstDll, aReason, aReserved);
+}
+
+extern "C" HRESULT __stdcall ProxyDllRegisterServer();
+
+extern "C" HRESULT __stdcall DllRegisterServer() {
+ HRESULT hr = mozilla::mscom::Handler::Register(CLSID_AccessibleHandler);
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return ProxyDllRegisterServer();
+}
+
+extern "C" HRESULT __stdcall ProxyDllUnregisterServer();
+
+extern "C" HRESULT __stdcall DllUnregisterServer() {
+ HRESULT hr = mozilla::mscom::Handler::Unregister(CLSID_AccessibleHandler);
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ return ProxyDllUnregisterServer();
+}
diff --git a/accessible/ipc/win/handler/AccessibleHandler.def b/accessible/ipc/win/handler/AccessibleHandler.def
new file mode 100644
index 0000000000..8f2a245922
--- /dev/null
+++ b/accessible/ipc/win/handler/AccessibleHandler.def
@@ -0,0 +1,11 @@
+;+# This Source Code Form is subject to the terms of the Mozilla Public
+;+# License, v. 2.0. If a copy of the MPL was not distributed with this
+;+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+LIBRARY AccessibleHandler.dll
+
+EXPORTS DllGetClassObject PRIVATE
+ DllCanUnloadNow PRIVATE
+ DllRegisterServer PRIVATE
+ DllUnregisterServer PRIVATE
+ GetProxyDllInfo PRIVATE
diff --git a/accessible/ipc/win/handler/AccessibleHandler.h b/accessible/ipc/win/handler/AccessibleHandler.h
new file mode 100644
index 0000000000..f99091d6c3
--- /dev/null
+++ b/accessible/ipc/win/handler/AccessibleHandler.h
@@ -0,0 +1,336 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_AccessibleHandler_h
+#define mozilla_a11y_AccessibleHandler_h
+
+#define NEWEST_IA2_BASENAME Accessible2_3
+
+#define __GENIFACE(base) I##base
+#define INTERFACEFOR(base) __GENIFACE(base)
+#define NEWEST_IA2_INTERFACE INTERFACEFOR(NEWEST_IA2_BASENAME)
+
+#define __GENIID(iface) IID_##iface
+#define IIDFOR(iface) __GENIID(iface)
+#define NEWEST_IA2_IID IIDFOR(NEWEST_IA2_INTERFACE)
+
+#if defined(__midl) || defined(__WIDL__)
+
+import "Accessible2_3.idl";
+
+#else
+
+# include "HandlerData.h"
+
+# include <windows.h>
+
+namespace mozilla {
+namespace a11y {
+
+static const GUID kUnsupportedServices[] = {
+ // clang-format off
+ // Unknown, queried by Windows on devices with touch screens or similar devices
+ // connected.
+ {0x33f139ee, 0xe509, 0x47f7, {0xbf, 0x39, 0x83, 0x76, 0x44, 0xf7, 0x45, 0x76}},
+ // Unknown, queried by Windows
+ {0xFDA075CF, 0x7C8B, 0x498C, { 0xB5, 0x14, 0xA9, 0xCB, 0x52, 0x1B, 0xBF, 0xB4 }},
+ // Unknown, queried by Windows
+ {0x8EDAA462, 0x21F4, 0x4C87, { 0xA0, 0x12, 0xB3, 0xCD, 0xA3, 0xAB, 0x01, 0xFC }},
+ // Unknown, queried by Windows
+ {0xacd46652, 0x829d, 0x41cb, { 0xa5, 0xfc, 0x17, 0xac, 0xf4, 0x36, 0x61, 0xac }},
+ // SID_IsUIAutomationObject (undocumented), queried by Windows
+ {0xb96fdb85, 0x7204, 0x4724, { 0x84, 0x2b, 0xc7, 0x05, 0x9d, 0xed, 0xb9, 0xd0 }},
+ // IIS_IsOleaccProxy (undocumented), queried by Windows
+ {0x902697FA, 0x80E4, 0x4560, {0x80, 0x2A, 0xA1, 0x3F, 0x22, 0xA6, 0x47, 0x09}},
+ // IID_IHTMLElement, queried by JAWS
+ {0x3050F1FF, 0x98B5, 0x11CF, {0xBB, 0x82, 0x00, 0xAA, 0x00, 0xBD, 0xCE, 0x0B}}
+ // clang-format on
+};
+
+}
+} // namespace mozilla
+
+# if !defined(MOZILLA_INTERNAL_API)
+
+# include "Accessible2_3.h"
+# include "AccessibleHyperlink.h"
+# include "AccessibleHypertext2.h"
+# include "AccessibleTableCell.h"
+# include "Handler.h"
+# include "mozilla/mscom/StructStream.h"
+# include "mozilla/UniquePtr.h"
+
+# include <ocidl.h>
+# include <servprov.h>
+
+namespace mozilla {
+namespace a11y {
+
+class AccessibleHandler final : public mscom::Handler,
+ public NEWEST_IA2_INTERFACE,
+ public IServiceProvider,
+ public IProvideClassInfo,
+ public IAccessibleHyperlink,
+ public IAccessibleTableCell,
+ public IAccessibleHypertext2 {
+ public:
+ static HRESULT Create(IUnknown* aOuter, REFIID aIid, void** aOutInterface);
+
+ // mscom::Handler
+ HRESULT QueryHandlerInterface(IUnknown* aProxyUnknown, REFIID aIid,
+ void** aOutInterface) override;
+ HRESULT ReadHandlerPayload(IStream* aStream, REFIID aIid) override;
+
+ REFIID MarshalAs(REFIID aRequestedIid) override;
+ HRESULT GetMarshalInterface(REFIID aMarshalAsIid, NotNull<IUnknown*> aProxy,
+ NotNull<IID*> aOutIid,
+ NotNull<IUnknown**> aOutUnk) override;
+ HRESULT GetHandlerPayloadSize(REFIID aIid, DWORD* aOutPayloadSize) override;
+ HRESULT WriteHandlerPayload(IStream* aStream, REFIID aIId) override;
+
+ // IUnknown
+ STDMETHODIMP QueryInterface(REFIID riid, void** ppv) override;
+ STDMETHODIMP_(ULONG) AddRef() override;
+ STDMETHODIMP_(ULONG) Release() override;
+
+ // IDispatch
+ STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) override;
+ STDMETHODIMP GetTypeInfo(UINT iTInfo, LCID lcid,
+ ITypeInfo** ppTInfo) override;
+ STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
+ LCID lcid, DISPID* rgDispId) override;
+ STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
+ DISPPARAMS* pDispParams, VARIANT* pVarResult,
+ EXCEPINFO* pExcepInfo, UINT* puArgErr) override;
+
+ // IAccessible
+ STDMETHODIMP get_accParent(IDispatch** ppdispParent) override;
+ STDMETHODIMP get_accChildCount(long* pcountChildren) override;
+ STDMETHODIMP get_accChild(VARIANT varChild, IDispatch** ppdispChild) override;
+ STDMETHODIMP get_accName(VARIANT varChild, BSTR* pszName) override;
+ STDMETHODIMP get_accValue(VARIANT varChild, BSTR* pszValue) override;
+ STDMETHODIMP get_accDescription(VARIANT varChild,
+ BSTR* pszDescription) override;
+ STDMETHODIMP get_accRole(VARIANT varChild, VARIANT* pvarRole) override;
+ STDMETHODIMP get_accState(VARIANT varChild, VARIANT* pvarState) override;
+ STDMETHODIMP get_accHelp(VARIANT varChild, BSTR* pszHelp) override;
+ STDMETHODIMP get_accHelpTopic(BSTR* pszHelpFile, VARIANT varChild,
+ long* pidTopic) override;
+ STDMETHODIMP get_accKeyboardShortcut(VARIANT varChild,
+ BSTR* pszKeyboardShortcut) override;
+ STDMETHODIMP get_accFocus(VARIANT* pvarChild) override;
+ STDMETHODIMP get_accSelection(VARIANT* pvarChildren) override;
+ STDMETHODIMP get_accDefaultAction(VARIANT varChild,
+ BSTR* pszDefaultAction) override;
+ STDMETHODIMP accSelect(long flagsSelect, VARIANT varChild) override;
+ STDMETHODIMP accLocation(long* pxLeft, long* pyTop, long* pcxWidth,
+ long* pcyHeight, VARIANT varChild) override;
+ STDMETHODIMP accNavigate(long navDir, VARIANT varStart,
+ VARIANT* pvarEndUpAt) override;
+ STDMETHODIMP accHitTest(long xLeft, long yTop, VARIANT* pvarChild) override;
+ STDMETHODIMP accDoDefaultAction(VARIANT varChild) override;
+ STDMETHODIMP put_accName(VARIANT varChild, BSTR szName) override;
+ STDMETHODIMP put_accValue(VARIANT varChild, BSTR szValue) override;
+
+ // IAccessible2
+ STDMETHODIMP get_nRelations(long* nRelations) override;
+ STDMETHODIMP get_relation(long relationIndex,
+ IAccessibleRelation** relation) override;
+ STDMETHODIMP get_relations(long maxRelations, IAccessibleRelation** relations,
+ long* nRelations) override;
+ STDMETHODIMP role(long* role) override;
+ STDMETHODIMP scrollTo(IA2ScrollType scrollType) override;
+ STDMETHODIMP scrollToPoint(IA2CoordinateType coordinateType, long x,
+ long y) override;
+ STDMETHODIMP get_groupPosition(long* groupLevel, long* similarItemsInGroup,
+ long* positionInGroup) override;
+ STDMETHODIMP get_states(AccessibleStates* states) override;
+ STDMETHODIMP get_extendedRole(BSTR* extendedRole) override;
+ STDMETHODIMP get_localizedExtendedRole(BSTR* localizedExtendedRole) override;
+ STDMETHODIMP get_nExtendedStates(long* nExtendedStates) override;
+ STDMETHODIMP get_extendedStates(long maxExtendedStates, BSTR** extendedStates,
+ long* nExtendedStates) override;
+ STDMETHODIMP get_localizedExtendedStates(
+ long maxLocalizedExtendedStates, BSTR** localizedExtendedStates,
+ long* nLocalizedExtendedStates) override;
+ STDMETHODIMP get_uniqueID(long* uniqueID) override;
+ STDMETHODIMP get_windowHandle(HWND* windowHandle) override;
+ STDMETHODIMP get_indexInParent(long* indexInParent) override;
+ STDMETHODIMP get_locale(IA2Locale* locale) override;
+ STDMETHODIMP get_attributes(BSTR* attributes) override;
+
+ // IAccessible2_2
+ STDMETHODIMP get_attribute(BSTR name, VARIANT* attribute) override;
+ STDMETHODIMP get_accessibleWithCaret(IUnknown** accessible,
+ long* caretOffset) override;
+ STDMETHODIMP get_relationTargetsOfType(BSTR type, long maxTargets,
+ IUnknown*** targets,
+ long* nTargets) override;
+
+ // IAccessible2_3
+ STDMETHODIMP get_selectionRanges(IA2Range** ranges, long* nRanges) override;
+
+ // IServiceProvider
+ STDMETHODIMP QueryService(REFGUID aServiceId, REFIID aIid,
+ void** aOutInterface) override;
+
+ // IProvideClassInfo
+ STDMETHODIMP GetClassInfo(ITypeInfo** aOutTypeInfo) override;
+
+ // IAccessibleAction
+ STDMETHODIMP nActions(long* nActions) override;
+ STDMETHODIMP doAction(long actionIndex) override;
+ STDMETHODIMP get_description(long actionIndex, BSTR* description) override;
+ STDMETHODIMP get_keyBinding(long actionIndex, long nMaxBindings,
+ BSTR** keyBindings, long* nBindings) override;
+ STDMETHODIMP get_name(long actionIndex, BSTR* name) override;
+ STDMETHODIMP get_localizedName(long actionIndex,
+ BSTR* localizedName) override;
+
+ // IAccessibleHyperlink
+ STDMETHODIMP get_anchor(long index, VARIANT* anchor) override;
+ STDMETHODIMP get_anchorTarget(long index, VARIANT* anchorTarget) override;
+ STDMETHODIMP get_startIndex(long* index) override;
+ STDMETHODIMP get_endIndex(long* index) override;
+ STDMETHODIMP get_valid(boolean* valid) override;
+
+ // IAccessibleTableCell
+ STDMETHODIMP get_columnExtent(long* nColumnsSpanned) override;
+ STDMETHODIMP get_columnHeaderCells(IUnknown*** cellAccessibles,
+ long* nColumnHeaderCells) override;
+ STDMETHODIMP get_columnIndex(long* columnIndex) override;
+ STDMETHODIMP get_rowExtent(long* nRowsSpanned) override;
+ STDMETHODIMP get_rowHeaderCells(IUnknown*** cellAccessibles,
+ long* nRowHeaderCells) override;
+ STDMETHODIMP get_rowIndex(long* rowIndex) override;
+ STDMETHODIMP get_isSelected(boolean* isSelected) override;
+ STDMETHODIMP get_rowColumnExtents(long* row, long* column, long* rowExtents,
+ long* columnExtents,
+ boolean* isSelected) override;
+ STDMETHODIMP get_table(IUnknown** table) override;
+
+ // IAccessibleText
+ STDMETHODIMP addSelection(long startOffset, long endOffset) override;
+ STDMETHODIMP get_attributes(long offset, long* startOffset, long* endOffset,
+ BSTR* textAttributes) override;
+ STDMETHODIMP get_caretOffset(long* offset) override;
+ STDMETHODIMP get_characterExtents(long offset,
+ enum IA2CoordinateType coordType, long* x,
+ long* y, long* width,
+ long* height) override;
+ STDMETHODIMP get_nSelections(long* nSelections) override;
+ STDMETHODIMP get_offsetAtPoint(long x, long y,
+ enum IA2CoordinateType coordType,
+ long* offset) override;
+ STDMETHODIMP get_selection(long selectionIndex, long* startOffset,
+ long* endOffset) override;
+ STDMETHODIMP get_text(long startOffset, long endOffset, BSTR* text) override;
+ STDMETHODIMP get_textBeforeOffset(long offset,
+ enum IA2TextBoundaryType boundaryType,
+ long* startOffset, long* endOffset,
+ BSTR* text) override;
+ STDMETHODIMP get_textAfterOffset(long offset,
+ enum IA2TextBoundaryType boundaryType,
+ long* startOffset, long* endOffset,
+ BSTR* text) override;
+ STDMETHODIMP get_textAtOffset(long offset,
+ enum IA2TextBoundaryType boundaryType,
+ long* startOffset, long* endOffset,
+ BSTR* text) override;
+ STDMETHODIMP removeSelection(long selectionIndex) override;
+ STDMETHODIMP setCaretOffset(long offset) override;
+ STDMETHODIMP setSelection(long selectionIndex, long startOffset,
+ long endOffset) override;
+ STDMETHODIMP get_nCharacters(long* nCharacters) override;
+ STDMETHODIMP scrollSubstringTo(long startIndex, long endIndex,
+ enum IA2ScrollType scrollType) override;
+ STDMETHODIMP scrollSubstringToPoint(long startIndex, long endIndex,
+ enum IA2CoordinateType coordinateType,
+ long x, long y) override;
+ STDMETHODIMP get_newText(IA2TextSegment* newText) override;
+ STDMETHODIMP get_oldText(IA2TextSegment* oldText) override;
+
+ // IAccessibleHypertext
+ STDMETHODIMP get_nHyperlinks(long* hyperlinkCount) override;
+ STDMETHODIMP get_hyperlink(long index,
+ IAccessibleHyperlink** hyperlink) override;
+ STDMETHODIMP get_hyperlinkIndex(long charIndex,
+ long* hyperlinkIndex) override;
+
+ // IAccessibleHypertext2
+ STDMETHODIMP get_hyperlinks(IAccessibleHyperlink*** hyperlinks,
+ long* nHyperlinks) override;
+
+ private:
+ AccessibleHandler(IUnknown* aOuter, HRESULT* aResult);
+ virtual ~AccessibleHandler();
+
+ HRESULT ResolveIA2();
+ HRESULT ResolveIDispatch();
+ HRESULT ResolveIAHyperlink();
+ HRESULT ResolveIAHypertext();
+ HRESULT ResolveIATableCell();
+ HRESULT MaybeUpdateCachedData();
+ HRESULT GetAllTextInfo(BSTR* aText);
+ void ClearTextCache();
+ HRESULT GetRelationsInfo();
+ void ClearRelationCache();
+
+ RefPtr<IUnknown> mDispatchUnk;
+ /**
+ * Handlers aggregate their proxies. This means that their proxies delegate
+ * their IUnknown implementation to us.
+ *
+ * mDispatchUnk and the result of Handler::GetProxy() are both strong
+ * references to the aggregated objects. OTOH, any interfaces that are QI'd
+ * from those aggregated objects have delegated unknowns.
+ *
+ * AddRef'ing an interface with a delegated unknown ends up incrementing the
+ * refcount of the *aggregator*. Since we are the aggregator of mDispatchUnk
+ * and of the wrapped proxy, holding a strong reference to any interfaces
+ * QI'd off of those objects would create a reference cycle.
+ *
+ * We may hold onto pointers to those references, but when we query them we
+ * must immediately Release() them to prevent these cycles.
+ *
+ * It is safe for us to use these raw pointers because the aggregated
+ * objects's lifetimes are proper subsets of our own lifetime.
+ */
+ IDispatch* mDispatch; // weak
+ NEWEST_IA2_INTERFACE* mIA2PassThru; // weak
+ IServiceProvider* mServProvPassThru; // weak
+ IAccessibleHyperlink* mIAHyperlinkPassThru; // weak
+ IAccessibleTableCell* mIATableCellPassThru; // weak
+ IAccessibleHypertext2* mIAHypertextPassThru; // weak
+ IA2Payload mCachedData;
+ bool mCachedDynamicDataMarshaledByCom;
+ UniquePtr<mscom::StructToStream> mSerializer;
+ uint32_t mCacheGen;
+ IAccessibleHyperlink** mCachedHyperlinks;
+ long mCachedNHyperlinks;
+ IA2TextSegment* mCachedTextAttribRuns;
+ long mCachedNTextAttribRuns;
+ IARelationData* mCachedRelations;
+ long mCachedNRelations;
+ bool mIsEmulatedWindow;
+};
+
+inline static BSTR CopyBSTR(BSTR aSrc) {
+ if (!aSrc) {
+ return nullptr;
+ }
+
+ return ::SysAllocStringLen(aSrc, ::SysStringLen(aSrc));
+}
+
+} // namespace a11y
+} // namespace mozilla
+
+# endif // !defined(MOZILLA_INTERNAL_API)
+
+#endif // defined(__midl)
+
+#endif // mozilla_a11y_AccessibleHandler_h
diff --git a/accessible/ipc/win/handler/AccessibleHandler.rc b/accessible/ipc/win/handler/AccessibleHandler.rc
new file mode 100644
index 0000000000..3dac2f89d5
--- /dev/null
+++ b/accessible/ipc/win/handler/AccessibleHandler.rc
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+1 typelib HandlerData.tlb
diff --git a/accessible/ipc/win/handler/AccessibleHandlerControl.cpp b/accessible/ipc/win/handler/AccessibleHandlerControl.cpp
new file mode 100644
index 0000000000..24324c1b5e
--- /dev/null
+++ b/accessible/ipc/win/handler/AccessibleHandlerControl.cpp
@@ -0,0 +1,205 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(MOZILLA_INTERNAL_API)
+# error This code is NOT for internal Gecko use!
+#endif // defined(MOZILLA_INTERNAL_API)
+
+#include "AccessibleHandlerControl.h"
+
+#include <utility>
+
+#include "AccessibleEventId.h"
+#include "AccessibleHandler.h"
+#include "mozilla/RefPtr.h"
+
+namespace mozilla {
+namespace a11y {
+
+mscom::SingletonFactory<AccessibleHandlerControl> gControlFactory;
+
+namespace detail {
+
+TextChange::TextChange() : mIA2UniqueId(0), mIsInsert(false), mText() {}
+
+TextChange::TextChange(long aIA2UniqueId, bool aIsInsert,
+ NotNull<IA2TextSegment*> aText)
+ : mIA2UniqueId(aIA2UniqueId),
+ mIsInsert(aIsInsert),
+ mText{BSTRCopy(aText->text), aText->start, aText->end} {}
+
+TextChange::TextChange(TextChange&& aOther) : mText() {
+ *this = std::move(aOther);
+}
+
+TextChange::TextChange(const TextChange& aOther) : mText() { *this = aOther; }
+
+TextChange& TextChange::operator=(TextChange&& aOther) {
+ mIA2UniqueId = aOther.mIA2UniqueId;
+ mIsInsert = aOther.mIsInsert;
+ aOther.mIA2UniqueId = 0;
+ ::SysFreeString(mText.text);
+ mText = aOther.mText;
+ aOther.mText.text = nullptr;
+ return *this;
+}
+
+TextChange& TextChange::operator=(const TextChange& aOther) {
+ mIA2UniqueId = aOther.mIA2UniqueId;
+ mIsInsert = aOther.mIsInsert;
+ ::SysFreeString(mText.text);
+ mText = {BSTRCopy(aOther.mText.text), aOther.mText.start, aOther.mText.end};
+ return *this;
+}
+
+TextChange::~TextChange() { ::SysFreeString(mText.text); }
+
+HRESULT
+TextChange::GetOld(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutOldSegment) {
+ if (mIsInsert || aIA2UniqueId != mIA2UniqueId) {
+ return S_OK;
+ }
+
+ return SegCopy(*aOutOldSegment, mText);
+}
+
+HRESULT
+TextChange::GetNew(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutNewSegment) {
+ if (!mIsInsert || aIA2UniqueId != mIA2UniqueId) {
+ return S_OK;
+ }
+
+ return SegCopy(*aOutNewSegment, mText);
+}
+
+/* static */
+BSTR TextChange::BSTRCopy(const BSTR& aIn) {
+ return ::SysAllocStringLen(aIn, ::SysStringLen(aIn));
+}
+
+/* static */
+HRESULT TextChange::SegCopy(IA2TextSegment& aDest, const IA2TextSegment& aSrc) {
+ aDest = {BSTRCopy(aSrc.text), aSrc.start, aSrc.end};
+ if (aSrc.text && !aDest.text) {
+ return E_OUTOFMEMORY;
+ }
+ if (!::SysStringLen(aDest.text)) {
+ return S_FALSE;
+ }
+ return S_OK;
+}
+
+} // namespace detail
+
+HRESULT
+AccessibleHandlerControl::Create(AccessibleHandlerControl** aOutObject) {
+ if (!aOutObject) {
+ return E_INVALIDARG;
+ }
+
+ RefPtr<AccessibleHandlerControl> ctl(new AccessibleHandlerControl());
+ ctl.forget(aOutObject);
+ return S_OK;
+}
+
+AccessibleHandlerControl::AccessibleHandlerControl()
+ : mIsRegistered(false),
+ mCacheGen(0),
+ mIA2Proxy(mscom::RegisterProxy(L"ia2marshal.dll")),
+ mHandlerProxy(mscom::RegisterProxy()) {
+ MOZ_ASSERT(mIA2Proxy);
+}
+
+IMPL_IUNKNOWN1(AccessibleHandlerControl, IHandlerControl)
+
+HRESULT
+AccessibleHandlerControl::Invalidate() {
+ ++mCacheGen;
+ // We can't just call mAccessibleCache.clear() because doing so would release
+ // remote objects, making remote COM calls. Since this is an STA, an incoming
+ // COM call might be handled which might marshal an AccessibleHandler,
+ // which in turn might add itself to mAccessibleCache. Since we'd be in the
+ // middle of mutating mAccessibleCache, that might cause a crash. Instead,
+ // swap mAccessibleCache into a temporary map first, which will empty
+ // mAccessibleCache without releasing remote objects. Once mAccessibleCache
+ // is empty, it's safe to let the temporary map be destroyed when it goes
+ // out of scope. Remote calls will be made, but nothing will re-enter
+ // the temporary map while it's being destroyed.
+ AccessibleCache oldCache;
+ mAccessibleCache.swap(oldCache);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandlerControl::OnTextChange(long aHwnd, long aIA2UniqueId,
+ VARIANT_BOOL aIsInsert,
+ IA2TextSegment* aText) {
+ if (!aText) {
+ return E_INVALIDARG;
+ }
+
+ mTextChange = detail::TextChange(aIA2UniqueId, aIsInsert, WrapNotNull(aText));
+ NotifyWinEvent(aIsInsert ? IA2_EVENT_TEXT_INSERTED : IA2_EVENT_TEXT_REMOVED,
+ reinterpret_cast<HWND>(static_cast<uintptr_t>(aHwnd)),
+ OBJID_CLIENT, aIA2UniqueId);
+ return S_OK;
+}
+
+HRESULT
+AccessibleHandlerControl::GetNewText(long aIA2UniqueId,
+ NotNull<IA2TextSegment*> aOutNewText) {
+ return mTextChange.GetNew(aIA2UniqueId, aOutNewText);
+}
+
+HRESULT
+AccessibleHandlerControl::GetOldText(long aIA2UniqueId,
+ NotNull<IA2TextSegment*> aOutOldText) {
+ return mTextChange.GetOld(aIA2UniqueId, aOutOldText);
+}
+
+HRESULT
+AccessibleHandlerControl::GetHandlerTypeInfo(ITypeInfo** aOutTypeInfo) {
+ if (!mHandlerProxy) {
+ return E_UNEXPECTED;
+ }
+
+ return mHandlerProxy->GetTypeInfoForGuid(CLSID_AccessibleHandler,
+ aOutTypeInfo);
+}
+
+HRESULT
+AccessibleHandlerControl::Register(NotNull<IGeckoBackChannel*> aGecko) {
+ if (mIsRegistered) {
+ return S_OK;
+ }
+
+ long pid = static_cast<long>(::GetCurrentProcessId());
+ HRESULT hr = aGecko->put_HandlerControl(pid, this);
+ mIsRegistered = SUCCEEDED(hr);
+ MOZ_ASSERT(mIsRegistered);
+ return hr;
+}
+
+void AccessibleHandlerControl::CacheAccessible(long aUniqueId,
+ AccessibleHandler* aAccessible) {
+ MOZ_ASSERT(aUniqueId && aAccessible);
+ mAccessibleCache[aUniqueId] = aAccessible;
+}
+
+HRESULT AccessibleHandlerControl::GetCachedAccessible(
+ long aUniqueId, AccessibleHandler** aAccessible) {
+ MOZ_ASSERT(aUniqueId && aAccessible);
+ auto it = mAccessibleCache.find(aUniqueId);
+ if (it == mAccessibleCache.end()) {
+ return E_INVALIDARG;
+ }
+ RefPtr<AccessibleHandler> ref = it->second;
+ ref.forget(aAccessible);
+ return S_OK;
+}
+
+} // namespace a11y
+} // namespace mozilla
diff --git a/accessible/ipc/win/handler/AccessibleHandlerControl.h b/accessible/ipc/win/handler/AccessibleHandlerControl.h
new file mode 100644
index 0000000000..d016ecb98b
--- /dev/null
+++ b/accessible/ipc/win/handler/AccessibleHandlerControl.h
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(MOZILLA_INTERNAL_API)
+# error This code is NOT for internal Gecko use!
+#endif // defined(MOZILLA_INTERNAL_API)
+
+#ifndef mozilla_a11y_AccessibleHandlerControl_h
+# define mozilla_a11y_AccessibleHandlerControl_h
+
+# include <unordered_map>
+# include "Factory.h"
+# include "HandlerData.h"
+# include "IUnknownImpl.h"
+# include "mozilla/mscom/Registration.h"
+# include "mozilla/NotNull.h"
+
+namespace mozilla {
+namespace a11y {
+
+namespace detail {
+
+class TextChange final {
+ public:
+ TextChange();
+ TextChange(long aIA2UniqueId, bool aIsInsert, NotNull<IA2TextSegment*> aText);
+ TextChange(TextChange&& aOther);
+ TextChange(const TextChange& aOther);
+
+ TextChange& operator=(TextChange&& aOther);
+ TextChange& operator=(const TextChange& aOther);
+
+ ~TextChange();
+
+ HRESULT GetOld(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutOldSegment);
+ HRESULT GetNew(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutNewSegment);
+
+ private:
+ static BSTR BSTRCopy(const BSTR& aIn);
+ static HRESULT SegCopy(IA2TextSegment& aDest, const IA2TextSegment& aSrc);
+
+ long mIA2UniqueId;
+ bool mIsInsert;
+ IA2TextSegment mText;
+};
+
+} // namespace detail
+
+class AccessibleHandler;
+
+class AccessibleHandlerControl final : public IHandlerControl {
+ public:
+ static HRESULT Create(AccessibleHandlerControl** aOutObject);
+
+ DECL_IUNKNOWN
+
+ // IHandlerControl
+ STDMETHODIMP Invalidate() override;
+ STDMETHODIMP OnTextChange(long aHwnd, long aIA2UniqueId,
+ VARIANT_BOOL aIsInsert,
+ IA2TextSegment* aText) override;
+
+ uint32_t GetCacheGen() const { return mCacheGen; }
+
+ HRESULT GetNewText(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutNewText);
+ HRESULT GetOldText(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutOldText);
+
+ HRESULT GetHandlerTypeInfo(ITypeInfo** aOutTypeInfo);
+
+ HRESULT Register(NotNull<IGeckoBackChannel*> aGecko);
+
+ void CacheAccessible(long aUniqueId, AccessibleHandler* aAccessible);
+ HRESULT GetCachedAccessible(long aUniqueId, AccessibleHandler** aAccessible);
+
+ private:
+ AccessibleHandlerControl();
+ ~AccessibleHandlerControl() = default;
+
+ bool mIsRegistered;
+ uint32_t mCacheGen;
+ detail::TextChange mTextChange;
+ UniquePtr<mscom::RegisteredProxy> mIA2Proxy;
+ UniquePtr<mscom::RegisteredProxy> mHandlerProxy;
+ // We can't use Gecko APIs in this dll, hence the use of std::unordered_map.
+ typedef std::unordered_map<long, RefPtr<AccessibleHandler>> AccessibleCache;
+ AccessibleCache mAccessibleCache;
+};
+
+extern mscom::SingletonFactory<AccessibleHandlerControl> gControlFactory;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_AccessibleHandlerControl_h
diff --git a/accessible/ipc/win/handler/HandlerChildEnumerator.cpp b/accessible/ipc/win/handler/HandlerChildEnumerator.cpp
new file mode 100644
index 0000000000..2062387bf6
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerChildEnumerator.cpp
@@ -0,0 +1,170 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(MOZILLA_INTERNAL_API)
+# error This code is NOT for internal Gecko use!
+#endif // defined(MOZILLA_INTERNAL_API)
+
+#include "HandlerChildEnumerator.h"
+#include "HandlerTextLeaf.h"
+#include "mozilla/Assertions.h"
+
+namespace mozilla {
+namespace a11y {
+
+HandlerChildEnumerator::HandlerChildEnumerator(
+ AccessibleHandler* aHandler, IGeckoBackChannel* aGeckoBackChannel)
+ : mHandler(aHandler),
+ mGeckoBackChannel(aGeckoBackChannel),
+ mChildCount(0),
+ mNextChild(0) {
+ MOZ_ASSERT(aHandler);
+ MOZ_ASSERT(aGeckoBackChannel);
+}
+
+HandlerChildEnumerator::HandlerChildEnumerator(
+ const HandlerChildEnumerator& aEnumerator)
+ : mHandler(aEnumerator.mHandler),
+ mGeckoBackChannel(aEnumerator.mGeckoBackChannel),
+ mChildCount(aEnumerator.mChildCount),
+ mNextChild(aEnumerator.mNextChild) {
+ if (mChildCount == 0) {
+ return;
+ }
+ mChildren = MakeUnique<VARIANT[]>(mChildCount);
+ CopyMemory(mChildren.get(), aEnumerator.mChildren.get(),
+ sizeof(VARIANT) * mChildCount);
+ for (ULONG index = 0; index < mChildCount; ++index) {
+ mChildren[index].pdispVal->AddRef();
+ }
+}
+
+HandlerChildEnumerator::~HandlerChildEnumerator() { ClearCache(); }
+
+void HandlerChildEnumerator::ClearCache() {
+ if (!mChildren) {
+ return;
+ }
+
+ for (ULONG index = 0; index < mChildCount; ++index) {
+ mChildren[index].pdispVal->Release();
+ }
+
+ mChildren = nullptr;
+ mChildCount = 0;
+}
+
+HRESULT
+HandlerChildEnumerator::MaybeCacheChildren() {
+ if (mChildren) {
+ // Already cached.
+ return S_OK;
+ }
+
+ AccChildData* children;
+ HRESULT hr = mGeckoBackChannel->get_AllChildren(&children, &mChildCount);
+ if (FAILED(hr)) {
+ mChildCount = 0;
+ ClearCache();
+ return hr;
+ }
+
+ HWND hwnd = nullptr;
+ hr = mHandler->get_windowHandle(&hwnd);
+ MOZ_ASSERT(SUCCEEDED(hr));
+
+ RefPtr<IDispatch> parent;
+ hr = mHandler->QueryInterface(IID_IDispatch, getter_AddRefs(parent));
+ MOZ_ASSERT(SUCCEEDED(hr));
+
+ mChildren = MakeUnique<VARIANT[]>(mChildCount);
+ for (ULONG index = 0; index < mChildCount; ++index) {
+ AccChildData& data = children[index];
+ VARIANT& child = mChildren[index];
+ if (data.mAccessible) {
+ RefPtr<IDispatch> disp;
+ hr =
+ data.mAccessible->QueryInterface(IID_IDispatch, getter_AddRefs(disp));
+ data.mAccessible->Release();
+ MOZ_ASSERT(SUCCEEDED(hr));
+ if (FAILED(hr)) {
+ child.vt = VT_EMPTY;
+ continue;
+ }
+ child.vt = VT_DISPATCH;
+ disp.forget(&child.pdispVal);
+ } else {
+ // Text leaf.
+ RefPtr<IDispatch> leaf(new HandlerTextLeaf(parent, index, hwnd, data));
+ child.vt = VT_DISPATCH;
+ leaf.forget(&child.pdispVal);
+ }
+ }
+
+ ::CoTaskMemFree(children);
+ return S_OK;
+}
+
+IMPL_IUNKNOWN_QUERY_HEAD(HandlerChildEnumerator)
+IMPL_IUNKNOWN_QUERY_IFACE(IEnumVARIANT)
+IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mHandler)
+
+/*** IEnumVARIANT ***/
+
+HRESULT
+HandlerChildEnumerator::Clone(IEnumVARIANT** aPpEnum) {
+ RefPtr<HandlerChildEnumerator> newEnum(new HandlerChildEnumerator(*this));
+ newEnum.forget(aPpEnum);
+ return S_OK;
+}
+
+HRESULT
+HandlerChildEnumerator::Next(ULONG aCelt, VARIANT* aRgVar,
+ ULONG* aPCeltFetched) {
+ if (!aRgVar || aCelt == 0) {
+ return E_INVALIDARG;
+ }
+
+ HRESULT hr = MaybeCacheChildren();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ for (ULONG index = 0; index < aCelt; ++index) {
+ if (mNextChild >= mChildCount) {
+ // Less elements remaining than were requested.
+ if (aPCeltFetched) {
+ *aPCeltFetched = index;
+ }
+ return S_FALSE;
+ }
+ aRgVar[index] = mChildren[mNextChild];
+ aRgVar[index].pdispVal->AddRef();
+ ++mNextChild;
+ }
+ *aPCeltFetched = aCelt;
+ return S_OK;
+}
+
+HRESULT
+HandlerChildEnumerator::Reset() {
+ mNextChild = 0;
+ ClearCache();
+ return S_OK;
+}
+
+HRESULT
+HandlerChildEnumerator::Skip(ULONG aCelt) {
+ mNextChild += aCelt;
+ if (mNextChild > mChildCount) {
+ // Less elements remaining than the client requested to skip.
+ return S_FALSE;
+ }
+ return S_OK;
+}
+
+} // namespace a11y
+} // namespace mozilla
diff --git a/accessible/ipc/win/handler/HandlerChildEnumerator.h b/accessible/ipc/win/handler/HandlerChildEnumerator.h
new file mode 100644
index 0000000000..df0218c6ed
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerChildEnumerator.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(MOZILLA_INTERNAL_API)
+# error This code is NOT for internal Gecko use!
+#endif // defined(MOZILLA_INTERNAL_API)
+
+#ifndef mozilla_a11y_HandlerChildEnumerator_h
+# define mozilla_a11y_HandlerChildEnumerator_h
+
+# include "AccessibleHandler.h"
+# include "IUnknownImpl.h"
+# include "mozilla/RefPtr.h"
+
+namespace mozilla {
+namespace a11y {
+
+class HandlerChildEnumerator final : public IEnumVARIANT {
+ public:
+ explicit HandlerChildEnumerator(AccessibleHandler* aHandler,
+ IGeckoBackChannel* aGeckoBackChannel);
+
+ DECL_IUNKNOWN
+
+ // IEnumVARIANT
+ STDMETHODIMP Clone(IEnumVARIANT** aPpEnum) override;
+ STDMETHODIMP Next(ULONG aCelt, VARIANT* aRgVar,
+ ULONG* aPCeltFetched) override;
+ STDMETHODIMP Reset() override;
+ STDMETHODIMP Skip(ULONG aCelt) override;
+
+ private:
+ explicit HandlerChildEnumerator(const HandlerChildEnumerator& aEnumerator);
+ ~HandlerChildEnumerator();
+ void ClearCache();
+ HRESULT MaybeCacheChildren();
+
+ RefPtr<AccessibleHandler> mHandler;
+ RefPtr<IGeckoBackChannel> mGeckoBackChannel;
+ UniquePtr<VARIANT[]> mChildren;
+ ULONG mChildCount;
+ ULONG mNextChild;
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_HandlerChildEnumerator_h
diff --git a/accessible/ipc/win/handler/HandlerData.acf b/accessible/ipc/win/handler/HandlerData.acf
new file mode 100644
index 0000000000..993240b063
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerData.acf
@@ -0,0 +1,11 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+[explicit_handle]
+interface HandlerData
+{
+ typedef [encode,decode] IA2Payload;
+}
diff --git a/accessible/ipc/win/handler/HandlerData.idl b/accessible/ipc/win/handler/HandlerData.idl
new file mode 100644
index 0000000000..06f6a8ac21
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerData.idl
@@ -0,0 +1,212 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla-config.h"
+#include "AccessibleHandler.h"
+
+import "ocidl.idl";
+import "servprov.idl";
+
+import "Accessible2_3.idl";
+import "AccessibleHypertext2.idl";
+import "AccessibleHyperlink.idl";
+import "AccessibleTable.idl";
+import "AccessibleTable2.idl";
+import "AccessibleTableCell.idl";
+
+typedef struct _StaticIA2Data
+{
+ NEWEST_IA2_INTERFACE* mIA2;
+ IAccessibleHypertext2* mIAHypertext;
+ IAccessibleHyperlink* mIAHyperlink;
+ IAccessibleTable* mIATable;
+ IAccessibleTable2* mIATable2;
+ IAccessibleTableCell* mIATableCell;
+} StaticIA2Data;
+
+typedef struct _DynamicIA2Data
+{
+ // From IAccessible/IAccessible2
+ VARIANT mRole;
+ long mState;
+ long mChildCount;
+ long mIA2Role;
+ AccessibleStates mIA2States;
+ long mLeft;
+ long mTop;
+ long mWidth;
+ long mHeight;
+ long mHwnd;
+ BSTR mKeyboardShortcut;
+ BSTR mName;
+ BSTR mDescription;
+ BSTR mDefaultAction;
+ BSTR mValue;
+ BSTR mAttributes;
+ IA2Locale mIA2Locale;
+ // From IAccessibleAction
+ long mNActions;
+ // From IAccessibleTableCell
+ long mRowIndex;
+ long mColumnIndex;
+ long mRowExtent;
+ long mColumnExtent;
+ boolean mCellIsSelected;
+ long mNRowHeaderCells;
+ [size_is(mNRowHeaderCells)] long* mRowHeaderCellIds;
+ long mNColumnHeaderCells;
+ [size_is(mNColumnHeaderCells)] long* mColumnHeaderCellIds;
+ // From IAccessible2
+ long mUniqueId;
+} DynamicIA2Data;
+
+interface IGeckoBackChannel;
+
+// We define different CLSIDs and IIDs depending on channel and officiality.
+// This prevents handlers from installing overtop one another when multiple
+// channels are present. Note that we do not do this for all UUIDs in this IDL,
+// just the ones that are written to the registry (coclass and interfaces that
+// have the [object] annotation)
+#if defined(USE_LOCAL_UUID)
+
+# if defined(DEBUG)
+
+// Local debug builds
+# define HANDLER_CLSID 398ffd8d-5382-48f7-9e3b-19012762d39a
+# define IHANDLERCONTROL_IID a218497e-8b10-460b-b668-a92b7ee39ff2
+# define ASYNCIHANDLERCONTROL_IID ca18b9ab-04b6-41be-87f7-d99913d6a2e8
+# define IGECKOBACKCHANNEL_IID 231c4946-4479-4c8e-aadc-8a0e48fc4c51
+
+# else
+
+// Local non-debug builds
+# define HANDLER_CLSID ce573faf-7815-4fc2-a031-b092268ace9e
+# define IHANDLERCONTROL_IID 2b715cce-1790-4fe1-aef5-48bb5acdf3a1
+# define ASYNCIHANDLERCONTROL_IID 8e089670-4f57-41a7-89c0-37f17482fa6f
+# define IGECKOBACKCHANNEL_IID 18e2488d-310f-400f-8339-0e50b513e801
+
+# endif
+
+#elif defined(NIGHTLY_BUILD)
+
+// Nightly Builds
+# define IHANDLERCONTROL_IID c57343fc-e011-40c2-b748-da82eabf0f1f
+# define ASYNCIHANDLERCONTROL_IID 648c92a1-ea35-46da-a806-6b55c6247373
+# define HANDLER_CLSID 4629216b-8753-41bf-9527-5bff51401671
+# define IGECKOBACKCHANNEL_IID e61e038d-40dd-464a-9aba-66b206b6911b
+
+#elif defined(USE_BETA_UUID)
+
+// Beta Builds
+# define IHANDLERCONTROL_IID 119149fa-d212-4f22-9517-082eecc1a084
+# define ASYNCIHANDLERCONTROL_IID 4e253d9b-59cf-4b32-a973-38bc85495d61
+# define HANDLER_CLSID 21e9f98d-a6c9-4cb5-b288-ae2fd2a96c58
+# define IGECKOBACKCHANNEL_IID 77b75c7d-d1c2-4469-864d-31aaebb67cc6
+
+#elif defined(RELEASE_OR_BETA)
+
+// Release Builds
+# define IHANDLERCONTROL_IID ce30f77e-8847-44f0-a648-a9656bd89c0d
+# define ASYNCIHANDLERCONTROL_IID dca8d857-1a63-4045-8f36-8809eb093d04
+# define HANDLER_CLSID 1baa303d-b4b9-45e5-9ccb-e3fca3e274b6
+# define IGECKOBACKCHANNEL_IID b32983ff-ef84-4945-8f86-fb7491b4f57b
+
+#else
+
+// Catch-all
+# define IHANDLERCONTROL_IID 3316ce35-f892-4832-97c5-06c52c03cdba
+# define ASYNCIHANDLERCONTROL_IID 15b48b76-ad38-4ad3-bd1a-d3c48a5a9947
+# define HANDLER_CLSID 4a195748-dca2-45fb-9295-0a139e76a9e7
+# define IGECKOBACKCHANNEL_IID dd2e4a89-999e-4d65-8b65-440c923ddb61
+
+#endif
+
+[uuid(2b0e83b3-fd1a-443f-9ed6-c00d39055b58)]
+interface HandlerData
+{
+ typedef struct _IA2Payload
+ {
+ StaticIA2Data mStaticData;
+ DynamicIA2Data mDynamicData;
+ IGeckoBackChannel* mGeckoBackChannel;
+ } IA2Payload;
+}
+
+[object,
+ uuid(IHANDLERCONTROL_IID),
+ async_uuid(ASYNCIHANDLERCONTROL_IID),
+ pointer_default(unique)]
+interface IHandlerControl : IUnknown
+{
+ HRESULT Invalidate();
+ HRESULT OnTextChange([in] long aHwnd, [in] long aIA2UniqueId,
+ [in] VARIANT_BOOL aIsInsert,
+ [in] IA2TextSegment* aText);
+}
+
+typedef struct _IARelationData
+{
+ BSTR mType;
+ long mNTargets;
+} IARelationData;
+
+typedef struct _AccChildData
+{
+ NEWEST_IA2_INTERFACE* mAccessible;
+ BSTR mText;
+ long mTextRole;
+ long mTextId;
+ long mTextState;
+ long mTextLeft;
+ long mTextTop;
+ long mTextWidth;
+ long mTextHeight;
+} AccChildData;
+
+[object,
+ uuid(IGECKOBACKCHANNEL_IID),
+ pointer_default(unique)]
+interface IGeckoBackChannel : IUnknown
+{
+ [propput] HRESULT HandlerControl([in] long aPid, [in] IHandlerControl* aCtrl);
+ HRESULT Refresh([out] DynamicIA2Data* aOutData);
+ [propget] HRESULT AllTextInfo([out] BSTR* aText,
+ [out, size_is(,*aNHyperlinks)] IAccessibleHyperlink*** aHyperlinks,
+ [out] long* aNHyperlinks,
+ [out, size_is(,*aNAttribRuns)] IA2TextSegment** aAttribRuns,
+ [out] long* aNAttribRuns);
+ [propget] HRESULT RelationsInfo(
+ [out, size_is(,*aNRelations)] IARelationData** aRelations,
+ [out] long* aNRelations);
+ [propget] HRESULT AllChildren(
+ [out, size_is(,*aNChildren)] AccChildData** aChildren,
+ [out] ULONG* aNChildren);
+}
+
+[uuid(1e545f07-f108-4912-9471-546827a80983)]
+library AccessibleHandlerTypeLib
+{
+ importlib("stdole2.tlb");
+
+ /**
+ * This definition is required in order for the handler implementation to
+ * support IDispatch (aka Automation). This is used by interpreted language
+ * FFIs to discover which interfaces may be controlled via IDispatch.
+ * (In particular, the python FFI used by NVDA needs this).
+ *
+ * In reality, the only a11y interface that is Automation compliant is
+ * IAccessible; our remaining interfaces are not.
+ *
+ * Once the FFI knows that IAccessible is supported, the FFI queries for
+ * IAccessible and is then able to resolve non-automation interfaces from
+ * there.
+ */
+ [uuid(HANDLER_CLSID)]
+ coclass AccessibleHandler
+ {
+ [default] interface IAccessible;
+ };
+};
diff --git a/accessible/ipc/win/handler/HandlerDataCleanup.h b/accessible/ipc/win/handler/HandlerDataCleanup.h
new file mode 100644
index 0000000000..14d9995c19
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerDataCleanup.h
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_HandlerDataCleanup_h
+#define mozilla_a11y_HandlerDataCleanup_h
+
+#include <oleauto.h>
+
+namespace mozilla {
+namespace a11y {
+
+inline void ReleaseStaticIA2DataInterfaces(StaticIA2Data& aData) {
+ // Only interfaces of the proxied object wrapped by this handler should be
+ // released here, never other objects!
+ // For example, if StaticIA2Data were to include accParent in future,
+ // that must not be released here.
+ if (aData.mIA2) {
+ aData.mIA2->Release();
+ }
+ if (aData.mIAHypertext) {
+ aData.mIAHypertext->Release();
+ }
+ if (aData.mIAHyperlink) {
+ aData.mIAHyperlink->Release();
+ }
+ if (aData.mIATable) {
+ aData.mIATable->Release();
+ }
+ if (aData.mIATable2) {
+ aData.mIATable2->Release();
+ }
+ if (aData.mIATableCell) {
+ aData.mIATableCell->Release();
+ }
+}
+
+/**
+ * Pass true for aMarshaledByCom if this struct was directly marshaled as an
+ * out parameter of a COM method, currently only IGeckoBackChannel::Refresh.
+ */
+inline void CleanupDynamicIA2Data(DynamicIA2Data& aData,
+ bool aMarshaledByCom = false) {
+ // If freeing generic memory returned to the client, you *must* use freeMem,
+ // not CoTaskMemFree!
+ auto freeMem = [aMarshaledByCom](void* aMem) {
+ if (aMarshaledByCom) {
+ ::CoTaskMemFree(aMem);
+ } else {
+ ::midl_user_free(aMem);
+ }
+ };
+
+ ::VariantClear(&aData.mRole);
+ if (aData.mKeyboardShortcut) {
+ ::SysFreeString(aData.mKeyboardShortcut);
+ }
+ if (aData.mName) {
+ ::SysFreeString(aData.mName);
+ }
+ if (aData.mDescription) {
+ ::SysFreeString(aData.mDescription);
+ }
+ if (aData.mDefaultAction) {
+ ::SysFreeString(aData.mDefaultAction);
+ }
+ if (aData.mValue) {
+ ::SysFreeString(aData.mValue);
+ }
+ if (aData.mAttributes) {
+ ::SysFreeString(aData.mAttributes);
+ }
+ if (aData.mIA2Locale.language) {
+ ::SysFreeString(aData.mIA2Locale.language);
+ }
+ if (aData.mIA2Locale.country) {
+ ::SysFreeString(aData.mIA2Locale.country);
+ }
+ if (aData.mIA2Locale.variant) {
+ ::SysFreeString(aData.mIA2Locale.variant);
+ }
+ if (aData.mRowHeaderCellIds) {
+ freeMem(aData.mRowHeaderCellIds);
+ }
+ if (aData.mColumnHeaderCellIds) {
+ freeMem(aData.mColumnHeaderCellIds);
+ }
+}
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_HandlerDataCleanup_h
diff --git a/accessible/ipc/win/handler/HandlerRelation.cpp b/accessible/ipc/win/handler/HandlerRelation.cpp
new file mode 100644
index 0000000000..8e03da5360
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerRelation.cpp
@@ -0,0 +1,138 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(MOZILLA_INTERNAL_API)
+# error This code is NOT for internal Gecko use!
+#endif // defined(MOZILLA_INTERNAL_API)
+
+#include "HandlerRelation.h"
+#include "mozilla/Assertions.h"
+
+#include "AccessibleRelation_i.c"
+
+namespace mozilla {
+namespace a11y {
+
+HandlerRelation::HandlerRelation(AccessibleHandler* aHandler,
+ IARelationData& aData)
+ : mHandler(aHandler), mData(aData), mTargets(nullptr) {
+ // This instance now owns any pointers, so ensure no one else can
+ // manipulate them.
+ aData.mType = nullptr;
+}
+
+HandlerRelation::~HandlerRelation() {
+ if (mData.mType) {
+ ::SysFreeString(mData.mType);
+ }
+
+ if (mTargets) {
+ for (long index = 0; index < mData.mNTargets; ++index) {
+ mTargets[index]->Release();
+ }
+ ::CoTaskMemFree(mTargets);
+ mTargets = nullptr;
+ }
+}
+
+HRESULT
+HandlerRelation::GetTargets() {
+ if (mTargets) {
+ // Already cached.
+ return S_OK;
+ }
+
+ // Marshaling all of the IAccessibleRelation objects across processes is
+ // slow, and the client probably only wants targets for a few of them.
+ // Therefore, we just use IAccessible2_2::relationTargetsOfType, passing
+ // the type we have cached. This is a bit inefficient because Gecko has
+ // to look up the relation twice, but it's significantly faster than
+ // marshaling the relation objects regardless.
+ return mHandler->get_relationTargetsOfType(mData.mType, 0, &mTargets,
+ &mData.mNTargets);
+}
+
+IMPL_IUNKNOWN1(HandlerRelation, IAccessibleRelation)
+
+/*** IAccessibleRelation ***/
+
+HRESULT
+HandlerRelation::get_relationType(BSTR* aType) {
+ if (!aType) {
+ return E_INVALIDARG;
+ }
+ if (!mData.mType) {
+ return E_FAIL;
+ }
+ *aType = CopyBSTR(mData.mType);
+ return S_OK;
+}
+
+HRESULT
+HandlerRelation::get_localizedRelationType(BSTR* aLocalizedType) {
+ // This is not implemented as per ia2AccessibleRelation.
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerRelation::get_nTargets(long* aNTargets) {
+ if (!aNTargets) {
+ return E_INVALIDARG;
+ }
+ if (mData.mNTargets == -1) {
+ return E_FAIL;
+ }
+ *aNTargets = mData.mNTargets;
+ return S_OK;
+}
+
+HRESULT
+HandlerRelation::get_target(long aIndex, IUnknown** aTarget) {
+ if (!aTarget) {
+ return E_INVALIDARG;
+ }
+
+ HRESULT hr = GetTargets();
+ if (FAILED(hr)) {
+ return hr;
+ }
+ if (aIndex >= mData.mNTargets) {
+ return E_INVALIDARG;
+ }
+
+ *aTarget = mTargets[aIndex];
+ (*aTarget)->AddRef();
+ return S_OK;
+}
+
+HRESULT
+HandlerRelation::get_targets(long aMaxTargets, IUnknown** aTargets,
+ long* aNTargets) {
+ if (aMaxTargets == 0 || !aTargets || !aNTargets) {
+ return E_INVALIDARG;
+ }
+
+ HRESULT hr = GetTargets();
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ if (mData.mNTargets > aMaxTargets) {
+ // Don't give back more targets than were requested.
+ *aNTargets = aMaxTargets;
+ } else {
+ *aNTargets = mData.mNTargets;
+ }
+
+ for (long index = 0; index < *aNTargets; ++index) {
+ aTargets[index] = mTargets[index];
+ aTargets[index]->AddRef();
+ }
+ return S_OK;
+}
+
+} // namespace a11y
+} // namespace mozilla
diff --git a/accessible/ipc/win/handler/HandlerRelation.h b/accessible/ipc/win/handler/HandlerRelation.h
new file mode 100644
index 0000000000..e25b4ee189
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerRelation.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(MOZILLA_INTERNAL_API)
+# error This code is NOT for internal Gecko use!
+#endif // defined(MOZILLA_INTERNAL_API)
+
+#ifndef mozilla_a11y_HandlerRelation_h
+# define mozilla_a11y_HandlerRelation_h
+
+# include "AccessibleHandler.h"
+# include "IUnknownImpl.h"
+# include "mozilla/RefPtr.h"
+
+namespace mozilla {
+namespace a11y {
+
+class HandlerRelation final : public IAccessibleRelation {
+ public:
+ explicit HandlerRelation(AccessibleHandler* aHandler, IARelationData& aData);
+
+ DECL_IUNKNOWN
+
+ // IAccessibleRelation
+ STDMETHODIMP get_relationType(BSTR* aType) override;
+ STDMETHODIMP get_localizedRelationType(BSTR* aLocalizedType) override;
+ STDMETHODIMP get_nTargets(long* aNTargets) override;
+ STDMETHODIMP get_target(long aIndex, IUnknown** aTarget) override;
+ STDMETHODIMP get_targets(long aMaxTargets, IUnknown** aTargets,
+ long* aNTargets) override;
+
+ private:
+ virtual ~HandlerRelation();
+ HRESULT GetTargets();
+ RefPtr<AccessibleHandler> mHandler;
+ IARelationData mData;
+ IUnknown** mTargets;
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_HandlerRelation_h
diff --git a/accessible/ipc/win/handler/HandlerTextLeaf.cpp b/accessible/ipc/win/handler/HandlerTextLeaf.cpp
new file mode 100644
index 0000000000..730aa88df9
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerTextLeaf.cpp
@@ -0,0 +1,337 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(MOZILLA_INTERNAL_API)
+# error This code is NOT for internal Gecko use!
+#endif // defined(MOZILLA_INTERNAL_API)
+
+#include "HandlerTextLeaf.h"
+#include "mozilla/Assertions.h"
+
+namespace mozilla {
+namespace a11y {
+
+HandlerTextLeaf::HandlerTextLeaf(IDispatch* aParent, long aIndexInParent,
+ HWND aHwnd, AccChildData& aData)
+ : mParent(aParent),
+ mIndexInParent(aIndexInParent),
+ mHwnd(aHwnd),
+ mData(aData) {
+ MOZ_ASSERT(aParent);
+}
+
+HandlerTextLeaf::~HandlerTextLeaf() {
+ if (mData.mText) {
+ ::SysFreeString(mData.mText);
+ }
+}
+
+IMPL_IUNKNOWN_QUERY_HEAD(HandlerTextLeaf)
+IMPL_IUNKNOWN_QUERY_IFACE(IDispatch)
+IMPL_IUNKNOWN_QUERY_IFACE(IAccessible)
+IMPL_IUNKNOWN_QUERY_IFACE(IAccessible2)
+IMPL_IUNKNOWN_QUERY_IFACE(IServiceProvider)
+IMPL_IUNKNOWN_QUERY_TAIL
+
+/*** IDispatch ***/
+
+HRESULT
+HandlerTextLeaf::GetTypeInfoCount(UINT* pctinfo) { return E_NOTIMPL; }
+
+HRESULT
+HandlerTextLeaf::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
+ LCID lcid, DISPID* rgDispId) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
+ WORD wFlags, DISPPARAMS* pDispParams,
+ VARIANT* pVarResult, EXCEPINFO* pExcepInfo,
+ UINT* puArgErr) {
+ return E_NOTIMPL;
+}
+
+/*** IAccessible ***/
+
+HRESULT
+HandlerTextLeaf::get_accParent(IDispatch** ppdispParent) {
+ if (!ppdispParent) {
+ return E_INVALIDARG;
+ }
+
+ RefPtr<IDispatch> parent(mParent);
+ parent.forget(ppdispParent);
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::get_accChildCount(long* pcountChildren) {
+ if (!pcountChildren) {
+ return E_INVALIDARG;
+ }
+
+ *pcountChildren = 0;
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::get_accChild(VARIANT varChild, IDispatch** ppdispChild) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_accName(VARIANT varChild, BSTR* pszName) {
+ if (varChild.lVal != CHILDID_SELF || !pszName) {
+ return E_INVALIDARG;
+ }
+
+ *pszName = CopyBSTR(mData.mText);
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::get_accValue(VARIANT varChild, BSTR* pszValue) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_accDescription(VARIANT varChild, BSTR* pszDescription) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_accRole(VARIANT varChild, VARIANT* pvarRole) {
+ if (varChild.lVal != CHILDID_SELF || !pvarRole) {
+ return E_INVALIDARG;
+ }
+
+ pvarRole->vt = VT_I4;
+ pvarRole->lVal = mData.mTextRole;
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::get_accState(VARIANT varChild, VARIANT* pvarState) {
+ if (varChild.lVal != CHILDID_SELF || !pvarState) {
+ return E_INVALIDARG;
+ }
+
+ pvarState->vt = VT_I4;
+ pvarState->lVal = mData.mTextState;
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::get_accHelp(VARIANT varChild, BSTR* pszHelp) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_accHelpTopic(BSTR* pszHelpFile, VARIANT varChild,
+ long* pidTopic) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_accKeyboardShortcut(VARIANT varChild,
+ BSTR* pszKeyboardShortcut) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_accFocus(VARIANT* pvarChild) { return E_NOTIMPL; }
+
+HRESULT
+HandlerTextLeaf::get_accSelection(VARIANT* pvarChildren) { return E_NOTIMPL; }
+
+HRESULT
+HandlerTextLeaf::get_accDefaultAction(VARIANT varChild,
+ BSTR* pszDefaultAction) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::accSelect(long flagsSelect, VARIANT varChild) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::accLocation(long* pxLeft, long* pyTop, long* pcxWidth,
+ long* pcyHeight, VARIANT varChild) {
+ if (varChild.lVal != CHILDID_SELF || !pxLeft || !pyTop || !pcxWidth ||
+ !pcyHeight) {
+ return E_INVALIDARG;
+ }
+
+ *pxLeft = mData.mTextLeft;
+ *pyTop = mData.mTextTop;
+ *pcxWidth = mData.mTextWidth;
+ *pcyHeight = mData.mTextHeight;
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::accNavigate(long navDir, VARIANT varStart,
+ VARIANT* pvarEndUpAt) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::accHitTest(long xLeft, long yTop, VARIANT* pvarChild) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::accDoDefaultAction(VARIANT varChild) { return E_NOTIMPL; }
+
+HRESULT
+HandlerTextLeaf::put_accName(VARIANT varChild, BSTR szName) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::put_accValue(VARIANT varChild, BSTR szValue) {
+ return E_NOTIMPL;
+}
+
+/*** IAccessible2 ***/
+
+HRESULT
+HandlerTextLeaf::get_nRelations(long* nRelations) { return E_NOTIMPL; }
+
+HRESULT
+HandlerTextLeaf::get_relation(long relationIndex,
+ IAccessibleRelation** relation) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_relations(long maxRelations,
+ IAccessibleRelation** relations,
+ long* nRelations) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::role(long* role) {
+ if (!role) {
+ return E_INVALIDARG;
+ }
+
+ *role = mData.mTextRole;
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::scrollTo(IA2ScrollType scrollType) { return E_NOTIMPL; }
+
+HRESULT
+HandlerTextLeaf::scrollToPoint(IA2CoordinateType coordinateType, long x,
+ long y) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_groupPosition(long* groupLevel, long* similarItemsInGroup,
+ long* positionInGroup) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_states(AccessibleStates* states) {
+ if (!states) {
+ return E_INVALIDARG;
+ }
+
+ *states = 0;
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::get_extendedRole(BSTR* extendedRole) { return E_NOTIMPL; }
+
+HRESULT
+HandlerTextLeaf::get_localizedExtendedRole(BSTR* localizedExtendedRole) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_nExtendedStates(long* nExtendedStates) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_extendedStates(long maxExtendedStates,
+ BSTR** extendedStates,
+ long* nExtendedStates) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_localizedExtendedStates(long maxLocalizedExtendedStates,
+ BSTR** localizedExtendedStates,
+ long* nLocalizedExtendedStates) {
+ return E_NOTIMPL;
+}
+
+HRESULT
+HandlerTextLeaf::get_uniqueID(long* uniqueID) {
+ if (!uniqueID) {
+ return E_INVALIDARG;
+ }
+
+ *uniqueID = mData.mTextId;
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::get_windowHandle(HWND* windowHandle) {
+ if (!windowHandle) {
+ return E_INVALIDARG;
+ }
+
+ *windowHandle = mHwnd;
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::get_indexInParent(long* indexInParent) {
+ if (!indexInParent) {
+ return E_INVALIDARG;
+ }
+
+ *indexInParent = mIndexInParent;
+ return S_OK;
+}
+
+HRESULT
+HandlerTextLeaf::get_locale(IA2Locale* locale) { return E_NOTIMPL; }
+
+HRESULT
+HandlerTextLeaf::get_attributes(BSTR* attributes) { return E_NOTIMPL; }
+
+/*** IServiceProvider ***/
+
+HRESULT
+HandlerTextLeaf::QueryService(REFGUID aServiceId, REFIID aIid,
+ void** aOutInterface) {
+ if (aIid == IID_IAccessible2) {
+ RefPtr<IAccessible2> ia2(this);
+ ia2.forget(aOutInterface);
+ return S_OK;
+ }
+
+ return E_INVALIDARG;
+}
+
+} // namespace a11y
+} // namespace mozilla
diff --git a/accessible/ipc/win/handler/HandlerTextLeaf.h b/accessible/ipc/win/handler/HandlerTextLeaf.h
new file mode 100644
index 0000000000..f1a31b9219
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerTextLeaf.h
@@ -0,0 +1,110 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(MOZILLA_INTERNAL_API)
+# error This code is NOT for internal Gecko use!
+#endif // defined(MOZILLA_INTERNAL_API)
+
+#ifndef mozilla_a11y_HandlerTextLeaf_h
+# define mozilla_a11y_HandlerTextLeaf_h
+
+# include "AccessibleHandler.h"
+# include "IUnknownImpl.h"
+# include "mozilla/RefPtr.h"
+
+namespace mozilla {
+namespace a11y {
+
+class HandlerTextLeaf final : public IAccessible2, public IServiceProvider {
+ public:
+ explicit HandlerTextLeaf(IDispatch* aParent, long aIndexInParent, HWND aHwnd,
+ AccChildData& aData);
+
+ DECL_IUNKNOWN
+
+ // IDispatch
+ STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) override;
+ STDMETHODIMP GetTypeInfo(UINT iTInfo, LCID lcid,
+ ITypeInfo** ppTInfo) override;
+ STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
+ LCID lcid, DISPID* rgDispId) override;
+ STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
+ DISPPARAMS* pDispParams, VARIANT* pVarResult,
+ EXCEPINFO* pExcepInfo, UINT* puArgErr) override;
+
+ // IAccessible
+ STDMETHODIMP get_accParent(IDispatch** ppdispParent) override;
+ STDMETHODIMP get_accChildCount(long* pcountChildren) override;
+ STDMETHODIMP get_accChild(VARIANT varChild, IDispatch** ppdispChild) override;
+ STDMETHODIMP get_accName(VARIANT varChild, BSTR* pszName) override;
+ STDMETHODIMP get_accValue(VARIANT varChild, BSTR* pszValue) override;
+ STDMETHODIMP get_accDescription(VARIANT varChild,
+ BSTR* pszDescription) override;
+ STDMETHODIMP get_accRole(VARIANT varChild, VARIANT* pvarRole) override;
+ STDMETHODIMP get_accState(VARIANT varChild, VARIANT* pvarState) override;
+ STDMETHODIMP get_accHelp(VARIANT varChild, BSTR* pszHelp) override;
+ STDMETHODIMP get_accHelpTopic(BSTR* pszHelpFile, VARIANT varChild,
+ long* pidTopic) override;
+ STDMETHODIMP get_accKeyboardShortcut(VARIANT varChild,
+ BSTR* pszKeyboardShortcut) override;
+ STDMETHODIMP get_accFocus(VARIANT* pvarChild) override;
+ STDMETHODIMP get_accSelection(VARIANT* pvarChildren) override;
+ STDMETHODIMP get_accDefaultAction(VARIANT varChild,
+ BSTR* pszDefaultAction) override;
+ STDMETHODIMP accSelect(long flagsSelect, VARIANT varChild) override;
+ STDMETHODIMP accLocation(long* pxLeft, long* pyTop, long* pcxWidth,
+ long* pcyHeight, VARIANT varChild) override;
+ STDMETHODIMP accNavigate(long navDir, VARIANT varStart,
+ VARIANT* pvarEndUpAt) override;
+ STDMETHODIMP accHitTest(long xLeft, long yTop, VARIANT* pvarChild) override;
+ STDMETHODIMP accDoDefaultAction(VARIANT varChild) override;
+ STDMETHODIMP put_accName(VARIANT varChild, BSTR szName) override;
+ STDMETHODIMP put_accValue(VARIANT varChild, BSTR szValue) override;
+
+ // IAccessible2
+ STDMETHODIMP get_nRelations(long* nRelations) override;
+ STDMETHODIMP get_relation(long relationIndex,
+ IAccessibleRelation** relation) override;
+ STDMETHODIMP get_relations(long maxRelations, IAccessibleRelation** relations,
+ long* nRelations) override;
+ STDMETHODIMP role(long* role) override;
+ STDMETHODIMP scrollTo(IA2ScrollType scrollType) override;
+ STDMETHODIMP scrollToPoint(IA2CoordinateType coordinateType, long x,
+ long y) override;
+ STDMETHODIMP get_groupPosition(long* groupLevel, long* similarItemsInGroup,
+ long* positionInGroup) override;
+ STDMETHODIMP get_states(AccessibleStates* states) override;
+ STDMETHODIMP get_extendedRole(BSTR* extendedRole) override;
+ STDMETHODIMP get_localizedExtendedRole(BSTR* localizedExtendedRole) override;
+ STDMETHODIMP get_nExtendedStates(long* nExtendedStates) override;
+ STDMETHODIMP get_extendedStates(long maxExtendedStates, BSTR** extendedStates,
+ long* nExtendedStates) override;
+ STDMETHODIMP get_localizedExtendedStates(
+ long maxLocalizedExtendedStates, BSTR** localizedExtendedStates,
+ long* nLocalizedExtendedStates) override;
+ STDMETHODIMP get_uniqueID(long* uniqueID) override;
+ STDMETHODIMP get_windowHandle(HWND* windowHandle) override;
+ STDMETHODIMP get_indexInParent(long* indexInParent) override;
+ STDMETHODIMP get_locale(IA2Locale* locale) override;
+ STDMETHODIMP get_attributes(BSTR* attributes) override;
+
+ // IServiceProvider
+ STDMETHODIMP QueryService(REFGUID aServiceId, REFIID aIid,
+ void** aOutInterface) override;
+
+ private:
+ ~HandlerTextLeaf();
+
+ RefPtr<IDispatch> mParent;
+ long mIndexInParent;
+ HWND mHwnd;
+ AccChildData mData;
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_HandlerTextLeaf_h
diff --git a/accessible/ipc/win/handler/moz.build b/accessible/ipc/win/handler/moz.build
new file mode 100644
index 0000000000..46f3cb95a4
--- /dev/null
+++ b/accessible/ipc/win/handler/moz.build
@@ -0,0 +1,128 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+SharedLibrary("AccessibleHandler")
+
+EXPORTS.mozilla.a11y += [
+ "AccessibleHandler.h",
+ "HandlerDataCleanup.h",
+]
+
+LOCAL_INCLUDES += [
+ "/accessible/interfaces/ia2",
+ "/ipc/mscom/oop",
+]
+
+# We want to generate distinct UUIDs on a per-channel basis, so we need
+# finer granularity than the standard preprocessor definitions offer.
+# These defines allow us to separate local builds from automated builds,
+# as well as separate beta from release.
+flags = []
+if CONFIG["MOZ_UPDATE_CHANNEL"] == "default":
+ flags += ["-DUSE_LOCAL_UUID"]
+elif CONFIG["MOZ_UPDATE_CHANNEL"] == "beta":
+ flags += ["-DUSE_BETA_UUID"]
+
+GeneratedFile(
+ "HandlerData.h",
+ "HandlerData_p.c",
+ "HandlerData_i.c",
+ "HandlerData_c.c",
+ "HandlerData_dlldata.c",
+ "HandlerData.tlb",
+ inputs=["HandlerData.idl"],
+ script="/build/midl.py",
+ entry_point="midl",
+ flags=flags
+ + [
+ "-I",
+ TOPOBJDIR,
+ "-I",
+ TOPOBJDIR + "/dist/include",
+ "-I",
+ TOPSRCDIR + "/other-licenses/ia2",
+ "-I",
+ SRCDIR,
+ "-acf",
+ SRCDIR + "/HandlerData.acf",
+ "-dlldata",
+ OBJDIR + "/HandlerData_dlldata.c",
+ ],
+)
+
+SOURCES += [
+ "!HandlerData_c.c",
+ "!HandlerData_dlldata.c",
+ "!HandlerData_i.c",
+ "!HandlerData_p.c",
+ "AccessibleHandler.cpp",
+ "AccessibleHandlerControl.cpp",
+ "HandlerChildEnumerator.cpp",
+ "HandlerRelation.cpp",
+ "HandlerTextLeaf.cpp",
+]
+
+EXPORTS += [
+ "!HandlerData.h",
+ "!HandlerData_i.c",
+]
+
+# Give some symbols a unique name in each translation unit, to avoid
+# collisions caused by https://llvm.org/pr41817.
+if CONFIG["CC_TYPE"] == "clang-cl":
+ SOURCES["!HandlerData_p.c"].flags += [
+ "-DHandlerData__MIDL_ProcFormatString=HandlerData__MIDL_ProcFormatString__HandlerData_p"
+ ]
+ SOURCES["!HandlerData_p.c"].flags += [
+ "-DHandlerData__MIDL_TypeFormatString=HandlerData__MIDL_TypeFormatString__HandlerData_p"
+ ]
+ for p in ("dlldata", "c", "i", "p"):
+ SOURCES["!HandlerData_%s.c" % p].flags += [
+ "-DUserMarshalRoutines=UserMarshalRoutines__HandlerData_%s" % p
+ ]
+
+DEFFILE = "AccessibleHandler.def"
+
+USE_LIBS += [
+ "mscom_oop",
+]
+
+OS_LIBS += [
+ "rpcrt4",
+ "oleacc",
+]
+
+RCINCLUDE = "AccessibleHandler.rc"
+
+# Suppress warnings from the MIDL generated code.
+if CONFIG["CC_TYPE"] == "clang-cl":
+ CFLAGS += [
+ "-Wno-extern-initializer",
+ "-Wno-incompatible-pointer-types",
+ "-Wno-missing-braces",
+ "-Wno-unused-const-variable",
+ ]
+
+# Since we are defining our own COM entry points (DllRegisterServer et al),
+# but we still want to be able to delegate some work to the generated code,
+# we add the prefix "Proxy" to all of the generated counterparts.
+DEFINES["ENTRY_PREFIX"] = "Proxy"
+DEFINES["REGISTER_PROXY_DLL"] = True
+LIBRARY_DEFINES["MOZ_MSCOM_REMARSHAL_NO_HANDLER"] = True
+
+# This DLL may be loaded into other processes, so we need static libs for
+# Windows 7 and Windows 8.
+USE_STATIC_LIBS = True
+
+LIBRARY_DEFINES["UNICODE"] = True
+LIBRARY_DEFINES["_UNICODE"] = True
+LIBRARY_DEFINES["MOZ_NO_MOZALLOC"] = True
+DisableStlWrapping()
+
+DELAYLOAD_DLLS += [
+ "advapi32.dll",
+ "ktmw32.dll",
+]
diff --git a/accessible/ipc/win/moz.build b/accessible/ipc/win/moz.build
new file mode 100644
index 0000000000..ab6b3beb78
--- /dev/null
+++ b/accessible/ipc/win/moz.build
@@ -0,0 +1,72 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+if CONFIG["COMPILE_ENVIRONMENT"] and CONFIG["ACCESSIBILITY"]:
+ DIRS += [
+ "handler",
+ "typelib",
+ ]
+
+if CONFIG["ACCESSIBILITY"]:
+ IPDL_SOURCES += ["PDocAccessible.ipdl"]
+
+ if not CONFIG["HAVE_64BIT_BUILD"]:
+ EXPORTS += [
+ "IAccessible32.manifest",
+ ]
+
+ EXPORTS += [
+ "IAccessible64.manifest",
+ ]
+
+ EXPORTS.mozilla.a11y += [
+ "COMPtrTypes.h",
+ "DocAccessibleChild.h",
+ "HandlerProvider.h",
+ "PlatformChild.h",
+ "ProxyAccessible.h",
+ ]
+
+ SOURCES += [
+ "!./handler/HandlerData_c.c",
+ "COMPtrTypes.cpp",
+ "DocAccessibleChild.cpp",
+ "HandlerProvider.cpp",
+ "PlatformChild.cpp",
+ "ProxyAccessible.cpp",
+ ]
+
+ # Give some symbols a unique name in each translation unit, to avoid
+ # collisions caused by https://llvm.org/pr41817.
+ if CONFIG["CC_TYPE"] == "clang-cl":
+ SOURCES["!./handler/HandlerData_c.c"].flags += [
+ "-DUserMarshalRoutines=UserMarshalRoutines__HandlerData_c"
+ ]
+
+ LOCAL_INCLUDES += [
+ "/accessible/base",
+ "/accessible/generic",
+ "/accessible/windows/ia2",
+ "/accessible/windows/msaa",
+ "/accessible/xpcom",
+ ]
+
+ # Suppress warnings from the MIDL generated code.
+ if CONFIG["CC_TYPE"] == "clang-cl":
+ CFLAGS += [
+ "-Wno-extern-initializer",
+ "-Wno-incompatible-pointer-types",
+ "-Wno-missing-braces",
+ "-Wno-unused-const-variable",
+ ]
+
+ CXXFLAGS += [
+ "-Wno-missing-braces",
+ ]
+
+include("/ipc/chromium/chromium-config.mozbuild")
+
+FINAL_LIBRARY = "xul"
diff --git a/accessible/ipc/win/typelib/Accessible.idl b/accessible/ipc/win/typelib/Accessible.idl
new file mode 100644
index 0000000000..82ddcf5065
--- /dev/null
+++ b/accessible/ipc/win/typelib/Accessible.idl
@@ -0,0 +1,16 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+import "oaidl.idl";
+import "servprov.idl";
+
+[uuid(b4d37cda-0dac-45e6-b613-158a5eb94293)]
+library Accessible
+{
+ interface IEnumVARIANT;
+ interface IServiceProvider;
+};
+
diff --git a/accessible/ipc/win/typelib/moz.build b/accessible/ipc/win/typelib/moz.build
new file mode 100644
index 0000000000..2992deda1a
--- /dev/null
+++ b/accessible/ipc/win/typelib/moz.build
@@ -0,0 +1,16 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+FINAL_TARGET_FILES += [
+ "!Accessible.tlb",
+]
+
+GeneratedFile(
+ "Accessible.tlb",
+ inputs=["Accessible.idl"],
+ script="/build/midl.py",
+ entry_point="midl",
+)