Bug 1247641 - When loading a background thumbnail, load about:blank asynchronously when a load fails to avoid endless redirects. r=markh
authorDrew Willcoxon <adw@mozilla.com>
Tue, 16 Feb 2016 16:34:25 -0800
changeset 284533 bf152107a11d801dec09449aa24140bd4d9f518e
parent 284532 e0197b0616f937b19d5ba740cb221cde454e03fa
child 284534 4b710f2e4e64c30525d667492d6de6e499d3213b
push id71993
push usercbook@mozilla.com
push dateWed, 17 Feb 2016 11:16:29 +0000
treeherdermozilla-inbound@60f020c84b23 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1247641
milestone47.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 1247641 - When loading a background thumbnail, load about:blank asynchronously when a load fails to avoid endless redirects. r=markh
toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
--- a/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
+++ b/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
@@ -103,30 +103,39 @@ const backgroundPageThumbsContent = {
       if (req.name == "about:blank") {
         if (this._state == STATE_CAPTURING) {
           // about:blank has loaded, ending the current capture.
           this._finishCurrentCapture();
           delete this._currentCapture;
           this._startNextCapture();
         }
         else if (this._state == STATE_CANCELED) {
-          // A capture request was received while the current capture's page
-          // was still loading.
           delete this._currentCapture;
           this._startNextCapture();
         }
       }
       else if (this._state == STATE_LOADING &&
                Components.isSuccessCode(status)) {
         // The requested page has loaded.  Capture it.
         this._state = STATE_CAPTURING;
         this._captureCurrentPage();
-      } else {
+      }
+      else if (this._state != STATE_CANCELED) {
+        // Something went wrong.  Cancel the capture.  Loading about:blank
+        // while onStateChange is still on the stack does not actually stop
+        // the request if it redirects, so do it asyncly.
         this._state = STATE_CANCELED;
-        this._loadAboutBlank();
+        if (!this._cancelTimer) {
+          this._cancelTimer =
+            Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+          this._cancelTimer.init(() => {
+            this._loadAboutBlank();
+            delete this._cancelTimer;
+          }, 0, Ci.nsITimer.TYPE_ONE_SHOT);
+        }
       }
     }
   },
 
   _captureCurrentPage: function () {
     let capture = this._currentCapture;
     capture.finalURL = this._webNav.currentURI.spec;
     capture.pageLoadTime = new Date() - capture.pageLoadStartDate;