Bug 1299344 - Fix exceptions when accessing DOMWindow and contentCharset when reload page against the netmonitor. r=Honza
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 13 Aug 2018 12:37:41 +0000
changeset 486298 e906e53dd6ba1b75a2b6ab6913776cb931810a70
parent 486297 a28c7f13b6a6f5d1471cb98de79a59316cd25475
child 486299 b7941dfa029aa597b9a1e165bceb10c418f00c7b
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1299344
milestone63.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 1299344 - Fix exceptions when accessing DOMWindow and contentCharset when reload page against the netmonitor. r=Honza Differential Revision: https://phabricator.services.mozilla.com/D3020
devtools/server/actors/targets/browsing-context.js
devtools/shared/webconsole/network-monitor.js
--- a/devtools/server/actors/targets/browsing-context.js
+++ b/devtools/server/actors/targets/browsing-context.js
@@ -1602,26 +1602,29 @@ DebuggerProgressListener.prototype = {
     }
   }, "DebuggerProgressListener.prototype.observe"),
 
   onStateChange:
   DevToolsUtils.makeInfallible(function(progress, request, flag, status) {
     if (!this._targetActor.attached) {
       return;
     }
+    progress.QueryInterface(Ci.nsIDocShell);
+    if (progress.isBeingDestroyed()) {
+      return;
+    }
 
     const isStart = flag & Ci.nsIWebProgressListener.STATE_START;
     const isStop = flag & Ci.nsIWebProgressListener.STATE_STOP;
     const isDocument = flag & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT;
     const isWindow = flag & Ci.nsIWebProgressListener.STATE_IS_WINDOW;
 
     // Catch any iframe location change
     if (isDocument && isStop) {
       // Watch document stop to ensure having the new iframe url.
-      progress.QueryInterface(Ci.nsIDocShell);
       this._targetActor._notifyDocShellsUpdate([progress]);
     }
 
     const window = progress.DOMWindow;
     if (isDocument && isStart) {
       // One of the earliest events that tells us a new URI
       // is being loaded in this window.
       const newURI = request instanceof Ci.nsIChannel ? request.URI.spec : null;
--- a/devtools/shared/webconsole/network-monitor.js
+++ b/devtools/shared/webconsole/network-monitor.js
@@ -475,17 +475,26 @@ NetworkResponseListener.prototype = {
     try {
       if (channel instanceof Ci.nsICacheInfoChannel) {
         isOptimizedContent = channel.alternativeDataType;
       }
     } catch (e) {
       // Accessing `alternativeDataType` for some SW requests throws.
     }
     if (isOptimizedContent) {
-      const charset = this.request.contentCharset || this.httpActivity.charset;
+      let charset;
+      try {
+        charset = this.request.contentCharset;
+      } catch (e) {
+        // Accessing the charset sometimes throws NS_ERROR_NOT_AVAILABLE when
+        // reloading the page
+      }
+      if (!charset) {
+        charset = 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
@@ -631,17 +640,26 @@ NetworkResponseListener.prototype = {
       this._fetchCacheInformation();
     }
 
     if (!this.httpActivity.discardResponseBody && this.receivedData.length) {
       this._onComplete(this.receivedData);
     } else if (!this.httpActivity.discardResponseBody &&
                this.httpActivity.responseStatus == 304) {
       // Response is cached, so we load it from cache.
-      const charset = this.request.contentCharset || this.httpActivity.charset;
+      let charset;
+      try {
+        charset = this.request.contentCharset;
+      } catch (e) {
+        // Accessing the charset sometimes throws NS_ERROR_NOT_AVAILABLE when
+        // reloading the page
+      }
+      if (!charset) {
+        charset = this.httpActivity.charset;
+      }
       NetworkHelper.loadFromCache(this.httpActivity.url, charset,
                                   this._onComplete.bind(this));
     } else {
       this._onComplete();
     }
   },
 
   /**