tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DocAccessibleChild.h (7546B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_a11y_DocAccessibleChild_h
      8 #define mozilla_a11y_DocAccessibleChild_h
      9 
     10 #include "mozilla/a11y/DocAccessible.h"
     11 #include "mozilla/a11y/PDocAccessibleChild.h"
     12 #include "nsISupportsImpl.h"
     13 
     14 namespace mozilla {
     15 namespace a11y {
     16 
     17 class LocalAccessible;
     18 class AccShowEvent;
     19 
     20 /**
     21 * These objects handle content side communication for an accessible document,
     22 * and their lifetime is the same as the document they represent.
     23 */
     24 class DocAccessibleChild : public PDocAccessibleChild {
     25 public:
     26  DocAccessibleChild(DocAccessible* aDoc,
     27                     mozilla::ipc::IRefCountedProtocol* aManager)
     28      : mDoc(aDoc) {
     29    MOZ_COUNT_CTOR(DocAccessibleChild);
     30    SetManager(aManager);
     31  }
     32 
     33  ~DocAccessibleChild() {
     34    // Shutdown() should have been called, but maybe it isn't if the process is
     35    // killed?
     36    MOZ_ASSERT(!mDoc);
     37    if (mDoc) {
     38      mDoc->SetIPCDoc(nullptr);
     39    }
     40 
     41    MOZ_COUNT_DTOR(DocAccessibleChild);
     42  }
     43 
     44  virtual void Shutdown() {
     45    DetachDocument();
     46    SendShutdown();
     47  }
     48 
     49  /**
     50   * Serializes a shown tree and pushes the show event data to the mutation
     51   * event queue with PushMutationEventData. This function may push multiple
     52   * show events depending on the size of the flattened tree.
     53   */
     54  void InsertIntoIpcTree(LocalAccessible* aChild, bool aSuppressShowEvent);
     55  void ShowEvent(AccShowEvent* aShowEvent);
     56 
     57  /**
     58   * Append the mutation event to mutation event queue, potentially creating a
     59   * new batch of mutation events. This function may send queued mutation events
     60   * if the number of batches meets or exceeds a set limit.
     61   */
     62  void PushMutationEventData(MutationEventData aData, uint32_t aAccCount = 1);
     63  void SendQueuedMutationEvents();
     64  size_t MutationEventQueueLength() const;
     65 
     66  bool HasUnackedMutationEvents() const { return mHasUnackedMutationEvents; }
     67 
     68  virtual void ActorDestroy(ActorDestroyReason) override {
     69    if (!mDoc) {
     70      return;
     71    }
     72 
     73    mDoc->SetIPCDoc(nullptr);
     74    mDoc = nullptr;
     75  }
     76 
     77  virtual mozilla::ipc::IPCResult RecvTakeFocus(const uint64_t& aID) override;
     78 
     79  MOZ_CAN_RUN_SCRIPT_BOUNDARY
     80  virtual mozilla::ipc::IPCResult RecvScrollTo(
     81      const uint64_t& aID, const uint32_t& aScrollType) override;
     82 
     83  virtual mozilla::ipc::IPCResult RecvTakeSelection(
     84      const uint64_t& aID) override;
     85  virtual mozilla::ipc::IPCResult RecvSetSelected(const uint64_t& aID,
     86                                                  const bool& aSelect) override;
     87 
     88  virtual mozilla::ipc::IPCResult RecvVerifyCache(
     89      const uint64_t& aID, const uint64_t& aCacheDomain,
     90      AccAttributes* aFields) override;
     91 
     92  virtual mozilla::ipc::IPCResult RecvDoActionAsync(
     93      const uint64_t& aID, const uint8_t& aIndex) override;
     94 
     95  MOZ_CAN_RUN_SCRIPT_BOUNDARY
     96  virtual mozilla::ipc::IPCResult RecvSetTextSelection(
     97      const uint64_t& aStartID, const int32_t& aStartOffset,
     98      const uint64_t& aEndID, const int32_t& aEndOffset,
     99      const int32_t& aSelectionNum, const bool& aSetFocus) override;
    100 
    101  MOZ_CAN_RUN_SCRIPT_BOUNDARY
    102  virtual mozilla::ipc::IPCResult RecvScrollTextLeafRangeIntoView(
    103      const uint64_t& aStartID, const int32_t& aStartOffset,
    104      const uint64_t& aEndID, const int32_t& aEndOffset,
    105      const uint32_t& aScrollType) override;
    106 
    107  virtual mozilla::ipc::IPCResult RecvRemoveTextSelection(
    108      const uint64_t& aID, const int32_t& aSelectionNum) override;
    109 
    110  virtual mozilla::ipc::IPCResult RecvSetCurValue(
    111      const uint64_t& aID, const double& aValue) override;
    112 
    113  virtual mozilla::ipc::IPCResult RecvReplaceText(
    114      const uint64_t& aID, const nsAString& aText) override;
    115 
    116  virtual mozilla::ipc::IPCResult RecvInsertText(
    117      const uint64_t& aID, const nsAString& aText,
    118      const int32_t& aPosition) override;
    119 
    120  virtual mozilla::ipc::IPCResult RecvCopyText(const uint64_t& aID,
    121                                               const int32_t& aStartPos,
    122                                               const int32_t& aEndPos) override;
    123 
    124  virtual mozilla::ipc::IPCResult RecvCutText(const uint64_t& aID,
    125                                              const int32_t& aStartPos,
    126                                              const int32_t& aEndPos) override;
    127 
    128  virtual mozilla::ipc::IPCResult RecvDeleteText(
    129      const uint64_t& aID, const int32_t& aStartPos,
    130      const int32_t& aEndPos) override;
    131 
    132  MOZ_CAN_RUN_SCRIPT_BOUNDARY
    133  virtual mozilla::ipc::IPCResult RecvPasteText(
    134      const uint64_t& aID, const int32_t& aPosition) override;
    135 
    136  virtual mozilla::ipc::IPCResult RecvRestoreFocus() override;
    137 
    138  virtual mozilla::ipc::IPCResult RecvScrollToPoint(const uint64_t& aID,
    139                                                    const uint32_t& aScrollType,
    140                                                    const int32_t& aX,
    141                                                    const int32_t& aY) override;
    142 
    143 #if !defined(XP_WIN)
    144  virtual mozilla::ipc::IPCResult RecvAnnounce(
    145      const uint64_t& aID, const nsAString& aAnnouncement,
    146      const uint16_t& aPriority) override;
    147 #endif  // !defined(XP_WIN)
    148 
    149  virtual mozilla::ipc::IPCResult RecvScrollSubstringToPoint(
    150      const uint64_t& aID, const int32_t& aStartOffset,
    151      const int32_t& aEndOffset, const uint32_t& aCoordinateType,
    152      const int32_t& aX, const int32_t& aY) override;
    153 
    154  virtual mozilla::ipc::IPCResult RecvAckMutationEvents() override;
    155 
    156 private:
    157  // Set to true if we have sent mutation events that have not yet been
    158  // acknowledged by the parent process. We only request and receive one ACK per
    159  // tick, regardless of how many mutation events we send. Additional ticks
    160  // cannot occur (and thus additional mutation events cannot be sent) before we
    161  // receive this ACK.
    162  bool mHasUnackedMutationEvents = false;
    163 
    164 protected:
    165  static void FlattenTree(LocalAccessible* aRoot,
    166                          nsTArray<LocalAccessible*>& aTree);
    167 
    168  static AccessibleData SerializeAcc(LocalAccessible* aAcc);
    169 
    170  void DetachDocument() {
    171    if (mDoc) {
    172      mDoc->SetIPCDoc(nullptr);
    173      mDoc = nullptr;
    174    }
    175  }
    176 
    177  LocalAccessible* IdToAccessible(const uint64_t& aID) const;
    178  HyperTextAccessible* IdToHyperTextAccessible(const uint64_t& aID) const;
    179 
    180  DocAccessible* mDoc;
    181 
    182  // Utility structure that encapsulates mutation event batching.
    183  struct MutationEventBatcher {
    184    void PushMutationEventData(MutationEventData aData, uint32_t aAccCount,
    185                               DocAccessibleChild& aDocAcc);
    186    void SendQueuedMutationEvents(DocAccessibleChild& aDocAcc);
    187    uint32_t AccCount() const { return mAccCount; }
    188    size_t EventCount() const { return mMutationEventData.Length(); }
    189 
    190   private:
    191    // A batch of mutation events to be sent in one IPC message.
    192    nsTArray<MutationEventData> mMutationEventData;
    193 
    194    // The number of accessibles in the mutation event data batch. A show event
    195    // may have many accessibles shown, where each accessible in the show event
    196    // counts separately here. Every other mutation event adds one to this
    197    // count.
    198    uint32_t mAccCount = 0;
    199  };
    200  MutationEventBatcher mMutationEventBatcher;
    201 
    202  friend void DocAccessible::DoInitialUpdate();
    203 };
    204 
    205 }  // namespace a11y
    206 }  // namespace mozilla
    207 
    208 #endif  // mozilla_a11y_DocAccessibleChild_h