Bug 1244227 - NetworkResponseListener does not need to implement nsIInterfaceRequestor. r=Honza draft
authorTom Tromey <tom@tromey.com>
Tue, 16 Feb 2016 15:03:23 -0700
changeset 396353 396be6287ef8802befc15bebb5e70194598d6bb5
parent 396352 87082f17550c81c4ba62ab16b3798e5f00aeaaf9
child 396354 fd4646cda4b497358e05e7e64c7c43ddda8e9d85
push id24964
push userbmo:ttromey@mozilla.com
push dateWed, 03 Aug 2016 17:20:57 +0000
reviewersHonza
bugs1244227
milestone51.0a1
Bug 1244227 - NetworkResponseListener does not need to implement nsIInterfaceRequestor. r=Honza MozReview-Commit-ID: 9TMlmdjQWLL
devtools/shared/webconsole/network-monitor.js
--- a/devtools/shared/webconsole/network-monitor.js
+++ b/devtools/shared/webconsole/network-monitor.js
@@ -297,75 +297,31 @@ exports.StackTraceCollector = StackTrace
  *        HttpActivity object associated with this request. See NetworkMonitor
  *        for more information.
  */
 function NetworkResponseListener(owner, httpActivity) {
   this.owner = owner;
   this.receivedData = "";
   this.httpActivity = httpActivity;
   this.bodySize = 0;
-  let channel = this.httpActivity.channel;
-  this._wrappedNotificationCallbacks = channel.notificationCallbacks;
-  channel.notificationCallbacks = this;
 }
 
 NetworkResponseListener.prototype = {
   QueryInterface:
     XPCOMUtils.generateQI([Ci.nsIStreamListener, Ci.nsIInputStreamCallback,
-                           Ci.nsIRequestObserver, Ci.nsIInterfaceRequestor,
-                           Ci.nsISupports]),
-
-  // nsIInterfaceRequestor implementation
-
-  /**
-   * This object implements nsIProgressEventSink, but also needs to forward
-   * interface requests to the notification callbacks of other objects.
-   */
-  getInterface(iid) {
-    if (iid.equals(Ci.nsIProgressEventSink)) {
-      return this;
-    }
-    if (this._wrappedNotificationCallbacks) {
-      return this._wrappedNotificationCallbacks.getInterface(iid);
-    }
-    throw Cr.NS_ERROR_NO_INTERFACE;
-  },
-
-  /**
-   * Forward notifications for interfaces this object implements, in case other
-   * objects also implemented them.
-   */
-  _forwardNotification(iid, method, args) {
-    if (!this._wrappedNotificationCallbacks) {
-      return;
-    }
-    try {
-      let impl = this._wrappedNotificationCallbacks.getInterface(iid);
-      impl[method].apply(impl, args);
-    } catch (e) {
-      if (e.result != Cr.NS_ERROR_NO_INTERFACE) {
-        throw e;
-      }
-    }
-  },
+                           Ci.nsIRequestObserver, Ci.nsISupports]),
 
   /**
    * This NetworkResponseListener tracks the NetworkMonitor.openResponses object
    * to find the associated uncached headers.
    * @private
    */
   _foundOpenResponse: false,
 
   /**
-   * If the channel already had notificationCallbacks, hold them here internally
-   * so that we can forward getInterface requests to that object.
-   */
-  _wrappedNotificationCallbacks: null,
-
-  /**
    * The response listener owner.
    */
   owner: null,
 
   /**
    * The response will be written into the outputStream of this nsIPipe.
    * Both ends of the pipe must be blocking.
    */
@@ -451,19 +407,16 @@ NetworkResponseListener.prototype = {
     // Converter will call this again, we should just ignore that.
     if (this.request) {
       return;
     }
 
     this.request = request;
     this._getSecurityInfo();
     this._findOpenResponse();
-    // We need to track the offset for the onDataAvailable calls where
-    // we pass the data from our pipe to the coverter.
-    this.offset = 0;
 
     // In the multi-process mode, the conversion happens on the child
     // side while we can only monitor the channel on the parent
     // side. If the content is gzipped, we have to unzip it
     // ourself. For that we use the stream converter services.  Do not
     // do that for Service workers as they are run in the child
     // process.
     let channel = this.request;
@@ -514,33 +467,16 @@ NetworkResponseListener.prototype = {
    * For more documentation about nsIRequestObserver go to:
    * https://developer.mozilla.org/En/NsIRequestObserver
    */
   onStopRequest: function () {
     this._findOpenResponse();
     this.sink.outputStream.close();
   },
 
-  // nsIProgressEventSink implementation
-
-  /**
-   * Handle progress event as data is transferred.  This is used to record the
-   * size on the wire, which may be compressed / encoded.
-   */
-  onProgress: function (request, context, progress, progressMax) {
-    this.transferredSize = progress;
-    // Need to forward as well to keep things like Download Manager's progress
-    // bar working properly.
-    this._forwardNotification(Ci.nsIProgressEventSink, "onProgress", arguments);
-  },
-
-  onStatus: function () {
-    this._forwardNotification(Ci.nsIProgressEventSink, "onStatus", arguments);
-  },
-
   /**
    * Find the open response object associated to the current request. The
    * NetworkMonitor._httpResponseExaminer() method saves the response headers in
    * NetworkMonitor.openResponses. This method takes the data from the open
    * response object and puts it into the HTTP activity object, then sends it to
    * the remote Web Console instance.
    *
    * @private
@@ -638,17 +574,16 @@ NetworkResponseListener.prototype = {
 
     this.receivedData = "";
 
     this.httpActivity.owner.addResponseContent(
       response,
       this.httpActivity.discardResponseBody
     );
 
-    this._wrappedNotificationCallbacks = null;
     this.httpActivity.channel = null;
     this.httpActivity.owner = null;
     this.httpActivity = null;
     this.sink = null;
     this.inputStream = null;
     this.converter = null;
     this.request = null;
     this.owner = null;
@@ -671,30 +606,33 @@ NetworkResponseListener.prototype = {
     try {
       // This may throw if the stream is closed normally or due to an error.
       available = stream.available();
     } catch (ex) {
       // Ignore.
     }
 
     if (available != -1) {
+      if (this.transferredSize === null) {
+        this.transferredSize = 0;
+      }
+
       if (available != 0) {
         if (this.converter) {
           this.converter.onDataAvailable(this.request, null, stream,
-                                         this.offset, available);
+                                         this.transferredSize, available);
         } else {
-          this.onDataAvailable(this.request, null, stream, this.offset,
+          this.onDataAvailable(this.request, null, stream, this.transferredSize,
                                available);
         }
       }
-      this.offset += available;
+      this.transferredSize += available;
       this.setAsyncListener(stream, this);
     } else {
       this.onStreamClose();
-      this.offset = 0;
     }
   },
 };
 
 /**
  * The network monitor uses the nsIHttpActivityDistributor to monitor network
  * requests. The nsIObserverService is also used for monitoring
  * http-on-examine-response notifications. All network request information is