Bug 1680440 - [devtools] Remove backward compatibility code in getNodeFrontFromNodeGrip. r=ladybenko,devtools-backward-compat-reviewers.

Since we now always have a contentDomReference in grips, we
don't need to fallback on gripToNodeFront.
And since gripToNodeFront was only used from getNodeFrontFromNodeGrip,
we can remove it, as well as the walker actor method getNodeActorFromObjectActor.

We also had to get a content reference from a rendered Reps in the console, for
the "Reveal in inspector" context menu entry, so we stringigy it in a data attribute.

Differential Revision: https://phabricator.services.mozilla.com/D98720
This commit is contained in:
Nicolas Chevobbe 2020-12-11 13:53:14 +00:00
Родитель 920d7235e4
Коммит 48fff0a45c
10 изменённых файлов: 26 добавлений и 67 удалений

Просмотреть файл

@ -3963,14 +3963,11 @@ Toolbox.prototype = {
);
},
viewElementInInspector: async function(objectActor, reason) {
viewElementInInspector: async function(objectGrip, reason) {
// Open the inspector and select the DOM Element.
await this.loadTool("inspector");
const inspector = this.getPanel("inspector");
const nodeFound = await inspector.inspectNodeActor(
objectActor.actor,
reason
);
const nodeFound = await inspector.inspectNodeActor(objectGrip, reason);
if (nodeFound) {
await this.selectTool("inspector", reason);
}

Просмотреть файл

@ -176,14 +176,6 @@ class InspectorFront extends FrontClassWithSpec(inspectorSpec) {
* if the NodeFront couldn't be created/retrieved.
*/
async getNodeFrontFromNodeGrip(grip) {
// @backward-compat { version 71 } If the grip does not have a contentDomReference,
// we can't know in which browsing context id the node lives.
// We fall back on gripToNodeFront that might retrieve the expected nodeFront.
const gripHasContentDomReference = "contentDomReference" in grip;
if (!gripHasContentDomReference) {
return this.walker.gripToNodeFront(grip);
}
return this.getNodeActorFromContentDomReference(grip.contentDomReference);
}

Просмотреть файл

@ -146,17 +146,6 @@ class WalkerFront extends FrontClassWithSpec(walkerSpec) {
return response.node;
}
async gripToNodeFront(grip) {
const response = await this.getNodeActorFromObjectActor(grip.actor);
const nodeFront = response ? response.node : null;
if (!nodeFront) {
throw new Error(
"The ValueGrip passed could not be translated to a NodeFront"
);
}
return nodeFront;
}
async getNodeActorFromWindowID(windowID) {
const response = await super.getNodeActorFromWindowID(windowID);
return response ? response.node : null;

Просмотреть файл

@ -1948,10 +1948,10 @@ Inspector.prototype = {
);
},
async inspectNodeActor(nodeActor, reason) {
const nodeFront = await this.inspectorFront.getNodeFrontFromNodeGrip({
actor: nodeActor,
});
async inspectNodeActor(nodeGrip, reason) {
const nodeFront = await this.inspectorFront.getNodeFrontFromNodeGrip(
nodeGrip
);
if (!nodeFront) {
console.error(
"The object cannot be linked to the inspector, the " +

Просмотреть файл

@ -121,6 +121,9 @@ define(function(require, exports, module) {
// Initiate config
const config = {
"data-link-actor-id": object.actor,
"data-link-content-dom-reference": JSON.stringify(
object.contentDomReference
),
className: "objectBox objectBox-node",
};

Просмотреть файл

@ -67,6 +67,9 @@ define(function(require, exports, module) {
const config = {
"data-link-actor-id": object.actor,
"data-link-content-dom-reference": JSON.stringify(
object.contentDomReference
),
className: "objectBox objectBox-textNode",
title: shouldRenderTooltip ? `#text "${getTextContent(object)}"` : null,
};

Просмотреть файл

@ -34,9 +34,9 @@ function unHighlightDomElement(grip) {
};
}
function openNodeInInspector(actor) {
function openNodeInInspector(contentDomReference) {
return ({ hud }) => {
hud.openNodeInInspector({ actor: actor });
hud.openNodeInInspector({ contentDomReference });
};
}

Просмотреть файл

@ -144,14 +144,24 @@ function createContextMenu(event, message, webConsoleWrapper) {
);
// Open DOM node in the Inspector panel.
if (isConnectedElement) {
const contentDomReferenceEl = target.closest(
"[data-link-content-dom-reference]"
);
if (isConnectedElement && contentDomReferenceEl) {
const contentDomReference = contentDomReferenceEl.getAttribute(
"data-link-content-dom-reference"
);
menu.append(
new MenuItem({
id: "console-menu-open-node",
label: l10n.getStr("webconsole.menu.openNodeInInspector.label"),
accesskey: l10n.getStr("webconsole.menu.openNodeInInspector.accesskey"),
disabled: false,
click: () => dispatch(actions.openNodeInInspector(actor)),
click: () =>
dispatch(
actions.openNodeInInspector(JSON.parse(contentDomReference))
),
})
);
}

Просмотреть файл

@ -2620,33 +2620,6 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
return this._isInDOMTree(node.rawNode);
},
/**
* Given an ObjectActor (identified by its ID), commonly used in the debugger,
* webconsole and variablesView, return the corresponding inspector's
* NodeActor
*/
getNodeActorFromObjectActor: function(objectActorID) {
const actor = this.conn.getActor(objectActorID);
if (!actor) {
return null;
}
const debuggerObject = this.conn.getActor(objectActorID).obj;
let rawNode = debuggerObject.unsafeDereference();
if (!this._isInDOMTree(rawNode)) {
return null;
}
// This is a special case for the document object whereby it is considered
// as document.documentElement (the <html> node)
if (rawNode.defaultView && rawNode === rawNode.defaultView.document) {
rawNode = rawNode.documentElement;
}
return this.attachElement(rawNode);
},
/**
* Given a windowID return the NodeActor for the corresponding frameElement,
* unless it's the root window

Просмотреть файл

@ -287,14 +287,6 @@ const walkerSpec = generateActorSpec({
request: { node: Arg(0, "domnode") },
response: { attached: RetVal("boolean") },
},
getNodeActorFromObjectActor: {
request: {
objectActorID: Arg(0, "string"),
},
response: {
nodeFront: RetVal("nullable:disconnectedNode"),
},
},
getNodeActorFromWindowID: {
request: {
windowID: Arg(0, "string"),