Bug 1468754 Part 5: Make some server methods async and track changes made in NodeActor.modifyProperties. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 20 Jul 2018 15:53:33 -0700
changeset 826141 f032a2fc2b0237383a950635a4723b47bbad1254
parent 826140 caf0102c0b4d9452a5d102d382e2a98146bcdb6a
child 826142 fed4a2ecea15714bd04b4f65144a50550415e1a4
push id118245
push userbwerth@mozilla.com
push dateFri, 03 Aug 2018 00:03:09 +0000
bugs1468754
milestone63.0a1
Bug 1468754 Part 5: Make some server methods async and track changes made in NodeActor.modifyProperties. MozReview-Commit-ID: 4oXfVRKz8u3
devtools/server/actors/inspector/node.js
devtools/server/actors/inspector/walker.js
--- 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;
     }
   },