Verified Commit 9022c51d authored by James Teh's avatar James Teh Committed by ma1
Browse files

Bug 2052562: Don't allow moves into a detached subtree. a=pascalc

parent d35af1a8
Loading
Loading
Loading
Loading
+22 −11
Original line number Diff line number Diff line
@@ -141,6 +141,16 @@ mozilla::ipc::IPCResult DocAccessibleParent::ProcessShowEvent(
      // This is the first Accessible, which is the root of the shown subtree.
      root = child;
      rootParent = parent;
      if (!aComplete) {
        // This is the first message for a show event split across multiple
        // messages. Save the show target for subsequent messages and return.
        mPendingShowChild = accData.ID();
        mPendingShowParent = accData.ParentID();
        mPendingShowIndex = accData.IndexInParent();
        if (!rootParent->IsDoc() && !rootParent->RemoteParent()) {
          return IPC_FAIL(this, "Attempt to split show with detached root");
        }
      }
    }
    // If this show event has been split across multiple messages and this is
    // not the last message, don't attach the shown root to the tree yet.
@@ -155,21 +165,11 @@ mozilla::ipc::IPCResult DocAccessibleParent::ProcessShowEvent(

  MOZ_ASSERT(CheckDocTree());

  if (!aComplete && !mPendingShowChild) {
    // This is the first message for a show event split across multiple
    // messages. Save the show target for subsequent messages and return.
    const auto& accData = aNewTree[0];
    mPendingShowChild = accData.ID();
    mPendingShowParent = accData.ParentID();
    mPendingShowIndex = accData.IndexInParent();
    return IPC_OK();
  }
  if (!aComplete) {
    // This show event has been split into multiple messages, but this is
    // neither the first nor the last message. There's nothing more to do here.
    // not the last message. There's nothing more to do here.
    return IPC_OK();
  }
  MOZ_ASSERT(aComplete);
  if (mPendingShowChild) {
    // This is the last message for a show event split across multiple
    // messages. Retrieve the saved show target, attach it to the tree and fire
@@ -242,6 +242,8 @@ RemoteAccessible* DocAccessibleParent::CreateAcc(
          "Attempt to move RemoteAccessible which has a pending parent");
      return nullptr;
    }
    MOZ_RELEASE_ASSERT(newProxy->ChildCount() == 0 || newProxy->IsOuterDoc(),
                       "Reused RemoteAccessible unexpectedly has children!");
    return newProxy;
  }

@@ -293,6 +295,15 @@ bool DocAccessibleParent::AttachChild(RemoteAccessible* aParent,
    return false;
  }

  if (!aParent->IsDoc() && !aParent->RemoteParent() &&
      aParent->ID() != mPendingShowChild) {
    MOZ_ASSERT_UNREACHABLE("Attempt to attach child to a detached parent!");
    return false;
  }

  MOZ_RELEASE_ASSERT(!mPendingShowChild || aChild->ID() != mPendingShowParent,
                     "Attempt to attach the pending show's parent as a child!");

  if (aParent == aChild) {
    MOZ_ASSERT_UNREACHABLE("Attempt to make an accessible its own child!");
    return false;