Bug 1372115 - Prevent exception in network monitor when JS file is loaded throught the bytecode cache. r=Honza draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 15 Nov 2017 06:12:09 -0800
changeset 701134 a8885c780eae50a7957ed8bf7aebc856920e9b1d
parent 700338 dd08f8b19cc32da161811abb2f7093e0f5392e69
child 701138 03e09e71ce0ca9e9aae2bd6c4dd7957404285ad7
push id90080
push userbmo:poirot.alex@gmail.com
push dateTue, 21 Nov 2017 08:48:02 +0000
reviewersHonza
bugs1372115
milestone59.0a1
Bug 1372115 - Prevent exception in network monitor when JS file is loaded throught the bytecode cache. r=Honza 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*/);