Commit 3c196757 authored by Nicolas Chevobbe's avatar Nicolas Chevobbe
Browse files

Bug 1730167 - [devtools] Use appropriate walker front to retrieve frame...

Bug 1730167 - [devtools] Use appropriate walker front to retrieve frame children when EFT is enabled in a11y panel. r=ochameau.

This is a similar change to what was done to node actors in the previous patch
of this queue.

Differential Revision: https://phabricator.services.mozilla.com/D126804
parent 58313c2a
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -43,11 +43,14 @@ class AccessibleFront extends FrontClassWithSpec(accessibleSpec) {
    return this.getParent();
  }

  get remoteFrame() {
  get useChildTargetToFetchChildren() {
    if (!BROWSER_TOOLBOX_FISSION_ENABLED && this.targetFront.isParentProcess) {
      return false;
    }
    return this._form.remoteFrame;
    // @backward-compat { version 94 } useChildTargetToFetchChildren was added in 94, so
    // we still need to check for `remoteFrame` when connecting to older server.
    // When 94 is in release, we can check useChildTargetToFetchChildren only
    return this._form.useChildTargetToFetchChildren || this._form.remoteFrame;
  }

  get role() {
@@ -173,7 +176,7 @@ class AccessibleFront extends FrontClassWithSpec(accessibleSpec) {
  }

  async children() {
    if (!this.remoteFrame) {
    if (!this.useChildTargetToFetchChildren) {
      return super.children();
    }

@@ -212,7 +215,7 @@ class AccessibleFront extends FrontClassWithSpec(accessibleSpec) {
   *         Complete snapshot of current accessible front.
   */
  async _accumulateSnapshot(snapshot) {
    const { childCount, remoteFrame } = snapshot;
    const { childCount, useChildTargetToFetchChildren } = snapshot;
    // No children, we are done.
    if (childCount === 0) {
      return snapshot;
@@ -220,7 +223,7 @@ class AccessibleFront extends FrontClassWithSpec(accessibleSpec) {

    // If current accessible is not a remote frame, continue accumulating inside
    // its children.
    if (!remoteFrame) {
    if (!useChildTargetToFetchChildren) {
      const childSnapshots = [];
      for (const childSnapshot of snapshot.children) {
        childSnapshots.push(this._accumulateSnapshot(childSnapshot));
@@ -235,9 +238,9 @@ class AccessibleFront extends FrontClassWithSpec(accessibleSpec) {
    const frameNodeFront = await inspectorFront.getNodeActorFromContentDomReference(
      snapshot.contentDOMReference
    );
    // Remove contentDOMReference and remoteFrame properties.
    // Remove contentDOMReference and useChildTargetToFetchChildren properties.
    delete snapshot.contentDOMReference;
    delete snapshot.remoteFrame;
    delete snapshot.useChildTargetToFetchChildren;
    if (!frameNodeFront) {
      return snapshot;
    }
@@ -484,7 +487,7 @@ class AccessibleWalkerFront extends FrontClassWithSpec(accessibleWalkerSpec) {
    // If no remote frames were found, currentElm will be null.
    while (currentElm) {
      // Safety check to ensure that the currentElm is a remote frame.
      if (currentElm.remoteFrame) {
      if (currentElm.useChildTargetToFetchChildren) {
        const {
          walker: domWalkerFront,
        } = await currentElm.targetFront.getFront("inspector");
+27 −12
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ loader.lazyRequireGetter(
);
loader.lazyRequireGetter(
  this,
  "isRemoteFrame",
  "isFrameWithChildTarget",
  "devtools/shared/layout/utils",
  true
);
@@ -110,10 +110,11 @@ function getNodeDescription(node) {
 * @param  {nsIAccessibilityService} a11yService
 *         Accessibility service instance in the current process, used to get localized
 *         string representation of various accessible properties.
 * @param  {WindowGlobalTargetActor} targetActor
 * @return {JSON}
 *         JSON snapshot of the accessibility tree with root at current accessible.
 */
function getSnapshot(acc, a11yService) {
function getSnapshot(acc, a11yService, targetActor) {
  if (isDefunct(acc)) {
    return {
      states: [a11yService.getStringStates(0, STATE_DEFUNCT)],
@@ -139,7 +140,14 @@ function getSnapshot(acc, a11yService) {

  const children = [];
  for (let child = acc.firstChild; child; child = child.nextSibling) {
    children.push(getSnapshot(child, a11yService));
    // Ignore children from different documents when we have targets for every documents.
    if (
      targetActor.ignoreSubFrames &&
      child.DOMNode.ownerDocument !== targetActor.contentDocument
    ) {
      continue;
    }
    children.push(getSnapshot(child, a11yService, targetActor));
  }

  const { nodeType, nodeCssSelector } = getNodeDescription(acc.DOMNode);
@@ -158,11 +166,11 @@ function getSnapshot(acc, a11yService) {
    children,
    attributes,
  };
  const remoteFrame =
  const useChildTargetToFetchChildren =
    acc.role === Ci.nsIAccessibleRole.ROLE_INTERNAL_FRAME &&
    isRemoteFrame(acc.DOMNode);
  if (remoteFrame) {
    snapshot.remoteFrame = remoteFrame;
    isFrameWithChildTarget(targetActor, acc.DOMNode);
  if (useChildTargetToFetchChildren) {
    snapshot.useChildTargetToFetchChildren = useChildTargetToFetchChildren;
    snapshot.childCount = 1;
    snapshot.contentDOMReference = ContentDOMReference.get(acc.DOMNode);
  }
@@ -260,7 +268,7 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
    }
    // In case of a remote frame declare at least one child (the #document
    // element) so that they can be expanded.
    if (this.remoteFrame) {
    if (this.useChildTargetToFetchChildren) {
      return 1;
    }

@@ -432,14 +440,17 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
    return relationObjects;
  },

  get remoteFrame() {
  get useChildTargetToFetchChildren() {
    if (this.isDefunct) {
      return false;
    }

    return (
      this.rawAccessible.role === Ci.nsIAccessibleRole.ROLE_INTERNAL_FRAME &&
      isRemoteFrame(this.rawAccessible.DOMNode)
      isFrameWithChildTarget(
        this.walker.targetActor,
        this.rawAccessible.DOMNode
      )
    );
  },

@@ -448,7 +459,7 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
      actor: this.actorID,
      role: this.role,
      name: this.name,
      remoteFrame: this.remoteFrame,
      useChildTargetToFetchChildren: this.useChildTargetToFetchChildren,
      childCount: this.childCount,
      checks: this._lastAudit,
    };
@@ -626,7 +637,11 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
  },

  snapshot() {
    return getSnapshot(this.rawAccessible, this.walker.a11yService);
    return getSnapshot(
      this.rawAccessible,
      this.walker.a11yService,
      this.walker.targetActor
    );
  },
});