Bug 1468754 Part 5: Make some server methods async and track changes made in NodeActor.modifyProperties.
MozReview-Commit-ID: 4oXfVRKz8u3
--- a/devtools/server/actors/inspector/node.js
+++ b/devtools/server/actors/inspector/node.js
@@ -642,30 +642,61 @@ const NodeActor = protocol.ActorClassWit
* attributeNamespace: <optional string>
* newValue: <optional string> - If null or undefined, the attribute
* will be removed.
* }
*
* Returns when the modifications have been made. Mutations will
* be queued for any changes made.
*/
- modifyAttributes: function(modifications) {
+ async modifyAttributes(modifications) {
const rawNode = this.rawNode;
+
+ // Keep our inspector's ChangesActor informed of these changes.
+ const changesActor = await this.walker.inspector.getChanges();
+
for (const change of modifications) {
if (change.newValue == null) {
if (change.attributeNamespace) {
+ const oldValue = rawNode.getAttributeNS(change.attributeNamespace,
+ change.attributeName);
+ changesActor.pushAttributeChange(rawNode,
+ change.attributeNamespace,
+ change.attributeName,
+ oldValue,
+ null);
rawNode.removeAttributeNS(change.attributeNamespace,
change.attributeName);
+
} else {
+ const oldValue = rawNode.getAttribute(change.attributeName);
+ changesActor.pushAttributeChange(rawNode,
+ null,
+ change.attributeName,
+ oldValue,
+ null);
rawNode.removeAttribute(change.attributeName);
}
} else if (change.attributeNamespace) {
+ const oldValue = rawNode.getAttribute(change.attributeNamespace,
+ change.attributeName);
+ changesActor.pushAttributeChange(rawNode,
+ change.attributeNamespace,
+ change.attributeName,
+ oldValue,
+ change.newValue);
rawNode.setAttributeNS(change.attributeNamespace, change.attributeName,
change.newValue);
} else {
+ const oldValue = rawNode.getAttribute(change.attributeName);
+ changesActor.pushAttributeChange(rawNode,
+ null,
+ change.attributeName,
+ oldValue,
+ change.newValue);
rawNode.setAttribute(change.attributeName, change.newValue);
}
}
},
/**
* Given the font and fill style, get the image data of a canvas with the
* preview text and font.
--- a/devtools/server/actors/inspector/walker.js
+++ b/devtools/server/actors/inspector/walker.js
@@ -1356,17 +1356,17 @@ var WalkerActor = protocol.ActorClassWit
},
/**
* Set a node's outerHTML property.
*
* @param {NodeActor} node The node.
* @param {string} value The piece of HTML content.
*/
- setOuterHTML: function(node, value) {
+ async setOuterHTML(node, value) {
if (isNodeDead(node)) {
return;
}
const parsedDOM = new DOMParser().parseFromString(value, "text/html");
const rawNode = node.rawNode;
const parentNode = rawNode.parentNode;
@@ -1400,17 +1400,17 @@ var WalkerActor = protocol.ActorClassWit
attributeModifications[attribute.name] = attribute.value;
}
for (const key in attributeModifications) {
finalAttributeModifications.push({
attributeName: key,
newValue: attributeModifications[key]
});
}
- node.modifyAttributes(finalAttributeModifications);
+ await node.modifyAttributes(finalAttributeModifications);
rawNode.replaceChild(parsedDOM.head, rawNode.querySelector("head"));
rawNode.replaceChild(parsedDOM.body, rawNode.querySelector("body"));
} else {
// eslint-disable-next-line no-unsanitized/property
rawNode.outerHTML = value;
}
},