Bug 862341 Part 3: Display cached network requests in the network panel. r=vporof
authorPanos Astithas <past@mozilla.com>
Tue, 28 Apr 2015 20:20:20 +0300
changeset 242941 f5f7375211fc791ec36154f837e2a4127d31b826
parent 242940 cba10c0c94343d97b88d78242bafefaff0245ee9
child 242942 6db74fd5b4474861726f4673bc233d8b1c19ec2c
push id28714
push userkwierso@gmail.com
push dateFri, 08 May 2015 17:29:48 +0000
treeherdermozilla-central@5e8adf0e7f2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvporof
bugs862341
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 862341 Part 3: Display cached network requests in the network panel. r=vporof
browser/devtools/netmonitor/netmonitor-controller.js
toolkit/devtools/webconsole/client.js
--- a/browser/devtools/netmonitor/netmonitor-controller.js
+++ b/browser/devtools/netmonitor/netmonitor-controller.js
@@ -522,119 +522,133 @@ NetworkEventsHandler.prototype = {
   get client() NetMonitorController._target.client,
   get webConsoleClient() NetMonitorController.webConsoleClient,
 
   /**
    * Connect to the current target client.
    */
   connect: function() {
     dumpn("NetworkEventsHandler is connecting...");
-    this.client.addListener("networkEvent", this._onNetworkEvent);
-    this.client.addListener("networkEventUpdate", this._onNetworkEventUpdate);
+    this.webConsoleClient.on("networkEvent", this._onNetworkEvent);
+    this.webConsoleClient.on("networkEventUpdate", this._onNetworkEventUpdate);
+    this._displayCachedEvents();
+  },
+
+  /**
+   * Display any network events already in the cache.
+   */
+  _displayCachedEvents: function() {
+    for (let cachedEvent of this.webConsoleClient.getNetworkEvents()) {
+      // First add the request to the timeline.
+      this._onNetworkEvent("networkEvent", cachedEvent);
+      // Then replay any updates already received.
+      for (let update of cachedEvent.updates) {
+        this._onNetworkEventUpdate("networkEventUpdate", {
+          packet: {
+            updateType: update
+          },
+          networkInfo: cachedEvent
+        });
+      }
+    }
   },
 
   /**
    * Disconnect from the client.
    */
   disconnect: function() {
     if (!this.client) {
       return;
     }
     dumpn("NetworkEventsHandler is disconnecting...");
-    this.client.removeListener("networkEvent", this._onNetworkEvent);
-    this.client.removeListener("networkEventUpdate", this._onNetworkEventUpdate);
+    this.webConsoleClient.off("networkEvent", this._onNetworkEvent);
+    this.webConsoleClient.off("networkEventUpdate", this._onNetworkEventUpdate);
   },
 
   /**
    * The "networkEvent" message type handler.
    *
-   * @param string aType
+   * @param string type
    *        Message type.
-   * @param object aPacket
-   *        The message received from the server.
+   * @param object networkInfo
+   *        The network request information.
    */
-  _onNetworkEvent: function(aType, aPacket) {
-    if (aPacket.from != this.webConsoleClient.actor) {
-      // Skip events from different console actors.
-      return;
-    }
+  _onNetworkEvent: function(type, networkInfo) {
+    let { actor, startedDateTime, request: { method, url }, isXHR, fromCache } = networkInfo;
 
-    let { actor, startedDateTime, method, url, isXHR, fromCache } = aPacket.eventActor;
     NetMonitorView.RequestsMenu.addRequest(
       actor, startedDateTime, method, url, isXHR, fromCache
     );
     window.emit(EVENTS.NETWORK_EVENT, actor);
   },
 
   /**
    * The "networkEventUpdate" message type handler.
    *
-   * @param string aType
+   * @param string type
    *        Message type.
-   * @param object aPacket
+   * @param object packet
    *        The message received from the server.
+   * @param object networkInfo
+   *        The network request information.
    */
-  _onNetworkEventUpdate: function(aType, aPacket) {
-    let actor = aPacket.from;
-    if (!NetMonitorView.RequestsMenu.getItemByValue(actor)) {
-      // Skip events from unknown actors.
-      return;
-    }
+  _onNetworkEventUpdate: function(type, { packet, networkInfo }) {
+    let actor = networkInfo.actor;
 
-    switch (aPacket.updateType) {
+    switch (packet.updateType) {
       case "requestHeaders":
         this.webConsoleClient.getRequestHeaders(actor, this._onRequestHeaders);
         window.emit(EVENTS.UPDATING_REQUEST_HEADERS, actor);
         break;
       case "requestCookies":
         this.webConsoleClient.getRequestCookies(actor, this._onRequestCookies);
         window.emit(EVENTS.UPDATING_REQUEST_COOKIES, actor);
         break;
       case "requestPostData":
         this.webConsoleClient.getRequestPostData(actor, this._onRequestPostData);
         window.emit(EVENTS.UPDATING_REQUEST_POST_DATA, actor);
         break;
       case "securityInfo":
-        NetMonitorView.RequestsMenu.updateRequest(aPacket.from, {
-          securityState: aPacket.state,
+        NetMonitorView.RequestsMenu.updateRequest(actor, {
+          securityState: networkInfo.securityInfo,
         });
         this.webConsoleClient.getSecurityInfo(actor, this._onSecurityInfo);
         window.emit(EVENTS.UPDATING_SECURITY_INFO, actor);
         break;
       case "responseHeaders":
         this.webConsoleClient.getResponseHeaders(actor, this._onResponseHeaders);
         window.emit(EVENTS.UPDATING_RESPONSE_HEADERS, actor);
         break;
       case "responseCookies":
         this.webConsoleClient.getResponseCookies(actor, this._onResponseCookies);
         window.emit(EVENTS.UPDATING_RESPONSE_COOKIES, actor);
         break;
       case "responseStart":
-        NetMonitorView.RequestsMenu.updateRequest(aPacket.from, {
-          httpVersion: aPacket.response.httpVersion,
-          remoteAddress: aPacket.response.remoteAddress,
-          remotePort: aPacket.response.remotePort,
-          status: aPacket.response.status,
-          statusText: aPacket.response.statusText,
-          headersSize: aPacket.response.headersSize
+        NetMonitorView.RequestsMenu.updateRequest(actor, {
+          httpVersion: networkInfo.response.httpVersion,
+          remoteAddress: networkInfo.response.remoteAddress,
+          remotePort: networkInfo.response.remotePort,
+          status: networkInfo.response.status,
+          statusText: networkInfo.response.statusText,
+          headersSize: networkInfo.response.headersSize
         });
         window.emit(EVENTS.STARTED_RECEIVING_RESPONSE, actor);
         break;
       case "responseContent":
-        NetMonitorView.RequestsMenu.updateRequest(aPacket.from, {
-          contentSize: aPacket.contentSize,
-          transferredSize: aPacket.transferredSize,
-          mimeType: aPacket.mimeType
+        NetMonitorView.RequestsMenu.updateRequest(actor, {
+          contentSize: networkInfo.response.bodySize,
+          transferredSize: networkInfo.response.transferredSize,
+          mimeType: networkInfo.response.content.mimeType
         });
         this.webConsoleClient.getResponseContent(actor, this._onResponseContent);
         window.emit(EVENTS.UPDATING_RESPONSE_CONTENT, actor);
         break;
       case "eventTimings":
-        NetMonitorView.RequestsMenu.updateRequest(aPacket.from, {
-          totalTime: aPacket.totalTime
+        NetMonitorView.RequestsMenu.updateRequest(actor, {
+          totalTime: networkInfo.totalTime
         });
         this.webConsoleClient.getEventTimings(actor, this._onEventTimings);
         window.emit(EVENTS.UPDATING_EVENT_TIMINGS, actor);
         break;
     }
   },
 
   /**
--- a/toolkit/devtools/webconsole/client.js
+++ b/toolkit/devtools/webconsole/client.js
@@ -100,16 +100,17 @@ WebConsoleClient.prototype = {
           url: actor.url,
           method: actor.method,
         },
         isXHR: actor.isXHR,
         response: {},
         timings: {},
         updates: [], // track the list of network event updates
         private: actor.private,
+        fromCache: actor.fromCache
       };
       this._networkRequests.set(actor.actor, networkInfo);
 
       this.emit("networkEvent", networkInfo);
     }
   },
 
   /**
@@ -139,28 +140,34 @@ WebConsoleClient.prototype = {
         networkInfo.discardRequestBody = packet.discardRequestBody;
         networkInfo.request.bodySize = packet.dataSize;
         break;
       case "responseStart":
         networkInfo.response.httpVersion = packet.response.httpVersion;
         networkInfo.response.status = packet.response.status;
         networkInfo.response.statusText = packet.response.statusText;
         networkInfo.response.headersSize = packet.response.headersSize;
+        networkInfo.response.remoteAddress = packet.response.remoteAddress;
+        networkInfo.response.remotePort = packet.response.remotePort;
         networkInfo.discardResponseBody = packet.response.discardResponseBody;
         break;
       case "responseContent":
         networkInfo.response.content = {
           mimeType: packet.mimeType,
         };
         networkInfo.response.bodySize = packet.contentSize;
+        networkInfo.response.transferredSize = packet.transferredSize;
         networkInfo.discardResponseBody = packet.discardResponseBody;
         break;
       case "eventTimings":
         networkInfo.totalTime = packet.totalTime;
         break;
+      case "securityInfo":
+        networkInfo.securityInfo = packet.state;
+        break;
     }
 
     this.emit("networkEventUpdate", {
       packet: packet,
       networkInfo
     });
   },