Closed Bug 1568126 Opened 5 years ago Closed 5 years ago

Fetch the inspector and its related fronts (walker, highlighter, selection) via the nodeFront rather than from toolbox or inspector panel singleton

Categories

(DevTools :: Inspector, enhancement, P1)

enhancement

Tracking

(firefox71 fixed)

RESOLVED FIXED
Firefox 71
Tracking Status
firefox71 --- fixed

People

(Reporter: ochameau, Assigned: gl)

References

(Blocks 1 open bug)

Details

(Whiteboard: dt-fission-m1)

Attachments

(3 files, 2 obsolete files)

For now, the whole codebase assumes that the inspector front is unique.
But with Fission, we will start having more than one. We will still have the one related to the top level tab document, but we will then have one per iframe running in a distinct process.

This change makes it so that we can't be using a static reference to just one inspector front.
We should rather dynamically retrieve the inspector front which relates to the current context we are currently inspecting.

For example, this markup view code:
https://searchfox.org/mozilla-central/rev/4436573fa3d5c4311822090e188504c10c916c6f/devtools/client/inspector/markup/markup.js#2172-2185

  /**
   * Return a list of the children to display for this container.
   */
  _getVisibleChildren: function(container, centered) {
    let maxChildren = container.maxChildren || this.maxChildren;
    if (maxChildren == -1) {
      maxChildren = undefined;
    }

    return this.walker.children(container.node, {
      maxNodes: maxChildren,
      center: centered,
    });
  },

this.walker.children will break with fission as we have to call the WalkerFront related to the current node we are expanding. Not just one hardcoded WalkerFront, which today, will always be the WalkerFront of the top level tab's document. If container.node relates to a DOM Element from an iframe running in a distinct process, we have to call children on the WalkerFront related to this distinct process, and not the one related to the top level document's process.

This work depends on bug 1539764, which is meant to expose the related target object on all the fronts. Then, from the target object, you can derivate almost all other fronts.
For example:
const inspectorFront = target.getInspector();
const walkerFront = target.getInspector().walker;
const consoleFront = target.getFront("console");
const threadFront = target.getFront("thread");
Note that the inspector is special and still requires a special getInspector() method. Some work is still required in order to replace this by getFront("inspector"). But this work is independant from this one.

Once bug 1539764 is completed we should be able to replace
this.walker.children(container.node, ...)
by:

const inspectorFront = await container.node.getTargetToBeImplementedInBug1539764().getInspector();
inspectorFront.walker.children(container.node, ...);

This is just an example, this may be different. For example we may try to expose a synchronous API rather than the async getFront/getInspector. We can have an attribute instead of a function on Front...

Whiteboard: dt-fission
Priority: -- → P2

Selection was extracted from InspectorFront to Toolbox in bug 1572460

I think we are going to fix these problems in multiple different bugs. Some have been fixed already, and this will continue.
I think we should be able to close this one.

Assignee: nobody → gl
Status: NEW → ASSIGNED
Priority: P2 → P1

So, I went over the codebase to try and find occurrences of code that still need to be changed. A bunch of them are related to features we will fix in M2, so I ignored these ones. From what I can see, the following pieces of code do need to be fixed in this bug:

devtools/client/inspector/shared/style-change-tracker.js
27 this.walker.on("mutations", this.onMutations);
34 this.walker.off("mutations", this.onMutations);
devtools/client/inspector/shared/highlighters-overlay.js
1107 const isInTree = await this.walker.isInDOMTree(node);
devtools/client/inspector/markup/markup.js
316 this.walker.on("display-change", this._onWalkerNodeStatesChanged);
317 this.walker.on("scrollable-change", this._onWalkerNodeStatesChanged);
318 this.walker.on("mutations", this._mutationObserver);
2298 this.walker.off("display-change", this._onWalkerNodeStatesChanged);
2299 this.walker.off("scrollable-change", this._onWalkerNodeStatesChanged);
2300 this.walker.off("mutations", this._mutationObserver);
devtools/client/inspector/inspector.js
460 return walker.querySelector(rootNode, this.selectionCssSelector);
474 return walker.querySelector(rootNode, "body");
486 return this.walker.documentElement();

(In reply to Patrick Brosset <:pbro> from comment #3)

devtools/client/inspector/inspector.js
460 return walker.querySelector(rootNode, this.selectionCssSelector);
474 return walker.querySelector(rootNode, "body");
486 return this.walker.documentElement();

I think these ones are fine since they are related to getting the default selection on a new root. Unless the current target is updated on each new root/navigation and therefore we need to get a new WalkerFront, I don't think we need to do anything here. @ochameau can you confirm if this thinking is correct?

Flags: needinfo?(poirot.alex)

(In reply to Gabriel [:gl] (ΦωΦ) from comment #5)

(In reply to Patrick Brosset <:pbro> from comment #3)

devtools/client/inspector/inspector.js
460 return walker.querySelector(rootNode, this.selectionCssSelector);
474 return walker.querySelector(rootNode, "body");
486 return this.walker.documentElement();

I think these ones are fine since they are related to getting the default selection on a new root. Unless the current target is updated on each new root/navigation and therefore we need to get a new WalkerFront, I don't think we need to do anything here. @ochameau can you confirm if this thinking is correct?

I think the 2 last lines are indeed fine, you are right.
However the first one worries me, because I don't even remember how it works today across normal iframes. I'll do some research and report back.

Ok, the feature that re-selects the last selected node in the inspector does not work across iframes today. So there's no point trying to make it work with fission. We just want parity now. We should file a bug to add iframe support in the future, but for the sake of the fission project in devtools, let's not worry about this. Which means, you're right, these 3 lines you mentioned are not anything we need to fix.
It would, however, be nice to add a comment near them that says that we use the top level walkerFront here on purpose, to always do the default selection on the top level document only.

+1
Note that if you happen to fix return walker.querySelector(rootNode, this.selectionCssSelector); and make it return a NodeFront from another iframe, you would have to change the two following callsites mentioned:

474 return walker.querySelector(rootNode, "body");
486 return this.walker.documentElement();
As this will modify rootNode and we should then use rootNode.walkerFront.querySelector as well as rootNode.walkerFront.documentElement.

Flags: needinfo?(poirot.alex)
Keywords: leave-open
Pushed by gluong@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/906c06cac59d
Part 1: Use the contextual WalkerFront in _hideHighlighterIfDeadNode. r=pbro
Backout by rgurzau@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6b9df1cffc79
Backed out changeset 906c06cac59d for devtools tests timing out e.g browser_rules_flexbox-highlighter-on-mutation.js on a CLOSED TREE.
Attachment #9100008 - Attachment is obsolete: true
Pushed by gluong@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/dc0dd7454893
Part 1: Use the contextual WalkerFront in _hideHighlighterIfDeadNode. r=pbro
Blocks: 1588868
Pushed by gluong@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/dc53e489f541
Part 2: Make InspectorStyleChangeTracker work with fission. r=ochameau
Pushed by gluong@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6470ba2c5a50
Part 3: Use the contextual WalkerFront in the markup view event handlers. r=ochameau
Keywords: leave-open
Blocks: 1589178
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 71
Attachment #9101935 - Attachment is obsolete: true
Whiteboard: dt-fission → dt-fission dt-fission-m1
Whiteboard: dt-fission dt-fission-m1 → dt-fission-m1
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: