DocAccessibleChild.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "DocAccessibleChild.h"
  6. #include "Accessible-inl.h"
  7. #include "mozilla/a11y/PlatformChild.h"
  8. #include "mozilla/ClearOnShutdown.h"
  9. #include "RootAccessible.h"
  10. namespace mozilla {
  11. namespace a11y {
  12. static StaticAutoPtr<PlatformChild> sPlatformChild;
  13. DocAccessibleChild::DocAccessibleChild(DocAccessible* aDoc)
  14. : DocAccessibleChildBase(aDoc)
  15. , mIsRemoteConstructed(false)
  16. {
  17. MOZ_COUNT_CTOR_INHERITED(DocAccessibleChild, DocAccessibleChildBase);
  18. if (!sPlatformChild) {
  19. sPlatformChild = new PlatformChild();
  20. ClearOnShutdown(&sPlatformChild, ShutdownPhase::Shutdown);
  21. }
  22. }
  23. DocAccessibleChild::~DocAccessibleChild()
  24. {
  25. MOZ_COUNT_DTOR_INHERITED(DocAccessibleChild, DocAccessibleChildBase);
  26. }
  27. void
  28. DocAccessibleChild::Shutdown()
  29. {
  30. if (IsConstructedInParentProcess()) {
  31. DocAccessibleChildBase::Shutdown();
  32. return;
  33. }
  34. PushDeferredEvent(MakeUnique<SerializedShutdown>(this));
  35. DetachDocument();
  36. }
  37. bool
  38. DocAccessibleChild::RecvParentCOMProxy(const IAccessibleHolder& aParentCOMProxy)
  39. {
  40. MOZ_ASSERT(!mParentProxy && !aParentCOMProxy.IsNull());
  41. mParentProxy.reset(const_cast<IAccessibleHolder&>(aParentCOMProxy).Release());
  42. SetConstructedInParentProcess();
  43. for (uint32_t i = 0, l = mDeferredEvents.Length(); i < l; ++i) {
  44. mDeferredEvents[i]->Dispatch();
  45. }
  46. mDeferredEvents.Clear();
  47. return true;
  48. }
  49. void
  50. DocAccessibleChild::PushDeferredEvent(UniquePtr<DeferredEvent> aEvent)
  51. {
  52. DocAccessibleChild* topLevelIPCDoc = nullptr;
  53. if (mDoc && mDoc->IsRoot()) {
  54. topLevelIPCDoc = this;
  55. } else {
  56. auto tabChild = static_cast<dom::TabChild*>(Manager());
  57. if (!tabChild) {
  58. return;
  59. }
  60. nsTArray<PDocAccessibleChild*> ipcDocAccs;
  61. tabChild->ManagedPDocAccessibleChild(ipcDocAccs);
  62. // Look for the top-level DocAccessibleChild - there will only be one
  63. // per TabChild.
  64. for (uint32_t i = 0, l = ipcDocAccs.Length(); i < l; ++i) {
  65. auto ipcDocAcc = static_cast<DocAccessibleChild*>(ipcDocAccs[i]);
  66. if (ipcDocAcc->mDoc && ipcDocAcc->mDoc->IsRoot()) {
  67. topLevelIPCDoc = ipcDocAcc;
  68. break;
  69. }
  70. }
  71. }
  72. if (topLevelIPCDoc) {
  73. topLevelIPCDoc->mDeferredEvents.AppendElement(Move(aEvent));
  74. }
  75. }
  76. bool
  77. DocAccessibleChild::SendEvent(const uint64_t& aID, const uint32_t& aType)
  78. {
  79. if (IsConstructedInParentProcess()) {
  80. return PDocAccessibleChild::SendEvent(aID, aType);
  81. }
  82. PushDeferredEvent(MakeUnique<SerializedEvent>(this, aID, aType));
  83. return false;
  84. }
  85. void
  86. DocAccessibleChild::MaybeSendShowEvent(ShowEventData& aData, bool aFromUser)
  87. {
  88. if (IsConstructedInParentProcess()) {
  89. Unused << SendShowEvent(aData, aFromUser);
  90. return;
  91. }
  92. PushDeferredEvent(MakeUnique<SerializedShow>(this, aData, aFromUser));
  93. }
  94. bool
  95. DocAccessibleChild::SendHideEvent(const uint64_t& aRootID,
  96. const bool& aFromUser)
  97. {
  98. if (IsConstructedInParentProcess()) {
  99. return PDocAccessibleChild::SendHideEvent(aRootID, aFromUser);
  100. }
  101. PushDeferredEvent(MakeUnique<SerializedHide>(this, aRootID, aFromUser));
  102. return true;
  103. }
  104. bool
  105. DocAccessibleChild::SendStateChangeEvent(const uint64_t& aID,
  106. const uint64_t& aState,
  107. const bool& aEnabled)
  108. {
  109. if (IsConstructedInParentProcess()) {
  110. return PDocAccessibleChild::SendStateChangeEvent(aID, aState, aEnabled);
  111. }
  112. PushDeferredEvent(MakeUnique<SerializedStateChange>(this, aID, aState,
  113. aEnabled));
  114. return true;
  115. }
  116. bool
  117. DocAccessibleChild::SendCaretMoveEvent(const uint64_t& aID,
  118. const int32_t& aOffset)
  119. {
  120. if (IsConstructedInParentProcess()) {
  121. return PDocAccessibleChild::SendCaretMoveEvent(aID, aOffset);
  122. }
  123. PushDeferredEvent(MakeUnique<SerializedCaretMove>(this, aID, aOffset));
  124. return true;
  125. }
  126. bool
  127. DocAccessibleChild::SendTextChangeEvent(const uint64_t& aID,
  128. const nsString& aStr,
  129. const int32_t& aStart,
  130. const uint32_t& aLen,
  131. const bool& aIsInsert,
  132. const bool& aFromUser)
  133. {
  134. if (IsConstructedInParentProcess()) {
  135. return PDocAccessibleChild::SendTextChangeEvent(aID, aStr, aStart,
  136. aLen, aIsInsert, aFromUser);
  137. }
  138. PushDeferredEvent(MakeUnique<SerializedTextChange>(this, aID, aStr, aStart,
  139. aLen, aIsInsert, aFromUser));
  140. return true;
  141. }
  142. bool
  143. DocAccessibleChild::SendSelectionEvent(const uint64_t& aID,
  144. const uint64_t& aWidgetID,
  145. const uint32_t& aType)
  146. {
  147. if (IsConstructedInParentProcess()) {
  148. return PDocAccessibleChild::SendSelectionEvent(aID, aWidgetID, aType);
  149. }
  150. PushDeferredEvent(MakeUnique<SerializedSelection>(this, aID,
  151. aWidgetID,
  152. aType));
  153. return true;
  154. }
  155. bool
  156. DocAccessibleChild::SendRoleChangedEvent(const uint32_t& aRole)
  157. {
  158. if (IsConstructedInParentProcess()) {
  159. return PDocAccessibleChild::SendRoleChangedEvent(aRole);
  160. }
  161. PushDeferredEvent(MakeUnique<SerializedRoleChanged>(this, aRole));
  162. return true;
  163. }
  164. bool
  165. DocAccessibleChild::ConstructChildDocInParentProcess(
  166. DocAccessibleChild* aNewChildDoc,
  167. uint64_t aUniqueID, uint32_t aMsaaID)
  168. {
  169. if (IsConstructedInParentProcess()) {
  170. // We may send the constructor immediately
  171. auto tabChild = static_cast<dom::TabChild*>(Manager());
  172. MOZ_ASSERT(tabChild);
  173. bool result = tabChild->SendPDocAccessibleConstructor(aNewChildDoc, this,
  174. aUniqueID, aMsaaID,
  175. IAccessibleHolder());
  176. if (result) {
  177. aNewChildDoc->SetConstructedInParentProcess();
  178. }
  179. return result;
  180. }
  181. PushDeferredEvent(MakeUnique<SerializedChildDocConstructor>(aNewChildDoc, this,
  182. aUniqueID, aMsaaID));
  183. return true;
  184. }
  185. bool
  186. DocAccessibleChild::SendBindChildDoc(DocAccessibleChild* aChildDoc,
  187. const uint64_t& aNewParentID)
  188. {
  189. if (IsConstructedInParentProcess()) {
  190. return DocAccessibleChildBase::SendBindChildDoc(aChildDoc, aNewParentID);
  191. }
  192. PushDeferredEvent(MakeUnique<SerializedBindChildDoc>(this, aChildDoc,
  193. aNewParentID));
  194. return true;
  195. }
  196. } // namespace a11y
  197. } // namespace mozilla