Bug 1456274 - Remove local progress listener in DevTools target. r=ochameau draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Mon, 23 Apr 2018 19:09:40 -0500
changeset 788113 1b297758ff835a7378698ab88e1bfec936bf9fdf
parent 788112 99c19a66c3a2fbf8108d4b8a161cded31e948409
child 788114 4036e713829d82493983441b35af76b10d0837bd
push id107908
push userbmo:jryans@gmail.com
push dateWed, 25 Apr 2018 23:00:31 +0000
reviewersochameau
bugs1456274
milestone61.0a1
Bug 1456274 - Remove local progress listener in DevTools target. r=ochameau DevTools targets have used a local progress listener for a long time to track tab navigation. However, this is redundant with server side code that does the same thing. Removing this from the target reduces differences between local and remote debugging. It also simplifies one piece of the target, which is a massively twisted module. MozReview-Commit-ID: E7lm4GUFZQO
devtools/client/framework/target.js
--- a/devtools/client/framework/target.js
+++ b/devtools/client/framework/target.js
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const { Ci } = require("chrome");
 const defer = require("devtools/shared/defer");
 const EventEmitter = require("devtools/shared/event-emitter");
 const Services = require("Services");
-const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
 
 loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true);
 loader.lazyRequireGetter(this, "DebuggerClient",
   "devtools/shared/client/debugger-client", true);
 loader.lazyRequireGetter(this, "gDevTools",
   "devtools/client/framework/devtools", true);
 
 const targets = new WeakMap();
@@ -140,18 +139,16 @@ function TabTarget(tab) {
   } else {
     this._isTabActor = true;
   }
 }
 
 exports.TabTarget = TabTarget;
 
 TabTarget.prototype = {
-  _webProgressListener: null,
-
   /**
    * Returns a promise for the protocol description from the root actor. Used
    * internally with `target.actorHasMethod`. Takes advantage of caching if
    * definition was fetched previously with the corresponding actor information.
    * Actors are lazily loaded, so not only must the tool using a specific actor
    * be in use, the actors are only registered after invoking a method (for
    * performance reasons, added in bug 988237), so to use these actor detection
    * methods, one must already be communicating with a specific actor of that
@@ -491,32 +488,26 @@ TabTarget.prototype = {
 
     return this._remote.promise;
   },
 
   /**
    * Listen to the different events.
    */
   _setupListeners: function() {
-    this._webProgressListener = new TabWebProgressListener(this);
-    this.tab.linkedBrowser.addProgressListener(this._webProgressListener);
     this.tab.addEventListener("TabClose", this);
     this.tab.parentNode.addEventListener("TabSelect", this);
     this.tab.ownerDocument.defaultView.addEventListener("unload", this);
     this.tab.addEventListener("TabRemotenessChange", this);
   },
 
   /**
    * Teardown event listeners.
    */
   _teardownListeners: function() {
-    if (this._webProgressListener) {
-      this._webProgressListener.destroy();
-    }
-
     this._tab.ownerDocument.defaultView.removeEventListener("unload", this);
     this._tab.removeEventListener("TabClose", this);
     this._tab.parentNode.removeEventListener("TabSelect", this);
     this._tab.removeEventListener("TabRemotenessChange", this);
   },
 
   /**
    * Setup listeners for remote debugging, updating existing ones as necessary.
@@ -755,91 +746,16 @@ TabTarget.prototype = {
         text,
         category,
       };
       this.client.request(packet);
     }
   },
 };
 
-/**
- * WebProgressListener for TabTarget.
- *
- * @param object target
- *        The TabTarget instance to work with.
- */
-function TabWebProgressListener(target) {
-  this.target = target;
-}
-
-TabWebProgressListener.prototype = {
-  target: null,
-
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
-                                         Ci.nsISupportsWeakReference]),
-
-  onStateChange: function(progress, request, flag) {
-    let isStart = flag & Ci.nsIWebProgressListener.STATE_START;
-    let isDocument = flag & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT;
-    let isNetwork = flag & Ci.nsIWebProgressListener.STATE_IS_NETWORK;
-    let isRequest = flag & Ci.nsIWebProgressListener.STATE_IS_REQUEST;
-
-    // Skip non-interesting states.
-    if (!isStart || !isDocument || !isRequest || !isNetwork) {
-      return;
-    }
-
-    // emit event if the top frame is navigating
-    if (progress.isTopLevel) {
-      // Emit the event if the target is not remoted or store the payload for
-      // later emission otherwise.
-      if (this.target._client) {
-        this.target._navRequest = request;
-      } else {
-        this.target.emit("will-navigate", request);
-      }
-    }
-  },
-
-  onProgressChange: function() {},
-  onSecurityChange: function() {},
-  onStatusChange: function() {},
-
-  onLocationChange: function(webProgress, request, URI, flags) {
-    if (this.target &&
-        !(flags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT)) {
-      let window = webProgress.DOMWindow;
-      // Emit the event if the target is not remoted or store the payload for
-      // later emission otherwise.
-      if (this.target._client) {
-        this.target._navWindow = window;
-      } else {
-        this.target.emit("navigate", window);
-      }
-    }
-  },
-
-  /**
-   * Destroy the progress listener instance.
-   */
-  destroy: function() {
-    if (this.target.tab) {
-      try {
-        this.target.tab.linkedBrowser.removeProgressListener(this);
-      } catch (ex) {
-        // This can throw when a tab crashes in e10s.
-      }
-    }
-    this.target._webProgressListener = null;
-    this.target._navRequest = null;
-    this.target._navWindow = null;
-    this.target = null;
-  }
-};
-
 function WorkerTarget(workerClient) {
   EventEmitter.decorate(this);
   this._workerClient = workerClient;
 }
 
 /**
  * A WorkerTarget represents a worker. Unlike TabTarget, which can represent
  * either a local or remote tab, WorkerTarget always represents a remote worker.