Bug 1372115 - Prevent exception in network monitor when JS file is loaded throught the bytecode cache. r=Honza, a=jcristau
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 15 Nov 2017 06:12:09 -0800
changeset 445429 64d69f61379046ae2f57c15b8bedae5be09720e1
parent 445428 323b7fc81663971d8b1491f50263e997eb2cbf3b
child 445430 9e7435aeb7bd1cb9825c092db7f7eb938def0945
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza, jcristau
bugs1372115
milestone58.0
Bug 1372115 - Prevent exception in network monitor when JS file is loaded throught the bytecode cache. r=Honza, a=jcristau MozReview-Commit-ID: 5w6Bj9213ba
devtools/shared/webconsole/network-monitor.js
--- a/devtools/shared/webconsole/network-monitor.js
+++ b/devtools/shared/webconsole/network-monitor.js
@@ -434,23 +434,44 @@ NetworkResponseListener.prototype = {
 
     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 converter.
     this.offset = 0;
 
+    let channel = this.request;
+
+    // Bug 1372115 - We should load bytecode cached requests from cache as the actual
+    // channel content is going to be optimized data that reflects platform internals
+    // instead of the content user expects (i.e. content served by HTTP server)
+    // Note that bytecode cached is one example, there may be wasm or other usecase in
+    // future.
+    let isOptimizedContent = false;
+    try {
+      if (channel instanceof Ci.nsICacheInfoChannel) {
+        isOptimizedContent = channel.alternativeDataType;
+      }
+    } catch (e) {
+      // Accessing `alternativeDataType` for some SW requests throws.
+    }
+    if (isOptimizedContent) {
+      let charset = this.request.contentCharset || this.httpActivity.charset;
+      NetworkHelper.loadFromCache(this.httpActivity.url, charset,
+                                  this._onComplete.bind(this));
+      return;
+    }
+
     // 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;
     if (!this.httpActivity.fromServiceWorker &&
         channel instanceof Ci.nsIEncodedChannel &&
         channel.contentEncodings &&
         !channel.applyConversion) {
       let encodingHeader = channel.getResponseHeader("Content-Encoding");
       let scs = Cc["@mozilla.org/streamConverters;1"]
         .getService(Ci.nsIStreamConverterService);
       let encodings = encodingHeader.split(/\s*\t*,\s*\t*/);