Bug 1512665 - Clear changes only when parent document navigates, not iframes; r=bradwerth, a=RyanVM
authorRazvan Caliman <rcaliman@mozilla.com>
Thu, 13 Dec 2018 16:19:08 +0000
changeset 509006 23693d234e3707f419b60eac254633031ef94dd5
parent 509005 bc01e30511057c6b9b3c7c728675c016806d67b5
child 509007 d68c09b685cc5a7fb915fed38c0201c0c48a62ff
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbradwerth, RyanVM
bugs1512665
milestone65.0
Bug 1512665 - Clear changes only when parent document navigates, not iframes; r=bradwerth, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D14460
devtools/server/actors/changes.js
--- a/devtools/server/actors/changes.js
+++ b/devtools/server/actors/changes.js
@@ -21,17 +21,17 @@ const ChangesActor = protocol.ActorClass
    * @param {TargetActor} targetActor
    *    The top-level Actor for this tab.
    */
   initialize: function(conn, targetActor) {
     protocol.Actor.prototype.initialize.call(this, conn);
     this.targetActor = targetActor;
 
     this.onTrackChange = this.pushChange.bind(this);
-    this.onWillNavigate = this.clearChanges.bind(this);
+    this.onWillNavigate = this.onWillNavigate.bind(this);
 
     TrackChangeEmitter.on("track-change", this.onTrackChange);
     this.targetActor.on("will-navigate", this.onWillNavigate);
 
     this.changes = [];
   },
 
   destroy: function() {
@@ -69,16 +69,38 @@ const ChangesActor = protocol.ActorClass
      * to get their initial state synchronized with the ChangesActor. We
      * set a flag when this function is called so we know that it's worthwhile
      * to send events.
      */
     this._changesHaveBeenRequested = true;
     return this.changes.slice();
   },
 
+  /**
+   * Handler for "will-navigate" event from the browsing context. The event is fired for
+   * the host page and any nested resources, like iframes. The list of changes should be
+   * cleared only when the host page navigates, ignoring any of its iframes.
+   *
+   * TODO: Clear changes made within sources in iframes when they navigate. Bug 1513940
+   *
+   * @param {Object} eventData
+   *        Event data with these properties:
+   *        {
+   *          window: Object      // Window DOM object of the event source page
+   *          isTopLevel: Boolean // true if the host page will navigate
+   *          newURI: String      // URI towards which the page will navigate
+   *          request: Object     // Request data.
+   *        }
+   */
+  onWillNavigate: function(eventData) {
+    if (eventData.isTopLevel) {
+      this.clearChanges();
+    }
+  },
+
   pushChange: function(change) {
     this.changes.push(change);
     if (this._changesHaveBeenRequested) {
       this.emit("add-change", change);
     }
   },
 
   popChange: function() {